Skip to content

Commit

Permalink
Renamed OneLineGlyphs class to GlyphLine.
Browse files Browse the repository at this point in the history
  • Loading branch information
shlzxjp committed Nov 15, 2024
1 parent 2065282 commit c52626c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions include/tgfx/layers/TextLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ class TextLayer : public Layer {
std::shared_ptr<Typeface> _typeface;
};

class OneLineGlyphs final {
class GlyphLine final {
public:
OneLineGlyphs() = default;
GlyphLine() = default;

void append(const std::shared_ptr<GlyphInfo>& glyphInfo, const float advance) {
_glyphInfosAndAdvance.emplace_back(std::move(glyphInfo), advance);
Expand Down Expand Up @@ -211,9 +211,9 @@ class TextLayer : public Layer {
const std::string& text, const std::shared_ptr<Typeface>& typeface);

float calcAdvance(const std::shared_ptr<GlyphInfo>& glyphInfo, float emptyAdvance) const;
float getLineHeight(const std::shared_ptr<OneLineGlyphs>& oneLineGlyphs) const;
void TruncateGlyphLines(std::vector<std::shared_ptr<OneLineGlyphs>>& glyphLines) const;
void resolveTextAlignment(const std::vector<std::shared_ptr<OneLineGlyphs>>& glyphLines,
float getLineHeight(const std::shared_ptr<GlyphLine>& glyphLine) const;
void TruncateGlyphLines(std::vector<std::shared_ptr<GlyphLine>>& glyphLines) const;
void resolveTextAlignment(const std::vector<std::shared_ptr<GlyphLine>>& glyphLines,
float emptyAdvance,
std::vector<std::shared_ptr<GlyphInfo>>& finalGlyphInfos,
std::vector<Point>& positions) const;
Expand Down
22 changes: 11 additions & 11 deletions src/layers/TextLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ std::unique_ptr<LayerContent> TextLayer::onUpdateContent() {
}

// 3. Handle text wrapping and auto-wrapping
std::vector<std::shared_ptr<OneLineGlyphs>> glyphLines = {};
auto glyphLine = std::make_shared<OneLineGlyphs>();
std::vector<std::shared_ptr<GlyphLine>> glyphLines = {};
auto glyphLine = std::make_shared<GlyphLine>();
const auto emptyAdvance = _font.getSize() / 2.0f;
float xOffset = 0;
for (size_t i = 0; i < glyphInfos.size(); i++) {
Expand All @@ -130,15 +130,15 @@ std::unique_ptr<LayerContent> TextLayer::onUpdateContent() {
if ('\n' == characterUnicode) {
xOffset = 0;
glyphLines.emplace_back(glyphLine);
glyphLine = std::make_shared<OneLineGlyphs>();
glyphLine = std::make_shared<GlyphLine>();
} else {
const float advance = calcAdvance(glyphInfo, emptyAdvance);
// If _width is 0, auto-wrap is disabled and no wrapping will occur.
if (_autoWrap && (0.0f != _width) && (xOffset + advance > _width)) {
xOffset = 0;
if (glyphLine->getGlyphCount() > 0) {
glyphLines.emplace_back(glyphLine);
glyphLine = std::make_shared<OneLineGlyphs>();
glyphLine = std::make_shared<GlyphLine>();
}
}
glyphLine->append(glyphInfo, advance);
Expand Down Expand Up @@ -217,13 +217,13 @@ float TextLayer::calcAdvance(const std::shared_ptr<GlyphInfo>& glyphInfo,
return advance;
}

float TextLayer::getLineHeight(const std::shared_ptr<OneLineGlyphs>& oneLineGlyphs) const {
if (oneLineGlyphs == nullptr) {
float TextLayer::getLineHeight(const std::shared_ptr<GlyphLine>& 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);
Expand All @@ -234,9 +234,9 @@ float TextLayer::getLineHeight(const std::shared_ptr<OneLineGlyphs>& oneLineGlyp
float leading = 0.0f;
std::shared_ptr<Typeface> 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;
}
Expand All @@ -253,7 +253,7 @@ float TextLayer::getLineHeight(const std::shared_ptr<OneLineGlyphs>& oneLineGlyp
return ascent + descent + leading;
}

void TextLayer::TruncateGlyphLines(std::vector<std::shared_ptr<OneLineGlyphs>>& glyphLines) const {
void TextLayer::TruncateGlyphLines(std::vector<std::shared_ptr<GlyphLine>>& glyphLines) const {
if (_height == 0.0f || glyphLines.empty()) {
return;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ std::vector<std::shared_ptr<TextLayer::GlyphInfo>> TextLayer::shapeText(
return glyphInfos;
}

void TextLayer::resolveTextAlignment(const std::vector<std::shared_ptr<OneLineGlyphs>>& glyphLines,
void TextLayer::resolveTextAlignment(const std::vector<std::shared_ptr<GlyphLine>>& glyphLines,
float emptyAdvance,
std::vector<std::shared_ptr<GlyphInfo>>& finalGlyphInfos,
std::vector<Point>& positions) const {
Expand Down

0 comments on commit c52626c

Please sign in to comment.