[08/10] gdiplus: GdipMeasureString/GdipDrawString should add extra space around the text.

Dmitry Timoshkov dmitry at baikal.ru
Thu Aug 16 23:43:38 CDT 2012


---
 dlls/gdiplus/graphics.c       | 42 +++++++++++++++++++++++++++++++++++-------
 dlls/gdiplus/tests/graphics.c |  9 ++++-----
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 2870146..8a02860 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -5019,6 +5019,8 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
     HDC temp_hdc=NULL, hdc;
     GpPointF pt[3];
     RectF scaled_rect;
+    REAL margin_x;
+    INT lines, glyphs;
 
     TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
         debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
@@ -5053,13 +5055,21 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
     args.rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
                       (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
 
-    get_font_hfont(graphics, font, &gdifont);
-    oldfont = SelectObject(hdc, gdifont);
+    /* FIXME: GenericTypographic format prevents extra margins */
+    margin_x = units_to_pixels(font->emSize / 6.0, font->unit, graphics->xres);
 
-    scaled_rect.X = rect->X * args.rel_width;
+    scaled_rect.X = rect->X * args.rel_width + margin_x;
     scaled_rect.Y = rect->Y * args.rel_height;
     scaled_rect.Width = rect->Width * args.rel_width;
     scaled_rect.Height = rect->Height * args.rel_height;
+    if (scaled_rect.Width >= 0.5)
+    {
+        scaled_rect.Width -= margin_x * 2.0;
+        if (scaled_rect.Width < 0.5) return Ok; /* doesn't fit */
+    }
+
+    get_font_hfont(graphics, font, &gdifont);
+    oldfont = SelectObject(hdc, gdifont);
 
     bounds->X = rect->X;
     bounds->Y = rect->Y;
@@ -5067,12 +5077,22 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
     bounds->Height = 0.0;
 
     args.bounds = bounds;
-    args.codepointsfitted = codepointsfitted;
-    args.linesfilled = linesfilled;
+    args.codepointsfitted = &glyphs;
+    args.linesfilled = &lines;
+    lines = glyphs = 0;
 
     gdip_format_string(hdc, string, length, font, &scaled_rect, format,
         measure_string_callback, &args);
 
+    if (linesfilled) *linesfilled = lines;
+    if (codepointsfitted) *codepointsfitted = glyphs;
+
+    if (lines)
+    {
+        margin_x = pixels_to_units(margin_x, graphics->unit, graphics->xres);
+        bounds->Width += margin_x * 2.0;
+    }
+
     SelectObject(hdc, oldfont);
     DeleteObject(gdifont);
 
@@ -5143,7 +5163,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
     HFONT gdifont;
     GpPointF pt[3], rectcpy[4];
     POINT corners[4];
-    REAL rel_width, rel_height;
+    REAL rel_width, rel_height, margin_x;
     INT save_state;
     REAL offsety = 0.0;
     struct draw_string_args args;
@@ -5206,10 +5226,18 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
     rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height;
     transform_and_round_points(graphics, corners, rectcpy, 4);
 
-    scaled_rect.X = 0.0;
+    /* FIXME: GenericTypographic format prevents extra margins */
+    margin_x = units_to_pixels(font->emSize / 6.0, font->unit, graphics->xres);
+
+    scaled_rect.X = margin_x;
     scaled_rect.Y = 0.0;
     scaled_rect.Width = rel_width * rect->Width;
     scaled_rect.Height = rel_height * rect->Height;
+    if (scaled_rect.Width >= 0.5)
+    {
+        scaled_rect.Width -= margin_x * 2.0;
+        if (scaled_rect.Width < 0.5) return Ok; /* doesn't fit */
+    }
 
     if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
     {
diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c
index 8c55abe..e46cc6c 100644
--- a/dlls/gdiplus/tests/graphics.c
+++ b/dlls/gdiplus/tests/graphics.c
@@ -3506,7 +3506,7 @@ static void test_GdipMeasureString(void)
         expectf(0.0, bounds.X);
         expectf(0.0, bounds.Y);
         expectf_(height, bounds.Height, height / 100.0);
-        expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.05);
+        expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
         expect(7, chars);
         expect(1, lines);
 
@@ -3522,7 +3522,7 @@ static void test_GdipMeasureString(void)
         expectf(50.0, bounds.X);
         expectf(50.0, bounds.Y);
         expectf_(height, bounds.Height, height / 100.0);
-        expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.05);
+        expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
         expect(7, chars);
         expect(1, lines);
 
@@ -3588,7 +3588,7 @@ static void test_GdipMeasureString(void)
             expectf(0.0, bounds.X);
             expectf(0.0, bounds.Y);
             expectf_(height, bounds.Height, height / 85.0);
-            expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.05);
+            expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
             expect(7, chars);
             expect(1, lines);
 
@@ -3604,7 +3604,7 @@ static void test_GdipMeasureString(void)
             expectf(50.0, bounds.X);
             expectf(50.0, bounds.Y);
             expectf_(height, bounds.Height, height / 85.0);
-            expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.05);
+            expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
             expect(7, chars);
             expect(1, lines);
 
@@ -3950,7 +3950,6 @@ static void test_measured_extra_space(void)
             /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
             margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
             /*trace("margin %f pixels\n", margin);*/
-todo_wine
             expectf_(font_size / 6.0, margin, font_size / 100.0);
         }
 
-- 
1.7.11.5




More information about the wine-patches mailing list