@@ -781,6 +781,12 @@ String FixupGUIName272(const String &name)
781781 return name;
782782}
783783
784+ int CalcFontGraphicalHExtent (int font)
785+ {
786+ const auto hextent = get_font_surface_hextent (font);
787+ return hextent >= 0 ? 0 : hextent;
788+ }
789+
784790Line CalcFontGraphicalVExtent (int font)
785791{
786792 // Following factors are affecting the graphical vertical metrics:
@@ -816,8 +822,9 @@ Point CalcTextPosition(const String &text, int font, const Rect &frame, FrameAli
816822 Rect rc = AlignInRect (frame, RectWH (0 , 0 , get_text_width_outlined (text.GetCStr (), font), use_height), align);
817823 if (gr_rect)
818824 {
825+ int h_ext = CalcFontGraphicalHExtent (font);
819826 Line vextent = CalcFontGraphicalVExtent (font);
820- *gr_rect = RectWH (rc.Left , rc.Top + vextent.Y1 , rc.GetWidth (), vextent.Y2 - vextent.Y1 );
827+ *gr_rect = RectWH (rc.Left + h_ext , rc.Top + vextent.Y1 , rc.GetWidth () + (-h_ext) * 2 , vextent.Y2 - vextent.Y1 );
821828 }
822829 return rc.GetLT ();
823830}
@@ -833,8 +840,9 @@ Rect CalcTextGraphicalRect(const String &text, int font, const Point &at)
833840{
834841 // Calc only width, and let CalcFontGraphicalVExtent() calc height
835842 int w = get_text_width_outlined (text.GetCStr (), font);
843+ int h_ext = CalcFontGraphicalHExtent (font);
836844 Line vextent = CalcFontGraphicalVExtent (font);
837- return RectWH (at.X , at.Y + vextent.Y1 , w, vextent.Y2 - vextent.Y1 );
845+ return RectWH (at.X + h_ext , at.Y + vextent.Y1 , w + (-h_ext) * 2 , vextent.Y2 - vextent.Y1 );
838846}
839847
840848Rect CalcTextGraphicalRect (const String &text, int font, const Rect &frame, FrameAlignment align)
@@ -869,8 +877,9 @@ Rect CalcTextGraphicalRect(const std::vector<String> &text, size_t item_count, i
869877 }
870878 // Include font fixes for the first and last text line,
871879 // in case graphical height is different, and there's a VerticalOffset
880+ int h_ext = CalcFontGraphicalHExtent (font);
872881 Line vextent = GUI::CalcFontGraphicalVExtent (font);
873- Rect text_rc = RectWH (0 , vextent.Y1 , max_line.X2 - max_line.X1 + 1 ,
882+ Rect text_rc = RectWH (h_ext , vextent.Y1 , max_line.X2 - max_line.X1 + 1 + (-h_ext) * 2 ,
874883 at_y - linespace + (vextent.Y2 - vextent.Y1 ));
875884 return text_rc;
876885}
0 commit comments