diff options
author | chai <chaifix@163.com> | 2021-10-31 14:27:26 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-31 14:27:26 +0800 |
commit | 601442f94fc0dcfdc5a117c5f87d90b156d53045 (patch) | |
tree | b006bcd6a28a965a900c64f4716007fcb45eee98 /Runtime/GUI/TextGenerator.cpp | |
parent | 26f05c6e3dcac9995345fb5a2b031be7e3ea79e9 (diff) |
+static initiator
Diffstat (limited to 'Runtime/GUI/TextGenerator.cpp')
-rw-r--r-- | Runtime/GUI/TextGenerator.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/Runtime/GUI/TextGenerator.cpp b/Runtime/GUI/TextGenerator.cpp index a518772..1b34d1b 100644 --- a/Runtime/GUI/TextGenerator.cpp +++ b/Runtime/GUI/TextGenerator.cpp @@ -38,7 +38,7 @@ character::Hash TextGenerator::GetHash(Codepoint codepoint, int pixelSize) return hash; } -Character TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelSize) +const Character* TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); auto iter = m_Characters.find(hash); @@ -48,14 +48,22 @@ Character TextGenerator::GetCharacter(character::Codepoint codepoint, int pixelS iter = m_Characters.find(hash); } Assert(iter != m_Characters.end()); - return iter->second; + return &iter->second; +} + +void TextGenerator::RenderCharacters(character::Codepoint* codepoint, int n, int pixelSize) +{ + for (int i = 0; i < n; ++i) + { + RenderCharacter(codepoint[i], pixelSize); + } } void TextGenerator::RenderCharacter(character::Codepoint codepoint, int pixelSize) { character::Hash hash = GetHash(codepoint, pixelSize); -// if (m_Characters.count(hash) != 0) -// return; + if (m_Characters.count(hash) != 0) + return; FT_Set_Pixel_Sizes(m_FTFace, 0, pixelSize); if (FT_Load_Char(m_FTFace, codepoint, FT_LOAD_RENDER)) { @@ -88,12 +96,12 @@ void TextGenerator::RenderCharacter(character::Codepoint codepoint, int pixelSiz character.atlas = atlas->index; character.position = rect; character.bearing = Internal::Vector2(m_FTFace->glyph->bitmap_left, m_FTFace->glyph->bitmap_top); - character.advance = m_FTFace->glyph->advance.x; + character.advance = m_FTFace->glyph->advance.x * 1/64.f; m_Characters.insert(std::pair<character::Hash, Character>(hash, character)); } -GlyphAtals* TextGenerator::GetGlyphAtlas(int index) +const GlyphAtals* TextGenerator::GetGlyphAtlas(int index) { if (index >= m_Atlases.size()) return NULL; @@ -104,25 +112,25 @@ Internal::Rect TextGenerator::GetRenderChartAndMove(GlyphAtals* atlas, Internal: { Internal::Rect rect; Internal::Vector2 space; - space.x = atlas->width - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.x; - space.y = atlas->height - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.y; + space.x = atlas->width - atlas->cursor.x - m_AtlasMargin; + space.y = atlas->height - atlas->cursor.y - m_AtlasMargin; if (space.x > preferSize.x && space.y > preferSize.y) { rect.x = atlas->cursor.x; rect.y = atlas->cursor.y; rect.width = preferSize.x; rect.height = preferSize.y; - atlas->cursor.x += rect.width; + atlas->cursor.x += rect.width + m_GlyphPadding; atlas->rowHeight = max(atlas->rowHeight, preferSize.y); } - else if (space.y - atlas->rowHeight > preferSize.y) + else if (space.y - atlas->rowHeight - m_GlyphPadding - m_AtlasMargin > preferSize.y) { rect.x = m_AtlasMargin; rect.y = atlas->cursor.y + m_GlyphPadding + atlas->rowHeight; rect.width = preferSize.x; rect.height = preferSize.y; atlas->cursor.x = m_AtlasMargin; - atlas->cursor.y += atlas->rowHeight; + atlas->cursor.y += atlas->rowHeight + m_GlyphPadding; atlas->rowHeight = rect.height; } else @@ -178,11 +186,11 @@ bool TextGenerator::HasEnoughSpace(GlyphAtals* atlas, Internal::Vector2 preferSi if (atlas == NULL) return false; Internal::Vector2 space; - space.x = atlas->width - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.x; - space.y = atlas->height - m_AtlasMargin * 2 - m_GlyphPadding - atlas->cursor.y; + space.x = atlas->width - atlas->cursor.x - m_AtlasMargin; + space.y = atlas->height - atlas->cursor.y - m_AtlasMargin; if (space.x > preferSize.x && space.y > preferSize.y) return true; - if (space.y - atlas->rowHeight > preferSize.y) + if (space.y - atlas->rowHeight - m_GlyphPadding - m_AtlasMargin > preferSize.y) return true; return false; } |