| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #include "BsFont.h"
- #include "BsFontRTTI.h"
- #include "BsFontManager.h"
- #include "BsResources.h"
- namespace BansheeEngine
- {
- const CHAR_DESC& FontData::getCharDesc(UINT32 charId) const
- {
- auto iterFind = fontDesc.characters.find(charId);
- if(iterFind != fontDesc.characters.end())
- {
- return fontDesc.characters.at(charId);
- }
- return fontDesc.missingGlyph;
- }
- RTTITypeBase* FontData::getRTTIStatic()
- {
- return FontDataRTTI::instance();
- }
- RTTITypeBase* FontData::getRTTI() const
- {
- return FontData::getRTTIStatic();
- }
- Font::Font()
- :Resource(false)
- { }
- Font::~Font()
- { }
- void Font::initialize(const Vector<FontData>& fontData)
- {
- for(auto iter = fontData.begin(); iter != fontData.end(); ++iter)
- mFontDataPerSize[iter->size] = *iter;
- Resource::initialize();
- }
- const FontData* Font::getFontDataForSize(UINT32 size) const
- {
- auto iterFind = mFontDataPerSize.find(size);
- if(iterFind == mFontDataPerSize.end())
- return nullptr;
- return &iterFind->second;
- }
- INT32 Font::getClosestAvailableSize(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::getCoreDependencies(Vector<SPtr<CoreObject>>& dependencies)
- {
- for (auto& fontDataEntry : mFontDataPerSize)
- {
- for (auto& texture : fontDataEntry.second.texturePages)
- {
- if (texture.isLoaded())
- dependencies.push_back(texture.getInternalPtr());
- }
- }
- }
- HFont Font::create(const Vector<FontData>& fontData)
- {
- FontPtr newFont = _createPtr(fontData);
- return static_resource_cast<Font>(gResources()._createResourceHandle(newFont));
- }
- FontPtr Font::_createPtr(const Vector<FontData>& fontData)
- {
- return FontManager::instance().create(fontData);
- }
- RTTITypeBase* Font::getRTTIStatic()
- {
- return FontRTTI::instance();
- }
- RTTITypeBase* Font::getRTTI() const
- {
- return Font::getRTTIStatic();
- }
- }
|