зеркало из https://github.com/mozilla/moz-skia.git
[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
This commit is contained in:
Родитель
4a947d264b
Коммит
fb6a53a406
|
@ -37,11 +37,24 @@ public:
|
|||
SK_API SkPDFDocument();
|
||||
SK_API ~SkPDFDocument();
|
||||
|
||||
/** Output the PDF to the passed stream.
|
||||
/** Output the PDF to the passed stream. It is an error to call this (it
|
||||
* will return false and not modify stream) if no pages have been added
|
||||
* or there are pages missing (i.e. page 1 and 3 have been added, but not
|
||||
* page 2).
|
||||
*
|
||||
* @param stream The writable output stream to send the PDF to.
|
||||
*/
|
||||
SK_API bool emitPDF(SkWStream* stream);
|
||||
|
||||
/** Sets the specific page to the passed PDF device. If the specified
|
||||
* page is already set, this overrides it. Returns true if successful.
|
||||
* Will fail if the document has already been emitted.
|
||||
*
|
||||
* @param pageNumber The position to add the passed device (1 based).
|
||||
* @param pdfDevice The page to add to this document.
|
||||
*/
|
||||
SK_API bool setPage(int pageNumber, const SkRefPtr<SkPDFDevice>& pdfDevice);
|
||||
|
||||
/** Append the passed pdf device to the document as a new page. Returns
|
||||
* true if successful. Will fail if the document has already been emitted.
|
||||
*
|
||||
|
|
|
@ -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::appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice) {
|
||||
if (fPageTree.count() != 0)
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
|
|||
catalog->addObject(curNodes[i], false);
|
||||
} else {
|
||||
SkSafeUnref(curNodes[i]);
|
||||
catalog->addObject(curNodes[i], true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче