Skip to content

Commit 81d9ca8

Browse files
committed
Correctly apply scaling to TTF rendered strings
This fixes weird misplaced special characters since the TTF strings weren't rendered at the right position. This should fix that. This fixes an issue reported on the forums by Novachen.
1 parent ffe647b commit 81d9ca8

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

code/graphics/opengl/gropengldraw.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ void gr_opengl_string_old(float sx, float sy, const char* s, const char* end, fo
553553
break;
554554
}
555555

556-
letter = font::get_char_width_old(fontData, s[0], s[1], &width, &spacing);
556+
letter = font::get_char_width_old(fontData, (ubyte)s[0], (ubyte)s[1], &width, &spacing);
557557
s++;
558558

559559
// not in font, draw as space
@@ -793,24 +793,21 @@ void gr_opengl_string(float sx, float sy, const char *s, int resize_mode, int in
793793

794794
int width;
795795
int spacing;
796-
get_char_width_old(nvgFont->getSpecialCharacterFont(), *text, '\0', &width, &spacing);
796+
get_char_width_old(nvgFont->getSpecialCharacterFont(), (ubyte)*text, (ubyte)*(text + 1), &width, &spacing);
797797

798-
x += spacing;
798+
x += i2fl(spacing) * invscaleX;
799799
}
800800
else if (doRender) {
801801
if (doRender && tokenLength > 0) {
802802
float advance;
803-
float currentX = x;
803+
float currentX = x * scaleX;
804804
float currentY = y + nvgFont->getTopOffset();
805805

806806
if (pass == 0) {
807-
advance = path->text(currentX, currentY, text, text + tokenLength) - currentX;
808-
}
809-
else {
810-
advance =
811-
path->textBounds(currentX, currentY, text, text + tokenLength, nullptr) - currentX;
807+
path->text(currentX, currentY, text, text + tokenLength);
812808
}
813809

810+
advance = path->textBounds(0.f, 0.f, text, text + tokenLength, nullptr);
814811
x += advance * invscaleX;
815812
}
816813
}

0 commit comments

Comments
 (0)