_font getchar opt2
This commit is contained in:
@@ -30,10 +30,9 @@ Font::Font(FontAsset* parentAsset, float size)
|
||||
_descender = Convert26Dot6ToRoundedPixel<int16>(face->size->metrics.descender);
|
||||
_lineGap = _height - _ascender + _descender;
|
||||
#if USE_ARRAY_CHARACTER_STORAGE
|
||||
_characters.SetCapacity(256);
|
||||
_characters.Resize(256);
|
||||
for (int i = 0; i < _characters.Count(); i++)
|
||||
_characters[i].IsValid = false;
|
||||
_characters.SetCapacity(256, false);
|
||||
_characters.Resize(256, false);
|
||||
Platform::MemoryClear(_characters.Get(), _characters.Count() * sizeof(FontCharacterEntry*));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -59,17 +58,18 @@ void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback)
|
||||
int newSize = Math::Min(c + 64, 65536);
|
||||
_characters.SetCapacity(newSize);
|
||||
_characters.Resize(newSize);
|
||||
for (int i = oldSize; i < newSize; i++)
|
||||
_characters[i].IsValid = false;
|
||||
Platform::MemoryClear(&_characters.Get()[oldSize], (newSize - oldSize) * sizeof(FontCharacterEntry*));
|
||||
}
|
||||
}
|
||||
result = _characters[c];
|
||||
if (!result.IsValid)
|
||||
FontCharacterEntry* entry = _characters[c];
|
||||
if (entry == nullptr)
|
||||
{
|
||||
// Create character cache
|
||||
FontManager::AddNewEntry(this, c, _characters[c]);
|
||||
result = _characters[c];
|
||||
entry = New<FontCharacterEntry>();
|
||||
FontManager::AddNewEntry(this, c, *entry);
|
||||
_characters[c] = entry;
|
||||
}
|
||||
result = *entry;
|
||||
#else
|
||||
// Try to get the character or cache it if cannot be found
|
||||
if (!_characters.TryGet(c, result))
|
||||
@@ -107,9 +107,12 @@ void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback)
|
||||
|
||||
int32 Font::GetKerning(Char first, Char second) const
|
||||
{
|
||||
if (!_hasKerning)
|
||||
return 0;
|
||||
|
||||
int32 kerning = 0;
|
||||
const uint32 key = (uint32)first << 16 | second;
|
||||
if (_hasKerning && !_kerningTable.TryGet(key, kerning))
|
||||
if (!_kerningTable.TryGet(key, kerning))
|
||||
{
|
||||
// This thread race condition may happen in editor but in game we usually do all stuff with fonts on main thread (chars caching)
|
||||
ScopeLock lock(_asset->Locker);
|
||||
@@ -151,7 +154,8 @@ void Font::Invalidate()
|
||||
#if USE_ARRAY_CHARACTER_STORAGE
|
||||
for (int32 i = 0; i < _characters.Count(); i++)
|
||||
{
|
||||
FontManager::Invalidate(_characters[i]);
|
||||
FontManager::Invalidate(*_characters[i]);
|
||||
Delete(_characters[i]);
|
||||
}
|
||||
_characters.Clear();
|
||||
#else
|
||||
|
||||
@@ -242,7 +242,7 @@ private:
|
||||
int32 _lineGap;
|
||||
bool _hasKerning;
|
||||
#if USE_ARRAY_CHARACTER_STORAGE
|
||||
Array<FontCharacterEntry> _characters;
|
||||
Array<FontCharacterEntry*> _characters;
|
||||
#else
|
||||
Dictionary<Char, FontCharacterEntry> _characters;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user