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

Unified Diff: experimental/svg/model/SkSVGRenderContext.cpp

Issue 2259473002: [SVGDom] Add support for assorted absolute units (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: plumb DPI 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') | no next file » | 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 8ad881429a21b906a3041a06753bb5b045c61757..4a1d77d6e450ea463cdd9210ac64a30041c36ceb 100644
--- a/experimental/svg/model/SkSVGRenderContext.cpp
+++ b/experimental/svg/model/SkSVGRenderContext.cpp
@@ -26,6 +26,13 @@ SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length
return 0;
}
+// Multipliers for DPI-relative units.
+constexpr SkScalar kINMultiplier = 1.00f;
+constexpr SkScalar kPTMultiplier = kINMultiplier / 72.272f;
+constexpr SkScalar kPCMultiplier = kPTMultiplier * 12;
+constexpr SkScalar kMMMultiplier = kINMultiplier / 25.4f;
+constexpr SkScalar kCMMultiplier = kMMMultiplier * 10;
+
} // anonymous ns
SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
@@ -36,6 +43,16 @@ SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
return l.value();
case SkSVGLength::Unit::kPercentage:
return l.value() * length_size_for_type(fViewport, t) / 100;
+ case SkSVGLength::Unit::kCM:
+ return l.value() * fDPI * kCMMultiplier;
+ case SkSVGLength::Unit::kMM:
+ return l.value() * fDPI * kMMMultiplier;
+ case SkSVGLength::Unit::kIN:
+ return l.value() * fDPI * kINMultiplier;
+ case SkSVGLength::Unit::kPT:
+ return l.value() * fDPI * kPTMultiplier;
+ case SkSVGLength::Unit::kPC:
+ return l.value() * fDPI * kPCMultiplier;
default:
SkDebugf("unsupported unit type: <%d>\n", l.unit());
return 0;
« no previous file with comments | « experimental/svg/model/SkSVGRenderContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698