Merge from google/chrome/m55
[platform/upstream/libSkiaSharp.git] / src / c / sk_paint.cpp
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "SkColorFilter.h"
9 #include "SkMaskFilter.h"
10 #include "SkPaint.h"
11 #include "SkShader.h"
12 #include "SkTypeface.h"
13
14 #include "sk_paint.h"
15
16 #include "sk_types_priv.h"
17
18 //////////////////////////////////////////////////////////////////////////////////////////////////
19
20 sk_paint_t* sk_paint_new() { return (sk_paint_t*)new SkPaint; }
21
22 void sk_paint_delete(sk_paint_t* cpaint) { delete AsPaint(cpaint); }
23
24 bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
25     return AsPaint(*cpaint).isAntiAlias();
26 }
27
28 void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
29     AsPaint(cpaint)->setAntiAlias(aa);
30 }
31
32 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
33     return AsPaint(*cpaint).getColor();
34 }
35
36 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
37     AsPaint(cpaint)->setColor(c);
38 }
39
40 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
41     AsPaint(cpaint)->setShader(sk_ref_sp(AsShader(cshader)));
42 }
43
44 void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
45     AsPaint(cpaint)->setMaskFilter(sk_ref_sp(AsMaskFilter(cfilter)));
46 }
47
48 sk_paint_style_t sk_paint_get_style(const sk_paint_t* cpaint) {
49     return (sk_paint_style_t)AsPaint(*cpaint).getStyle();
50 }
51
52 void sk_paint_set_style(sk_paint_t* cpaint, sk_paint_style_t style) {
53     AsPaint(cpaint)->setStyle((SkPaint::Style)style);
54 }
55
56 float sk_paint_get_stroke_width(const sk_paint_t* cpaint) {
57     return AsPaint(*cpaint).getStrokeWidth();
58 }
59
60 void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) {
61     AsPaint(cpaint)->setStrokeWidth(width);
62 }
63
64 float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) {
65     return AsPaint(*cpaint).getStrokeMiter();
66 }
67
68 void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) {
69     AsPaint(cpaint)->setStrokeMiter(miter);
70 }
71
72 sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) {
73     return (sk_stroke_cap_t)AsPaint(*cpaint).getStrokeCap();
74 }
75
76 void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) {
77     AsPaint(cpaint)->setStrokeCap((SkPaint::Cap)ccap);
78 }
79
80 sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) {
81     return (sk_stroke_join_t)AsPaint(*cpaint).getStrokeJoin();
82 }
83
84 void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
85     AsPaint(cpaint)->setStrokeJoin((SkPaint::Join)cjoin);
86 }
87
88 void sk_paint_set_xfermode_mode(sk_paint_t* paint, sk_xfermode_mode_t mode) {
89     SkASSERT(paint);
90     AsPaint(paint)->setXfermodeMode((SkXfermode::Mode)mode);
91 }
92
93 bool sk_paint_is_dither(const sk_paint_t* cpaint) {
94     return AsPaint(*cpaint).isDither();
95 }
96
97 void sk_paint_set_dither(sk_paint_t* cpaint, bool isdither) {
98     AsPaint(cpaint)->setDither(isdither);
99 }
100
101 bool sk_paint_is_verticaltext(const sk_paint_t* cpaint) {
102     return AsPaint(*cpaint).isVerticalText();
103 }
104
105 void sk_paint_set_verticaltext(sk_paint_t* cpaint, bool vt) {
106     AsPaint(cpaint)->setVerticalText(vt);
107 }
108
109 sk_shader_t* sk_paint_get_shader(sk_paint_t* cpaint) {
110     return ToShader(AsPaint(cpaint)->getShader());
111 }
112
113 sk_maskfilter_t* sk_paint_get_maskfilter(sk_paint_t* cpaint) {
114     return ToMaskFilter(AsPaint(cpaint)->getMaskFilter());
115 }
116
117 void sk_paint_set_colorfilter(sk_paint_t* cpaint, sk_colorfilter_t* cfilter) {
118     AsPaint(cpaint)->setColorFilter(sk_ref_sp(AsColorFilter(cfilter)));
119 }
120
121 sk_colorfilter_t* sk_paint_get_colorfilter(sk_paint_t* cpaint) {
122     return ToColorFilter(AsPaint(cpaint)->getColorFilter());
123 }
124
125 void sk_paint_set_imagefilter(sk_paint_t* cpaint, sk_imagefilter_t* cfilter) {
126     AsPaint(cpaint)->setImageFilter(AsImageFilter(cfilter));
127 }
128
129 sk_imagefilter_t* sk_paint_get_imagefilter(sk_paint_t* cpaint) {
130     return ToImageFilter(AsPaint(cpaint)->getImageFilter());
131 }
132
133 sk_xfermode_mode_t sk_paint_get_xfermode_mode(sk_paint_t* paint) {
134     SkASSERT(paint);
135     SkXfermode::Mode mode;
136     if (SkXfermode::AsMode(AsPaint(paint)->getXfermode(), &mode)) {
137         return (sk_xfermode_mode_t)mode;
138     }
139     return SRCOVER_SK_XFERMODE_MODE;
140 }
141
142 void sk_paint_set_filter_quality(sk_paint_t* cpaint, sk_filter_quality_t filterQuality)
143 {
144     SkASSERT(cpaint);
145     AsPaint(cpaint)->setFilterQuality((SkFilterQuality)filterQuality);
146 }
147
148 sk_filter_quality_t sk_paint_get_filter_quality(sk_paint_t* cpaint)
149 {
150     SkASSERT(cpaint);
151     return (sk_filter_quality_t)AsPaint(cpaint)->getFilterQuality();
152 }
153
154 sk_typeface_t* sk_paint_get_typeface(sk_paint_t* paint)
155 {
156     return ToTypeface(AsPaint(paint)->getTypeface());
157 }
158
159 void sk_paint_set_typeface(sk_paint_t* paint, sk_typeface_t* typeface)
160 {
161     AsPaint(paint)->setTypeface(sk_ref_sp(AsTypeface(typeface)));
162 }
163
164 float sk_paint_get_textsize(sk_paint_t* paint)
165 {
166     return AsPaint(paint)->getTextSize();
167 }
168
169 void sk_paint_set_textsize(sk_paint_t* paint, float size)
170 {
171     AsPaint(paint)->setTextSize(size);
172 }
173
174 sk_text_align_t sk_paint_get_text_align(const sk_paint_t* cpaint) {
175     return (sk_text_align_t)AsPaint(*cpaint).getTextAlign();
176 }
177
178 void sk_paint_set_text_align(sk_paint_t* cpaint, sk_text_align_t calign) {
179     AsPaint(cpaint)->setTextAlign((SkPaint::Align)calign);
180 }
181
182 sk_text_encoding_t sk_paint_get_text_encoding(const sk_paint_t* cpaint) {
183     return (sk_text_encoding_t)AsPaint(*cpaint).getTextEncoding();
184 }
185
186 void sk_paint_set_text_encoding(sk_paint_t* cpaint, sk_text_encoding_t cencoding) {
187     AsPaint(cpaint)->setTextEncoding((SkPaint::TextEncoding)cencoding);
188 }
189
190 float sk_paint_get_text_scale_x(const sk_paint_t* cpaint) {
191     return AsPaint(cpaint)->getTextScaleX();
192 }
193
194 void sk_paint_set_text_scale_x(sk_paint_t* cpaint, float scale) {
195     AsPaint(cpaint)->setTextScaleX(scale);
196 }
197
198 float sk_paint_get_text_skew_x(const sk_paint_t* cpaint) {
199     return AsPaint(cpaint)->getTextSkewX();
200 }
201
202 void sk_paint_set_text_skew_x(sk_paint_t* cpaint, float skew) {
203     AsPaint(cpaint)->setTextSkewX(skew);
204 }
205
206 size_t sk_paint_break_text(const sk_paint_t* cpaint, const void* text, size_t length, float maxWidth, float* measuredWidth) {
207     return AsPaint(cpaint)->breakText(text, length, maxWidth, measuredWidth);
208 }
209
210 float sk_paint_measure_text(const sk_paint_t* cpaint, const void* text, size_t length, sk_rect_t* bounds) {
211     return AsPaint(cpaint)->measureText(text, length, AsRect(bounds));
212 }
213
214 sk_path_t* sk_paint_get_text_path(sk_paint_t* cpaint, const void* text, size_t length, float x, float y) {
215     SkPath* path = new SkPath();
216     AsPaint(cpaint)->getTextPath(text, length, x, y, path);
217     return ToPath(path);
218 }
219
220 sk_path_t* sk_paint_get_pos_text_path(sk_paint_t* cpaint, const void* text, size_t length, const sk_point_t pos[]) {
221     SkPath* path = new SkPath();
222     AsPaint(cpaint)->getPosTextPath(text, length, reinterpret_cast<const SkPoint*>(pos), path);
223     return ToPath(path);
224 }
225
226 float sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetrics, float scale)
227 {
228     SkPaint *paint = AsPaint(cpaint);
229     return paint->getFontMetrics(AsFontMetrics(cfontmetrics), scale);
230 }
231
232 sk_path_effect_t* sk_paint_get_path_effect(sk_paint_t* cpaint) {
233     return ToPathEffect(AsPaint(cpaint)->getPathEffect());
234 }
235
236 void sk_paint_set_path_effect(sk_paint_t* cpaint, sk_path_effect_t* effect) {
237     AsPaint(cpaint)->setPathEffect(sk_ref_sp(AsPathEffect(effect)));
238 }
239
240 bool sk_paint_is_linear_text(const sk_paint_t* cpaint) {
241     return AsPaint(cpaint)->isLinearText();
242 }
243
244 void sk_paint_set_linear_text(sk_paint_t* cpaint, bool linearText) {
245     AsPaint(cpaint)->setLinearText(linearText);
246 }
247
248 bool sk_paint_is_subpixel_text(const sk_paint_t* cpaint) {
249     return AsPaint(cpaint)->isSubpixelText();
250 }
251
252 void sk_paint_set_subpixel_text(sk_paint_t* cpaint, bool subpixelText) {
253     AsPaint(cpaint)->setSubpixelText(subpixelText);
254 }
255
256 bool sk_paint_is_lcd_render_text(const sk_paint_t* cpaint) {
257     return AsPaint(cpaint)->isLCDRenderText();
258 }
259
260 void sk_paint_set_lcd_render_text(sk_paint_t* cpaint, bool lcdText) {
261     AsPaint(cpaint)->setLCDRenderText(lcdText);
262 }
263
264 bool sk_paint_is_embedded_bitmap_text(const sk_paint_t* cpaint) {
265     return AsPaint(cpaint)->isEmbeddedBitmapText();
266 }
267
268 void sk_paint_set_embedded_bitmap_text(sk_paint_t* cpaint, bool useEmbeddedBitmapText) {
269     AsPaint(cpaint)->setEmbeddedBitmapText(useEmbeddedBitmapText);
270 }
271
272 bool sk_paint_is_autohinted(const sk_paint_t* cpaint) {
273     return AsPaint(cpaint)->isAutohinted();
274 }
275
276 void sk_paint_set_autohinted(sk_paint_t* cpaint, bool useAutohinter) {
277     AsPaint(cpaint)->setAutohinted(useAutohinter);
278 }
279
280 sk_paint_hinting_t sk_paint_get_hinting(const sk_paint_t* cpaint) {
281     return (sk_paint_hinting_t) AsPaint(cpaint)->getHinting();
282 }
283
284 void sk_paint_set_hinting(sk_paint_t* cpaint, sk_paint_hinting_t hintingLevel) {
285     AsPaint(cpaint)->setHinting((SkPaint::Hinting)hintingLevel);
286 }
287
288 bool sk_paint_is_underline_text(const sk_paint_t* cpaint) {
289     return AsPaint(cpaint)->isUnderlineText();
290 }
291
292 void sk_paint_set_underline_text(sk_paint_t* cpaint, bool underlineText) {
293     AsPaint(cpaint)->setUnderlineText(underlineText);
294 }
295
296 bool sk_paint_is_strikethru_text(const sk_paint_t* cpaint) {
297     return AsPaint(cpaint)->isStrikeThruText();
298 }
299
300 void sk_paint_set_strikethru_text(sk_paint_t* cpaint, bool strikeThruText) {
301     AsPaint(cpaint)->setStrikeThruText(strikeThruText);
302 }
303
304 bool sk_paint_is_fake_bold_text(const sk_paint_t* cpaint) {
305     return AsPaint(cpaint)->isFakeBoldText();
306 }
307
308 void sk_paint_set_fake_bold_text(sk_paint_t* cpaint, bool fakeBoldText) {
309     AsPaint(cpaint)->setFakeBoldText(fakeBoldText);
310 }
311
312 bool sk_paint_is_dev_kern_text(const sk_paint_t* cpaint) {
313     return AsPaint(cpaint)->isDevKernText();
314 }
315
316 void sk_paint_set_dev_kern_text(sk_paint_t* cpaint, bool devKernText) {
317     AsPaint(cpaint)->setDevKernText(devKernText);
318 }