| 1 |
/* |
| 2 |
* Copyright 2016 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 "modules/svg/include/SkSVGPoly.h" |
| 9 |
|
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkPathTypes.h" |
| 12 |
#include "include/core/SkPoint.h" |
| 13 |
#include "modules/svg/include/SkSVGAttribute.h" |
| 14 |
#include "modules/svg/include/SkSVGAttributeParser.h" |
| 15 |
#include "modules/svg/include/SkSVGRenderContext.h" |
| 16 |
|
| 17 |
class SkPaint; |
| 18 |
|
| 19 |
SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {} |
| 20 |
|
| 21 |
bool SkSVGPoly::parseAndSetAttribute(const char* n, const char* v) { |
| 22 |
if (INHERITED::parseAndSetAttribute(n, v)) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
if (this->setPoints(SkSVGAttributeParser::parse<SkSVGPointsType>("points", n, v))) { |
| 27 |
// TODO: we can likely just keep the points array and create the SkPath when needed. |
| 28 |
// only polygons are auto-closed |
| 29 |
fPath = SkPath::Polygon(fPoints, this->tag() == SkSVGTag::kPolygon); |
| 30 |
} |
| 31 |
|
| 32 |
// No other attributes on this node |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint, |
| 37 |
SkPathFillType fillType) const { |
| 38 |
// the passed fillType follows inheritance rules and needs to be applied at draw time. |
| 39 |
fPath.setFillType(fillType); |
| 40 |
canvas->drawPath(fPath, paint); |
| 41 |
} |
| 42 |
|
| 43 |
SkPath SkSVGPoly::onAsPath(const SkSVGRenderContext& ctx) const { |
| 44 |
SkPath path = fPath; |
| 45 |
|
| 46 |
// clip-rule can be inherited and needs to be applied at clip time. |
| 47 |
path.setFillType(ctx.presentationContext().fInherited.fClipRule->asFillType()); |
| 48 |
|
| 49 |
return this->mapToParent(path); |
| 50 |
} |
| 51 |
|
| 52 |
SkRect SkSVGPoly::onTransformableObjectBoundingBox(const SkSVGRenderContext& ctx) const { |
| 53 |
return fPath.getBounds(); |
| 54 |
} |