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 NULL, // 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 const char* svg_cap(SkPaint::Cap cap) { | |
43 SkASSERT(cap < SK_ARRAY_COUNT(cap_map)); | |
44 return cap_map[cap]; | |
45 } | |
46 | |
47 // Keep in sync with SkPaint::Join | |
48 static const char* join_map[] = { | |
49 NULL, // 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 const char* svg_join(SkPaint::Join join) { | |
56 SkASSERT(join < SK_ARRAY_COUNT(join_map)); | |
57 return 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 { |
225 SkASSERT(style == SkPaint::kStroke_Style); | |
195 this->addAttribute("fill", "none"); | 226 this->addAttribute("fill", "none"); |
196 } | 227 } |
197 | 228 |
198 if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Styl e) { | 229 if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Styl e) { |
199 this->addAttribute("stroke", resources.fPaintServer); | 230 this->addAttribute("stroke", resources.fPaintServer); |
200 this->addAttribute("stroke-width", paint.getStrokeWidth()); | 231 |
232 SkScalar strokeWidth = paint.getStrokeWidth(); | |
233 if (strokeWidth == 0) { | |
234 // Hairline stroke | |
235 strokeWidth = 1; | |
236 this->addAttribute("vector-effect", "non-scaling-stroke"); | |
237 } | |
238 this->addAttribute("stroke-width", strokeWidth); | |
239 | |
240 const char* cap = svg_cap(paint.getStrokeCap()); | |
241 if (SkToBool(cap)) { | |
mtklein
2015/02/04 22:46:35
If you're feeling frisky, these can be
if (const
f(malita)
2015/02/04 22:50:51
Done.
| |
242 this->addAttribute("stroke-linecap", cap); | |
243 } | |
244 | |
245 const char* join = svg_join(paint.getStrokeJoin()); | |
246 if (SkToBool(join)) { | |
247 this->addAttribute("stroke-linejoin", join); | |
248 } | |
249 | |
250 if (paint.getStrokeJoin() == SkPaint::kMiter_Join) { | |
251 this->addAttribute("stroke-miterlimit", paint.getStrokeMiter()); | |
252 } | |
253 | |
254 if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { | |
255 this->addAttribute("stroke-opacity", svg_opacity(paint.getColor())); | |
256 } | |
201 } else { | 257 } else { |
258 SkASSERT(style == SkPaint::kFill_Style); | |
mtklein
2015/02/04 22:46:35
May be a stray space here?
f(malita)
2015/02/04 22:50:51
Done.
| |
202 this->addAttribute("stroke", "none"); | 259 this->addAttribute("stroke", "none"); |
203 } | 260 } |
204 | 261 |
205 if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { | |
206 this->addAttribute("opacity", svg_opacity(paint.getColor())); | |
207 } | |
208 | |
209 if (!resources.fClip.isEmpty()) { | 262 if (!resources.fClip.isEmpty()) { |
210 this->addAttribute("clip-path", resources.fClip); | 263 this->addAttribute("clip-path", resources.fClip); |
211 } | 264 } |
212 } | 265 } |
213 | 266 |
214 void SkSVGDevice::AutoElement::addTransform(const SkMatrix& t, const char name[] ) { | 267 void SkSVGDevice::AutoElement::addTransform(const SkMatrix& t, const char name[] ) { |
215 if (t.isIdentity()) { | 268 if (t.isIdentity()) { |
216 return; | 269 return; |
217 } | 270 } |
218 | 271 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 const SkPaint& paint) { | 586 const SkPaint& paint) { |
534 // todo | 587 // todo |
535 SkDebugf("unsupported operation: drawVertices()\n"); | 588 SkDebugf("unsupported operation: drawVertices()\n"); |
536 } | 589 } |
537 | 590 |
538 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | 591 void SkSVGDevice::drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
539 const SkPaint&) { | 592 const SkPaint&) { |
540 // todo | 593 // todo |
541 SkDebugf("unsupported operation: drawDevice()\n"); | 594 SkDebugf("unsupported operation: drawDevice()\n"); |
542 } | 595 } |
OLD | NEW |