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 "sk_paint.h"
9 #include "sk_types_priv.h"
10
11 #include "SkPaint.h"
12
13 #define MAKE_FROM_TO_NAME(FROM) g_ ## FROM ## _map
14
15 const struct {
16 sk_stroke_cap_t fC;
17 SkPaint::Cap fSK;
18 } MAKE_FROM_TO_NAME(sk_stroke_cap_t)[] = {
19 { BUTT_SK_STROKE_CAP, SkPaint::kButt_Cap },
20 { ROUND_SK_STROKE_CAP, SkPaint::kRound_Cap },
21 { SQUARE_SK_STROKE_CAP, SkPaint::kSquare_Cap },
22 };
23
24 const struct {
25 sk_stroke_join_t fC;
26 SkPaint::Join fSK;
27 } MAKE_FROM_TO_NAME(sk_stroke_join_t)[] = {
28 { MITER_SK_STROKE_JOIN, SkPaint::kMiter_Join },
29 { ROUND_SK_STROKE_JOIN, SkPaint::kRound_Join },
30 { BEVEL_SK_STROKE_JOIN, SkPaint::kBevel_Join },
31 };
32
33 #define CType sk_stroke_cap_t
34 #define SKType SkPaint::Cap
35 #define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_cap_t)
36 #include "sk_c_from_to.h"
37
38 #define CType sk_stroke_join_t
39 #define SKType SkPaint::Join
40 #define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_join_t)
41 #include "sk_c_from_to.h"
42
43 //////////////////////////////////////////////////////////////////////////////////////////////////
44
sk_paint_new()45 sk_paint_t* sk_paint_new() {
46 return (sk_paint_t*)SkNEW(SkPaint);
47 }
48
sk_paint_delete(sk_paint_t * cpaint)49 void sk_paint_delete(sk_paint_t* cpaint) {
50 SkDELETE(AsPaint(cpaint));
51 }
52
sk_paint_is_antialias(const sk_paint_t * cpaint)53 bool sk_paint_is_antialias(const sk_paint_t* cpaint) {
54 return AsPaint(*cpaint).isAntiAlias();
55 }
56
sk_paint_set_antialias(sk_paint_t * cpaint,bool aa)57 void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) {
58 AsPaint(cpaint)->setAntiAlias(aa);
59 }
60
sk_paint_get_color(const sk_paint_t * cpaint)61 sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) {
62 return AsPaint(*cpaint).getColor();
63 }
64
sk_paint_set_color(sk_paint_t * cpaint,sk_color_t c)65 void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) {
66 AsPaint(cpaint)->setColor(c);
67 }
68
sk_paint_set_shader(sk_paint_t * cpaint,sk_shader_t * cshader)69 void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) {
70 AsPaint(cpaint)->setShader(AsShader(cshader));
71 }
72
sk_paint_set_maskfilter(sk_paint_t * cpaint,sk_maskfilter_t * cfilter)73 void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) {
74 AsPaint(cpaint)->setMaskFilter(AsMaskFilter(cfilter));
75 }
76
sk_paint_is_stroke(const sk_paint_t * cpaint)77 bool sk_paint_is_stroke(const sk_paint_t* cpaint) {
78 return AsPaint(*cpaint).getStyle() != SkPaint::kFill_Style;
79 }
80
sk_paint_set_stroke(sk_paint_t * cpaint,bool doStroke)81 void sk_paint_set_stroke(sk_paint_t* cpaint, bool doStroke) {
82 AsPaint(cpaint)->setStyle(doStroke ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
83 }
84
sk_paint_get_stroke_width(const sk_paint_t * cpaint)85 float sk_paint_get_stroke_width(const sk_paint_t* cpaint) {
86 return AsPaint(*cpaint).getStrokeWidth();
87 }
88
sk_paint_set_stroke_width(sk_paint_t * cpaint,float width)89 void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) {
90 AsPaint(cpaint)->setStrokeWidth(width);
91 }
92
sk_paint_get_stroke_miter(const sk_paint_t * cpaint)93 float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) {
94 return AsPaint(*cpaint).getStrokeMiter();
95 }
96
sk_paint_set_stroke_miter(sk_paint_t * cpaint,float miter)97 void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) {
98 AsPaint(cpaint)->setStrokeMiter(miter);
99 }
100
sk_paint_get_stroke_cap(const sk_paint_t * cpaint)101 sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) {
102 sk_stroke_cap_t ccap;
103 if (find_c(AsPaint(*cpaint).getStrokeCap(), &ccap)) {
104 ccap = BUTT_SK_STROKE_CAP;
105 }
106 return ccap;
107 }
108
sk_paint_set_stroke_cap(sk_paint_t * cpaint,sk_stroke_cap_t ccap)109 void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) {
110 SkPaint::Cap skcap;
111 if (find_sk(ccap, &skcap)) {
112 AsPaint(cpaint)->setStrokeCap(skcap);
113 } else {
114 // unknown ccap
115 }
116 }
117
sk_paint_get_stroke_join(const sk_paint_t * cpaint)118 sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) {
119 sk_stroke_join_t cjoin;
120 if (find_c(AsPaint(*cpaint).getStrokeJoin(), &cjoin)) {
121 cjoin = MITER_SK_STROKE_JOIN;
122 }
123 return cjoin;
124 }
125
sk_paint_set_stroke_join(sk_paint_t * cpaint,sk_stroke_join_t cjoin)126 void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) {
127 SkPaint::Join skjoin;
128 if (find_sk(cjoin, &skjoin)) {
129 AsPaint(cpaint)->setStrokeJoin(skjoin);
130 } else {
131 // unknown cjoin
132 }
133 }
134
135
136