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