diff options
author | 2011-07-18 23:13:19 +0000 | |
---|---|---|
committer | 2011-07-18 23:13:19 +0000 | |
commit | fb6a53a406636a81094be8b75180fddcc02ff957 (patch) | |
tree | 5b3bab9475dbbcf647b0788cb24d147a320da50f /src/pdf/SkPDFDocument.cpp | |
parent | 4a947d264b2764685e5f82b2e5d328a50e9612ea (diff) |
[PDF] Add setPage method to SkPDFDocument.
BUG=312
Review URL: http://codereview.appspot.com/4763047
git-svn-id: http://skia.googlecode.com/svn/trunk@1892 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pdf/SkPDFDocument.cpp')
-rw-r--r-- | src/pdf/SkPDFDocument.cpp | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp index faa93601de..3b7609fe95 100644 --- a/src/pdf/SkPDFDocument.cpp +++ b/src/pdf/SkPDFDocument.cpp @@ -56,8 +56,14 @@ SkPDFDocument::~SkPDFDocument() { } bool SkPDFDocument::emitPDF(SkWStream* stream) { - if (fPages.isEmpty()) + if (fPages.isEmpty()) { return false; + } + for (int i = 0; i < fPages.count(); i++) { + if (fPages[i] == NULL) { + return false; + } + } // We haven't emitted the document before if fPageTree is empty. if (fPageTree.count() == 0) { @@ -147,17 +153,36 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) { return true; } +bool SkPDFDocument::setPage(int pageNumber, + const SkRefPtr<SkPDFDevice>& pdfDevice) { + if (fPageTree.count() != 0) { + return false; + } + + pageNumber--; + SkASSERT(pageNumber >= 0); + + if (pageNumber > fPages.count()) { + int oldSize = fPages.count(); + fPages.setCount(pageNumber + 1); + for (int i = oldSize; i <= pageNumber; i++) { + fPages[i] = NULL; + } + } + + SkPDFPage* page = new SkPDFPage(pdfDevice); + SkSafeUnref(fPages[pageNumber]); + fPages[pageNumber] = page; // Reference from new passed to fPages. + return true; +} + bool SkPDFDocument::appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice) { - if (fPageTree.count() != 0) + if (fPageTree.count() != 0) { return false; + } SkPDFPage* page = new SkPDFPage(pdfDevice); fPages.push(page); // Reference from new passed to fPages. - // The rest of the pages will be added to the catalog along with the rest - // of the page tree. But the first page has to be marked as such, so we - // handle it here. - if (fPages.count() == 1) - fCatalog.addObject(page, true); return true; } |