diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index c27accb97..5ff3238ca 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -129,6 +129,7 @@ void Font::ProcessText(const StringView& text, Array& outputLines FontLineCache tmpLine; FontCharacterEntry entry; FontCharacterEntry previous; + Array CharacterEntries(textLength); float scale = layout.Scale / FontManager::FontScale; float boundsWidth = layout.Bounds.GetWidth(); float baseLinesDistance = static_cast(_height) * layout.BaseLinesGapScale * scale; @@ -233,6 +234,7 @@ void Font::ProcessText(const StringView& text, Array& outputLines break; } } + CharacterEntries.Add(entry); // Check if move to another line if (moveLine) @@ -242,6 +244,8 @@ void Font::ProcessText(const StringView& text, Array& outputLines tmpLine.Size.Y = baseLinesDistance; tmpLine.LastCharIndex = Math::Max(tmpLine.LastCharIndex, tmpLine.FirstCharIndex); outputLines.Add(tmpLine); + outputLines.Last().CharacterEntries.Set(CharacterEntries.Get(), CharacterEntries.Count()); + CharacterEntries.Clear(); // Reset line tmpLine.Location.Y += baseLinesDistance; @@ -265,6 +269,8 @@ void Font::ProcessText(const StringView& text, Array& outputLines tmpLine.Size.Y = baseLinesDistance; tmpLine.LastCharIndex = textLength - 1; outputLines.Add(tmpLine); + outputLines.Last().CharacterEntries.Set(CharacterEntries.Get(), CharacterEntries.Count()); + CharacterEntries.Clear(); tmpLine.Location.Y += baseLinesDistance; } diff --git a/Source/Engine/Render2D/Font.h b/Source/Engine/Render2D/Font.h index 187d5b24a..6783afc94 100644 --- a/Source/Engine/Render2D/Font.h +++ b/Source/Engine/Render2D/Font.h @@ -92,6 +92,46 @@ API_STRUCT(NoDefault) struct FLAXENGINE_API 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; + } + /// /// The root position of the line (upper left corner). /// @@ -111,12 +151,17 @@ API_STRUCT(NoDefault) struct FLAXENGINE_API FontLineCache /// The last character index (from the input text), inclusive. /// API_FIELD() int32 LastCharIndex; + + /// + /// Character entries for each character. + /// + API_FIELD() Array CharacterEntries; }; template<> struct TIsPODType { - enum { Value = true }; + enum { Value = false }; }; // Font glyph metrics: diff --git a/Source/Engine/Render2D/Render2D.cpp b/Source/Engine/Render2D/Render2D.cpp index 31136b455..91a30b2cd 100644 --- a/Source/Engine/Render2D/Render2D.cpp +++ b/Source/Engine/Render2D/Render2D.cpp @@ -1281,7 +1281,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, font->ProcessText(text, Lines, layout); // Render all lines - FontCharacterEntry entry; + //FontCharacterEntry entry; Render2DDrawCall drawCall; if (customMaterial) { @@ -1299,6 +1299,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, Float2 pointer = line.Location; // Render all characters from the line + int32 entryIndex = 0; for (int32 charIndex = line.FirstCharIndex; charIndex <= line.LastCharIndex; charIndex++) { // Cache current character @@ -1308,7 +1309,8 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, if (currentChar != '\n') { // 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) if (fontAtlas == nullptr || entry.TextureIndex != fontAtlasIndex) @@ -1365,6 +1367,7 @@ void Render2D::DrawText(Font* font, const StringView& text, const Color& color, // Move pointer.X += entry.AdvanceX * scale; } + entryIndex++; } } }