_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);
|
_descender = Convert26Dot6ToRoundedPixel<int16>(face->size->metrics.descender);
|
||||||
_lineGap = _height - _ascender + _descender;
|
_lineGap = _height - _ascender + _descender;
|
||||||
#if USE_ARRAY_CHARACTER_STORAGE
|
#if USE_ARRAY_CHARACTER_STORAGE
|
||||||
_characters.SetCapacity(256);
|
_characters.SetCapacity(256, false);
|
||||||
_characters.Resize(256);
|
_characters.Resize(256, false);
|
||||||
for (int i = 0; i < _characters.Count(); i++)
|
Platform::MemoryClear(_characters.Get(), _characters.Count() * sizeof(FontCharacterEntry*));
|
||||||
_characters[i].IsValid = false;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,17 +58,18 @@ void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback)
|
|||||||
int newSize = Math::Min(c + 64, 65536);
|
int newSize = Math::Min(c + 64, 65536);
|
||||||
_characters.SetCapacity(newSize);
|
_characters.SetCapacity(newSize);
|
||||||
_characters.Resize(newSize);
|
_characters.Resize(newSize);
|
||||||
for (int i = oldSize; i < newSize; i++)
|
Platform::MemoryClear(&_characters.Get()[oldSize], (newSize - oldSize) * sizeof(FontCharacterEntry*));
|
||||||
_characters[i].IsValid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = _characters[c];
|
FontCharacterEntry* entry = _characters[c];
|
||||||
if (!result.IsValid)
|
if (entry == nullptr)
|
||||||
{
|
{
|
||||||
// Create character cache
|
// Create character cache
|
||||||
FontManager::AddNewEntry(this, c, _characters[c]);
|
entry = New<FontCharacterEntry>();
|
||||||
result = _characters[c];
|
FontManager::AddNewEntry(this, c, *entry);
|
||||||
|
_characters[c] = entry;
|
||||||
}
|
}
|
||||||
|
result = *entry;
|
||||||
#else
|
#else
|
||||||
// Try to get the character or cache it if cannot be found
|
// Try to get the character or cache it if cannot be found
|
||||||
if (!_characters.TryGet(c, result))
|
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
|
int32 Font::GetKerning(Char first, Char second) const
|
||||||
{
|
{
|
||||||
|
if (!_hasKerning)
|
||||||
|
return 0;
|
||||||
|
|
||||||
int32 kerning = 0;
|
int32 kerning = 0;
|
||||||
const uint32 key = (uint32)first << 16 | second;
|
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)
|
// 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);
|
ScopeLock lock(_asset->Locker);
|
||||||
@@ -151,7 +154,8 @@ void Font::Invalidate()
|
|||||||
#if USE_ARRAY_CHARACTER_STORAGE
|
#if USE_ARRAY_CHARACTER_STORAGE
|
||||||
for (int32 i = 0; i < _characters.Count(); i++)
|
for (int32 i = 0; i < _characters.Count(); i++)
|
||||||
{
|
{
|
||||||
FontManager::Invalidate(_characters[i]);
|
FontManager::Invalidate(*_characters[i]);
|
||||||
|
Delete(_characters[i]);
|
||||||
}
|
}
|
||||||
_characters.Clear();
|
_characters.Clear();
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ private:
|
|||||||
int32 _lineGap;
|
int32 _lineGap;
|
||||||
bool _hasKerning;
|
bool _hasKerning;
|
||||||
#if USE_ARRAY_CHARACTER_STORAGE
|
#if USE_ARRAY_CHARACTER_STORAGE
|
||||||
Array<FontCharacterEntry> _characters;
|
Array<FontCharacterEntry*> _characters;
|
||||||
#else
|
#else
|
||||||
Dictionary<Char, FontCharacterEntry> _characters;
|
Dictionary<Char, FontCharacterEntry> _characters;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user