| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Text/BsFont.h"
- #include "Private/RTTI/BsFontRTTI.h"
- #include "Text/BsFontManager.h"
- #include "Resources/BsResources.h"
- namespace bs
- {
- const CharDesc& FontBitmap::getCharDesc(UINT32 charId) const
- {
- auto iterFind = characters.find(charId);
- if(iterFind != characters.end())
- {
- return characters.at(charId);
- }
- return missingGlyph;
- }
- RTTITypeBase* FontBitmap::getRTTIStatic()
- {
- return FontBitmapRTTI::instance();
- }
- RTTITypeBase* FontBitmap::getRTTI() const
- {
- return FontBitmap::getRTTIStatic();
- }
- Font::Font()
- :Resource(false)
- { }
- Font::~Font()
- { }
- void Font::initialize(const Vector<SPtr<FontBitmap>>& fontData)
- {
- for(auto iter = fontData.begin(); iter != fontData.end(); ++iter)
- mFontDataPerSize[(*iter)->size] = *iter;
- Resource::initialize();
- }
- SPtr<FontBitmap> Font::getBitmap(UINT32 size) const
- {
- auto iterFind = mFontDataPerSize.find(size);
- if(iterFind == mFontDataPerSize.end())
- return nullptr;
- return iterFind->second;
- }
- INT32 Font::getClosestSize(UINT32 size) const
- {
- UINT32 minDiff = std::numeric_limits<UINT32>::max();
- UINT32 bestSize = size;
- for(auto iter = mFontDataPerSize.begin(); iter != mFontDataPerSize.end(); ++iter)
- {
- if(iter->first == size)
- return size;
- else if(iter->first > size)
- {
- UINT32 diff = iter->first - size;
- if(diff < minDiff)
- {
- minDiff = diff;
- bestSize = iter->first;
- }
- }
- else
- {
- UINT32 diff = size - iter->first;
- if(diff < minDiff)
- {
- minDiff = diff;
- bestSize = iter->first;
- }
- }
- }
- return bestSize;
- }
- void Font::getResourceDependencies(FrameVector<HResource>& dependencies) const
- {
- for (auto& fontDataEntry : mFontDataPerSize)
- {
- for (auto& texture : fontDataEntry.second->texturePages)
- {
- if (texture != nullptr)
- dependencies.push_back(texture);
- }
- }
- }
- void Font::getCoreDependencies(Vector<CoreObject*>& dependencies)
- {
- for (auto& fontDataEntry : mFontDataPerSize)
- {
- for (auto& texture : fontDataEntry.second->texturePages)
- {
- if (texture.isLoaded())
- dependencies.push_back(texture.get());
- }
- }
- }
- HFont Font::create(const Vector<SPtr<FontBitmap>>& fontData)
- {
- SPtr<Font> newFont = _createPtr(fontData);
- return static_resource_cast<Font>(gResources()._createResourceHandle(newFont));
- }
- SPtr<Font> Font::_createPtr(const Vector<SPtr<FontBitmap>>& fontData)
- {
- return FontManager::instance().create(fontData);
- }
- RTTITypeBase* Font::getRTTIStatic()
- {
- return FontRTTI::instance();
- }
- RTTITypeBase* Font::getRTTI() const
- {
- return Font::getRTTIStatic();
- }
- }
|