Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit c6038b7

Browse files
committed
Apply alignment to bounding box in cairo_MeasureString.
1 parent b1908c9 commit c6038b7

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/text-cairo.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,40 @@ MeasureString (GpGraphics *graphics, GDIPCONST WCHAR *stringUnicode, int *length
705705
boundingBox->Width = gdip_convgr_unitx (graphics, boundingBox->Width);
706706
boundingBox->Height = gdip_convgr_unity (graphics, boundingBox->Height);
707707
}
708+
709+
switch (AlignVert) {
710+
case StringAlignmentCenter:
711+
if (format->formatFlags & StringFormatFlagsDirectionVertical) {
712+
boundingBox->X += (FrameHeight - MaxY) * 0.5;
713+
} else {
714+
boundingBox->Y += (FrameHeight - MaxY) * 0.5;
715+
}
716+
break;
717+
case StringAlignmentFar:
718+
if (format->formatFlags & StringFormatFlagsDirectionVertical) {
719+
boundingBox->X += (FrameHeight - MaxY);
720+
} else {
721+
boundingBox->Y += (FrameHeight - MaxY);
722+
}
723+
break;
724+
}
725+
726+
switch (AlignHorz) {
727+
case StringAlignmentCenter:
728+
if (format->formatFlags & StringFormatFlagsDirectionVertical) {
729+
boundingBox->Y += (FrameWidth - MaxX) * 0.5;
730+
} else {
731+
boundingBox->X += (FrameWidth - MaxX) * 0.5;
732+
}
733+
break;
734+
case StringAlignmentFar:
735+
if (format->formatFlags & StringFormatFlagsDirectionVertical) {
736+
boundingBox->Y += (FrameWidth - MaxX);
737+
} else {
738+
boundingBox->X += (FrameWidth - MaxX);
739+
}
740+
break;
741+
}
708742
}
709743

710744
if (codepointsFitted) {

tests/testtext.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,12 @@ static void test_measure_string_alignment(void)
191191
rect.Width = 200.0;
192192
rect.Height = 100.0;
193193
set_rect_empty (&bounds);
194-
#ifdef USE_PANGO_RENDERING
195194
status = GdipMeasureString (graphics, teststring1, 1, font, &rect, format, &bounds, NULL, NULL);
196195
expect (Ok, status);
197196
expectf_ (td[i].x_x0 + td[i].x_xx * bounds.Width + 5.0, bounds.X, 0.6);
198197
expectf_ (td[i].y_y0 + td[i].y_yy * bounds.Height + 10.0, bounds.Y, 0.6);
199198
expectf_ (td[i].right_x0 + td[i].right_xx * bounds.Width + 5.0, bounds.X + bounds.Width, 0.6);
200199
expectf_ (td[i].bottom_y0 + td[i].bottom_yy * bounds.Height + 10.0, bounds.Y + bounds.Height, 0.6);
201-
#endif
202200

203201
status = GdipMeasureCharacterRanges (graphics, teststring1, 1, font, &rect, format, 1, &region);
204202
expect (Ok, status);

0 commit comments

Comments
 (0)