_font small opt
This commit is contained in:
@@ -163,19 +163,18 @@ void Font::Invalidate()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines, const TextLayoutOptions& layout, Array<FontCharacterEntry>& characterEntries, Array<float>& characterKernings)
|
||||
void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines, const TextLayoutOptions& layout, Array<FontCharacterEntry>& characterEntries, Array<int32>& characterKernings)
|
||||
{
|
||||
int32 textLength = text.Length();
|
||||
if (textLength == 0)
|
||||
return;
|
||||
float cursorX = 0;
|
||||
int32 cursorX = 0;
|
||||
int32 kerning;
|
||||
FontLineCache tmpLine;
|
||||
FontCharacterEntry entry;
|
||||
FontCharacterEntry previous;
|
||||
Array<FontCharacterEntry> CharacterEntries(textLength);
|
||||
Char previous = 0;
|
||||
float scale = layout.Scale / FontManager::FontScale;
|
||||
float boundsWidth = layout.Bounds.GetWidth();
|
||||
int32 boundsWidth = layout.Bounds.GetWidth() / scale;
|
||||
float baseLinesDistance = static_cast<float>(_height) * layout.BaseLinesGapScale * scale;
|
||||
tmpLine.Location = Float2::Zero;
|
||||
tmpLine.Size = Float2::Zero;
|
||||
@@ -183,22 +182,22 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
||||
tmpLine.LastCharIndex = -1;
|
||||
|
||||
int32 lastWrapCharIndex = INVALID_INDEX;
|
||||
float lastWrapCharX = 0;
|
||||
int32 lastWrapCharX = 0;
|
||||
bool lastMoveLine = false;
|
||||
|
||||
// Process each character to split text into single lines
|
||||
for (int32 currentIndex = 0; currentIndex < textLength;)
|
||||
{
|
||||
bool moveLine = false;
|
||||
float xAdvance = 0;
|
||||
int32 xAdvance = 0;
|
||||
int32 nextCharIndex = currentIndex + 1;
|
||||
|
||||
// Cache current character
|
||||
const Char currentChar = text[currentIndex];
|
||||
const bool isWhitespace = StringUtils::IsWhitespace(currentChar);
|
||||
|
||||
const bool isWrapChar = isWhitespace || StringUtils::IsUpper(currentChar) || !StringUtils::IsAlnum(currentChar);
|
||||
|
||||
// Check if character can wrap words
|
||||
const bool isWrapChar = !StringUtils::IsAlnum(currentChar) || isWhitespace || StringUtils::IsUpper(currentChar);
|
||||
if (isWrapChar && currentIndex != 0)
|
||||
{
|
||||
lastWrapCharIndex = currentIndex;
|
||||
@@ -219,16 +218,16 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
||||
GetCharacter(currentChar, entry);
|
||||
|
||||
// Get kerning
|
||||
if (!isWhitespace && previous.IsValid)
|
||||
if (!isWhitespace && previous != 0)
|
||||
{
|
||||
kerning = entry.Font->GetKerning(previous.Character, entry.Character);
|
||||
kerning = GetKerning(previous, entry.Character);
|
||||
}
|
||||
else
|
||||
{
|
||||
kerning = 0;
|
||||
}
|
||||
previous = entry;
|
||||
xAdvance = (kerning + entry.AdvanceX) * scale;
|
||||
previous = currentChar;
|
||||
xAdvance = (kerning + entry.AdvanceX);
|
||||
|
||||
// Check if character fits the line or skip wrapping
|
||||
if (cursorX + xAdvance <= boundsWidth || layout.TextWrapping == TextWrapping::NoWrap)
|
||||
@@ -279,15 +278,14 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
||||
}
|
||||
|
||||
characterEntries.Add(entry);
|
||||
characterKernings.Add((float)kerning * scale);
|
||||
characterKernings.Add(kerning);
|
||||
}
|
||||
|
||||
|
||||
// Check if move to another line
|
||||
if (moveLine)
|
||||
{
|
||||
// Add line
|
||||
tmpLine.Size.X = cursorX;
|
||||
tmpLine.Size.X = (float)cursorX * scale;
|
||||
tmpLine.Size.Y = baseLinesDistance;
|
||||
tmpLine.LastCharIndex = Math::Max(tmpLine.LastCharIndex, tmpLine.FirstCharIndex);
|
||||
outputLines.Add(tmpLine);
|
||||
@@ -299,7 +297,7 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
||||
cursorX = 0;
|
||||
lastWrapCharIndex = INVALID_INDEX;
|
||||
lastWrapCharX = 0;
|
||||
previous.IsValid = false;
|
||||
previous = 0;
|
||||
}
|
||||
|
||||
currentIndex = nextCharIndex;
|
||||
@@ -310,7 +308,7 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
||||
if (tmpLine.LastCharIndex >= tmpLine.FirstCharIndex || text[textLength - 1] == '\n')
|
||||
{
|
||||
// Add line
|
||||
tmpLine.Size.X = cursorX;
|
||||
tmpLine.Size.X = (float)cursorX * scale;
|
||||
tmpLine.Size.Y = baseLinesDistance;
|
||||
tmpLine.LastCharIndex = textLength;
|
||||
outputLines.Add(tmpLine);
|
||||
@@ -361,7 +359,7 @@ Float2 Font::MeasureText(const StringView& text, const TextLayoutOptions& layout
|
||||
// Process text
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
ProcessText(text, lines, layout, characterEntries, xAdvances);
|
||||
|
||||
// Calculate bounds
|
||||
@@ -384,7 +382,7 @@ int32 Font::HitTestText(const StringView& text, const Float2& location, const Te
|
||||
// Process text
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
ProcessText(text, lines, layout, characterEntries, xAdvances);
|
||||
ASSERT(lines.HasItems());
|
||||
float scale = layout.Scale / FontManager::FontScale;
|
||||
@@ -460,7 +458,7 @@ Float2 Font::GetCharPosition(const StringView& text, int32 index, const TextLayo
|
||||
// Process text
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
ProcessText(text, lines, layout, characterEntries, xAdvances);
|
||||
ASSERT(lines.HasItems());
|
||||
float scale = layout.Scale / FontManager::FontScale;
|
||||
|
||||
@@ -350,7 +350,7 @@ public:
|
||||
/// <param name="text">The input text.</param>
|
||||
/// <param name="layout">The layout properties.</param>
|
||||
/// <param name="outputLines">The output lines list.</param>
|
||||
void ProcessText(const StringView& text, Array<FontLineCache>& outputLines, API_PARAM(Ref) const TextLayoutOptions& layout, Array<FontCharacterEntry>& characterEntries, Array<float>& characterKernings);
|
||||
void ProcessText(const StringView& text, Array<FontLineCache>& outputLines, API_PARAM(Ref) const TextLayoutOptions& layout, Array<FontCharacterEntry>& characterEntries, Array<int32>& characterKernings);
|
||||
|
||||
/// <summary>
|
||||
/// Processes text to get cached lines for rendering.
|
||||
@@ -362,7 +362,7 @@ public:
|
||||
{
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
ProcessText(text, lines, layout, characterEntries, xAdvances);
|
||||
return lines;
|
||||
}
|
||||
@@ -378,7 +378,7 @@ public:
|
||||
{
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
ProcessText(textRange.Substring(text), lines, layout, characterEntries, xAdvances);
|
||||
return lines;
|
||||
}
|
||||
|
||||
@@ -1357,7 +1357,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
// Process text to get lines
|
||||
Lines.Clear();
|
||||
static Array<FontCharacterEntry> characterEntries(128);
|
||||
static Array<float> characterKernings(128);
|
||||
static Array<int32> characterKernings(128);
|
||||
|
||||
characterEntries.Clear();
|
||||
characterKernings.Clear();
|
||||
@@ -1409,7 +1409,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
||||
}
|
||||
pointer.X += (float)kerning * scale;*/
|
||||
|
||||
pointer.X += kerning;
|
||||
pointer.X += kerning * scale;
|
||||
previous = entry;
|
||||
|
||||
// Omit whitespace characters
|
||||
|
||||
@@ -159,7 +159,7 @@ void TextRender::UpdateLayout()
|
||||
// Perform layout
|
||||
Array<FontLineCache> lines;
|
||||
Array<FontCharacterEntry> characterEntries;
|
||||
Array<float> xAdvances;
|
||||
Array<int32> xAdvances;
|
||||
font->ProcessText(text, lines, _layoutOptions, characterEntries, xAdvances);
|
||||
|
||||
// Prepare buffers capacity
|
||||
|
||||
Reference in New Issue
Block a user