configure: Build the import libraries without recursing when possible.
[wine/multimedia.git] / dlls / gdiplus / pen.c
blob53e47f08f77acdacfcdddcbaf9de62f41948a824
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 static GpPenType bt_to_pt(GpBrushType bt)
72 switch(bt){
73 case BrushTypeSolidColor:
74 return PenTypeSolidColor;
75 case BrushTypeHatchFill:
76 return PenTypeHatchFill;
77 case BrushTypeTextureFill:
78 return PenTypeTextureFill;
79 case BrushTypePathGradient:
80 return PenTypePathGradient;
81 case BrushTypeLinearGradient:
82 return PenTypeLinearGradient;
83 default:
84 return PenTypeUnknown;
88 GpStatus WINGDIPAPI GdipClonePen(GpPen *pen, GpPen **clonepen)
90 TRACE("(%p, %p)\n", pen, clonepen);
92 if(!pen || !clonepen)
93 return InvalidParameter;
95 *clonepen = GdipAlloc(sizeof(GpPen));
96 if(!*clonepen) return OutOfMemory;
98 **clonepen = *pen;
100 GdipCloneCustomLineCap(pen->customstart, &(*clonepen)->customstart);
101 GdipCloneCustomLineCap(pen->customend, &(*clonepen)->customend);
102 GdipCloneBrush(pen->brush, &(*clonepen)->brush);
104 TRACE("<-- %p\n", *clonepen);
106 return Ok;
109 GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit,
110 GpPen **pen)
112 GpBrush *brush;
113 GpStatus status;
115 TRACE("(%x, %.2f, %d, %p)\n", color, width, unit, pen);
117 GdipCreateSolidFill(color, (GpSolidFill **)(&brush));
118 status = GdipCreatePen2(brush, width, unit, pen);
119 GdipDeleteBrush(brush);
120 return status;
123 GpStatus WINGDIPAPI GdipCreatePen2(GpBrush *brush, REAL width, GpUnit unit,
124 GpPen **pen)
126 GpPen *gp_pen;
127 GpBrush *clone_brush;
129 TRACE("(%p, %.2f, %d, %p)\n", brush, width, unit, pen);
131 if(!pen || !brush)
132 return InvalidParameter;
134 gp_pen = GdipAlloc(sizeof(GpPen));
135 if(!gp_pen) return OutOfMemory;
137 gp_pen->style = GP_DEFAULT_PENSTYLE;
138 gp_pen->width = width;
139 gp_pen->unit = unit;
140 gp_pen->endcap = LineCapFlat;
141 gp_pen->join = LineJoinMiter;
142 gp_pen->miterlimit = 10.0;
143 gp_pen->dash = DashStyleSolid;
144 gp_pen->offset = 0.0;
145 gp_pen->customstart = NULL;
146 gp_pen->customend = NULL;
148 if(!((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel))) {
149 FIXME("UnitWorld, UnitPixel only supported units\n");
150 GdipFree(gp_pen);
151 return NotImplemented;
154 GdipCloneBrush(brush, &clone_brush);
155 gp_pen->brush = clone_brush;
157 *pen = gp_pen;
159 TRACE("<-- %p\n", *pen);
161 return Ok;
164 GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
166 TRACE("(%p)\n", pen);
168 if(!pen) return InvalidParameter;
170 GdipDeleteBrush(pen->brush);
171 GdipDeleteCustomLineCap(pen->customstart);
172 GdipDeleteCustomLineCap(pen->customend);
173 GdipFree(pen->dashes);
174 GdipFree(pen);
176 return Ok;
179 GpStatus WINGDIPAPI GdipGetPenBrushFill(GpPen *pen, GpBrush **brush)
181 TRACE("(%p, %p)\n", pen, brush);
183 if(!pen || !brush)
184 return InvalidParameter;
186 return GdipCloneBrush(pen->brush, brush);
189 GpStatus WINGDIPAPI GdipGetPenColor(GpPen *pen, ARGB *argb)
191 TRACE("(%p, %p)\n", pen, argb);
193 if(!pen || !argb)
194 return InvalidParameter;
196 if(pen->brush->bt != BrushTypeSolidColor)
197 return NotImplemented;
199 return GdipGetSolidFillColor(((GpSolidFill*)pen->brush), argb);
202 GpStatus WINGDIPAPI GdipGetPenCustomEndCap(GpPen *pen, GpCustomLineCap** customCap)
204 TRACE("(%p, %p)\n", pen, customCap);
206 if(!pen || !customCap)
207 return InvalidParameter;
209 if(!pen->customend){
210 *customCap = NULL;
211 return Ok;
214 return GdipCloneCustomLineCap(pen->customend, customCap);
217 GpStatus WINGDIPAPI GdipGetPenCustomStartCap(GpPen *pen, GpCustomLineCap** customCap)
219 TRACE("(%p, %p)\n", pen, customCap);
221 if(!pen || !customCap)
222 return InvalidParameter;
224 if(!pen->customstart){
225 *customCap = NULL;
226 return Ok;
229 return GdipCloneCustomLineCap(pen->customstart, customCap);
232 GpStatus WINGDIPAPI GdipGetPenDashArray(GpPen *pen, REAL *dash, INT count)
234 TRACE("(%p, %p, %d)\n", pen, dash, count);
236 if(!pen || !dash || count > pen->numdashes)
237 return InvalidParameter;
239 /* note: if you pass a negative value for count, it crashes native gdiplus. */
240 if(count < 0)
241 return GenericError;
243 memcpy(dash, pen->dashes, count * sizeof(REAL));
245 return Ok;
248 GpStatus WINGDIPAPI GdipGetPenDashCap197819(GpPen *pen, GpDashCap *dashCap)
250 TRACE("(%p, %p)\n", pen, dashCap);
252 if(!pen || !dashCap)
253 return InvalidParameter;
255 *dashCap = pen->dashcap;
257 return Ok;
260 GpStatus WINGDIPAPI GdipGetPenDashCount(GpPen *pen, INT *count)
262 TRACE("(%p, %p)\n", pen, count);
264 if(!pen || !count)
265 return InvalidParameter;
267 *count = pen->numdashes;
269 return Ok;
272 GpStatus WINGDIPAPI GdipGetPenDashOffset(GpPen *pen, REAL *offset)
274 TRACE("(%p, %p)\n", pen, offset);
276 if(!pen || !offset)
277 return InvalidParameter;
279 *offset = pen->offset;
281 return Ok;
284 GpStatus WINGDIPAPI GdipGetPenDashStyle(GpPen *pen, GpDashStyle *dash)
286 TRACE("(%p, %p)\n", pen, dash);
288 if(!pen || !dash)
289 return InvalidParameter;
291 *dash = pen->dash;
293 return Ok;
296 GpStatus WINGDIPAPI GdipGetPenEndCap(GpPen *pen, GpLineCap *endCap)
298 TRACE("(%p, %p)\n", pen, endCap);
300 if(!pen || !endCap)
301 return InvalidParameter;
303 *endCap = pen->endcap;
305 return Ok;
308 GpStatus WINGDIPAPI GdipGetPenFillType(GpPen *pen, GpPenType* type)
310 TRACE("(%p, %p)\n", pen, type);
312 if(!pen || !type)
313 return InvalidParameter;
315 *type = bt_to_pt(pen->brush->bt);
317 return Ok;
320 GpStatus WINGDIPAPI GdipGetPenLineJoin(GpPen *pen, GpLineJoin *lineJoin)
322 TRACE("(%p, %p)\n", pen, lineJoin);
324 if(!pen || !lineJoin)
325 return InvalidParameter;
327 *lineJoin = pen->join;
329 return Ok;
332 GpStatus WINGDIPAPI GdipGetPenMode(GpPen *pen, GpPenAlignment *mode)
334 TRACE("(%p, %p)\n", pen, mode);
336 if(!pen || !mode)
337 return InvalidParameter;
339 *mode = pen->align;
341 return Ok;
344 GpStatus WINGDIPAPI GdipGetPenMiterLimit(GpPen *pen, REAL *miterLimit)
346 TRACE("(%p, %p)\n", pen, miterLimit);
348 if(!pen || !miterLimit)
349 return InvalidParameter;
351 *miterLimit = pen->miterlimit;
353 return Ok;
356 GpStatus WINGDIPAPI GdipGetPenStartCap(GpPen *pen, GpLineCap *startCap)
358 TRACE("(%p, %p)\n", pen, startCap);
360 if(!pen || !startCap)
361 return InvalidParameter;
363 *startCap = pen->startcap;
365 return Ok;
368 GpStatus WINGDIPAPI GdipGetPenUnit(GpPen *pen, GpUnit *unit)
370 TRACE("(%p, %p)\n", pen, unit);
372 if(!pen || !unit)
373 return InvalidParameter;
375 *unit = pen->unit;
377 return Ok;
380 GpStatus WINGDIPAPI GdipGetPenWidth(GpPen *pen, REAL *width)
382 TRACE("(%p, %p)\n", pen, width);
384 if(!pen || !width)
385 return InvalidParameter;
387 *width = pen->width;
389 return Ok;
392 GpStatus WINGDIPAPI GdipResetPenTransform(GpPen *pen)
394 static int calls;
396 TRACE("(%p)\n", pen);
398 if(!pen)
399 return InvalidParameter;
401 if(!(calls++))
402 FIXME("(%p) stub\n", pen);
404 return NotImplemented;
407 GpStatus WINGDIPAPI GdipScalePenTransform(GpPen *pen, REAL sx, REAL sy, GpMatrixOrder order)
409 static int calls;
411 TRACE("(%p,%0.2f,%0.2f,%u)\n", pen, sx, sy, order);
413 if(!pen)
414 return InvalidParameter;
416 if(!(calls++))
417 FIXME("(%p, %.2f, %.2f, %d) stub\n", pen, sx, sy, order);
419 return NotImplemented;
422 GpStatus WINGDIPAPI GdipMultiplyPenTransform(GpPen *pen, GDIPCONST GpMatrix *matrix,
423 GpMatrixOrder order)
425 static int calls;
427 TRACE("(%p,%p,%u)\n", pen, matrix, order);
429 if(!pen)
430 return InvalidParameter;
432 if(!(calls++))
433 FIXME("not implemented\n");
435 return NotImplemented;
438 GpStatus WINGDIPAPI GdipSetPenBrushFill(GpPen *pen, GpBrush *brush)
440 TRACE("(%p, %p)\n", pen, brush);
442 if(!pen || !brush)
443 return InvalidParameter;
445 GdipDeleteBrush(pen->brush);
446 return GdipCloneBrush(brush, &pen->brush);
449 GpStatus WINGDIPAPI GdipSetPenColor(GpPen *pen, ARGB argb)
451 TRACE("(%p, %x)\n", pen, argb);
453 if(!pen)
454 return InvalidParameter;
456 if(pen->brush->bt != BrushTypeSolidColor)
457 return NotImplemented;
459 return GdipSetSolidFillColor(((GpSolidFill*)pen->brush), argb);
462 GpStatus WINGDIPAPI GdipGetPenCompoundCount(GpPen *pen, INT *count)
464 FIXME("(%p, %p): stub\n", pen, count);
466 if (!pen || !count)
467 return InvalidParameter;
469 return NotImplemented;
472 GpStatus WINGDIPAPI GdipSetPenCompoundArray(GpPen *pen, GDIPCONST REAL *dash,
473 INT count)
475 FIXME("(%p, %p, %i): stub\n", pen, dash, count);
477 if (!pen || !dash || count < 2 || count%2 == 1)
478 return InvalidParameter;
480 return NotImplemented;
483 GpStatus WINGDIPAPI GdipSetPenCustomEndCap(GpPen *pen, GpCustomLineCap* customCap)
485 GpCustomLineCap * cap;
486 GpStatus ret;
488 TRACE("(%p, %p)\n", pen, customCap);
490 /* native crashes on pen == NULL, customCap != NULL */
491 if(!customCap) return InvalidParameter;
493 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
494 GdipDeleteCustomLineCap(pen->customend);
495 pen->endcap = LineCapCustom;
496 pen->customend = cap;
499 return ret;
502 GpStatus WINGDIPAPI GdipSetPenCustomStartCap(GpPen *pen, GpCustomLineCap* customCap)
504 GpCustomLineCap * cap;
505 GpStatus ret;
507 TRACE("(%p, %p)\n", pen, customCap);
509 /* native crashes on pen == NULL, customCap != NULL */
510 if(!customCap) return InvalidParameter;
512 if((ret = GdipCloneCustomLineCap(customCap, &cap)) == Ok){
513 GdipDeleteCustomLineCap(pen->customstart);
514 pen->startcap = LineCapCustom;
515 pen->customstart = cap;
518 return ret;
521 GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash,
522 INT count)
524 INT i;
525 REAL sum = 0;
527 TRACE("(%p, %p, %d)\n", pen, dash, count);
529 if(!pen || !dash)
530 return InvalidParameter;
532 if(count <= 0)
533 return OutOfMemory;
535 for(i = 0; i < count; i++){
536 sum += dash[i];
537 if(dash[i] < 0.0)
538 return InvalidParameter;
541 if(sum == 0.0 && count)
542 return InvalidParameter;
544 GdipFree(pen->dashes);
545 pen->dashes = NULL;
547 if(count > 0)
548 pen->dashes = GdipAlloc(count * sizeof(REAL));
549 if(!pen->dashes){
550 pen->numdashes = 0;
551 return OutOfMemory;
554 GdipSetPenDashStyle(pen, DashStyleCustom);
555 memcpy(pen->dashes, dash, count * sizeof(REAL));
556 pen->numdashes = count;
558 return Ok;
561 GpStatus WINGDIPAPI GdipSetPenDashCap197819(GpPen *pen, GpDashCap dashCap)
563 TRACE("(%p, %d)\n", pen, dashCap);
565 if(!pen)
566 return InvalidParameter;
568 pen->dashcap = dashCap;
570 return Ok;
573 /* FIXME: dash offset not used */
574 GpStatus WINGDIPAPI GdipSetPenDashOffset(GpPen *pen, REAL offset)
576 TRACE("(%p, %.2f)\n", pen, offset);
578 if(!pen)
579 return InvalidParameter;
581 pen->offset = offset;
583 return Ok;
586 GpStatus WINGDIPAPI GdipSetPenDashStyle(GpPen *pen, GpDashStyle dash)
588 TRACE("(%p, %d)\n", pen, dash);
590 if(!pen)
591 return InvalidParameter;
593 if(dash != DashStyleCustom){
594 GdipFree(pen->dashes);
595 pen->dashes = NULL;
596 pen->numdashes = 0;
599 pen->dash = dash;
600 pen->style &= ~(PS_ALTERNATE | PS_SOLID | PS_DASH | PS_DOT | PS_DASHDOT |
601 PS_DASHDOTDOT | PS_NULL | PS_USERSTYLE | PS_INSIDEFRAME);
602 pen->style |= gdip_to_gdi_dash(dash);
604 return Ok;
607 GpStatus WINGDIPAPI GdipSetPenEndCap(GpPen *pen, GpLineCap cap)
609 TRACE("(%p, %d)\n", pen, cap);
611 if(!pen) return InvalidParameter;
613 /* The old custom cap gets deleted even if the new style is LineCapCustom. */
614 GdipDeleteCustomLineCap(pen->customend);
615 pen->customend = NULL;
616 pen->endcap = cap;
618 return Ok;
621 /* FIXME: startcap, dashcap not used. */
622 GpStatus WINGDIPAPI GdipSetPenLineCap197819(GpPen *pen, GpLineCap start,
623 GpLineCap end, GpDashCap dash)
625 TRACE("%p, %d, %d, %d)\n", pen, start, end, dash);
627 if(!pen)
628 return InvalidParameter;
630 GdipDeleteCustomLineCap(pen->customend);
631 GdipDeleteCustomLineCap(pen->customstart);
632 pen->customend = NULL;
633 pen->customstart = NULL;
635 pen->startcap = start;
636 pen->endcap = end;
637 pen->dashcap = dash;
639 return Ok;
642 /* FIXME: Miter line joins behave a bit differently than they do in windows.
643 * Both kinds of miter joins clip if the angle is less than 11 degrees. */
644 GpStatus WINGDIPAPI GdipSetPenLineJoin(GpPen *pen, GpLineJoin join)
646 TRACE("(%p, %d)\n", pen, join);
648 if(!pen) return InvalidParameter;
650 pen->join = join;
651 pen->style &= ~(PS_JOIN_ROUND | PS_JOIN_BEVEL | PS_JOIN_MITER);
652 pen->style |= gdip_to_gdi_join(join);
654 return Ok;
657 GpStatus WINGDIPAPI GdipSetPenMiterLimit(GpPen *pen, REAL limit)
659 TRACE("(%p, %.2f)\n", pen, limit);
661 if(!pen)
662 return InvalidParameter;
664 pen->miterlimit = limit;
666 return Ok;
669 GpStatus WINGDIPAPI GdipSetPenStartCap(GpPen *pen, GpLineCap cap)
671 TRACE("(%p, %d)\n", pen, cap);
673 if(!pen) return InvalidParameter;
675 GdipDeleteCustomLineCap(pen->customstart);
676 pen->customstart = NULL;
677 pen->startcap = cap;
679 return Ok;
682 GpStatus WINGDIPAPI GdipSetPenWidth(GpPen *pen, REAL width)
684 TRACE("(%p, %.2f)\n", pen, width);
686 if(!pen) return InvalidParameter;
688 pen->width = width;
690 return Ok;
693 GpStatus WINGDIPAPI GdipSetPenMode(GpPen *pen, GpPenAlignment mode)
695 TRACE("(%p, %d)\n", pen, mode);
697 if(!pen) return InvalidParameter;
699 pen->align = mode;
701 return Ok;