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

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

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: typo 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 38498d36c819dd577a33d7219e883d84b5b7ba28..e902d4ecf3d389018535e941299ef989c1e7bd42 100644
--- a/experimental/svg/model/SkSVGRenderContext.cpp
+++ b/experimental/svg/model/SkSVGRenderContext.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkCanvas.h"
#include "SkSVGRenderContext.h"
#include "SkSVGTypes.h"
@@ -42,10 +43,27 @@ SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
return 0;
}
-SkSVGRenderContext::SkSVGRenderContext(const SkSize& initialViewport)
- : fLengthContext(initialViewport) {}
+SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength& y,
+ const SkSVGLength& w, const SkSVGLength& h) const {
+ return SkRect::MakeXYWH(
+ this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal),
+ this->resolve(y, SkSVGLengthContext::LengthType::kVertical),
+ this->resolve(w, SkSVGLengthContext::LengthType::kHorizontal),
+ this->resolve(h, SkSVGLengthContext::LengthType::kVertical));
+}
+
+SkSVGPresentationContext::SkSVGPresentationContext() {}
+
+SkSVGPresentationContext::SkSVGPresentationContext(const SkSVGPresentationContext& o) {
+ this->initFrom(o);
+}
+
+SkSVGPresentationContext& SkSVGPresentationContext::operator=(const SkSVGPresentationContext& o) {
+ this->initFrom(o);
+ return *this;
+}
-SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& other) {
+void SkSVGPresentationContext::initFrom(const SkSVGPresentationContext& other) {
if (other.fFill.isValid()) {
fFill.set(*other.fFill.get());
} else {
@@ -57,11 +75,9 @@ SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& othe
} else {
fStroke.reset();
}
-
- return *this;
}
-SkPaint& SkSVGRenderContext::ensureFill() {
+SkPaint& SkSVGPresentationContext::ensureFill() {
if (!fFill.isValid()) {
fFill.init();
fFill.get()->setStyle(SkPaint::kFill_Style);
@@ -70,7 +86,7 @@ SkPaint& SkSVGRenderContext::ensureFill() {
return *fFill.get();
}
-SkPaint& SkSVGRenderContext::ensureStroke() {
+SkPaint& SkSVGPresentationContext::ensureStroke() {
if (!fStroke.isValid()) {
fStroke.init();
fStroke.get()->setStyle(SkPaint::kStroke_Style);
@@ -79,10 +95,27 @@ SkPaint& SkSVGRenderContext::ensureStroke() {
return *fStroke.get();
}
-void SkSVGRenderContext::setFillColor(SkColor color) {
+void SkSVGPresentationContext::setFillColor(SkColor color) {
this->ensureFill().setColor(color);
}
-void SkSVGRenderContext::setStrokeColor(SkColor color) {
+void SkSVGPresentationContext::setStrokeColor(SkColor color) {
this->ensureStroke().setColor(color);
}
+
+SkSVGRenderContext::SkSVGRenderContext(SkCanvas* canvas,
+ const SkSVGLengthContext& lctx,
+ const SkSVGPresentationContext& pctx)
+ : fLengthContext(lctx)
+ , fPresentationContext(pctx)
+ , fCanvas(canvas)
+ , fCanvasSaveCount(canvas->getSaveCount()) {}
+
+SkSVGRenderContext::SkSVGRenderContext(const SkSVGRenderContext& other)
+ : SkSVGRenderContext(other.canvas(),
+ other.lengthContext(),
+ other.presentationContext()) {}
+
+SkSVGRenderContext::~SkSVGRenderContext() {
+ fCanvas->restoreToCount(fCanvasSaveCount);
+}
« 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