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

Unified Diff: experimental/svg/model/SkSVGRenderContext.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/SkSVGRenderContext.h ('k') | experimental/svg/model/SkSVGSVG.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/svg/model/SkSVGRenderContext.cpp
diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp
index 703606c5280b6404ccf332f11cab3e51b06f1685..38498d36c819dd577a33d7219e883d84b5b7ba28 100644
--- a/experimental/svg/model/SkSVGRenderContext.cpp
+++ b/experimental/svg/model/SkSVGRenderContext.cpp
@@ -6,8 +6,44 @@
*/
#include "SkSVGRenderContext.h"
+#include "SkSVGTypes.h"
-SkSVGRenderContext::SkSVGRenderContext() { }
+namespace {
+
+SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::LengthType t) {
+ switch (t) {
+ case SkSVGLengthContext::LengthType::kHorizontal:
+ return viewport.width();
+ case SkSVGLengthContext::LengthType::kVertical:
+ return viewport.height();
+ case SkSVGLengthContext::LengthType::kOther:
+ return SkScalarSqrt(viewport.width() * viewport.height());
+ }
+
+ SkASSERT(false); // Not reached.
+ return 0;
+}
+
+} // anonymous ns
+
+SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
+ switch (l.unit()) {
+ case SkSVGLength::Unit::kNumber:
+ return l.value();
+ break;
+ case SkSVGLength::Unit::kPercentage:
+ return l.value() * length_size_for_type(fViewport, t) / 100;
+ break;
+ default:
+ SkDebugf("unsupported unit type: <%d>\n", l.unit());
+ break;
+ }
+
+ return 0;
+}
+
+SkSVGRenderContext::SkSVGRenderContext(const SkSize& initialViewport)
+ : fLengthContext(initialViewport) {}
SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& other) {
if (other.fFill.isValid()) {
« no previous file with comments | « experimental/svg/model/SkSVGRenderContext.h ('k') | experimental/svg/model/SkSVGSVG.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698