gdiplus: Added rendering of fill-path type custom line caps.
[wine] / dlls / gdiplus / customlinecap.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
24 #include "gdiplus.h"
25 #include "gdiplus_private.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
29
30 GpStatus WINGDIPAPI GdipCloneCustomLineCap(GpCustomLineCap* from,
31     GpCustomLineCap** to)
32 {
33     if(!from || !to)
34         return InvalidParameter;
35
36     *to = GdipAlloc(sizeof(GpCustomLineCap));
37     if(!*to)   return OutOfMemory;
38
39     memcpy(*to, from, sizeof(GpCustomLineCap));
40
41     (*to)->pathdata.Points = GdipAlloc(from->pathdata.Count * sizeof(PointF));
42     (*to)->pathdata.Types = GdipAlloc(from->pathdata.Count);
43
44     if((!(*to)->pathdata.Types  || !(*to)->pathdata.Points) && (*to)->pathdata.Count){
45         GdipFree((*to)->pathdata.Points);
46         GdipFree((*to)->pathdata.Types);
47         GdipFree(*to);
48         return OutOfMemory;
49     }
50
51     memcpy((*to)->pathdata.Points, from->pathdata.Points, from->pathdata.Count
52            * sizeof(PointF));
53     memcpy((*to)->pathdata.Types, from->pathdata.Types, from->pathdata.Count);
54
55     return Ok;
56 }
57
58 /* FIXME: Sometimes when fillPath is non-null and stroke path is null, the native
59  * version of this function returns NotImplemented. I cannot figure out why. */
60 GpStatus WINGDIPAPI GdipCreateCustomLineCap(GpPath* fillPath, GpPath* strokePath,
61     GpLineCap baseCap, REAL baseInset, GpCustomLineCap **customCap)
62 {
63     GpPathData *pathdata;
64
65     TRACE("%p %p %d %f %p\n", fillPath, strokePath, baseCap, baseInset, customCap);
66
67     if(!customCap || !(fillPath || strokePath))
68         return InvalidParameter;
69
70     *customCap = GdipAlloc(sizeof(GpCustomLineCap));
71     if(!*customCap)    return OutOfMemory;
72
73     if(strokePath){
74         (*customCap)->fill = FALSE;
75         pathdata = &strokePath->pathdata;
76     }
77     else{
78         (*customCap)->fill = TRUE;
79         pathdata = &fillPath->pathdata;
80     }
81
82     (*customCap)->pathdata.Points = GdipAlloc(pathdata->Count * sizeof(PointF));
83     (*customCap)->pathdata.Types = GdipAlloc(pathdata->Count);
84
85     if((!(*customCap)->pathdata.Types || !(*customCap)->pathdata.Points) &&
86         pathdata->Count){
87         GdipFree((*customCap)->pathdata.Points);
88         GdipFree((*customCap)->pathdata.Types);
89         GdipFree(*customCap);
90         return OutOfMemory;
91     }
92
93     memcpy((*customCap)->pathdata.Points, pathdata->Points, pathdata->Count
94            * sizeof(PointF));
95     memcpy((*customCap)->pathdata.Types, pathdata->Types, pathdata->Count);
96     (*customCap)->pathdata.Count = pathdata->Count;
97
98     (*customCap)->inset = baseInset;
99     (*customCap)->cap = baseCap;
100
101     return Ok;
102 }
103
104 GpStatus WINGDIPAPI GdipDeleteCustomLineCap(GpCustomLineCap *customCap)
105 {
106     if(!customCap)
107         return InvalidParameter;
108
109     GdipFree(customCap->pathdata.Points);
110     GdipFree(customCap->pathdata.Types);
111     GdipFree(customCap);
112
113     return Ok;
114 }