@@ -2172,8 +2172,8 @@ IntRect Bitmap::textRect(const char *str)
21722172 // TODO: handle kerning
21732173 int bitmap_left = 0 ;
21742174 int bitmap_right = 0 ;
2175- int bitmap_top = 0 ;
2176- int bitmap_bottom = 0 ;
2175+ int bitmap_top = -font-> size -> metrics . ascender / 64 ;
2176+ int bitmap_bottom = -font-> size -> metrics . descender / 64 ;
21772177 int glyph_x = 0 ;
21782178 int glyph_y = 0 ;
21792179
@@ -2187,13 +2187,13 @@ IntRect Bitmap::textRect(const char *str)
21872187 int glyph_top = glyph_y - font->glyph ->bitmap_top ;
21882188 int glyph_bottom = glyph_top + font->glyph ->bitmap .rows ;
21892189
2190- bitmap_left = std::min (bitmap_left, glyph_left);
2191- bitmap_right = std::max (bitmap_right, glyph_right);
2192- bitmap_top = std::min (bitmap_top, glyph_top);
2193- bitmap_bottom = std::max (bitmap_bottom, glyph_bottom);
2194-
21952190 glyph_x += font->glyph ->advance .x / 64 ;
21962191 glyph_y += font->glyph ->advance .y / 64 ;
2192+
2193+ bitmap_left = std::min (bitmap_left, std::min (glyph_left, glyph_x));
2194+ bitmap_right = std::max (bitmap_right, std::max (glyph_right, glyph_x));
2195+ bitmap_top = std::min (bitmap_top, std::min (glyph_top, glyph_y));
2196+ bitmap_bottom = std::max (bitmap_bottom, std::max (glyph_bottom, glyph_y));
21972197 }
21982198
21992199 return IntRect (bitmap_left, bitmap_top, bitmap_right - bitmap_left, bitmap_bottom - bitmap_top);
@@ -2435,15 +2435,15 @@ IntRect Bitmap::textSize(const char *str)
24352435 // TODO: High-res Bitmap textSize not implemented, but I think it's the same as low-res?
24362436 // Need to double-check this.
24372437
2438+ std::string fixed = fixupString (str);
2439+ str = fixed.c_str ();
2440+
24382441#ifdef MKXPZ_RETRO
24392442 IntRect rect = textRect (str);
24402443 return IntRect (0 , 0 , rect.w , rect.h );
24412444#else
24422445 TTF_Font *font = p->font ->getSdlFont ();
24432446
2444- std::string fixed = fixupString (str);
2445- str = fixed.c_str ();
2446-
24472447 int w, h;
24482448 TTF_SizeUTF8 (font, str, &w, &h);
24492449
0 commit comments