From 3c974427a95e9f24eae39167cf972506d70359c9 Mon Sep 17 00:00:00 2001 From: "vandebo@chromium.org" Date: Wed, 30 Jan 2013 21:44:40 +0000 Subject: [PDF] Fix multi-level page count calculation. BUG=1091 Review URL: https://codereview.appspot.com/7220045 git-svn-id: http://skia.googlecode.com/svn/trunk@7478 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/pdf/SkPDFPage.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pdf/SkPDFPage.cpp b/src/pdf/SkPDFPage.cpp index a18beb156f..f47f8ffd46 100644 --- a/src/pdf/SkPDFPage.cpp +++ b/src/pdf/SkPDFPage.cpp @@ -112,12 +112,19 @@ void SkPDFPage::GeneratePageTree(const SkTDArray& pages, } } - newNode->insert(kidsName.get(), kids.get()); + // treeCapacity is the number of leaf nodes possible for the + // current set of subtrees being generated. (i.e. 8, 64, 512, ...). + // It is hard to count the number of leaf nodes in the current + // subtree. However, by construction, we know that unless it's the + // last subtree for the current depth, the leaf count will be + // treeCapacity, otherwise it's what ever is left over after + // consuming treeCapacity chunks. int pageCount = treeCapacity; - if (count < kNodeSize) { - pageCount = pages.count() % treeCapacity; + if (i == curNodes.count()) { + pageCount = ((pages.count() - 1) % treeCapacity) + 1; } newNode->insert(countName.get(), new SkPDFInt(pageCount))->unref(); + newNode->insert(kidsName.get(), kids.get()); nextRoundNodes.push(newNode); // Transfer reference. } -- cgit v1.2.3