Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: experimental/svg/model/SkSVGRect.cpp

Issue 2202053002: [SVGDom/experimental] Initial SVGLength support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/model/SkSVGRect.h ('k') | experimental/svg/model/SkSVGRenderContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "SkCanvas.h"
9 #include "SkRect.h"
10 #include "SkSVGRect.h"
11 #include "SkSVGRenderContext.h"
12 #include "SkSVGValue.h"
13
14 SkSVGRect::SkSVGRect() : INHERITED(SkSVGTag::kRect) {}
15
16 void SkSVGRect::setX(const SkSVGLength& x) {
17 fX = x;
18 }
19
20 void SkSVGRect::setY(const SkSVGLength& y) {
21 fY = y;
22 }
23
24 void SkSVGRect::setWidth(const SkSVGLength& w) {
25 fWidth = w;
26 }
27
28 void SkSVGRect::setHeight(const SkSVGLength& h) {
29 fHeight = h;
30 }
31
32 void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
33 switch (attr) {
34 case SkSVGAttribute::kX:
35 if (const auto* x = v.as<SkSVGLengthValue>()) {
36 this->setX(*x);
37 }
38 break;
39 case SkSVGAttribute::kY:
40 if (const auto* y = v.as<SkSVGLengthValue>()) {
41 this->setY(*y);
42 }
43 break;
44 case SkSVGAttribute::kWidth:
45 if (const auto* w = v.as<SkSVGLengthValue>()) {
46 this->setWidth(*w);
47 }
48 break;
49 case SkSVGAttribute::kHeight:
50 if (const auto* h = v.as<SkSVGLengthValue>()) {
51 this->setHeight(*h);
52 }
53 break;
54 default:
55 this->INHERITED::onSetAttribute(attr, v);
56 }
57 }
58
59 void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
60 const SkPaint& paint) const {
61 const SkRect r = SkRect::MakeXYWH(
62 lctx.resolve(fX, SkSVGLengthContext::LengthType::kHorizontal),
63 lctx.resolve(fY, SkSVGLengthContext::LengthType::kVertical),
64 lctx.resolve(fWidth, SkSVGLengthContext::LengthType::kHorizontal),
65 lctx.resolve(fHeight, SkSVGLengthContext::LengthType::kVertical));
66
67 canvas->drawRect(r, paint);
68 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGRect.h ('k') | experimental/svg/model/SkSVGRenderContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698