Evan Stade : gdiplus: Simplified GdipDrawPath by moving more of the code to the helpers.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jul 16 08:23:44 CDT 2007


Module: wine
Branch: master
Commit: 9e88347f4533a67df0b9cb119314b7cf5a8d4a8b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9e88347f4533a67df0b9cb119314b7cf5a8d4a8b

Author: Evan Stade <estade at gmail.com>
Date:   Fri Jul 13 17:51:49 2007 -0700

gdiplus: Simplified GdipDrawPath by moving more of the code to the helpers.

---

 dlls/gdiplus/graphics.c |  102 ++++++++++++++++++++++-------------------------
 1 files changed, 48 insertions(+), 54 deletions(-)

diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 5bfd79a..d28d76a 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -466,52 +466,60 @@ static GpStatus draw_poly(HDC hdc, GpPen *pen, GDIPCONST GpPointF * pt,
                 ERR("Bad bezier points\n");
                 goto end;
             }
-
             i += 2;
         }
     }
 
-    if((types[count - 1] & PathPointTypePathTypeMask) == PathPointTypeBezier){
-        ptf = GdipAlloc(4 * sizeof(GpPointF));
-        memcpy(ptf, &pt[count-4], 4 * sizeof(GpPointF));
+    for(i = 0; i < count; i++){
+        pti[i].x = roundr(pt[i].X);
+        pti[i].y = roundr(pt[i].Y);
+    }
 
-        if(caps){
-            if(pen->endcap == LineCapArrowAnchor)
-                shorten_bezier_amt(ptf, pen->width);
+    /* If we are drawing caps, go through the points and adjust them accordingly,
+     * and draw the caps. */
+    if(caps){
+        switch(types[count - 1] & PathPointTypePathTypeMask){
+            case PathPointTypeBezier:
+                ptf = GdipAlloc(4 * sizeof(GpPointF));
+                if(!ptf){
+                    status = OutOfMemory;
+                    goto end;
+                }
+                memcpy(ptf, &pt[count - 4], 4 * sizeof(GpPointF));
 
-            draw_cap(hdc, pen->color, pen->endcap, pen->width,
-                pt[count - 1].X - (ptf[3].X - ptf[2].X),
-                pt[count - 1].Y - (ptf[3].Y - ptf[2].Y),
-                pt[count - 1].X, pt[count - 1].Y);
-        }
-        for(i = 0; i < 4; i ++){
-            pti[i + count - 4].x = roundr(ptf[i].X);
-            pti[i + count - 4].y = roundr(ptf[i].Y);
-        }
-        for(i = 0; i < count - 4; i ++){
-            pti[i].x = roundr(pt[i].X);
-            pti[i].y = roundr(pt[i].Y);
-        }
-    }
-    else if((types[count - 1] & PathPointTypePathTypeMask) == PathPointTypeLine){
-        if(caps){
-            if(pen->endcap == LineCapArrowAnchor)
-                shorten_line_amt(pt[count-2].X, pt[count-2].Y, &x, &y, pen->width);
+                if(pen->endcap == LineCapArrowAnchor)
+                    shorten_bezier_amt(ptf, pen->width);
 
-            draw_cap(hdc, pen->color, pen->endcap, pen->width, pt[count-2].X,
-                pt[count-2].Y, pt[count - 1].X, pt[count - 1].Y);
-        }
-        pti[count - 1].x = roundr(x);
-        pti[count - 1].y = roundr(y);
-        for(i = 0; i < count - 1; i ++){
-            pti[i].x = roundr(pt[i].X);
-            pti[i].y = roundr(pt[i].Y);
+
+                draw_cap(hdc, pen->color, pen->endcap, pen->width,
+                    pt[count - 1].X - (ptf[3].X - ptf[2].X),
+                    pt[count - 1].Y - (ptf[3].Y - ptf[2].Y),
+                    pt[count - 1].X, pt[count - 1].Y);
+
+                for(i = 0; i < 4; i++){
+                    pti[i + count - 4].x = roundr(ptf[i].X);
+                    pti[i + count - 4].y = roundr(ptf[i].Y);
+                }
+
+                break;
+
+            case PathPointTypeLine:
+                if(pen->endcap == LineCapArrowAnchor)
+                    shorten_line_amt(pt[count - 2].X, pt[count - 2].Y, &x, &y,
+                                     pen->width);
+
+                draw_cap(hdc, pen->color, pen->endcap, pen->width, pt[count - 2].X,
+                         pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
+
+                pti[count - 1].x = roundr(x);
+                pti[count - 1].y = roundr(y);
+
+                break;
+            default:
+                ERR("Bad path last point\n");
+                goto end;
         }
     }
-    else{
-        ERR("Bad path last point\n");
-        goto end;
-    }
 
     for(i = 0; i < count; i++){
         tp[i] = convert_path_point_type(types[i]);
@@ -729,7 +737,7 @@ GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
 
 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
 {
-    INT save_state, i, this_fig = 0;
+    INT save_state;
     GpStatus retval;
 
     if(!pen || !graphics)
@@ -739,23 +747,9 @@ GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
     EndPath(graphics->hdc);
     SelectObject(graphics->hdc, pen->gdipen);
 
-    for(i = 0; i < path->pathdata.Count; i++){
-        if(path->pathdata.Types[i] == PathPointTypeStart){
-            retval = draw_poly(graphics->hdc, pen,
-                         &path->pathdata.Points[this_fig],
-                         &path->pathdata.Types[this_fig], i - this_fig, TRUE);
-            this_fig = i;
+    retval = draw_poly(graphics->hdc, pen, path->pathdata.Points,
+                       path->pathdata.Types, path->pathdata.Count, TRUE);
 
-            if(retval != Ok)
-                goto end;
-        }
-    }
-
-    retval = draw_poly(graphics->hdc, pen, &path->pathdata.Points[this_fig],
-                       &path->pathdata.Types[this_fig], path->pathdata.Count - this_fig,
-                       TRUE);
-
-end:
     RestoreDC(graphics->hdc, save_state);
 
     return retval;




More information about the wine-cvs mailing list