Chromium Code Reviews| Index: experimental/svg/SkSVGDevice.cpp |
| diff --git a/experimental/svg/SkSVGDevice.cpp b/experimental/svg/SkSVGDevice.cpp |
| index 9f4a54a8a8b5f4821be7467548d86de008654f27..3c861f3730f720ebf43a4712677f1ad386ed9216 100644 |
| --- a/experimental/svg/SkSVGDevice.cpp |
| +++ b/experimental/svg/SkSVGDevice.cpp |
| @@ -31,6 +31,32 @@ static SkScalar svg_opacity(SkColor color) { |
| return SkIntToScalar(SkColorGetA(color)) / SK_AlphaOPAQUE; |
| } |
| +// Keep in sync with SkPaint::Cap |
| +static const char* cap_map[] = { |
| + "", // kButt_Cap (default) |
| + "round", // kRound_Cap |
| + "square" // kSquare_Cap |
| +}; |
| +SK_COMPILE_ASSERT(SK_ARRAY_COUNT(cap_map) == SkPaint::kCapCount, missing_cap_map_entry); |
| + |
| +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.
|
| + SkASSERT(cap < SK_ARRAY_COUNT(cap_map)); |
| + return SkString(cap_map[cap]); |
| +} |
| + |
| +// Keep in sync with SkPaint::Join |
| +static const char* join_map[] = { |
| + "", // kMiter_Join (default) |
| + "round", // kRound_Join |
| + "bevel" // kBevel_Join |
| +}; |
| +SK_COMPILE_ASSERT(SK_ARRAY_COUNT(join_map) == SkPaint::kJoinCount, missing_join_map_entry); |
| + |
| +static SkString svg_join(SkPaint::Join join) { |
| + SkASSERT(join < SK_ARRAY_COUNT(join_map)); |
| + return SkString(join_map[join]); |
| +} |
| + |
| static void append_escaped_unichar(SkUnichar c, SkString* text) { |
| switch(c) { |
| case '&': |
| @@ -191,21 +217,46 @@ void SkSVGDevice::AutoElement::addPaint(const SkPaint& paint, const Resources& r |
| SkPaint::Style style = paint.getStyle(); |
| if (style == SkPaint::kFill_Style || style == SkPaint::kStrokeAndFill_Style) { |
| this->addAttribute("fill", resources.fPaintServer); |
| + |
| + if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { |
| + this->addAttribute("fill-opacity", svg_opacity(paint.getColor())); |
| + } |
| } else { |
| 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.
|
| } |
| if (style == SkPaint::kStroke_Style || style == SkPaint::kStrokeAndFill_Style) { |
| this->addAttribute("stroke", resources.fPaintServer); |
| - this->addAttribute("stroke-width", paint.getStrokeWidth()); |
| + |
| + SkScalar strokeWidth = paint.getStrokeWidth(); |
| + if (strokeWidth == 0) { |
| + // Hairline stroke |
| + strokeWidth = 1; |
| + this->addAttribute("vector-effect", "non-scaling-stroke"); |
| + } |
| + this->addAttribute("stroke-width", strokeWidth); |
| + |
| + SkString cap = svg_cap(paint.getStrokeCap()); |
| + if (!cap.isEmpty()) { |
| + this->addAttribute("stroke-linecap", cap); |
| + } |
| + |
| + SkString join = svg_join(paint.getStrokeJoin()); |
| + if (!join.isEmpty()) { |
| + this->addAttribute("stroke-linejoin", join); |
| + } |
| + |
| + if (paint.getStrokeJoin() == SkPaint::kMiter_Join) { |
| + this->addAttribute("stroke-miterlimit", paint.getStrokeMiter()); |
| + } |
| + |
| + if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { |
| + this->addAttribute("stroke-opacity", svg_opacity(paint.getColor())); |
| + } |
| } else { |
| this->addAttribute("stroke", "none"); |
|
mtklein
2015/02/04 22:37:49
And kFill_Style here?
|
| } |
| - if (SK_AlphaOPAQUE != SkColorGetA(paint.getColor())) { |
| - this->addAttribute("opacity", svg_opacity(paint.getColor())); |
| - } |
| - |
| if (!resources.fClip.isEmpty()) { |
| this->addAttribute("clip-path", resources.fClip); |
| } |