_font cache processtext entry
This commit is contained in:
@@ -129,6 +129,7 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
|||||||
FontLineCache tmpLine;
|
FontLineCache tmpLine;
|
||||||
FontCharacterEntry entry;
|
FontCharacterEntry entry;
|
||||||
FontCharacterEntry previous;
|
FontCharacterEntry previous;
|
||||||
|
Array<FontCharacterEntry> CharacterEntries(textLength);
|
||||||
float scale = layout.Scale / FontManager::FontScale;
|
float scale = layout.Scale / FontManager::FontScale;
|
||||||
float boundsWidth = layout.Bounds.GetWidth();
|
float boundsWidth = layout.Bounds.GetWidth();
|
||||||
float baseLinesDistance = static_cast<float>(_height) * layout.BaseLinesGapScale * scale;
|
float baseLinesDistance = static_cast<float>(_height) * layout.BaseLinesGapScale * scale;
|
||||||
@@ -233,6 +234,7 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CharacterEntries.Add(entry);
|
||||||
|
|
||||||
// Check if move to another line
|
// Check if move to another line
|
||||||
if (moveLine)
|
if (moveLine)
|
||||||
@@ -242,6 +244,8 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
|||||||
tmpLine.Size.Y = baseLinesDistance;
|
tmpLine.Size.Y = baseLinesDistance;
|
||||||
tmpLine.LastCharIndex = Math::Max(tmpLine.LastCharIndex, tmpLine.FirstCharIndex);
|
tmpLine.LastCharIndex = Math::Max(tmpLine.LastCharIndex, tmpLine.FirstCharIndex);
|
||||||
outputLines.Add(tmpLine);
|
outputLines.Add(tmpLine);
|
||||||
|
outputLines.Last().CharacterEntries.Set(CharacterEntries.Get(), CharacterEntries.Count());
|
||||||
|
CharacterEntries.Clear();
|
||||||
|
|
||||||
// Reset line
|
// Reset line
|
||||||
tmpLine.Location.Y += baseLinesDistance;
|
tmpLine.Location.Y += baseLinesDistance;
|
||||||
@@ -265,6 +269,8 @@ void Font::ProcessText(const StringView& text, Array<FontLineCache>& outputLines
|
|||||||
tmpLine.Size.Y = baseLinesDistance;
|
tmpLine.Size.Y = baseLinesDistance;
|
||||||
tmpLine.LastCharIndex = textLength - 1;
|
tmpLine.LastCharIndex = textLength - 1;
|
||||||
outputLines.Add(tmpLine);
|
outputLines.Add(tmpLine);
|
||||||
|
outputLines.Last().CharacterEntries.Set(CharacterEntries.Get(), CharacterEntries.Count());
|
||||||
|
CharacterEntries.Clear();
|
||||||
|
|
||||||
tmpLine.Location.Y += baseLinesDistance;
|
tmpLine.Location.Y += baseLinesDistance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,46 @@ API_STRUCT(NoDefault) struct FLAXENGINE_API FontLineCache
|
|||||||
{
|
{
|
||||||
DECLARE_SCRIPTING_TYPE_MINIMAL(FontLineCache);
|
DECLARE_SCRIPTING_TYPE_MINIMAL(FontLineCache);
|
||||||
|
|
||||||
|
FontLineCache() = default;
|
||||||
|
|
||||||
|
FontLineCache(const FontLineCache& other)
|
||||||
|
{
|
||||||
|
Location = other.Location;
|
||||||
|
Size = other.Size;
|
||||||
|
FirstCharIndex = other.FirstCharIndex;
|
||||||
|
LastCharIndex = other.LastCharIndex;
|
||||||
|
CharacterEntries.Set(other.CharacterEntries.Get(), other.CharacterEntries.Count());
|
||||||
|
}
|
||||||
|
|
||||||
|
FontLineCache(FontLineCache&& other) noexcept
|
||||||
|
{
|
||||||
|
Location = other.Location;
|
||||||
|
Size = other.Size;
|
||||||
|
FirstCharIndex = other.FirstCharIndex;
|
||||||
|
LastCharIndex = other.LastCharIndex;
|
||||||
|
CharacterEntries = MoveTemp(other.CharacterEntries);
|
||||||
|
}
|
||||||
|
|
||||||
|
FontLineCache& operator=(const FontLineCache& other)
|
||||||
|
{
|
||||||
|
Location = other.Location;
|
||||||
|
Size = other.Size;
|
||||||
|
FirstCharIndex = other.FirstCharIndex;
|
||||||
|
LastCharIndex = other.LastCharIndex;
|
||||||
|
CharacterEntries.Set(other.CharacterEntries.Get(), other.CharacterEntries.Count());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FontLineCache& operator=(FontLineCache&& other) noexcept
|
||||||
|
{
|
||||||
|
Location = other.Location;
|
||||||
|
Size = other.Size;
|
||||||
|
FirstCharIndex = other.FirstCharIndex;
|
||||||
|
LastCharIndex = other.LastCharIndex;
|
||||||
|
CharacterEntries = MoveTemp(other.CharacterEntries);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The root position of the line (upper left corner).
|
/// The root position of the line (upper left corner).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -111,12 +151,17 @@ API_STRUCT(NoDefault) struct FLAXENGINE_API FontLineCache
|
|||||||
/// The last character index (from the input text), inclusive.
|
/// The last character index (from the input text), inclusive.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD() int32 LastCharIndex;
|
API_FIELD() int32 LastCharIndex;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Character entries for each character.
|
||||||
|
/// </summary>
|
||||||
|
API_FIELD() Array<struct FontCharacterEntry> CharacterEntries;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct TIsPODType<FontLineCache>
|
struct TIsPODType<FontLineCache>
|
||||||
{
|
{
|
||||||
enum { Value = true };
|
enum { Value = false };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Font glyph metrics:
|
// Font glyph metrics:
|
||||||
|
|||||||
@@ -1281,7 +1281,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
font->ProcessText(text, Lines, layout);
|
font->ProcessText(text, Lines, layout);
|
||||||
|
|
||||||
// Render all lines
|
// Render all lines
|
||||||
FontCharacterEntry entry;
|
//FontCharacterEntry entry;
|
||||||
Render2DDrawCall drawCall;
|
Render2DDrawCall drawCall;
|
||||||
if (customMaterial)
|
if (customMaterial)
|
||||||
{
|
{
|
||||||
@@ -1299,6 +1299,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
Float2 pointer = line.Location;
|
Float2 pointer = line.Location;
|
||||||
|
|
||||||
// Render all characters from the line
|
// Render all characters from the line
|
||||||
|
int32 entryIndex = 0;
|
||||||
for (int32 charIndex = line.FirstCharIndex; charIndex <= line.LastCharIndex; charIndex++)
|
for (int32 charIndex = line.FirstCharIndex; charIndex <= line.LastCharIndex; charIndex++)
|
||||||
{
|
{
|
||||||
// Cache current character
|
// Cache current character
|
||||||
@@ -1308,7 +1309,8 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
if (currentChar != '\n')
|
if (currentChar != '\n')
|
||||||
{
|
{
|
||||||
// Get character entry
|
// Get character entry
|
||||||
font->GetCharacter(currentChar, entry, enableFallbackFonts);
|
//font->GetCharacter(currentChar, entry, enableFallbackFonts);
|
||||||
|
const FontCharacterEntry& entry = line.CharacterEntries[entryIndex];
|
||||||
|
|
||||||
// Check if need to select/change font atlas (since characters even in the same font may be located in different atlases)
|
// 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)
|
if (fontAtlas == nullptr || entry.TextureIndex != fontAtlasIndex)
|
||||||
@@ -1365,6 +1367,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color,
|
|||||||
// Move
|
// Move
|
||||||
pointer.X += entry.AdvanceX * scale;
|
pointer.X += entry.AdvanceX * scale;
|
||||||
}
|
}
|
||||||
|
entryIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user