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
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)
42 case DashStyleDashDot:
44 case DashStyleDashDotDot:
49 ERR("Not a member of GpDashStyle enumeration\n");
54 static DWORD gdip_to_gdi_join(GpLineJoin join)
62 case LineJoinMiterClipped:
65 ERR("Not a member of GpLineJoin enumeration\n");
70 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
72 TRACE("(%p, %p)\n", pen, clonepen);
75 return InvalidParameter;
77 *clonepen = GdipAlloc(sizeof(GpPen));
78 if(!*clonepen) return OutOfMemory;
82 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
83 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
84 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
89 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
95 TRACE("(%x, %.2f, %d, %p)\n", color, width, unit, pen);
97 GdipCreateSolidFill(color, (GpSolidFill **)(&brush));
98 status = GdipCreatePen2(brush, width, unit, pen);
99 GdipDeleteBrush(brush);
103 GpStatus WINGDIPAPI GdipCreatePen2(GpBrush *brush, REAL width, GpUnit unit,
107 GpBrush *clone_brush;
109 TRACE("(%p, %.2f, %d, %p)\n", brush, width, unit, pen);
112 return InvalidParameter;
114 gp_pen = GdipAlloc(sizeof(GpPen));
115 if(!gp_pen) return OutOfMemory;
117 gp_pen->style = GP_DEFAULT_PENSTYLE;
118 gp_pen->width = width;
120 gp_pen->endcap = LineCapFlat;
121 gp_pen->join = LineJoinMiter;
122 gp_pen->miterlimit = 10.0;
123 gp_pen->dash = DashStyleSolid;
124 gp_pen->offset = 0.0;
125 gp_pen->customstart = NULL;
126 gp_pen->customend = NULL;
128 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
129 FIXME("UnitWorld, UnitPixel only supported units\n");
131 return NotImplemented;
134 GdipCloneBrush(brush, &clone_brush);
135 gp_pen->brush = clone_brush;
142 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
144 TRACE("(%p)\n", pen);
146 if(!pen) return InvalidParameter;
148 GdipDeleteBrush(pen->brush);
149 GdipDeleteCustomLineCap(pen->customstart);
150 GdipDeleteCustomLineCap(pen->customend);
151 GdipFree(pen->dashes);
157 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
159 TRACE("(%p, %p)\n", pen, brush);
162 return InvalidParameter;
164 return GdipCloneBrush(pen->brush, brush);
167 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
169 TRACE("(%p, %p)\n", pen, argb);
172 return InvalidParameter;
174 if(pen->brush->bt != BrushTypeSolidColor)
175 return NotImplemented;
177 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
180 GpStatus WINGDIPAPI GdipGetPenCustomEndCap(GpPen *pen, GpCustomLineCap** customCap)
182 TRACE("(%p, %p)\n", pen, customCap);
184 if(!pen || !customCap)
185 return InvalidParameter;
192 return GdipCloneCustomLineCap(pen->customend, customCap);
195 GpStatus WINGDIPAPI GdipGetPenCustomStartCap(GpPen *pen, GpCustomLineCap** customCap)
197 TRACE("(%p, %p)\n", pen, customCap);
199 if(!pen || !customCap)
200 return InvalidParameter;
202 if(!pen->customstart){
207 return GdipCloneCustomLineCap(pen->customstart, customCap);
210 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
212 TRACE("(%p, %p, %d)\n", pen, dash, count);
214 if(!pen || !dash || count > pen->numdashes)
215 return InvalidParameter;
217 /* note: if you pass a negative value for count, it crashes native gdiplus. */
221 memcpy(dash, pen->dashes, count * sizeof(REAL));
226 GpStatus WINGDIPAPI GdipGetPenDashCap197819(GpPen *pen, GpDashCap *dashCap)
228 TRACE("(%p, %p)\n", pen, dashCap);
231 return InvalidParameter;
233 *dashCap = pen->dashcap;
238 GpStatus WINGDIPAPI GdipGetPenDashCount(GpPen *pen, INT *count)
240 TRACE("(%p, %p)\n", pen, count);
243 return InvalidParameter;
245 *count = pen->numdashes;
250 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
252 TRACE("(%p, %p)\n", pen, offset);
255 return InvalidParameter;
257 *offset = pen->offset;
262 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
264 TRACE("(%p, %p)\n", pen, dash);
267 return InvalidParameter;
274 GpStatus WINGDIPAPI GdipGetPenEndCap(GpPen *pen, GpLineCap *endCap)
276 TRACE("(%p, %p)\n", pen, endCap);
279 return InvalidParameter;
281 *endCap = pen->endcap;
286 GpStatus WINGDIPAPI GdipGetPenLineJoin(GpPen *pen, GpLineJoin *lineJoin)
288 TRACE("(%p, %p)\n", pen, lineJoin);
290 if(!pen || !lineJoin)
291 return InvalidParameter;
293 *lineJoin = pen->join;
298 GpStatus WINGDIPAPI GdipGetPenMode(GpPen *pen, GpPenAlignment *mode)
300 TRACE("(%p, %p)\n", pen, mode);
303 return InvalidParameter;
310 GpStatus WINGDIPAPI GdipGetPenMiterLimit(GpPen *pen, REAL *miterLimit)
312 TRACE("(%p, %p)\n", pen, miterLimit);
314 if(!pen || !miterLimit)
315 return InvalidParameter;
317 *miterLimit = pen->miterlimit;
322 GpStatus WINGDIPAPI GdipGetPenStartCap(GpPen *pen, GpLineCap *startCap)
324 TRACE("(%p, %p)\n", pen, startCap);
326 if(!pen || !startCap)
327 return InvalidParameter;
329 *startCap = pen->startcap;
334 GpStatus WINGDIPAPI GdipGetPenUnit(GpPen *pen, GpUnit *unit)
336 TRACE("(%p, %p)\n", pen, unit);
339 return InvalidParameter;
346 GpStatus WINGDIPAPI GdipGetPenWidth(GpPen *pen, REAL *width)
348 TRACE("(%p, %p)\n", pen, width);
351 return InvalidParameter;
358 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
360 TRACE("(%p, %p)\n", pen, brush);
363 return InvalidParameter;
365 GdipDeleteBrush(pen->brush);
366 return GdipCloneBrush(brush, &pen->brush);
369 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
371 TRACE("(%p, %x)\n", pen, argb);
374 return InvalidParameter;
376 if(pen->brush->bt != BrushTypeSolidColor)
377 return NotImplemented;
379 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
382 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
384 GpCustomLineCap * cap;
387 TRACE("(%p, %p)\n", pen, customCap);
389 /* native crashes on pen == NULL, customCap != NULL */
390 if(!customCap) return InvalidParameter;
392 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
393 GdipDeleteCustomLineCap(pen->customend);
394 pen->endcap = LineCapCustom;
395 pen->customend = cap;
401 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
403 GpCustomLineCap * cap;
406 TRACE("(%p, %p)\n", pen, customCap);
408 /* native crashes on pen == NULL, customCap != NULL */
409 if(!customCap) return InvalidParameter;
411 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
412 GdipDeleteCustomLineCap(pen->customstart);
413 pen->startcap = LineCapCustom;
414 pen->customstart = cap;
420 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
426 TRACE("(%p, %p, %d)\n", pen, dash, count);
429 return InvalidParameter;
434 for(i = 0; i < count; i++){
437 return InvalidParameter;
440 if(sum == 0.0 && count)
441 return InvalidParameter;
443 GdipFree(pen->dashes);
447 pen->dashes = GdipAlloc(count * sizeof(REAL));
453 GdipSetPenDashStyle(pen, DashStyleCustom);
454 memcpy(pen->dashes, dash, count * sizeof(REAL));
455 pen->numdashes = count;
460 GpStatus WINGDIPAPI GdipSetPenDashCap197819(GpPen *pen, GpDashCap dashCap)
462 TRACE("(%p, %d)\n", pen, dashCap);
465 return InvalidParameter;
467 pen->dashcap = dashCap;
472 /* FIXME: dash offset not used */
473 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
475 TRACE("(%p, %.2f)\n", pen, offset);
478 return InvalidParameter;
480 pen->offset = offset;
485 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
487 TRACE("(%p, %d)\n", pen, dash);
490 return InvalidParameter;
492 if(dash != DashStyleCustom){
493 GdipFree(pen->dashes);
499 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
500 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
501 pen->style |= gdip_to_gdi_dash(dash);
506 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
508 TRACE("(%p, %d)\n", pen, cap);
510 if(!pen) return InvalidParameter;
512 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
513 GdipDeleteCustomLineCap(pen->customend);
514 pen->customend = NULL;
520 /* FIXME: startcap, dashcap not used. */
521 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
522 GpLineCap end, GpDashCap dash)
524 TRACE("%p, %d, %d, %d)\n", pen, start, end, dash);
527 return InvalidParameter;
529 GdipDeleteCustomLineCap(pen->customend);
530 GdipDeleteCustomLineCap(pen->customstart);
531 pen->customend = NULL;
532 pen->customstart = NULL;
534 pen->startcap = start;
541 /* FIXME: Miter line joins behave a bit differently than they do in windows.
542 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
543 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
545 TRACE("(%p, %d)\n", pen, join);
547 if(!pen) return InvalidParameter;
550 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
551 pen->style |= gdip_to_gdi_join(join);
556 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
558 TRACE("(%p, %.2f)\n", pen, limit);
561 return InvalidParameter;
563 pen->miterlimit = limit;
568 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
570 TRACE("(%p, %d)\n", pen, cap);
572 if(!pen) return InvalidParameter;
574 GdipDeleteCustomLineCap(pen->customstart);
575 pen->customstart = NULL;
581 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
583 TRACE("(%p, %.2f)\n", pen, width);
585 if(!pen) return InvalidParameter;
592 GpStatus WINGDIPAPI GdipSetPenMode(GpPen *pen, GpPenAlignment mode)
594 TRACE("(%p, %d)\n", pen, mode);
596 if(!pen) return InvalidParameter;