OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSVGDevice.h" | 8 #include "SkSVGDevice.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 return SkStringPrintf("rgb(%u,%u,%u)", | 24 return SkStringPrintf("rgb(%u,%u,%u)", |
25 SkColorGetR(color), | 25 SkColorGetR(color), |
26 SkColorGetG(color), | 26 SkColorGetG(color), |
27 SkColorGetB(color)); | 27 SkColorGetB(color)); |
28 } | 28 } |
29 | 29 |
30 static SkScalar svg_opacity(SkColor color) { | 30 static SkScalar svg_opacity(SkColor color) { |
31 return SkIntToScalar(SkColorGetA(color)) / SK_AlphaOPAQUE; | 31 return SkIntToScalar(SkColorGetA(color)) / SK_AlphaOPAQUE; |
32 } | 32 } |
33 | 33 |
34 // Keep in sync with SkPaint::Cap | |
35 static const char* cap_map[] = { | |
36 "", // kButt_Cap (default) | |
37 "round", // kRound_Cap | |
38 "square" // kSquare_Cap | |
39 }; | |
40 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(cap_map) == SkPaint::kCapCount, missing_cap_map _entry); | |
41 | |
42 static SkString svg_cap(SkPaint::Cap cap) { | |
mtklein
2015/02/04 22:37:49
Why don't these just return const char* ? Seems l
reed1
2015/02/04 22:42:01
+1
f(malita)
2015/02/04 22:43:14
Done.
| |
43 SkASSERT(cap < SK_ARRAY_COUNT(cap_map)); | |
44 return SkString(cap_map[cap]); | |
45 } | |
46 | |
47 // Keep in sync with SkPaint::Join | |
48 static const char* join_map[] = { | |
49 "", // kMiter_Join (default) | |
50 "round", // kRound_Join | |
51 "bevel" // kBevel_Join | |
52 }; | |
53 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(join_map) == SkPaint::kJoinCount, missing_join_ map_entry); | |
54 | |
55 static SkString svg_join(SkPaint::Join join) { | |
56 SkASSERT(join < SK_ARRAY_COUNT(join_map)); | |
57 return SkString(join_map[join]); | |
58 } | |
59 | |
34 static void append_escaped_unichar(SkUnichar c, SkString* text) { | 60 static void append_escaped_unichar(SkUnichar c, SkString* text) { |
35 switch(c) { | 61 switch(c) { |
36 case '&': | 62 case '&': |
37 text->append("&"); | 63 text->append("&"); |
38 break; | 64 break; |
39 case '"': | 65 case '"': |
40 text->append("""); | 66 text->append("""); |
41 break; | 67 break; |
42 case '\'': | 68 case '\'': |
43 text->append("'"); | 69 text->append("'"); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 SkString addLinearGradientDef(const SkShader::GradientInfo& info, const SkSh ader* shader); | 210 SkString addLinearGradientDef(const SkShader::GradientInfo& info, const SkSh ader* shader); |
185 | 211 |
186 SkXMLWriter* fWriter; | 212 SkXMLWriter* fWriter; |
187 ResourceBucket* fResourceBucket; | 213 ResourceBucket* fResourceBucket; |
188 }; | 214 }; |
189 | 215 |
190 void SkSVGDevice::AutoElement::addPaint(const SkPaint& paint, const Resources& r esources) { | 216 void SkSVGDevice::AutoElement::addPaint(const SkPaint& paint, const Resources& r esources) { |
191 SkPaint::Style style = paint.getStyle(); | 217 SkPaint::Style style = paint.getStyle(); |
192 if (style == SkPaint::kFill_Style || style == SkPaint::kStrokeAndFill_Style) { | 218 if (style == SkPaint::kFill_Style || style == SkPaint::kStrokeAndFill_Style) { |
193 this->addAttribute("fill", resources.fPaintServer); | 219 this->addAttribute("fill", resources.fPaintServer); |
220 | |
221 if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { | |
222 this->addAttribute("fill-opacity", svg_opacity(paint.getColor())); | |
223 } | |
194 } else { | 224 } else { |
195 this->addAttribute("fill", "none"); | 225 this->addAttribute("fill", "none"); |
mtklein
2015/02/04 22:37:49
Can we assert kStroke_Style here?
f(malita)
2015/02/04 22:43:14
Done.
| |
196 } | 226 } |
197 | 227 |
198 if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Styl e) { | 228 if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Styl e) { |
199 this->addAttribute("stroke", resources.fPaintServer); | 229 this->addAttribute("stroke", resources.fPaintServer); |
200 this->addAttribute("stroke-width", paint.getStrokeWidth()); | 230 |
231 SkScalar strokeWidth = paint.getStrokeWidth(); | |
232 if (strokeWidth == 0) { | |
233 // Hairline stroke | |
234 strokeWidth = 1; | |
235 this->addAttribute("vector-effect", "non-scaling-stroke"); | |
236 } | |
237 this->addAttribute("stroke-width", strokeWidth); | |
238 | |
239 SkString cap = svg_cap(paint.getStrokeCap()); | |
240 if (!cap.isEmpty()) { | |
241 this->addAttribute("stroke-linecap", cap); | |
242 } | |
243 | |
244 SkString join = svg_join(paint.getStrokeJoin()); | |
245 if (!join.isEmpty()) { | |
246 this->addAttribute("stroke-linejoin", join); | |
247 } | |
248 | |
249 if (paint.getStrokeJoin() == SkPaint::kMiter_Join) { | |
250 this->addAttribute("stroke-miterlimit", paint.getStrokeMiter()); | |
251 } | |
252 | |
253 if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { | |
254 this->addAttribute("stroke-opacity", svg_opacity(paint.getColor())); | |
255 } | |
201 } else { | 256 } else { |
202 this->addAttribute("stroke", "none"); | 257 this->addAttribute("stroke", "none"); |
mtklein
2015/02/04 22:37:49
And kFill_Style here?
| |
203 } | 258 } |
204 | 259 |
205 if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { | |
206 this->addAttribute("opacity", svg_opacity(paint.getColor())); | |
207 } | |
208 | |
209 if (!resources.fClip.isEmpty()) { | 260 if (!resources.fClip.isEmpty()) { |
210 this->addAttribute("clip-path", resources.fClip); | 261 this->addAttribute("clip-path", resources.fClip); |
211 } | 262 } |
212 } | 263 } |
213 | 264 |
214 void SkSVGDevice::AutoElement::addTransform(const SkMatrix& t, const char name[] ) { | 265 void SkSVGDevice::AutoElement::addTransform(const SkMatrix& t, const char name[] ) { |
215 if (t.isIdentity()) { | 266 if (t.isIdentity()) { |
216 return; | 267 return; |
217 } | 268 } |
218 | 269 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 const SkPaint& paint) { | 584 const SkPaint& paint) { |
534 // todo | 585 // todo |
535 SkDebugf("unsupported operation: drawVertices()\n"); | 586 SkDebugf("unsupported operation: drawVertices()\n"); |
536 } | 587 } |
537 | 588 |
538 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | 589 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
539 const SkPaint&) { | 590 const SkPaint&) { |
540 // todo | 591 // todo |
541 SkDebugf("unsupported operation: drawDevice()\n"); | 592 SkDebugf("unsupported operation: drawDevice()\n"); |
542 } | 593 } |
OLD | NEW |