2016-07-27 01:46:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkSVGPath.h"
|
|
|
|
#include "SkSVGRenderContext.h"
|
|
|
|
#include "SkSVGValue.h"
|
|
|
|
|
2016-07-29 15:52:03 +00:00
|
|
|
SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
|
|
|
switch (attr) {
|
2016-07-29 15:52:03 +00:00
|
|
|
case SkSVGAttribute::kD:
|
2016-07-27 01:46:34 +00:00
|
|
|
if (const auto* path = v.as<SkSVGPathValue>()) {
|
|
|
|
this->setPath(*path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this->INHERITED::onSetAttribute(attr, v);
|
|
|
|
}
|
|
|
|
}
|
2016-08-03 17:21:11 +00:00
|
|
|
|
2016-12-01 18:35:11 +00:00
|
|
|
void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
|
|
|
|
SkPath::FillType fillType) const {
|
|
|
|
// the passed fillType follows inheritance rules and needs to be applied at draw time.
|
|
|
|
fPath.setFillType(fillType);
|
2016-08-03 17:21:11 +00:00
|
|
|
canvas->drawPath(fPath, paint);
|
|
|
|
}
|
2016-12-08 14:26:47 +00:00
|
|
|
|
|
|
|
SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {
|
|
|
|
// the computed fillType follows inheritance rules and needs to be applied at draw time.
|
|
|
|
fPath.setFillType(FillRuleToFillType(*ctx.presentationContext().fInherited.fFillRule.get()));
|
|
|
|
|
|
|
|
SkPath path = fPath;
|
|
|
|
this->mapToParent(&path);
|
|
|
|
return path;
|
|
|
|
}
|