2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkColorFilter.h"
9 #include "SkMaskFilter.h"
12 #include "SkTypeface.h"
16 #include "sk_types_priv.h"
18 //////////////////////////////////////////////////////////////////////////////////////////////////
20 sk_paint_t* sk_paint_new() { return (sk_paint_t*)new SkPaint; }
22 void sk_paint_delete(sk_paint_t* cpaint) { delete AsPaint(cpaint); }
24 bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
25 return AsPaint(*cpaint).isAntiAlias();
28 void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
29 AsPaint(cpaint)->setAntiAlias(aa);
32 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
33 return AsPaint(*cpaint).getColor();
36 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
37 AsPaint(cpaint)->setColor(c);
40 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
41 AsPaint(cpaint)->setShader(sk_ref_sp(AsShader(cshader)));
44 void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
45 AsPaint(cpaint)->setMaskFilter(sk_ref_sp(AsMaskFilter(cfilter)));
48 sk_paint_style_t sk_paint_get_style(const sk_paint_t* cpaint) {
49 return (sk_paint_style_t)AsPaint(*cpaint).getStyle();
52 void sk_paint_set_style(sk_paint_t* cpaint, sk_paint_style_t style) {
53 AsPaint(cpaint)->setStyle((SkPaint::Style)style);
56 float sk_paint_get_stroke_width(const sk_paint_t* cpaint) {
57 return AsPaint(*cpaint).getStrokeWidth();
60 void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) {
61 AsPaint(cpaint)->setStrokeWidth(width);
64 float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) {
65 return AsPaint(*cpaint).getStrokeMiter();
68 void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) {
69 AsPaint(cpaint)->setStrokeMiter(miter);
72 sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) {
73 return (sk_stroke_cap_t)AsPaint(*cpaint).getStrokeCap();
76 void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) {
77 AsPaint(cpaint)->setStrokeCap((SkPaint::Cap)ccap);
80 sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) {
81 return (sk_stroke_join_t)AsPaint(*cpaint).getStrokeJoin();
84 void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
85 AsPaint(cpaint)->setStrokeJoin((SkPaint::Join)cjoin);
88 void sk_paint_set_xfermode_mode(sk_paint_t* paint, sk_xfermode_mode_t mode) {
90 AsPaint(paint)->setXfermodeMode((SkXfermode::Mode)mode);
93 bool sk_paint_is_dither(const sk_paint_t* cpaint) {
94 return AsPaint(*cpaint).isDither();
97 void sk_paint_set_dither(sk_paint_t* cpaint, bool isdither) {
98 AsPaint(cpaint)->setDither(isdither);
101 bool sk_paint_is_verticaltext(const sk_paint_t* cpaint) {
102 return AsPaint(*cpaint).isVerticalText();
105 void sk_paint_set_verticaltext(sk_paint_t* cpaint, bool vt) {
106 AsPaint(cpaint)->setVerticalText(vt);
109 sk_shader_t* sk_paint_get_shader(sk_paint_t* cpaint) {
110 return ToShader(AsPaint(cpaint)->getShader());
113 sk_maskfilter_t* sk_paint_get_maskfilter(sk_paint_t* cpaint) {
114 return ToMaskFilter(AsPaint(cpaint)->getMaskFilter());
117 void sk_paint_set_colorfilter(sk_paint_t* cpaint, sk_colorfilter_t* cfilter) {
118 AsPaint(cpaint)->setColorFilter(sk_ref_sp(AsColorFilter(cfilter)));
121 sk_colorfilter_t* sk_paint_get_colorfilter(sk_paint_t* cpaint) {
122 return ToColorFilter(AsPaint(cpaint)->getColorFilter());
125 void sk_paint_set_imagefilter(sk_paint_t* cpaint, sk_imagefilter_t* cfilter) {
126 AsPaint(cpaint)->setImageFilter(AsImageFilter(cfilter));
129 sk_imagefilter_t* sk_paint_get_imagefilter(sk_paint_t* cpaint) {
130 return ToImageFilter(AsPaint(cpaint)->getImageFilter());
133 sk_xfermode_mode_t sk_paint_get_xfermode_mode(sk_paint_t* paint) {
135 SkXfermode::Mode mode;
136 if (SkXfermode::AsMode(AsPaint(paint)->getXfermode(), &mode)) {
137 return (sk_xfermode_mode_t)mode;
139 return SRCOVER_SK_XFERMODE_MODE;
142 void sk_paint_set_filter_quality(sk_paint_t* cpaint, sk_filter_quality_t filterQuality)
145 AsPaint(cpaint)->setFilterQuality((SkFilterQuality)filterQuality);
148 sk_filter_quality_t sk_paint_get_filter_quality(sk_paint_t* cpaint)
151 return (sk_filter_quality_t)AsPaint(cpaint)->getFilterQuality();
154 sk_typeface_t* sk_paint_get_typeface(sk_paint_t* paint)
156 return ToTypeface(AsPaint(paint)->getTypeface());
159 void sk_paint_set_typeface(sk_paint_t* paint, sk_typeface_t* typeface)
161 AsPaint(paint)->setTypeface(sk_ref_sp(AsTypeface(typeface)));
164 float sk_paint_get_textsize(sk_paint_t* paint)
166 return AsPaint(paint)->getTextSize();
169 void sk_paint_set_textsize(sk_paint_t* paint, float size)
171 AsPaint(paint)->setTextSize(size);
174 sk_text_align_t sk_paint_get_text_align(const sk_paint_t* cpaint) {
175 return (sk_text_align_t)AsPaint(*cpaint).getTextAlign();
178 void sk_paint_set_text_align(sk_paint_t* cpaint, sk_text_align_t calign) {
179 AsPaint(cpaint)->setTextAlign((SkPaint::Align)calign);
182 sk_text_encoding_t sk_paint_get_text_encoding(const sk_paint_t* cpaint) {
183 return (sk_text_encoding_t)AsPaint(*cpaint).getTextEncoding();
186 void sk_paint_set_text_encoding(sk_paint_t* cpaint, sk_text_encoding_t cencoding) {
187 AsPaint(cpaint)->setTextEncoding((SkPaint::TextEncoding)cencoding);
190 float sk_paint_get_text_scale_x(const sk_paint_t* cpaint) {
191 return AsPaint(cpaint)->getTextScaleX();
194 void sk_paint_set_text_scale_x(sk_paint_t* cpaint, float scale) {
195 AsPaint(cpaint)->setTextScaleX(scale);
198 float sk_paint_get_text_skew_x(const sk_paint_t* cpaint) {
199 return AsPaint(cpaint)->getTextSkewX();
202 void sk_paint_set_text_skew_x(sk_paint_t* cpaint, float skew) {
203 AsPaint(cpaint)->setTextSkewX(skew);
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);
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));
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);
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);
226 float sk_paint_get_fontmetrics(sk_paint_t* cpaint, sk_fontmetrics_t* cfontmetrics, float scale)
228 SkPaint *paint = AsPaint(cpaint);
229 return paint->getFontMetrics(AsFontMetrics(cfontmetrics), scale);
232 sk_path_effect_t* sk_paint_get_path_effect(sk_paint_t* cpaint) {
233 return ToPathEffect(AsPaint(cpaint)->getPathEffect());
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)));
240 bool sk_paint_is_linear_text(const sk_paint_t* cpaint) {
241 return AsPaint(cpaint)->isLinearText();
244 void sk_paint_set_linear_text(sk_paint_t* cpaint, bool linearText) {
245 AsPaint(cpaint)->setLinearText(linearText);
248 bool sk_paint_is_subpixel_text(const sk_paint_t* cpaint) {
249 return AsPaint(cpaint)->isSubpixelText();
252 void sk_paint_set_subpixel_text(sk_paint_t* cpaint, bool subpixelText) {
253 AsPaint(cpaint)->setSubpixelText(subpixelText);
256 bool sk_paint_is_lcd_render_text(const sk_paint_t* cpaint) {
257 return AsPaint(cpaint)->isLCDRenderText();
260 void sk_paint_set_lcd_render_text(sk_paint_t* cpaint, bool lcdText) {
261 AsPaint(cpaint)->setLCDRenderText(lcdText);
264 bool sk_paint_is_embedded_bitmap_text(const sk_paint_t* cpaint) {
265 return AsPaint(cpaint)->isEmbeddedBitmapText();
268 void sk_paint_set_embedded_bitmap_text(sk_paint_t* cpaint, bool useEmbeddedBitmapText) {
269 AsPaint(cpaint)->setEmbeddedBitmapText(useEmbeddedBitmapText);
272 bool sk_paint_is_autohinted(const sk_paint_t* cpaint) {
273 return AsPaint(cpaint)->isAutohinted();
276 void sk_paint_set_autohinted(sk_paint_t* cpaint, bool useAutohinter) {
277 AsPaint(cpaint)->setAutohinted(useAutohinter);
280 sk_paint_hinting_t sk_paint_get_hinting(const sk_paint_t* cpaint) {
281 return (sk_paint_hinting_t) AsPaint(cpaint)->getHinting();
284 void sk_paint_set_hinting(sk_paint_t* cpaint, sk_paint_hinting_t hintingLevel) {
285 AsPaint(cpaint)->setHinting((SkPaint::Hinting)hintingLevel);
288 bool sk_paint_is_underline_text(const sk_paint_t* cpaint) {
289 return AsPaint(cpaint)->isUnderlineText();
292 void sk_paint_set_underline_text(sk_paint_t* cpaint, bool underlineText) {
293 AsPaint(cpaint)->setUnderlineText(underlineText);
296 bool sk_paint_is_strikethru_text(const sk_paint_t* cpaint) {
297 return AsPaint(cpaint)->isStrikeThruText();
300 void sk_paint_set_strikethru_text(sk_paint_t* cpaint, bool strikeThruText) {
301 AsPaint(cpaint)->setStrikeThruText(strikeThruText);
304 bool sk_paint_is_fake_bold_text(const sk_paint_t* cpaint) {
305 return AsPaint(cpaint)->isFakeBoldText();
308 void sk_paint_set_fake_bold_text(sk_paint_t* cpaint, bool fakeBoldText) {
309 AsPaint(cpaint)->setFakeBoldText(fakeBoldText);
312 bool sk_paint_is_dev_kern_text(const sk_paint_t* cpaint) {
313 return AsPaint(cpaint)->isDevKernText();
316 void sk_paint_set_dev_kern_text(sk_paint_t* cpaint, bool devKernText) {
317 AsPaint(cpaint)->setDevKernText(devKernText);