/
customlinecap.c
277 lines (214 loc) · 6.35 KB
/
customlinecap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
* customlinecap.c
*
* Copyright (C) Novell, Inc. 2003-2004.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Author:
* Ravindra (rkumar@novell.com)
*
* Copyright (C) 2004 Novell, Inc. http://www.novell.com
*/
#include "customlinecap-private.h"
static GpStatus gdip_custom_linecap_setup (GpGraphics *graphics, GpCustomLineCap *cap);
static GpStatus gdip_custom_linecap_clone_cap (GpCustomLineCap *cap, GpCustomLineCap **clonedCap);
static GpStatus gdip_custom_linecap_destroy (GpCustomLineCap *cap);
/*
* we have a single copy of vtable for
* all instances of custom linecap.
*/
static CapClass vtable = { CustomLineCapTypeDefault,
gdip_custom_linecap_setup,
gdip_custom_linecap_clone_cap,
gdip_custom_linecap_destroy };
void
gdip_custom_linecap_init (GpCustomLineCap *cap, CapClass *vt)
{
cap->vtable = vt;
cap->base_cap = LineCapFlat;
cap->start_cap = LineCapFlat;
cap->end_cap = LineCapFlat;
cap->stroke_join = LineJoinMiter;
cap->base_inset = 0.0;
/* LAMESPEC: Default value is documented as 1.0, but actually it is 0.0 */
cap->width_scale = 0.0;
}
static GpCustomLineCap*
gdip_custom_linecap_new (void)
{
GpCustomLineCap *result = (GpCustomLineCap *) GdipAlloc (sizeof (GpCustomLineCap));
if (result)
gdip_custom_linecap_init (result, &vtable);
return result;
}
GpStatus
gdip_custom_linecap_clone_cap (GpCustomLineCap *cap, GpCustomLineCap **clonedCap)
{
GpCustomLineCap *newcap;
if (!cap || !clonedCap)
return InvalidParameter;
newcap = (GpCustomLineCap *) GdipAlloc (sizeof (GpCustomLineCap));
if (!newcap)
return OutOfMemory;
newcap->vtable = cap->vtable;
newcap->base_cap = cap->base_cap;
newcap->start_cap = cap->start_cap;
newcap->end_cap = cap->end_cap;
newcap->stroke_join = cap->stroke_join;
newcap->base_inset = cap->base_inset;
newcap->width_scale = cap->width_scale;
*clonedCap = newcap;
return Ok;
}
GpStatus
gdip_custom_linecap_destroy (GpCustomLineCap *cap)
{
if (!cap)
return InvalidParameter;
GdipFree (cap);
return Ok;
}
/* MonoTODO: Implement this function when cairo supports cairo_stroke_path API */
static GpStatus
gdip_custom_linecap_setup (GpGraphics *graphics, GpCustomLineCap *customCap)
{
if (!graphics || !customCap)
return InvalidParameter;
return NotImplemented;
}
/* this setup function gets called from pen */
GpStatus
gdip_linecap_setup (GpGraphics *graphics, GpCustomLineCap *customCap)
{
if (!graphics || !customCap)
return InvalidParameter;
return customCap->vtable->setup (graphics, customCap);
}
/* CustomLineCap functions */
// coverity[+alloc : arg-*4]
GpStatus
GdipCreateCustomLineCap (GpPath *fillPath, GpPath *strokePath, GpLineCap baseCap, float baseInset, GpCustomLineCap **customCap)
{
GpCustomLineCap *cap;
if ((!fillPath && !strokePath) || !customCap)
return InvalidParameter;
cap = gdip_custom_linecap_new ();
if (!cap)
return OutOfMemory;
cap->fill_path = fillPath;
cap->stroke_path = strokePath;
cap->base_cap = baseCap;
cap->base_inset = baseInset;
*customCap = cap;
return Ok;
}
GpStatus
GdipDeleteCustomLineCap (GpCustomLineCap *customCap)
{
if (!customCap)
return InvalidParameter;
return customCap->vtable->destroy (customCap);
}
GpStatus
GdipCloneCustomLineCap (GpCustomLineCap *customCap, GpCustomLineCap **clonedCap)
{
if (!customCap || !clonedCap)
return InvalidParameter;
return customCap->vtable->clone_cap (customCap, clonedCap);
}
GpStatus
GdipSetCustomLineCapStrokeCaps (GpCustomLineCap *customCap, GpLineCap startCap, GpLineCap endCap)
{
if (!customCap)
return InvalidParameter;
customCap->start_cap = startCap;
customCap->end_cap = endCap;
return Ok;
}
GpStatus
GdipGetCustomLineCapStrokeCaps (GpCustomLineCap *customCap, GpLineCap *startCap, GpLineCap *endCap)
{
if (!customCap || !startCap || !endCap)
return InvalidParameter;
*(startCap) = customCap->start_cap;
*(endCap) = customCap->end_cap;
return Ok;
}
GpStatus
GdipSetCustomLineCapStrokeJoin (GpCustomLineCap *customCap, GpLineJoin lineJoin)
{
if (!customCap)
return InvalidParameter;
customCap->stroke_join = lineJoin;
return Ok;
}
GpStatus
GdipGetCustomLineCapStrokeJoin (GpCustomLineCap *customCap, GpLineJoin *lineJoin)
{
if (!customCap || !lineJoin)
return InvalidParameter;
*(lineJoin) = customCap->stroke_join;
return Ok;
}
GpStatus
GdipSetCustomLineCapBaseCap (GpCustomLineCap *customCap, GpLineCap baseCap)
{
if (!customCap)
return InvalidParameter;
customCap->base_cap = baseCap;
return Ok;
}
GpStatus
GdipGetCustomLineCapBaseCap (GpCustomLineCap *customCap, GpLineCap *baseCap)
{
if (!customCap || !baseCap)
return InvalidParameter;
*(baseCap) = customCap->base_cap;
return Ok;
}
GpStatus
GdipSetCustomLineCapBaseInset (GpCustomLineCap *customCap, float inset)
{
if (!customCap)
return InvalidParameter;
customCap->base_inset = inset;
return Ok;
}
GpStatus
GdipGetCustomLineCapBaseInset (GpCustomLineCap *customCap, float *inset)
{
if (!customCap || !inset)
return InvalidParameter;
*(inset) = customCap->base_inset;
return Ok;
}
GpStatus
GdipSetCustomLineCapWidthScale (GpCustomLineCap *customCap, float widthScale)
{
if (!customCap)
return InvalidParameter;
customCap->width_scale = widthScale;
return Ok;
}
GpStatus
GdipGetCustomLineCapWidthScale (GpCustomLineCap *customCap, float *widthScale)
{
if (!customCap || !widthScale)
return InvalidParameter;
*(widthScale) = customCap->width_scale;
return Ok;
}