usp10: Do glyph translation for truetype fonts only.
[wine/multimedia.git] / dlls / gdiplus / pen.c
blob320f375b9af40b3ca48dfd4ebb3bc98ee3f5c052
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "wingdi.h"
25 #include "objbase.h"
27 #include "gdiplus.h"
28 #include "gdiplus_private.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
33 static DWORD gdip_to_gdi_dash(GpDashStyle dash)
35 switch(dash){
36 case DashStyleSolid:
37 return PS_SOLID;
38 case DashStyleDash:
39 return PS_DASH;
40 case DashStyleDot:
41 return PS_DOT;
42 case DashStyleDashDot:
43 return PS_DASHDOT;
44 case DashStyleDashDotDot:
45 return PS_DASHDOTDOT;
46 case DashStyleCustom:
47 return PS_USERSTYLE;
48 default:
49 ERR("Not a member of GpDashStyle enumeration\n");
50 return 0;
54 static DWORD gdip_to_gdi_join(GpLineJoin join)
56 switch(join){
57 case LineJoinRound:
58 return PS_JOIN_ROUND;
59 case LineJoinBevel:
60 return PS_JOIN_BEVEL;
61 case LineJoinMiter:
62 case LineJoinMiterClipped:
63 return PS_JOIN_MITER;
64 default:
65 ERR("Not a member of GpLineJoin enumeration\n");
66 return 0;
70 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
72 if(!pen || !clonepen)
73 return InvalidParameter;
75 *clonepen = GdipAlloc(sizeof(GpPen));
76 if(!*clonepen) return OutOfMemory;
78 memcpy(*clonepen, pen, sizeof(GpPen));
80 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
81 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
82 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
84 return Ok;
87 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
88 GpPen **pen)
90 GpPen *gp_pen;
92 if(!pen)
93 return InvalidParameter;
95 gp_pen = GdipAlloc(sizeof(GpPen));
96 if(!gp_pen) return OutOfMemory;
98 gp_pen->style = GP_DEFAULT_PENSTYLE;
99 gp_pen->width = width;
100 gp_pen->unit = unit;
101 gp_pen->endcap = LineCapFlat;
102 gp_pen->join = LineJoinMiter;
103 gp_pen->miterlimit = 10.0;
104 gp_pen->dash = DashStyleSolid;
105 gp_pen->offset = 0.0;
106 GdipCreateSolidFill(color, (GpSolidFill **)(&gp_pen->brush));
108 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
109 FIXME("UnitWorld, UnitPixel only supported units\n");
110 GdipFree(gp_pen);
111 return NotImplemented;
114 *pen = gp_pen;
116 return Ok;
119 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
121 if(!pen) return InvalidParameter;
123 GdipDeleteBrush(pen->brush);
124 GdipDeleteCustomLineCap(pen->customstart);
125 GdipDeleteCustomLineCap(pen->customend);
126 GdipFree(pen->dashes);
127 GdipFree(pen);
129 return Ok;
132 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
134 if(!pen || !brush)
135 return InvalidParameter;
137 return GdipCloneBrush(pen->brush, brush);
140 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
142 if(!pen || !argb)
143 return InvalidParameter;
145 if(pen->brush->bt != BrushTypeSolidColor)
146 return NotImplemented;
148 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
151 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
153 if(!pen || !dash || count > pen->numdashes)
154 return InvalidParameter;
156 /* note: if you pass a negative value for count, it crashes native gdiplus. */
157 if(count < 0)
158 return GenericError;
160 memcpy(dash, pen->dashes, count * sizeof(REAL));
162 return Ok;
165 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
167 if(!pen || !offset)
168 return InvalidParameter;
170 *offset = pen->offset;
172 return Ok;
175 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
177 if(!pen || !dash)
178 return InvalidParameter;
180 *dash = pen->dash;
182 return Ok;
185 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
187 if(!pen || !brush)
188 return InvalidParameter;
190 GdipDeleteBrush(pen->brush);
191 return GdipCloneBrush(brush, &pen->brush);
194 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
196 if(!pen)
197 return InvalidParameter;
199 if(pen->brush->bt != BrushTypeSolidColor)
200 return NotImplemented;
202 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
205 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
207 GpCustomLineCap * cap;
208 GpStatus ret;
210 if(!pen || !customCap) return InvalidParameter;
212 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
213 GdipDeleteCustomLineCap(pen->customend);
214 pen->endcap = LineCapCustom;
215 pen->customend = cap;
218 return ret;
221 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
223 GpCustomLineCap * cap;
224 GpStatus ret;
226 if(!pen || !customCap) return InvalidParameter;
228 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
229 GdipDeleteCustomLineCap(pen->customstart);
230 pen->startcap = LineCapCustom;
231 pen->customstart = cap;
234 return ret;
237 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
238 INT count)
240 INT i;
241 REAL sum = 0;
243 if(!pen || !dash)
244 return InvalidParameter;
246 for(i = 0; i < count; i++){
247 sum += dash[i];
248 if(dash[i] < 0.0)
249 return InvalidParameter;
252 if(sum == 0.0 && count)
253 return InvalidParameter;
255 GdipFree(pen->dashes);
256 pen->dashes = NULL;
258 if(count > 0)
259 pen->dashes = GdipAlloc(count * sizeof(REAL));
260 if(!pen->dashes){
261 pen->numdashes = 0;
262 return OutOfMemory;
265 GdipSetPenDashStyle(pen, DashStyleCustom);
266 memcpy(pen->dashes, dash, count * sizeof(REAL));
267 pen->numdashes = count;
269 return Ok;
272 /* FIXME: dash offset not used */
273 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
275 if(!pen)
276 return InvalidParameter;
278 pen->offset = offset;
280 return Ok;
283 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
285 if(!pen)
286 return InvalidParameter;
288 if(dash != DashStyleCustom){
289 GdipFree(pen->dashes);
290 pen->dashes = NULL;
291 pen->numdashes = 0;
294 pen->dash = dash;
295 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
296 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
297 pen->style |= gdip_to_gdi_dash(dash);
299 return Ok;
302 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
304 if(!pen) return InvalidParameter;
306 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
307 GdipDeleteCustomLineCap(pen->customend);
308 pen->customend = NULL;
309 pen->endcap = cap;
311 return Ok;
314 /* FIXME: startcap, dashcap not used. */
315 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
316 GpLineCap end, GpDashCap dash)
318 if(!pen)
319 return InvalidParameter;
321 GdipDeleteCustomLineCap(pen->customend);
322 GdipDeleteCustomLineCap(pen->customstart);
323 pen->customend = NULL;
324 pen->customstart = NULL;
326 pen->startcap = start;
327 pen->endcap = end;
328 pen->dashcap = dash;
330 return Ok;
333 /* FIXME: Miter line joins behave a bit differently than they do in windows.
334 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
335 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
337 if(!pen) return InvalidParameter;
339 pen->join = join;
340 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
341 pen->style |= gdip_to_gdi_join(join);
343 return Ok;
346 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
348 if(!pen)
349 return InvalidParameter;
351 pen->miterlimit = limit;
353 return Ok;
356 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
358 if(!pen) return InvalidParameter;
360 GdipDeleteCustomLineCap(pen->customstart);
361 pen->customstart = NULL;
362 pen->startcap = cap;
364 return Ok;
367 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
369 if(!pen) return InvalidParameter;
371 pen->width = width;
373 return Ok;