aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFPageObjectHelper.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-03-01 22:43:35 +0100
committerJay Berkenbilt <ejb@ql.org>2021-03-03 23:05:49 +0100
commite17585c2d2df9fea296364c0768c2ce5adbc4b91 (patch)
tree356a5b3c7096175ed1ed08d1535a1e4d50f0484d /libqpdf/QPDFPageObjectHelper.cc
parenta15ec6967dd3312223a6ab7d4198655234e1a4bf (diff)
downloadqpdf-e17585c2d2df9fea296364c0768c2ce5adbc4b91.tar.zst
Remove unreferenced: ignore names that are not Fonts or XObjects
Converted ResourceFinder to ParserCallbacks so we can better detect the name that precedes various operators and use the operators to sort the names into resource types. This enables us to be smarter about detecting unreferenced resources in pages and also sets the stage for reconciling differences in /DR across documents.
Diffstat (limited to 'libqpdf/QPDFPageObjectHelper.cc')
-rw-r--r--libqpdf/QPDFPageObjectHelper.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc
index 58144a3f..344ff15e 100644
--- a/libqpdf/QPDFPageObjectHelper.cc
+++ b/libqpdf/QPDFPageObjectHelper.cc
@@ -684,7 +684,7 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
ResourceFinder rf;
try
{
- ph.filterContents(&rf);
+ ph.parseContents(&rf);
}
catch (std::exception& e)
{
@@ -711,9 +711,9 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
QPDFObjectHandle resources = ph.getAttribute("/Resources", true);
std::vector<QPDFObjectHandle> rdicts;
std::set<std::string> known_names;
+ std::vector<std::string> to_filter = {"/Font", "/XObject"};
if (resources.isDictionary())
{
- std::vector<std::string> to_filter = {"/Font", "/XObject"};
for (auto const& iter: to_filter)
{
QPDFObjectHandle dict = resources.getKey(iter);
@@ -729,12 +729,17 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
}
std::set<std::string> local_unresolved;
- for (auto const& name: rf.getNames())
+ auto names_by_rtype = rf.getNamesByResourceType();
+ for (auto const& i1: to_filter)
{
- if (! known_names.count(name))
+ for (auto const& n_iter: names_by_rtype[i1])
{
- unresolved.insert(name);
- local_unresolved.insert(name);
+ std::string const& name = n_iter.first;
+ if (! known_names.count(name))
+ {
+ unresolved.insert(name);
+ local_unresolved.insert(name);
+ }
}
}
// Older versions of the PDF spec allowed form XObjects to omit
@@ -754,11 +759,17 @@ QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
if ((! local_unresolved.empty()) && resources.isDictionary())
{
- // Don't issue a warning for this case. There are some cases
- // of names that aren't XObject references, for example,
- // /Artifact in tagged PDF. Until we are certain that we know
- // the meaning of every name in a content stream, we don't
- // want to give warnings because they will be false positives.
+ // It's not worth issuing a warning for this case. From qpdf
+ // 10.3, we are hopefully only looking at names that are
+ // referencing fonts and XObjects, but until we're certain
+ // that we know the meaning of every name in a content stream,
+ // we don't want to give warnings that might be false
+ // positives. Also, this can happen in legitimate cases with
+ // older PDFs, and there's nothing to be done about it, so
+ // there's no good reason to issue a warning. The only sad
+ // thing is that it was a false positive that alerted me to a
+ // logic error in the code, and any future such errors would
+ // now be hidden.
QTC::TC("qpdf", "QPDFPageObjectHelper unresolved names");
return false;
}