Skip to content

Commit f648b68

Browse files
committed
Common: also apply negative glyph offset to non-clipping gui surfaces
1 parent ed06fb1 commit f648b68

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Common/gui/guilistbox.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ Rect GUIListBox::CalcGraphicRect(bool clipped)
132132
int last_line_y = pixel_size + 1 + (VisibleItemCount - 1) * RowHeight;
133133
// Include font fixes for the first and last text line,
134134
// in case graphical height is different, and there's a VerticalOffset
135+
int h_ext = GUI::CalcFontGraphicalHExtent(Font);
135136
Line vextent = GUI::CalcFontGraphicalVExtent(Font);
136-
Rect text_rc = RectWH(0, vextent.Y1, max_line.X2 - max_line.X1 + 1, last_line_y + (vextent.Y2 - vextent.Y1));
137+
Rect text_rc = RectWH(h_ext, vextent.Y1, max_line.X2 - max_line.X1 + 1 + (-h_ext) * 2,
138+
last_line_y + (vextent.Y2 - vextent.Y1));
137139
return SumRects(rc, text_rc);
138140
}
139141

Common/gui/guimain.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
784790
Line 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

840848
Rect 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
}

Common/gui/guimain.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ namespace GUI
394394
// if drawn aligned to the given frame
395395
Rect CalcTextGraphicalRect(const std::vector<String> &text, size_t item_count, int font, int linespace,
396396
const Rect &frame, FrameAlignment align, bool limit_by_frame = true);
397+
// Returns max potential negative offset position of a font's glyphs.
398+
int CalcFontGraphicalHExtent(int font);
397399
// Calculates a vertical graphical extent for a given font,
398400
// which is a top and bottom offsets in zero-based coordinates.
399401
// NOTE: this applies font size fixups.

0 commit comments

Comments
 (0)