@@ -1160,13 +1160,18 @@ void ofTrueTypeFont::drawCharAsShape(uint32_t c, float x, float y, bool vFlipped
11601160// -----------------------------------------------------------
11611161float ofTrueTypeFont::stringWidth (const string& c) const {
11621162// return getStringBoundingBox(c, 0,0).width;
1163- int w = 0 ;
1163+ float w = 0 ;
11641164 iterateString ( c, 0 , 0 , false , [&]( uint32_t c, glm::vec2 pos ){
1165- if ( c == ' \t ' ){
1166- w += getGlyphProperties (' ' ).advance * spaceSize * TAB_WIDTH;
1167- } else {
1168- w += getGlyphProperties ( c ).advance ;
1165+ float cWidth = 0 ;
1166+
1167+ if (settings.direction == OF_TTF_LEFT_TO_RIGHT){
1168+ if ( c == ' \t ' ){
1169+ cWidth = getGlyphProperties (' ' ).advance * spaceSize * TAB_WIDTH;
1170+ } else {
1171+ cWidth = getGlyphProperties ( c ).advance ;
1172+ }
11691173 }
1174+ w = std::max (w, std::abs (pos.x + cWidth));
11701175 });
11711176 return w;
11721177}
@@ -1192,12 +1197,19 @@ ofRectangle ofTrueTypeFont::getStringBoundingBox(const string& c, float x, float
11921197 float w = 0 ;
11931198 iterateString ( c, x, y, vflip, [&]( uint32_t c, glm::vec2 pos ){
11941199 auto props = getGlyphProperties ( c );
1195- if ( c == ' \t ' ){
1196- w += props.advance * spaceSize * TAB_WIDTH;
1197- } else {
1198- w += props.advance ;
1200+
1201+ float cWidth = 0 ;
1202+
1203+ if (settings.direction == OF_TTF_LEFT_TO_RIGHT){
1204+ if ( c == ' \t ' ){
1205+ cWidth = getGlyphProperties (' ' ).advance * spaceSize * TAB_WIDTH;
1206+ } else {
1207+ cWidth = getGlyphProperties ( c ).advance ;
1208+ }
11991209 }
12001210
1211+ w = std::max (w, std::abs (pos.x - x) + cWidth);
1212+
12011213 minX = min ( minX, pos.x );
12021214 if ( vflip ){
12031215 minY = min ( minY, pos.y - ( props.ymax - props.ymin ) );
0 commit comments