[PATCH] Add support for horizontal string alignment to GdipDrawString

Stephan Rose kermos at somrek.net
Sat Jun 6 14:13:37 CDT 2009


---
 dlls/gdiplus/graphics.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 2698159..c0c2453 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -2089,10 +2089,10 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
     POINT corners[4];
     WCHAR* stringdup;
     REAL angle, ang_cos, ang_sin, rel_width, rel_height;
-    INT sum = 0, height = 0, offsety = 0, fit, fitcpy, save_state, i, j, lret, nwidth,
-        nheight;
+    INT sum = 0, height = 0, offsety = 0, fit, fitcpy,
+        save_state, i, j, lret, nwidth, nheight;
     SIZE size;
-    RECT drawcoord;
+    RECT drawcoord, textsize;
 
     TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
         length, font, debugstr_rectf(rect), format, brush);
@@ -2239,6 +2239,32 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
                     }
                 }
         }
+
+        if(format->align == StringAlignmentCenter){
+            /* Initialize rect for measuring text size */
+            textsize.left = 0;
+            textsize.top = 0;
+
+            /* Measure text size */
+            DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, fit),
+                    &textsize, DT_NOCLIP | DT_EXPANDTABS | DT_CALCRECT);
+
+            /* Adjust coordinate position */
+            drawcoord.left += roundr((rect->Width / 2.0) - ((textsize.right - textsize.left) >> 1));
+        }
+        else if(format->align == StringAlignmentFar){
+            /* Initialize rect for measuring text size */
+            textsize.left = 0;
+            textsize.top = 0;
+
+            /* Measure text size */
+            DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, fit),
+                    &textsize, DT_NOCLIP | DT_EXPANDTABS | DT_CALCRECT);
+
+            /* Adjust coordinate position */
+            drawcoord.left += roundr(rect->Width - (textsize.right - textsize.left));
+        }
+
         DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, fit),
                   &drawcoord, DT_NOCLIP | DT_EXPANDTABS);
 
-- 
1.6.0.4


--=-TzANFA2MnQy82+nLuzdY--




More information about the wine-patches mailing list