gdiplus: GdipDrawString should handle alignment in both directions in a similar way. Take 2.

Dmitry Timoshkov dmitry at baikal.ru
Thu Feb 28 19:52:55 CST 2013


This version of the patch should fix an omission spotted by Vincent.
---
 dlls/gdiplus/graphics.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 853027c..ca356ad 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -4422,7 +4422,6 @@ GpStatus gdip_format_string(HDC hdc,
     int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
         nheight, lineend, lineno = 0;
     RectF bounds;
-    StringAlignment halign;
     GpStatus stat = Ok;
     SIZE size;
     HotkeyPrefix hkprefix;
@@ -4483,9 +4482,6 @@ GpStatus gdip_format_string(HDC hdc,
 
     length = j;
 
-    if (format) halign = format->align;
-    else halign = StringAlignmentNear;
-
     while(sum < length){
         GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
                               nwidth, &fit, NULL, &size);
@@ -4536,20 +4532,7 @@ GpStatus gdip_format_string(HDC hdc,
             bounds.Height = size.cy;
 
         bounds.Y = rect->Y + height;
-
-        switch (halign)
-        {
-        case StringAlignmentNear:
-        default:
-            bounds.X = rect->X;
-            break;
-        case StringAlignmentCenter:
-            bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
-            break;
-        case StringAlignmentFar:
-            bounds.X = rect->X + rect->Width - bounds.Width;
-            break;
-        }
+        bounds.X = rect->X;
 
         for (hotkeyprefix_end_pos=hotkeyprefix_pos; hotkeyprefix_end_pos<hotkeyprefix_count; hotkeyprefix_end_pos++)
             if (hotkeyprefix_offsets[hotkeyprefix_end_pos] >= sum + lineend)
@@ -4919,7 +4902,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
     POINT corners[4];
     REAL rel_width, rel_height, margin_x;
     INT save_state, format_flags = 0;
-    REAL offsety = 0.0;
+    REAL offsetx = 0.0, offsety = 0.0;
     struct draw_string_args args;
     RectF scaled_rect;
     HDC hdc, temp_hdc=NULL;
@@ -4947,7 +4930,8 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
 
         /* Should be no need to explicitly test for StringAlignmentNear as
          * that is default behavior if no alignment is passed. */
-        if(format->vertalign != StringAlignmentNear){
+        if (format->vertalign != StringAlignmentNear || format->align != StringAlignmentNear)
+        {
             RectF bounds, in_rect = *rect;
             in_rect.Height = 0.0; /* avoid height clipping */
             GdipMeasureString(graphics, string, length, font, &in_rect, format, &bounds, 0, 0);
@@ -4958,8 +4942,14 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
                 offsety = (rect->Height - bounds.Height) / 2;
             else if(format->vertalign == StringAlignmentFar)
                 offsety = (rect->Height - bounds.Height);
+
+            if (format->align == StringAlignmentCenter)
+                offsetx = (rect->Width - bounds.Width) / 2;
+            else if(format->align == StringAlignmentFar)
+                offsetx = (rect->Width - bounds.Width);
         }
-        TRACE("vertical align %d, offsety %f\n", format->vertalign, offsety);
+        TRACE("v.align %d, offsety %f, h.align %d, offsetx %f\n",
+              format->vertalign, offsety, format->align, offsetx);
     }
 
     save_state = SaveDC(hdc);
@@ -5018,7 +5008,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
     args.graphics = graphics;
     args.brush = brush;
 
-    args.x = rect->X;
+    args.x = rect->X + offsetx;
     args.y = rect->Y + offsety;
 
     args.rel_width = rel_width;
-- 
1.8.1.3




More information about the wine-patches mailing list