gdiplus: Initial path iterator implementation.
[wine] / dlls / gdiplus / pen.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
29
30 static DWORD gdip_to_gdi_join(GpLineJoin join)
31 {
32     switch(join){
33         case LineJoinRound:
34             return PS_JOIN_ROUND;
35         case LineJoinBevel:
36             return PS_JOIN_BEVEL;
37         case LineJoinMiter:
38         case LineJoinMiterClipped:
39             return PS_JOIN_MITER;
40         default:
41             ERR("Not a member of GpLineJoin enumeration\n");
42             return 0;
43     }
44 }
45
46 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, FLOAT width, GpUnit unit,
47     GpPen **pen)
48 {
49     LOGBRUSH lb;
50     GpPen *gp_pen;
51
52     if(!pen)
53         return InvalidParameter;
54
55     gp_pen = GdipAlloc(sizeof(GpPen));
56     if(!gp_pen)    return OutOfMemory;
57
58     gp_pen->style = GP_DEFAULT_PENSTYLE;
59     gp_pen->color = ARGB2COLORREF(color);
60     gp_pen->width = width;
61     gp_pen->unit = unit;
62     gp_pen->endcap = LineCapFlat;
63     gp_pen->join = LineJoinMiter;
64     gp_pen->miterlimit = 10.0;
65
66     /* FIXME: Currently only solid lines supported. */
67     lb.lbStyle = BS_SOLID;
68     lb.lbColor = gp_pen->color;
69     lb.lbHatch = 0;
70
71     if((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel)) {
72         gp_pen->gdipen = ExtCreatePen(gp_pen->style, (INT) gp_pen->width, &lb,
73             0, NULL);
74     } else {
75         FIXME("UnitWorld, UnitPixel only supported units\n");
76         GdipFree(gp_pen);
77         return NotImplemented;
78     }
79
80     *pen = gp_pen;
81
82     return Ok;
83 }
84
85 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
86 {
87     if(!pen)    return InvalidParameter;
88     DeleteObject(pen->gdipen);
89     GdipFree(pen);
90
91     return Ok;
92 }
93
94 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
95 {
96     if(!pen)    return InvalidParameter;
97
98     pen->endcap = cap;
99
100     return Ok;
101 }
102
103 /* FIXME: startcap, dashcap not used. */
104 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
105     GpLineCap end, GpDashCap dash)
106 {
107     if(!pen)
108         return InvalidParameter;
109
110     pen->startcap = start;
111     pen->endcap = end;
112     pen->dashcap = dash;
113
114     return Ok;
115 }
116
117 /* FIXME: Miter line joins behave a bit differently than they do in windows.
118  * Both kinds of miter joins clip if the angle is less than 11 degrees. */
119 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
120 {
121     LOGBRUSH lb;
122
123     if(!pen)    return InvalidParameter;
124
125     DeleteObject(pen->gdipen);
126     pen->join = join;
127     pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
128     pen->style |= gdip_to_gdi_join(join);
129
130     lb.lbStyle = BS_SOLID;
131     lb.lbColor = pen->color;
132     lb.lbHatch = 0;
133
134     pen->gdipen = ExtCreatePen(pen->style, (INT) pen->width, &lb, 0, NULL);
135
136     return Ok;
137 }
138
139 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
140 {
141     if(!pen)
142         return InvalidParameter;
143
144     pen->miterlimit = limit;
145
146     return Ok;
147 }