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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/svg/model/SkSVGRect.h ('k') | experimental/svg/model/SkSVGRenderContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/svg/model/SkSVGRect.cpp
diff --git a/experimental/svg/model/SkSVGRect.cpp b/experimental/svg/model/SkSVGRect.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..288fc4825828fc9f659452de8e2da392e2a65e09
--- /dev/null
+++ b/experimental/svg/model/SkSVGRect.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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 "SkRect.h"
+#include "SkSVGRect.h"
+#include "SkSVGRenderContext.h"
+#include "SkSVGValue.h"
+
+SkSVGRect::SkSVGRect() : INHERITED(SkSVGTag::kRect) {}
+
+void SkSVGRect::setX(const SkSVGLength& x) {
+ fX = x;
+}
+
+void SkSVGRect::setY(const SkSVGLength& y) {
+ fY = y;
+}
+
+void SkSVGRect::setWidth(const SkSVGLength& w) {
+ fWidth = w;
+}
+
+void SkSVGRect::setHeight(const SkSVGLength& h) {
+ fHeight = h;
+}
+
+void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
+ switch (attr) {
+ case SkSVGAttribute::kX:
+ if (const auto* x = v.as<SkSVGLengthValue>()) {
+ this->setX(*x);
+ }
+ break;
+ case SkSVGAttribute::kY:
+ if (const auto* y = v.as<SkSVGLengthValue>()) {
+ this->setY(*y);
+ }
+ break;
+ case SkSVGAttribute::kWidth:
+ if (const auto* w = v.as<SkSVGLengthValue>()) {
+ this->setWidth(*w);
+ }
+ break;
+ case SkSVGAttribute::kHeight:
+ if (const auto* h = v.as<SkSVGLengthValue>()) {
+ this->setHeight(*h);
+ }
+ break;
+ default:
+ this->INHERITED::onSetAttribute(attr, v);
+ }
+}
+
+void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
+ const SkPaint& paint) const {
+ const SkRect r = SkRect::MakeXYWH(
+ lctx.resolve(fX, SkSVGLengthContext::LengthType::kHorizontal),
+ lctx.resolve(fY, SkSVGLengthContext::LengthType::kVertical),
+ lctx.resolve(fWidth, SkSVGLengthContext::LengthType::kHorizontal),
+ lctx.resolve(fHeight, SkSVGLengthContext::LengthType::kVertical));
+
+ canvas->drawRect(r, paint);
+}
« 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