Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
| 9 #include "SkStream.h" | 9 #include "SkStream.h" |
| 10 | 10 |
| 11 SK_DEFINE_INST_COUNT(SkDocument) | 11 SK_DEFINE_INST_COUNT(SkDocument) |
| 12 | 12 |
| 13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) { | 13 SkDocument::SkDocument(SkWStream* stream, void (*doneProc)(SkWStream*)) { |
| 14 fStream = stream; // we do not own this object. | 14 fStream = stream; // we do not own this object. |
| 15 fDoneProc = doneProc; | 15 fDoneProc = doneProc; |
| 16 fState = kBetweenPages_State; | 16 fState = kBetweenPages_State; |
| 17 } | 17 } |
| 18 | 18 |
| 19 SkDocument::~SkDocument() { | 19 SkDocument::~SkDocument() { |
| 20 this->close(); | 20 this->close(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 SkCanvas* SkDocument::beginPage(SkScalar width, SkScalar height, | 23 SkCanvas* SkDocument::beginPage(const SkSize& trimSize, const SkRect* mediaBox) { |
| 24 const SkRect* content) { | 24 if (trimSize.width() <= 0 || trimSize.height() <= 0) { |
| 25 if (width <= 0 || height <= 0) { | |
| 26 return NULL; | 25 return NULL; |
| 27 } | 26 } |
| 28 | 27 |
| 29 SkRect outer = SkRect::MakeWH(width, height); | |
| 30 SkRect inner; | |
| 31 if (content) { | |
| 32 inner = *content; | |
| 33 if (!inner.intersect(outer)) { | |
|
reed1
2013/10/07 13:24:54
Why do we not check for valid mediaBox anymore?
edisonn
2013/10/07 19:29:06
Done.
| |
| 34 return NULL; | |
| 35 } | |
| 36 } else { | |
| 37 inner = outer; | |
| 38 } | |
| 39 | |
| 40 for (;;) { | 28 for (;;) { |
| 41 switch (fState) { | 29 switch (fState) { |
| 42 case kBetweenPages_State: | 30 case kBetweenPages_State: |
| 43 fState = kInPage_State; | 31 fState = kInPage_State; |
| 44 return this->onBeginPage(width, height, inner); | 32 return this->onBeginPage(trimSize, mediaBox); |
| 45 case kInPage_State: | 33 case kInPage_State: |
| 46 this->endPage(); | 34 this->endPage(); |
| 47 break; | 35 break; |
| 48 case kClosed_State: | 36 case kClosed_State: |
| 49 return NULL; | 37 return NULL; |
| 50 } | 38 } |
| 51 } | 39 } |
| 52 SkDEBUGFAIL("never get here"); | 40 SkDEBUGFAIL("never get here"); |
| 53 return NULL; | 41 return NULL; |
| 54 } | 42 } |
| 55 | 43 |
| 56 void SkDocument::endPage() { | 44 void SkDocument::endPage() { |
| 57 if (kInPage_State == fState) { | 45 if (kInPage_State == fState) { |
| 58 fState = kBetweenPages_State; | 46 fState = kBetweenPages_State; |
| 59 this->onEndPage(); | 47 this->onEndPage(); |
| 60 } | 48 } |
| 61 } | 49 } |
| 62 | 50 |
| 63 void SkDocument::close() { | 51 bool SkDocument::close() { |
| 64 for (;;) { | 52 for (;;) { |
| 65 switch (fState) { | 53 switch (fState) { |
| 66 case kBetweenPages_State: | 54 case kBetweenPages_State: { |
| 67 fState = kClosed_State; | 55 fState = kClosed_State; |
| 68 this->onClose(fStream); | 56 bool success = this->onClose(fStream); |
| 69 | 57 |
| 70 if (fDoneProc) { | 58 if (fDoneProc) { |
| 71 fDoneProc(fStream); | 59 fDoneProc(fStream); |
| 72 } | 60 } |
| 73 // we don't own the stream, but we mark it NULL since we can | 61 // we don't own the stream, but we mark it NULL since we can |
| 74 // no longer write to it. | 62 // no longer write to it. |
| 75 fStream = NULL; | 63 fStream = NULL; |
| 76 return; | 64 return success; |
| 65 } | |
| 77 case kInPage_State: | 66 case kInPage_State: |
| 78 this->endPage(); | 67 this->endPage(); |
| 79 break; | 68 break; |
| 80 case kClosed_State: | 69 case kClosed_State: |
| 81 return; | 70 return false; |
| 82 } | 71 } |
| 83 } | 72 } |
| 84 } | 73 } |
| 74 | |
| 75 void SkDocument::abort() { | |
| 76 fState = kClosed_State; | |
| 77 } | |
| OLD | NEW |