mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-22 22:58:33 +00:00
Build this->all_pages while traversing with pushInheritedAttributesToPage
This commit is contained in:
parent
e2dedde4bd
commit
39bbaa86e3
@ -913,6 +913,7 @@ class QPDF
|
||||
void pushInheritedAttributesToPageInternal(
|
||||
QPDFObjectHandle,
|
||||
std::map<std::string, std::vector<QPDFObjectHandle> >&,
|
||||
std::vector<QPDFObjectHandle>& all_pages,
|
||||
bool allow_changes, bool warn_skipped_keys);
|
||||
void updateObjectMaps(ObjUser const& ou, QPDFObjectHandle oh);
|
||||
void updateObjectMapsInternal(ObjUser const& ou, QPDFObjectHandle oh,
|
||||
|
@ -166,9 +166,8 @@ QPDF::optimize(std::map<int, int> const& object_stream_data,
|
||||
}
|
||||
|
||||
// Traverse pages tree pushing all inherited resources down to the
|
||||
// page level.
|
||||
// page level. This also initializes this->all_pages.
|
||||
pushInheritedAttributesToPage(allow_changes, false);
|
||||
getAllPages();
|
||||
|
||||
// Traverse pages
|
||||
int n = this->all_pages.size();
|
||||
@ -236,9 +235,10 @@ QPDF::pushInheritedAttributesToPage(bool allow_changes, bool warn_skipped_keys)
|
||||
// key_ancestors is a mapping of page attribute keys to a stack of
|
||||
// Pages nodes that contain values for them.
|
||||
std::map<std::string, std::vector<QPDFObjectHandle> > key_ancestors;
|
||||
this->all_pages.clear();
|
||||
pushInheritedAttributesToPageInternal(
|
||||
this->trailer.getKey("/Root").getKey("/Pages"),
|
||||
key_ancestors, allow_changes, warn_skipped_keys);
|
||||
key_ancestors, this->all_pages, allow_changes, warn_skipped_keys);
|
||||
assert(key_ancestors.empty());
|
||||
}
|
||||
|
||||
@ -246,6 +246,7 @@ void
|
||||
QPDF::pushInheritedAttributesToPageInternal(
|
||||
QPDFObjectHandle cur_pages,
|
||||
std::map<std::string, std::vector<QPDFObjectHandle> >& key_ancestors,
|
||||
std::vector<QPDFObjectHandle>& pages,
|
||||
bool allow_changes, bool warn_skipped_keys)
|
||||
{
|
||||
// Extract the underlying dictionary object
|
||||
@ -336,7 +337,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
pushInheritedAttributesToPageInternal(
|
||||
kids.getArrayItem(i), key_ancestors,
|
||||
kids.getArrayItem(i), key_ancestors, pages,
|
||||
allow_changes, warn_skipped_keys);
|
||||
}
|
||||
|
||||
@ -385,6 +386,7 @@ QPDF::pushInheritedAttributesToPageInternal(
|
||||
QTC::TC("qpdf", "QPDF opt page resource hides ancestor");
|
||||
}
|
||||
}
|
||||
pages.push_back(cur_pages);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -43,6 +43,8 @@
|
||||
std::vector<QPDFObjectHandle> const&
|
||||
QPDF::getAllPages()
|
||||
{
|
||||
// Note that pushInheritedAttributesToPage may also be used to
|
||||
// initialize this->all_pages.
|
||||
if (this->all_pages.empty())
|
||||
{
|
||||
getAllPagesInternal(getRoot().getKey("/Pages"), this->all_pages);
|
||||
@ -101,9 +103,9 @@ QPDF::flattenPagesTree()
|
||||
return;
|
||||
}
|
||||
|
||||
// Push inherited objects down to the /Page level
|
||||
// Push inherited objects down to the /Page level. As a side
|
||||
// effect this->all_pages will also be generated.
|
||||
pushInheritedAttributesToPage(true, true);
|
||||
getAllPages();
|
||||
|
||||
QPDFObjectHandle pages = getRoot().getKey("/Pages");
|
||||
|
||||
@ -228,14 +230,14 @@ QPDF::addPageAt(QPDFObjectHandle newpage, bool before,
|
||||
void
|
||||
QPDF::addPage(QPDFObjectHandle newpage, bool first)
|
||||
{
|
||||
getAllPages();
|
||||
if (first)
|
||||
{
|
||||
insertPage(newpage, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
insertPage(newpage, (int)this->all_pages.size());
|
||||
insertPage(newpage,
|
||||
getRoot().getKey("/Pages").getKey("/Count").getIntValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user