| 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/SkSVGLine.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/SkSVGAttributeParser.h" |
| 14 |
#include "modules/svg/include/SkSVGRenderContext.h" |
| 15 |
|
| 16 |
class SkPaint; |
| 17 |
|
| 18 |
SkSVGLine::SkSVGLine() : INHERITED(SkSVGTag::kLine) {} |
| 19 |
|
| 20 |
bool SkSVGLine::parseAndSetAttribute(const char* n, const char* v) { |
| 21 |
return INHERITED::parseAndSetAttribute(n, v) || |
| 22 |
this->setX1(SkSVGAttributeParser::parse<SkSVGLength>("x1", n, v)) || |
| 23 |
this->setY1(SkSVGAttributeParser::parse<SkSVGLength>("y1", n, v)) || |
| 24 |
this->setX2(SkSVGAttributeParser::parse<SkSVGLength>("x2", n, v)) || |
| 25 |
this->setY2(SkSVGAttributeParser::parse<SkSVGLength>("y2", n, v)); |
| 26 |
} |
| 27 |
|
| 28 |
std::tuple<SkPoint, SkPoint> SkSVGLine::resolve(const SkSVGLengthContext& lctx) const { |
| 29 |
return std::make_tuple( |
| 30 |
SkPoint::Make(lctx.resolve(fX1, SkSVGLengthContext::LengthType::kHorizontal), |
| 31 |
lctx.resolve(fY1, SkSVGLengthContext::LengthType::kVertical)), |
| 32 |
SkPoint::Make(lctx.resolve(fX2, SkSVGLengthContext::LengthType::kHorizontal), |
| 33 |
lctx.resolve(fY2, SkSVGLengthContext::LengthType::kVertical))); |
| 34 |
} |
| 35 |
|
| 36 |
void SkSVGLine::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, |
| 37 |
const SkPaint& paint, SkPathFillType) const { |
| 38 |
SkPoint p0, p1; |
| 39 |
std::tie(p0, p1) = this->resolve(lctx); |
| 40 |
|
| 41 |
canvas->drawLine(p0, p1, paint); |
| 42 |
} |
| 43 |
|
| 44 |
SkPath SkSVGLine::onAsPath(const SkSVGRenderContext& ctx) const { |
| 45 |
SkPoint p0, p1; |
| 46 |
std::tie(p0, p1) = this->resolve(ctx.lengthContext()); |
| 47 |
|
| 48 |
return this->mapToParent(SkPath::Line(p0, p1)); |
| 49 |
} |