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 "include/core/SkBlendMode.h" |
9 | #include "include/core/SkMaskFilter.h" |
10 | #include "include/core/SkPaint.h" |
11 | #include "include/core/SkShader.h" |
12 | |
13 | #include "include/c/sk_paint.h" |
14 | #include "src/c/sk_types_priv.h" |
15 | |
16 | #define MAKE_FROM_TO_NAME(FROM) g_ ## FROM ## _map |
17 | |
18 | const struct { |
19 | sk_stroke_cap_t fC; |
20 | SkPaint::Cap fSK; |
21 | } MAKE_FROM_TO_NAME(sk_stroke_cap_t)[] = { |
22 | { BUTT_SK_STROKE_CAP, SkPaint::kButt_Cap }, |
23 | { ROUND_SK_STROKE_CAP, SkPaint::kRound_Cap }, |
24 | { SQUARE_SK_STROKE_CAP, SkPaint::kSquare_Cap }, |
25 | }; |
26 | |
27 | const struct { |
28 | sk_stroke_join_t fC; |
29 | SkPaint::Join fSK; |
30 | } MAKE_FROM_TO_NAME(sk_stroke_join_t)[] = { |
31 | { MITER_SK_STROKE_JOIN, SkPaint::kMiter_Join }, |
32 | { ROUND_SK_STROKE_JOIN, SkPaint::kRound_Join }, |
33 | { BEVEL_SK_STROKE_JOIN, SkPaint::kBevel_Join }, |
34 | }; |
35 | |
36 | #define CType sk_stroke_cap_t |
37 | #define SKType SkPaint::Cap |
38 | #define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_cap_t) |
39 | #include "src/c/sk_c_from_to.h" |
40 | |
41 | #define CType sk_stroke_join_t |
42 | #define SKType SkPaint::Join |
43 | #define CTypeSkTypeMap MAKE_FROM_TO_NAME(sk_stroke_join_t) |
44 | #include "src/c/sk_c_from_to.h" |
45 | |
46 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | |
48 | sk_paint_t* sk_paint_new() { return (sk_paint_t*)new SkPaint; } |
49 | |
50 | void sk_paint_delete(sk_paint_t* cpaint) { delete AsPaint(cpaint); } |
51 | |
52 | bool sk_paint_is_antialias(const sk_paint_t* cpaint) { |
53 | return AsPaint(*cpaint).isAntiAlias(); |
54 | } |
55 | |
56 | void sk_paint_set_antialias(sk_paint_t* cpaint, bool aa) { |
57 | AsPaint(cpaint)->setAntiAlias(aa); |
58 | } |
59 | |
60 | sk_color_t sk_paint_get_color(const sk_paint_t* cpaint) { |
61 | return AsPaint(*cpaint).getColor(); |
62 | } |
63 | |
64 | void sk_paint_set_color(sk_paint_t* cpaint, sk_color_t c) { |
65 | AsPaint(cpaint)->setColor(c); |
66 | } |
67 | |
68 | void sk_paint_set_shader(sk_paint_t* cpaint, sk_shader_t* cshader) { |
69 | AsPaint(cpaint)->setShader(sk_ref_sp(AsShader(cshader))); |
70 | } |
71 | |
72 | void sk_paint_set_maskfilter(sk_paint_t* cpaint, sk_maskfilter_t* cfilter) { |
73 | AsPaint(cpaint)->setMaskFilter(sk_ref_sp(AsMaskFilter(cfilter))); |
74 | } |
75 | |
76 | bool sk_paint_is_stroke(const sk_paint_t* cpaint) { |
77 | return AsPaint(*cpaint).getStyle() != SkPaint::kFill_Style; |
78 | } |
79 | |
80 | void sk_paint_set_stroke(sk_paint_t* cpaint, bool doStroke) { |
81 | AsPaint(cpaint)->setStyle(doStroke ? SkPaint::kStroke_Style : SkPaint::kFill_Style); |
82 | } |
83 | |
84 | float sk_paint_get_stroke_width(const sk_paint_t* cpaint) { |
85 | return AsPaint(*cpaint).getStrokeWidth(); |
86 | } |
87 | |
88 | void sk_paint_set_stroke_width(sk_paint_t* cpaint, float width) { |
89 | AsPaint(cpaint)->setStrokeWidth(width); |
90 | } |
91 | |
92 | float sk_paint_get_stroke_miter(const sk_paint_t* cpaint) { |
93 | return AsPaint(*cpaint).getStrokeMiter(); |
94 | } |
95 | |
96 | void sk_paint_set_stroke_miter(sk_paint_t* cpaint, float miter) { |
97 | AsPaint(cpaint)->setStrokeMiter(miter); |
98 | } |
99 | |
100 | sk_stroke_cap_t sk_paint_get_stroke_cap(const sk_paint_t* cpaint) { |
101 | sk_stroke_cap_t ccap; |
102 | if (find_c(AsPaint(*cpaint).getStrokeCap(), &ccap)) { |
103 | ccap = BUTT_SK_STROKE_CAP; |
104 | } |
105 | return ccap; |
106 | } |
107 | |
108 | void sk_paint_set_stroke_cap(sk_paint_t* cpaint, sk_stroke_cap_t ccap) { |
109 | SkPaint::Cap skcap; |
110 | if (find_sk(ccap, &skcap)) { |
111 | AsPaint(cpaint)->setStrokeCap(skcap); |
112 | } else { |
113 | // unknown ccap |
114 | } |
115 | } |
116 | |
117 | sk_stroke_join_t sk_paint_get_stroke_join(const sk_paint_t* cpaint) { |
118 | sk_stroke_join_t cjoin; |
119 | if (find_c(AsPaint(*cpaint).getStrokeJoin(), &cjoin)) { |
120 | cjoin = MITER_SK_STROKE_JOIN; |
121 | } |
122 | return cjoin; |
123 | } |
124 | |
125 | void sk_paint_set_stroke_join(sk_paint_t* cpaint, sk_stroke_join_t cjoin) { |
126 | SkPaint::Join skjoin; |
127 | if (find_sk(cjoin, &skjoin)) { |
128 | AsPaint(cpaint)->setStrokeJoin(skjoin); |
129 | } else { |
130 | // unknown cjoin |
131 | } |
132 | } |
133 | |
134 | void sk_paint_set_xfermode_mode(sk_paint_t* paint, sk_xfermode_mode_t mode) { |
135 | SkASSERT(paint); |
136 | SkBlendMode skmode; |
137 | switch (mode) { |
138 | #define MAP(X, Y) case (X): skmode = (Y); break |
139 | MAP( CLEAR_SK_XFERMODE_MODE, SkBlendMode::kClear ); |
140 | MAP( SRC_SK_XFERMODE_MODE, SkBlendMode::kSrc ); |
141 | MAP( DST_SK_XFERMODE_MODE, SkBlendMode::kDst ); |
142 | MAP( SRCOVER_SK_XFERMODE_MODE, SkBlendMode::kSrcOver ); |
143 | MAP( DSTOVER_SK_XFERMODE_MODE, SkBlendMode::kDstOver ); |
144 | MAP( SRCIN_SK_XFERMODE_MODE, SkBlendMode::kSrcIn ); |
145 | MAP( DSTIN_SK_XFERMODE_MODE, SkBlendMode::kDstIn ); |
146 | MAP( SRCOUT_SK_XFERMODE_MODE, SkBlendMode::kSrcOut ); |
147 | MAP( DSTOUT_SK_XFERMODE_MODE, SkBlendMode::kDstOut ); |
148 | MAP( SRCATOP_SK_XFERMODE_MODE, SkBlendMode::kSrcATop ); |
149 | MAP( DSTATOP_SK_XFERMODE_MODE, SkBlendMode::kDstATop ); |
150 | MAP( XOR_SK_XFERMODE_MODE, SkBlendMode::kXor ); |
151 | MAP( PLUS_SK_XFERMODE_MODE, SkBlendMode::kPlus ); |
152 | MAP( MODULATE_SK_XFERMODE_MODE, SkBlendMode::kModulate ); |
153 | MAP( SCREEN_SK_XFERMODE_MODE, SkBlendMode::kScreen ); |
154 | MAP( OVERLAY_SK_XFERMODE_MODE, SkBlendMode::kOverlay ); |
155 | MAP( DARKEN_SK_XFERMODE_MODE, SkBlendMode::kDarken ); |
156 | MAP( LIGHTEN_SK_XFERMODE_MODE, SkBlendMode::kLighten ); |
157 | MAP( COLORDODGE_SK_XFERMODE_MODE, SkBlendMode::kColorDodge ); |
158 | MAP( COLORBURN_SK_XFERMODE_MODE, SkBlendMode::kColorBurn ); |
159 | MAP( HARDLIGHT_SK_XFERMODE_MODE, SkBlendMode::kHardLight ); |
160 | MAP( SOFTLIGHT_SK_XFERMODE_MODE, SkBlendMode::kSoftLight ); |
161 | MAP( DIFFERENCE_SK_XFERMODE_MODE, SkBlendMode::kDifference ); |
162 | MAP( EXCLUSION_SK_XFERMODE_MODE, SkBlendMode::kExclusion ); |
163 | MAP( MULTIPLY_SK_XFERMODE_MODE, SkBlendMode::kMultiply ); |
164 | MAP( HUE_SK_XFERMODE_MODE, SkBlendMode::kHue ); |
165 | MAP( SATURATION_SK_XFERMODE_MODE, SkBlendMode::kSaturation ); |
166 | MAP( COLOR_SK_XFERMODE_MODE, SkBlendMode::kColor ); |
167 | MAP( LUMINOSITY_SK_XFERMODE_MODE, SkBlendMode::kLuminosity ); |
168 | #undef MAP |
169 | default: |
170 | return; |
171 | } |
172 | AsPaint(paint)->setBlendMode(skmode); |
173 | } |
174 | |