SkDocument.cpp clean up

Change-Id: I125a773e29824cfdd60754e681182d37e828c4b9
Reviewed-on: https://skia-review.googlesource.com/24860
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2017-07-20 08:37:50 -04:00 committed by Skia Commit-Bot
parent af1813e3bf
commit fa486cf4de

View File

@ -9,53 +9,39 @@
#include "SkDocument.h" #include "SkDocument.h"
#include "SkStream.h" #include "SkStream.h"
SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*, bool)) { SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*, bool))
fStream = stream; // we do not own this object. : fStream(stream) // we do not own this object.
fDoneProc = doneProc; , fDoneProc(doneProc)
fState = kBetweenPages_State; , fState(kBetweenPages_State) {}
}
SkDocument::~SkDocument() { SkDocument::~SkDocument() {
this->close(); this->close();
} }
SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height, static SkCanvas* trim(SkCanvas* canvas, SkScalar width, SkScalar height,
const SkRect* content) { const SkRect* content) {
if (width <= 0 || height <= 0) { if (content && canvas) {
return nullptr; SkRect inner = *content;
} if (!inner.intersect({0, 0, width, height})) {
SkRect outer = SkRect::MakeWH(width, height);
SkRect inner;
if (content) {
inner = *content;
if (!inner.intersect(outer)) {
return nullptr; return nullptr;
} }
} else { canvas->clipRect(inner);
inner = outer; canvas->translate(inner.x(), inner.y());
} }
return canvas;
}
for (;;) { SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height,
switch (fState) { const SkRect* content) {
case kBetweenPages_State: { if (width <= 0 || height <= 0 || kClosed_State == fState) {
fState = kInPage_State; return nullptr;
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;
case kClosed_State:
return nullptr;
}
} }
SkDEBUGFAIL("never get here"); if (kInPage_State == fState) {
return nullptr; this->endPage();
}
SkASSERT(kBetweenPages_State == fState);
fState = kInPage_State;
return trim(this->onBeginPage(width, height), width, height, content);
} }
void SkDocument::endPage() { void SkDocument::endPage() {