Skip to content

Commit

Permalink
Fixed a label character number mismatch issue. [skip CI]
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Feb 25, 2025
1 parent eec3d98 commit 730509f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Source/Node/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ void Label::updateCharacters(const std::vector<uint32_t>& chars) {
uint32_t ch = chars[i];
CharItem* fontChar = _characters[i].get();

bool isTab = ch == '\t';
if (isTab) {
ch = ' ';
}

if (ch == '\n') {
nextFontPositionX = 0;
nextFontPositionY -= lineHeight;
Expand Down Expand Up @@ -609,7 +614,7 @@ void Label::updateCharacters(const std::vector<uint32_t>& chars) {
}

// update kerning
nextFontPositionX += fontDef->advance_x + kerningAmount;
nextFontPositionX += fontDef->advance_x * (isTab ? 2 : 1) + kerningAmount;
prev = ch;
if (longestLine < nextFontPositionX) {
longestLine = nextFontPositionX;
Expand All @@ -636,16 +641,7 @@ void Label::updateCharacters(const std::vector<uint32_t>& chars) {

void Label::updateLabel() {
if (!_font) return;
auto text = utf8_get_characters(_textUTF8.c_str());
_text.clear();
for (auto elem : text) {
if (elem == '\t') {
_text.push_back(' ');
_text.push_back(' ');
} else {
_text.push_back(elem);
}
}
_text = utf8_get_characters(_textUTF8.c_str());
_text.push_back('\0');

if (_flags.isOn(Label::TextBatched)) {
Expand Down

0 comments on commit 730509f

Please sign in to comment.