_font kerning cache
This commit is contained in:
@@ -1272,15 +1272,19 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
FontTextureAtlas* fontAtlas = nullptr;
|
||||
Float2 invAtlasSize = Float2::One;
|
||||
FontCharacterEntry previous;
|
||||
int32 kerning;
|
||||
//int32 kerning;
|
||||
float scale = layout.Scale / FontManager::FontScale;
|
||||
const bool enableFallbackFonts = EnumHasAllFlags(Features, RenderingFeatures::FallbackFonts);
|
||||
float fontHeightOffset = Math::Ceil((font->GetHeight() + font->GetDescender()) * scale);
|
||||
|
||||
// Process text to get lines
|
||||
Lines.Clear();
|
||||
static Array<FontCharacterEntry> characterEntries(128);
|
||||
static Array<float> characterKernings(128);
|
||||
|
||||
characterEntries.Clear();
|
||||
font->ProcessText(text, Lines, layout, characterEntries);
|
||||
characterKernings.Clear();
|
||||
font->ProcessText(text, Lines, layout, characterEntries, characterKernings);
|
||||
|
||||
// Render all lines
|
||||
//FontCharacterEntry entry;
|
||||
@@ -1313,6 +1317,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
// Get character entry
|
||||
//font->GetCharacter(currentChar, entry, enableFallbackFonts);
|
||||
const FontCharacterEntry& entry = characterEntries[entryIndex];
|
||||
float kerning = characterKernings[entryIndex];
|
||||
|
||||
// Check if need to select/change font atlas (since characters even in the same font may be located in different atlases)
|
||||
if (fontAtlas == nullptr || entry.TextureIndex != fontAtlasIndex)
|
||||
@@ -1335,7 +1340,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
|
||||
// Get kerning
|
||||
const bool isWhitespace = StringUtils::IsWhitespace(currentChar);
|
||||
if (!isWhitespace && previous.IsValid)
|
||||
/*if (!isWhitespace && previous.IsValid)
|
||||
{
|
||||
kerning = entry.Font->GetKerning(previous.Character, entry.Character);
|
||||
}
|
||||
@@ -1343,15 +1348,18 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
{
|
||||
kerning = 0;
|
||||
}
|
||||
pointer.X += (float)kerning * scale;
|
||||
pointer.X += (float)kerning * scale;*/
|
||||
|
||||
pointer.X += kerning;
|
||||
previous = entry;
|
||||
|
||||
// Omit whitespace characters
|
||||
if (!isWhitespace)
|
||||
//if (xAdvance != 0.0f)
|
||||
{
|
||||
// Calculate character size and atlas coordinates
|
||||
const float x = pointer.X + entry.OffsetX * scale;
|
||||
const float y = pointer.Y - entry.OffsetY * scale + Math::Ceil((font->GetHeight() + font->GetDescender()) * scale);
|
||||
const float y = pointer.Y - entry.OffsetY * scale + fontHeightOffset;
|
||||
|
||||
Rectangle charRect(x, y, entry.UVSize.X * scale, entry.UVSize.Y * scale);
|
||||
charRect.Offset(layout.Bounds.Location);
|
||||
|
||||
Reference in New Issue
Block a user