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