@@ -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
@@ -781,8 +781,14 @@ void gr_opengl_string(float sx, float sy, const char *s, int resize_mode, int in
781781
782782 if (specialChar) {
783783 if (pass == 1 ) {
784+ // We compute the top offset of the special character by aligning it to the base line of the string
785+ // This is done by moving to the base line of the string by adding the ascender value and then
786+ // accounting for the height of the text with the height of the special font
787+ auto yOffset = nvgFont->getTopOffset () +
788+ (nvgFont->getAscender () - nvgFont->getSpecialCharacterFont ()->h );
789+
784790 gr_opengl_string_old (sx + x * scaleX,
785- sy + (y + nvgFont-> getTopOffset () ) * scaleY,
791+ sy + (y + yOffset ) * scaleY,
786792 text,
787793 text + 1 ,
788794 nvgFont->getSpecialCharacterFont (),
@@ -793,24 +799,21 @@ void gr_opengl_string(float sx, float sy, const char *s, int resize_mode, int in
793799
794800 int width;
795801 int spacing;
796- get_char_width_old (nvgFont->getSpecialCharacterFont (), *text, ' \0 ' , &width, &spacing);
802+ get_char_width_old (nvgFont->getSpecialCharacterFont (), (ubyte) *text, (ubyte)*(text + 1 ) , &width, &spacing);
797803
798- x += spacing;
804+ x += i2fl ( spacing) * invscaleX ;
799805 }
800806 else if (doRender) {
801807 if (doRender && tokenLength > 0 ) {
802808 float advance;
803- float currentX = x;
809+ float currentX = x * scaleX ;
804810 float currentY = y + nvgFont->getTopOffset ();
805811
806812 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;
813+ path->text (currentX, currentY, text, text + tokenLength);
812814 }
813815
816+ advance = path->textBounds (0 .f , 0 .f , text, text + tokenLength, nullptr );
814817 x += advance * invscaleX;
815818 }
816819 }
0 commit comments