aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-01 22:17:15 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-05 21:35:37 +0000
commitb1de5f9f2737159ce055305d87d237be5b0dc010 (patch)
treed6dba8895e76746e19af8ae841c19b3c7cc11ff6 /src
parent8996e18358752bab9ce0a5da60dbc1af696ce282 (diff)
SkDocument: consolidate trimBox code
Change-Id: I56f651320964eb3bd33475d21e6977803c4ca140 Reviewed-on: https://skia-review.googlesource.com/21370 Reviewed-by: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkDocument.cpp11
-rw-r--r--src/pdf/SkPDFDocument.cpp7
-rw-r--r--src/pdf/SkPDFDocument.h2
-rw-r--r--src/utils/SkMultiPictureDocument.cpp17
-rw-r--r--src/xps/SkXPSDocument.cpp6
-rw-r--r--src/xps/SkXPSDocument.h2
6 files changed, 15 insertions, 30 deletions
diff --git a/src/core/SkDocument.cpp b/src/core/SkDocument.cpp
index 29db7f05e1..006be91439 100644
--- a/src/core/SkDocument.cpp
+++ b/src/core/SkDocument.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkCanvas.h"
#include "SkDocument.h"
#include "SkStream.h"
@@ -37,9 +38,15 @@ SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
for (;;) {
switch (fState) {
- case kBetweenPages_State:
+ case kBetweenPages_State: {
fState = kInPage_State;
- return this->onBeginPage(width, height, inner);
+ SkCanvas* canvas = this->onBeginPage(width, height);
+ if (content) {
+ canvas->clipRect(inner);
+ canvas->translate(inner.x(), inner.y());
+ }
+ return canvas;
+ }
case kInPage_State:
this->endPage();
break;
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 96a79aedb8..ee009651b6 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -193,8 +193,7 @@ void SkPDFDocument::serialize(const sk_sp<SkPDFObject>& object) {
fObjectSerializer.serializeObjects(this->getStream());
}
-SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height,
- const SkRect& trimBox) {
+SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height) {
SkASSERT(!fCanvas.get()); // endPage() was called before this.
if (fPages.empty()) {
// if this is the first page if the document.
@@ -218,10 +217,6 @@ SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height,
fPageDevice = sk_make_sp<SkPDFDevice>(pageSize, this);
fPageDevice->setFlip(); // Only the top-level device needs to be flipped.
fCanvas.reset(new SkPDFCanvas(fPageDevice));
- if (SkRect::MakeWH(width, height) != trimBox) {
- fCanvas->clipRect(trimBox);
- fCanvas->translate(trimBox.x(), trimBox.y());
- }
return fCanvas.get();
}
diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h
index 7f8b6c84a3..3e3a50ae83 100644
--- a/src/pdf/SkPDFDocument.h
+++ b/src/pdf/SkPDFDocument.h
@@ -61,7 +61,7 @@ public:
sk_sp<SkPixelSerializer>,
bool);
~SkPDFDocument() override;
- SkCanvas* onBeginPage(SkScalar, SkScalar, const SkRect&) override;
+ SkCanvas* onBeginPage(SkScalar, SkScalar) override;
void onEndPage() override;
void onClose(SkWStream*) override;
void onAbort() override;
diff --git a/src/utils/SkMultiPictureDocument.cpp b/src/utils/SkMultiPictureDocument.cpp
index 9868ca2692..4ff2d079e3 100644
--- a/src/utils/SkMultiPictureDocument.cpp
+++ b/src/utils/SkMultiPictureDocument.cpp
@@ -44,19 +44,6 @@ static SkSize join(const SkTArray<SkSize>& sizes) {
return joined;
}
-static SkCanvas* trim(SkCanvas* canvas,
- SkScalar w, SkScalar h,
- const SkRect& trimBox) {
- // Only trim if necessary.
- if (trimBox != SkRect::MakeWH(w, h)) {
- // All SkDocument implementations implement trimBox using a
- // clip+translate.
- canvas->clipRect(trimBox);
- canvas->translate(trimBox.x(), trimBox.y());
- }
- return canvas;
-}
-
struct MultiPictureDocument final : public SkDocument {
SkPictureRecorder fPictureRecorder;
SkSize fCurrentPageSize;
@@ -66,9 +53,9 @@ struct MultiPictureDocument final : public SkDocument {
: SkDocument(s, d) {}
~MultiPictureDocument() override { this->close(); }
- SkCanvas* onBeginPage(SkScalar w, SkScalar h, const SkRect& c) override {
+ SkCanvas* onBeginPage(SkScalar w, SkScalar h) override {
fCurrentPageSize.set(w, h);
- return trim(fPictureRecorder.beginRecording(w, h), w, h, c);
+ return fPictureRecorder.beginRecording(w, h);
}
void onEndPage() override {
fSizes.push_back(fCurrentPageSize);
diff --git a/src/xps/SkXPSDocument.cpp b/src/xps/SkXPSDocument.cpp
index 0d12e4f7f8..ac62c62002 100644
--- a/src/xps/SkXPSDocument.cpp
+++ b/src/xps/SkXPSDocument.cpp
@@ -33,13 +33,9 @@ SkXPSDocument::~SkXPSDocument() {
this->close();
}
-SkCanvas* SkXPSDocument::onBeginPage(SkScalar width,
- SkScalar height,
- const SkRect& trimBox) {
+SkCanvas* SkXPSDocument::onBeginPage(SkScalar width, SkScalar height) {
fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter, {width, height});
fCanvas.reset(new SkCanvas(&fDevice));
- fCanvas->clipRect(trimBox);
- fCanvas->translate(trimBox.x(), trimBox.y());
return fCanvas.get();
}
diff --git a/src/xps/SkXPSDocument.h b/src/xps/SkXPSDocument.h
index 726af8f58f..cccfc1f777 100644
--- a/src/xps/SkXPSDocument.h
+++ b/src/xps/SkXPSDocument.h
@@ -24,7 +24,7 @@ public:
virtual ~SkXPSDocument();
protected:
- SkCanvas* onBeginPage(SkScalar w, SkScalar h, const SkRect&) override;
+ SkCanvas* onBeginPage(SkScalar w, SkScalar h) override;
void onEndPage() override;
void onClose(SkWStream*) override;
void onAbort() override;