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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGPath.h"
|
|
|
|
#include "experimental/svg/model/SkSVGRenderContext.h"
|
2020-04-10 14:14:04 +00:00
|
|
|
#include "experimental/svg/model/SkSVGValue.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-07-29 15:52:03 +00:00
|
|
|
SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2020-04-10 14:14:04 +00:00
|
|
|
void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
2016-07-27 01:46:34 +00:00
|
|
|
switch (attr) {
|
2016-07-29 15:52:03 +00:00
|
|
|
case SkSVGAttribute::kD:
|
2020-04-10 14:14:04 +00:00
|
|
|
if (const auto* path = v.as<SkSVGPathValue>()) {
|
2016-07-27 01:46:34 +00:00
|
|
|
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,
|
2019-11-26 17:17:17 +00:00
|
|
|
SkPathFillType fillType) const {
|
2016-12-01 18:35:11 +00:00
|
|
|
// 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 {
|
|
|
|
SkPath path = fPath;
|
2017-10-10 15:22:08 +00:00
|
|
|
// clip-rule can be inherited and needs to be applied at clip time.
|
|
|
|
path.setFillType(ctx.presentationContext().fInherited.fClipRule.get()->asFillType());
|
2016-12-08 14:26:47 +00:00
|
|
|
this->mapToParent(&path);
|
|
|
|
return path;
|
|
|
|
}
|