From c52626cfad8f9bebe69c1866a7a8b43505a6ac54 Mon Sep 17 00:00:00 2001 From: shlzxjp Date: Fri, 15 Nov 2024 17:09:31 +0800 Subject: [PATCH] Renamed OneLineGlyphs class to GlyphLine. --- include/tgfx/layers/TextLayer.h | 10 +++++----- src/layers/TextLayer.cpp | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/tgfx/layers/TextLayer.h b/include/tgfx/layers/TextLayer.h index 3fc95475..9751398c 100644 --- a/include/tgfx/layers/TextLayer.h +++ b/include/tgfx/layers/TextLayer.h @@ -174,9 +174,9 @@ class TextLayer : public Layer { std::shared_ptr _typeface; }; - class OneLineGlyphs final { + class GlyphLine final { public: - OneLineGlyphs() = default; + GlyphLine() = default; void append(const std::shared_ptr& glyphInfo, const float advance) { _glyphInfosAndAdvance.emplace_back(std::move(glyphInfo), advance); @@ -211,9 +211,9 @@ class TextLayer : public Layer { const std::string& text, const std::shared_ptr& typeface); float calcAdvance(const std::shared_ptr& glyphInfo, float emptyAdvance) const; - float getLineHeight(const std::shared_ptr& oneLineGlyphs) const; - void TruncateGlyphLines(std::vector>& glyphLines) const; - void resolveTextAlignment(const std::vector>& glyphLines, + float getLineHeight(const std::shared_ptr& glyphLine) const; + void TruncateGlyphLines(std::vector>& glyphLines) const; + void resolveTextAlignment(const std::vector>& glyphLines, float emptyAdvance, std::vector>& finalGlyphInfos, std::vector& positions) const; diff --git a/src/layers/TextLayer.cpp b/src/layers/TextLayer.cpp index 220a5b2f..d4d8e688 100644 --- a/src/layers/TextLayer.cpp +++ b/src/layers/TextLayer.cpp @@ -120,8 +120,8 @@ std::unique_ptr TextLayer::onUpdateContent() { } // 3. Handle text wrapping and auto-wrapping - std::vector> glyphLines = {}; - auto glyphLine = std::make_shared(); + std::vector> glyphLines = {}; + auto glyphLine = std::make_shared(); const auto emptyAdvance = _font.getSize() / 2.0f; float xOffset = 0; for (size_t i = 0; i < glyphInfos.size(); i++) { @@ -130,7 +130,7 @@ std::unique_ptr TextLayer::onUpdateContent() { if ('\n' == characterUnicode) { xOffset = 0; glyphLines.emplace_back(glyphLine); - glyphLine = std::make_shared(); + glyphLine = std::make_shared(); } else { const float advance = calcAdvance(glyphInfo, emptyAdvance); // If _width is 0, auto-wrap is disabled and no wrapping will occur. @@ -138,7 +138,7 @@ std::unique_ptr TextLayer::onUpdateContent() { xOffset = 0; if (glyphLine->getGlyphCount() > 0) { glyphLines.emplace_back(glyphLine); - glyphLine = std::make_shared(); + glyphLine = std::make_shared(); } } glyphLine->append(glyphInfo, advance); @@ -217,13 +217,13 @@ float TextLayer::calcAdvance(const std::shared_ptr& glyphInfo, return advance; } -float TextLayer::getLineHeight(const std::shared_ptr& oneLineGlyphs) const { - if (oneLineGlyphs == nullptr) { +float TextLayer::getLineHeight(const std::shared_ptr& glyphLine) const { + if (glyphLine == nullptr) { return 0.0f; } // For a blank line with only newline characters, use the font's ascent, descent, and leading as the line height. - if (oneLineGlyphs->getGlyphCount() == 0) { + if (glyphLine->getGlyphCount() == 0) { const auto fontMetrics = _font.getMetrics(); return std::fabs(fontMetrics.ascent) + std::fabs(fontMetrics.descent) + std::fabs(fontMetrics.leading); @@ -234,9 +234,9 @@ float TextLayer::getLineHeight(const std::shared_ptr& oneLineGlyp float leading = 0.0f; std::shared_ptr lastTypeface = nullptr; - const auto size = oneLineGlyphs->getGlyphCount(); + const auto size = glyphLine->getGlyphCount(); for (size_t i = 0; i < size; ++i) { - const auto& typeface = oneLineGlyphs->getGlyphInfo(i)->getTypeface(); + const auto& typeface = glyphLine->getGlyphInfo(i)->getTypeface(); if (typeface == nullptr || lastTypeface == typeface) { continue; } @@ -253,7 +253,7 @@ float TextLayer::getLineHeight(const std::shared_ptr& oneLineGlyp return ascent + descent + leading; } -void TextLayer::TruncateGlyphLines(std::vector>& glyphLines) const { +void TextLayer::TruncateGlyphLines(std::vector>& glyphLines) const { if (_height == 0.0f || glyphLines.empty()) { return; } @@ -324,7 +324,7 @@ std::vector> TextLayer::shapeText( return glyphInfos; } -void TextLayer::resolveTextAlignment(const std::vector>& glyphLines, +void TextLayer::resolveTextAlignment(const std::vector>& glyphLines, float emptyAdvance, std::vector>& finalGlyphInfos, std::vector& positions) const {