summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-08 01:22:45 +0000
committervandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-08 01:22:45 +0000
commiteaf12a9e046b94e3aee7bc2ec984c1708852f175 (patch)
treef31085432c0440440462ea6a23c916339447c64c /pdf
parent53400b6aa8ff2c7b124728643b712220061c8bba (diff)
downloadsrc-eaf12a9e046b94e3aee7bc2ec984c1708852f175.tar.gz
[PDF] Fix node count in page tree.
It should be the number of leaves below a given node, not the number of direct children in the node. Review URL: http://codereview.appspot.com/4355044 git-svn-id: http://skia.googlecode.com/svn/trunk/src@1082 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'pdf')
-rw-r--r--pdf/SkPDFPage.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/pdf/SkPDFPage.cpp b/pdf/SkPDFPage.cpp
index 54f8dba8..9aa21c69 100644
--- a/pdf/SkPDFPage.cpp
+++ b/pdf/SkPDFPage.cpp
@@ -58,6 +58,13 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
SkPDFCatalog* catalog,
SkTDArray<SkPDFDict*>* pageTree,
SkPDFDict** rootNode) {
+ // PDF wants a tree describing all the pages in the document. We arbitrary
+ // choose 8 (kNodeSize) as the number of allowed children. The internal
+ // nodes have type "Pages" with an array of children, a parent pointer, and
+ // the number of leaves below the node as "Count." The leaves are passed
+ // into the method, have type "Page" and need a parent pointer. This method
+ // builds the tree bottom up, skipping internal nodes that would have only
+ // one child.
static const int kNodeSize = 8;
SkRefPtr<SkPDFName> kidsName = new SkPDFName("Kids");
@@ -79,6 +86,7 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
SkTDArray<SkPDFDict*> nextRoundNodes;
nextRoundNodes.setReserve((pages.count() + kNodeSize - 1)/kNodeSize);
+ int treeCapacity = kNodeSize;
do {
for (int i = 0; i < curNodes.count(); ) {
if (i > 0 && i + 1 == curNodes.count()) {
@@ -110,12 +118,17 @@ void SkPDFPage::generatePageTree(const SkTDArray<SkPDFPage*>& pages,
}
newNode->insert(kidsName.get(), kids.get());
- newNode->insert(countName.get(), new SkPDFInt(count))->unref();
+ int pageCount = treeCapacity;
+ if (count < kNodeSize) {
+ pageCount = pages.count() % treeCapacity;
+ }
+ newNode->insert(countName.get(), new SkPDFInt(pageCount))->unref();
nextRoundNodes.push(newNode); // Transfer reference.
}
curNodes = nextRoundNodes;
nextRoundNodes.rewind();
+ treeCapacity *= kNodeSize;
} while(curNodes.count() > 1);
pageTree->push(curNodes[0]); // Transfer reference.