Commit a148b87064b51a3293bdf56ed9b52b877b843fe5

Authored by m-holger
1 parent 949f2219

Derive QPDFObjectHelper from BaseHandle

Replace data member oh with accessors.

Remove redundant overloads from QPDFObjGen::set.
include/qpdf/QPDFObjGen.hh
... ... @@ -130,12 +130,6 @@ class QPDFObjGen
130 130 }
131 131  
132 132 QPDF_DLL
133   - bool add(QPDFObjectHandle const& oh);
134   -
135   - QPDF_DLL
136   - bool add(QPDFObjectHelper const& oh);
137   -
138   - QPDF_DLL
139 133 void
140 134 erase(QPDFObjGen og)
141 135 {
... ... @@ -143,12 +137,6 @@ class QPDFObjGen
143 137 std::set<QPDFObjGen>::erase(og);
144 138 }
145 139 }
146   -
147   - QPDF_DLL
148   - void erase(QPDFObjectHandle const& oh);
149   -
150   - QPDF_DLL
151   - void erase(QPDFObjectHelper const& oh);
152 140 };
153 141  
154 142 private:
... ...
include/qpdf/QPDFObjectHelper.hh
... ... @@ -31,13 +31,12 @@
31 31 // underlying QPDF objects unless there is a specific comment in a specific helper method that says
32 32 // otherwise. The pattern of using helper objects was introduced to allow creation of higher level
33 33 // helper functions without polluting the public interface of QPDFObjectHandle.
34   -
35   -class QPDF_DLL_CLASS QPDFObjectHelper
  34 +class QPDF_DLL_CLASS QPDFObjectHelper: public qpdf::BaseHandle
36 35 {
37 36 public:
38 37 QPDF_DLL
39 38 QPDFObjectHelper(QPDFObjectHandle oh) :
40   - oh(oh)
  39 + qpdf::BaseHandle(oh.getObj())
41 40 {
42 41 }
43 42 QPDF_DLL
... ... @@ -46,17 +45,29 @@ class QPDF_DLL_CLASS QPDFObjectHelper
46 45 QPDFObjectHandle
47 46 getObjectHandle()
48 47 {
49   - return this->oh;
  48 + return {obj};
50 49 }
51 50 QPDF_DLL
52 51 QPDFObjectHandle const
53 52 getObjectHandle() const
54 53 {
55   - return this->oh;
  54 + return {obj};
56 55 }
57 56  
58 57 protected:
59   - QPDFObjectHandle oh;
  58 + QPDF_DLL_PRIVATE
  59 + QPDFObjectHandle
  60 + oh()
  61 + {
  62 + return {obj};
  63 + }
  64 + QPDF_DLL_PRIVATE
  65 + QPDFObjectHandle const
  66 + oh() const
  67 + {
  68 + return {obj};
  69 + }
  70 + QPDFObjectHandle oh_;
60 71 };
61 72  
62 73 #endif // QPDFOBJECTHELPER_HH
... ...
libqpdf/CMakeLists.txt
... ... @@ -76,7 +76,6 @@ set(libqpdf_SOURCES
76 76 QPDFObject.cc
77 77 QPDFObjectHandle.cc
78 78 QPDFObjectHelper.cc
79   - QPDFObjGen.cc
80 79 QPDFOutlineDocumentHelper.cc
81 80 QPDFOutlineObjectHelper.cc
82 81 QPDFPageDocumentHelper.cc
... ...
libqpdf/QPDFAnnotationObjectHelper.cc
... ... @@ -13,27 +13,27 @@ QPDFAnnotationObjectHelper::QPDFAnnotationObjectHelper(QPDFObjectHandle oh) :
13 13 std::string
14 14 QPDFAnnotationObjectHelper::getSubtype()
15 15 {
16   - return this->oh.getKey("/Subtype").getName();
  16 + return oh().getKey("/Subtype").getName();
17 17 }
18 18  
19 19 QPDFObjectHandle::Rectangle
20 20 QPDFAnnotationObjectHelper::getRect()
21 21 {
22   - return this->oh.getKey("/Rect").getArrayAsRectangle();
  22 + return oh().getKey("/Rect").getArrayAsRectangle();
23 23 }
24 24  
25 25 QPDFObjectHandle
26 26 QPDFAnnotationObjectHelper::getAppearanceDictionary()
27 27 {
28   - return this->oh.getKey("/AP");
  28 + return oh().getKey("/AP");
29 29 }
30 30  
31 31 std::string
32 32 QPDFAnnotationObjectHelper::getAppearanceState()
33 33 {
34   - if (this->oh.getKey("/AS").isName()) {
  34 + if (oh().getKey("/AS").isName()) {
35 35 QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS present");
36   - return this->oh.getKey("/AS").getName();
  36 + return oh().getKey("/AS").getName();
37 37 }
38 38 QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS absent");
39 39 return "";
... ... @@ -42,7 +42,7 @@ QPDFAnnotationObjectHelper::getAppearanceState()
42 42 int
43 43 QPDFAnnotationObjectHelper::getFlags()
44 44 {
45   - QPDFObjectHandle flags_obj = this->oh.getKey("/F");
  45 + QPDFObjectHandle flags_obj = oh().getKey("/F");
46 46 return flags_obj.isInteger() ? flags_obj.getIntValueAsInt() : 0;
47 47 }
48 48  
... ... @@ -143,7 +143,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance(
143 143  
144 144 // 3. Apply the rotation to A as computed above to get the final appearance matrix.
145 145  
146   - QPDFObjectHandle rect_obj = this->oh.getKey("/Rect");
  146 + QPDFObjectHandle rect_obj = oh().getKey("/Rect");
147 147 QPDFObjectHandle as = getAppearanceStream("/N").getDict();
148 148 QPDFObjectHandle bbox_obj = as.getKey("/BBox");
149 149 QPDFObjectHandle matrix_obj = as.getKey("/Matrix");
... ...
libqpdf/QPDFEFStreamObjectHelper.cc
... ... @@ -16,7 +16,7 @@ QPDFEFStreamObjectHelper::QPDFEFStreamObjectHelper(QPDFObjectHandle oh) :
16 16 QPDFObjectHandle
17 17 QPDFEFStreamObjectHelper::getParam(std::string const& pkey)
18 18 {
19   - auto params = this->oh.getDict().getKey("/Params");
  19 + auto params = oh().getDict().getKey("/Params");
20 20 if (params.isDictionary()) {
21 21 return params.getKey(pkey);
22 22 }
... ... @@ -26,10 +26,9 @@ QPDFEFStreamObjectHelper::getParam(std::string const&amp; pkey)
26 26 void
27 27 QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval)
28 28 {
29   - auto params = this->oh.getDict().getKey("/Params");
  29 + auto params = oh().getDict().getKey("/Params");
30 30 if (!params.isDictionary()) {
31   - params =
32   - this->oh.getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary());
  31 + params = oh().getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary());
33 32 }
34 33 params.replaceKey(pkey, pval);
35 34 }
... ... @@ -67,7 +66,7 @@ QPDFEFStreamObjectHelper::getSize()
67 66 std::string
68 67 QPDFEFStreamObjectHelper::getSubtype()
69 68 {
70   - auto val = this->oh.getDict().getKey("/Subtype");
  69 + auto val = oh().getDict().getKey("/Subtype");
71 70 if (val.isName()) {
72 71 auto n = val.getName();
73 72 if (n.length() > 1) {
... ... @@ -124,7 +123,7 @@ QPDFEFStreamObjectHelper::setModDate(std::string const&amp; date)
124 123 QPDFEFStreamObjectHelper&
125 124 QPDFEFStreamObjectHelper::setSubtype(std::string const& subtype)
126 125 {
127   - this->oh.getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype));
  126 + oh().getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype));
128 127 return *this;
129 128 }
130 129  
... ...
libqpdf/QPDFFileSpecObjectHelper.cc
... ... @@ -25,7 +25,7 @@ std::string
25 25 QPDFFileSpecObjectHelper::getDescription()
26 26 {
27 27 std::string result;
28   - auto desc = this->oh.getKey("/Desc");
  28 + auto desc = oh().getKey("/Desc");
29 29 if (desc.isString()) {
30 30 result = desc.getUTF8Value();
31 31 }
... ... @@ -36,7 +36,7 @@ std::string
36 36 QPDFFileSpecObjectHelper::getFilename()
37 37 {
38 38 for (auto const& i: name_keys) {
39   - auto k = this->oh.getKey(i);
  39 + auto k = oh().getKey(i);
40 40 if (k.isString()) {
41 41 return k.getUTF8Value();
42 42 }
... ... @@ -49,7 +49,7 @@ QPDFFileSpecObjectHelper::getFilenames()
49 49 {
50 50 std::map<std::string, std::string> result;
51 51 for (auto const& i: name_keys) {
52   - auto k = this->oh.getKey(i);
  52 + auto k = oh().getKey(i);
53 53 if (k.isString()) {
54 54 result[i] = k.getUTF8Value();
55 55 }
... ... @@ -60,7 +60,7 @@ QPDFFileSpecObjectHelper::getFilenames()
60 60 QPDFObjectHandle
61 61 QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const& key)
62 62 {
63   - auto ef = this->oh.getKey("/EF");
  63 + auto ef = oh().getKey("/EF");
64 64 if (!ef.isDictionary()) {
65 65 return QPDFObjectHandle::newNull();
66 66 }
... ... @@ -79,7 +79,7 @@ QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const&amp; key)
79 79 QPDFObjectHandle
80 80 QPDFFileSpecObjectHelper::getEmbeddedFileStreams()
81 81 {
82   - return this->oh.getKey("/EF");
  82 + return oh().getKey("/EF");
83 83 }
84 84  
85 85 QPDFFileSpecObjectHelper
... ... @@ -110,7 +110,7 @@ QPDFFileSpecObjectHelper::createFileSpec(
110 110 QPDFFileSpecObjectHelper&
111 111 QPDFFileSpecObjectHelper::setDescription(std::string const& desc)
112 112 {
113   - this->oh.replaceKey("/Desc", QPDFObjectHandle::newUnicodeString(desc));
  113 + oh().replaceKey("/Desc", QPDFObjectHandle::newUnicodeString(desc));
114 114 return *this;
115 115 }
116 116  
... ... @@ -119,13 +119,13 @@ QPDFFileSpecObjectHelper::setFilename(
119 119 std::string const& unicode_name, std::string const& compat_name)
120 120 {
121 121 auto uf = QPDFObjectHandle::newUnicodeString(unicode_name);
122   - this->oh.replaceKey("/UF", uf);
  122 + oh().replaceKey("/UF", uf);
123 123 if (compat_name.empty()) {
124 124 QTC::TC("qpdf", "QPDFFileSpecObjectHelper empty compat_name");
125   - this->oh.replaceKey("/F", uf);
  125 + oh().replaceKey("/F", uf);
126 126 } else {
127 127 QTC::TC("qpdf", "QPDFFileSpecObjectHelper non-empty compat_name");
128   - this->oh.replaceKey("/F", QPDFObjectHandle::newString(compat_name));
  128 + oh().replaceKey("/F", QPDFObjectHandle::newString(compat_name));
129 129 }
130 130 return *this;
131 131 }
... ...
libqpdf/QPDFFormFieldObjectHelper.cc
... ... @@ -23,19 +23,19 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() :
23 23 bool
24 24 QPDFFormFieldObjectHelper::isNull()
25 25 {
26   - return this->oh.isNull();
  26 + return oh().isNull();
27 27 }
28 28  
29 29 QPDFFormFieldObjectHelper
30 30 QPDFFormFieldObjectHelper::getParent()
31 31 {
32   - return this->oh.getKey("/Parent"); // may be null
  32 + return oh().getKey("/Parent"); // may be null
33 33 }
34 34  
35 35 QPDFFormFieldObjectHelper
36 36 QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different)
37 37 {
38   - auto top_field = this->oh;
  38 + auto top_field = oh();
39 39 QPDFObjGen::set seen;
40 40 while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").isNull()) {
41 41 top_field = top_field.getKey("/Parent");
... ... @@ -51,7 +51,7 @@ QPDFFormFieldObjectHelper::getFieldFromAcroForm(std::string const&amp; name)
51 51 {
52 52 QPDFObjectHandle result = QPDFObjectHandle::newNull();
53 53 // Fields are supposed to be indirect, so this should work.
54   - QPDF* q = this->oh.getOwningQPDF();
  54 + QPDF* q = oh().getOwningQPDF();
55 55 if (!q) {
56 56 return result;
57 57 }
... ... @@ -65,7 +65,7 @@ QPDFFormFieldObjectHelper::getFieldFromAcroForm(std::string const&amp; name)
65 65 QPDFObjectHandle
66 66 QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name)
67 67 {
68   - QPDFObjectHandle node = this->oh;
  68 + QPDFObjectHandle node = oh();
69 69 if (!node.isDictionary()) {
70 70 return QPDFObjectHandle::newNull();
71 71 }
... ... @@ -116,7 +116,7 @@ std::string
116 116 QPDFFormFieldObjectHelper::getFullyQualifiedName()
117 117 {
118 118 std::string result;
119   - QPDFObjectHandle node = this->oh;
  119 + QPDFObjectHandle node = oh();
120 120 QPDFObjGen::set seen;
121 121 while (!node.isNull() && seen.add(node)) {
122 122 if (node.getKey("/T").isString()) {
... ... @@ -135,8 +135,8 @@ std::string
135 135 QPDFFormFieldObjectHelper::getPartialName()
136 136 {
137 137 std::string result;
138   - if (this->oh.getKey("/T").isString()) {
139   - result = this->oh.getKey("/T").getUTF8Value();
  138 + if (oh().getKey("/T").isString()) {
  139 + result = oh().getKey("/T").getUTF8Value();
140 140 }
141 141 return result;
142 142 }
... ... @@ -144,9 +144,9 @@ QPDFFormFieldObjectHelper::getPartialName()
144 144 std::string
145 145 QPDFFormFieldObjectHelper::getAlternativeName()
146 146 {
147   - if (this->oh.getKey("/TU").isString()) {
  147 + if (oh().getKey("/TU").isString()) {
148 148 QTC::TC("qpdf", "QPDFFormFieldObjectHelper TU present");
149   - return this->oh.getKey("/TU").getUTF8Value();
  149 + return oh().getKey("/TU").getUTF8Value();
150 150 }
151 151 QTC::TC("qpdf", "QPDFFormFieldObjectHelper TU absent");
152 152 return getFullyQualifiedName();
... ... @@ -155,9 +155,9 @@ QPDFFormFieldObjectHelper::getAlternativeName()
155 155 std::string
156 156 QPDFFormFieldObjectHelper::getMappingName()
157 157 {
158   - if (this->oh.getKey("/TM").isString()) {
  158 + if (oh().getKey("/TM").isString()) {
159 159 QTC::TC("qpdf", "QPDFFormFieldObjectHelper TM present");
160   - return this->oh.getKey("/TM").getUTF8Value();
  160 + return oh().getKey("/TM").getUTF8Value();
161 161 }
162 162 QTC::TC("qpdf", "QPDFFormFieldObjectHelper TM absent");
163 163 return getAlternativeName();
... ... @@ -287,13 +287,13 @@ QPDFFormFieldObjectHelper::getChoices()
287 287 void
288 288 QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, QPDFObjectHandle value)
289 289 {
290   - this->oh.replaceKey(key, value);
  290 + oh().replaceKey(key, value);
291 291 }
292 292  
293 293 void
294 294 QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, std::string const& utf8_value)
295 295 {
296   - this->oh.replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value));
  296 + oh().replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value));
297 297 }
298 298  
299 299 void
... ... @@ -310,18 +310,18 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
310 310 setCheckBoxValue((name != "/Off"));
311 311 }
312 312 if (!okay) {
313   - this->oh.warnIfPossible(
  313 + oh().warnIfPossible(
314 314 "ignoring attempt to set a checkbox field to a value whose type is not name");
315 315 }
316 316 } else if (isRadioButton()) {
317 317 if (value.isName()) {
318 318 setRadioButtonValue(value);
319 319 } else {
320   - this->oh.warnIfPossible(
  320 + oh().warnIfPossible(
321 321 "ignoring attempt to set a radio button field to an object that is not a name");
322 322 }
323 323 } else if (isPushbutton()) {
324   - this->oh.warnIfPossible("ignoring attempt set the value of a pushbutton field");
  324 + oh().warnIfPossible("ignoring attempt set the value of a pushbutton field");
325 325 }
326 326 return;
327 327 }
... ... @@ -331,7 +331,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances)
331 331 setFieldAttribute("/V", value);
332 332 }
333 333 if (need_appearances) {
334   - QPDF& qpdf = this->oh.getQPDF(
  334 + QPDF& qpdf = oh().getQPDF(
335 335 "QPDFFormFieldObjectHelper::setV called with need_appearances = "
336 336 "true on an object that is not associated with an owning QPDF");
337 337 QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true);
... ... @@ -355,7 +355,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
355 355 // its /AP (i.e. its normal appearance stream dictionary), set /AS to name; otherwise, if /Off
356 356 // is a member, set /AS to /Off.
357 357 // Note that we never turn on /NeedAppearances when setting a radio button field.
358   - QPDFObjectHandle parent = this->oh.getKey("/Parent");
  358 + QPDFObjectHandle parent = oh().getKey("/Parent");
359 359 if (parent.isDictionary() && parent.getKey("/Parent").isNull()) {
360 360 QPDFFormFieldObjectHelper ph(parent);
361 361 if (ph.isRadioButton()) {
... ... @@ -366,9 +366,9 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
366 366 }
367 367 }
368 368  
369   - QPDFObjectHandle kids = this->oh.getKey("/Kids");
  369 + QPDFObjectHandle kids = oh().getKey("/Kids");
370 370 if (!(isRadioButton() && parent.isNull() && kids.isArray())) {
371   - this->oh.warnIfPossible(
  371 + oh().warnIfPossible(
372 372 "don't know how to set the value"
373 373 " of this field as a radio button");
374 374 return;
... ... @@ -399,7 +399,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
399 399 }
400 400 if (!annot) {
401 401 QTC::TC("qpdf", "QPDFObjectHandle broken radio button");
402   - this->oh.warnIfPossible("unable to set the value of this radio button");
  402 + oh().warnIfPossible("unable to set the value of this radio button");
403 403 continue;
404 404 }
405 405 if (AP.isDictionary() && AP.getKey("/N").isDictionary() &&
... ... @@ -416,12 +416,12 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name)
416 416 void
417 417 QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
418 418 {
419   - QPDFObjectHandle AP = this->oh.getKey("/AP");
  419 + QPDFObjectHandle AP = oh().getKey("/AP");
420 420 QPDFObjectHandle annot;
421 421 if (AP.isNull()) {
422 422 // The widget may be below. If there is more than one, just
423 423 // find the first one.
424   - QPDFObjectHandle kids = this->oh.getKey("/Kids");
  424 + QPDFObjectHandle kids = oh().getKey("/Kids");
425 425 if (kids.isArray()) {
426 426 int nkids = kids.getArrayNItems();
427 427 for (int i = 0; i < nkids; ++i) {
... ... @@ -435,7 +435,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
435 435 }
436 436 }
437 437 } else {
438   - annot = this->oh;
  438 + annot = oh();
439 439 }
440 440 std::string on_value;
441 441 if (value) {
... ... @@ -462,7 +462,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value)
462 462 setFieldAttribute("/V", name);
463 463 if (!annot) {
464 464 QTC::TC("qpdf", "QPDFObjectHandle broken checkbox");
465   - this->oh.warnIfPossible("unable to set the value of this checkbox");
  465 + oh().warnIfPossible("unable to set the value of this checkbox");
466 466 return;
467 467 }
468 468 QTC::TC("qpdf", "QPDFFormFieldObjectHelper set checkbox AS");
... ... @@ -775,7 +775,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper&amp; ao
775 775 "<< /Resources << /ProcSet [ /PDF /Text ] >>"
776 776 " /Type /XObject /Subtype /Form >>");
777 777 dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox));
778   - AS = QPDFObjectHandle::newStream(this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n");
  778 + AS = QPDFObjectHandle::newStream(oh().getOwningQPDF(), "/Tx BMC\nEMC\n");
779 779 AS.replaceDict(dict);
780 780 QPDFObjectHandle AP = aoh.getAppearanceDictionary();
781 781 if (AP.isNull()) {
... ...
libqpdf/QPDFObjGen.cc deleted
1   -#include <qpdf/QPDFObjGen.hh>
2   -
3   -#include <qpdf/QPDFObjectHandle.hh>
4   -#include <qpdf/QPDFObjectHelper.hh>
5   -#include <qpdf/QPDFObject_private.hh>
6   -
7   -#include <stdexcept>
8   -
9   -bool
10   -QPDFObjGen::set::add(QPDFObjectHandle const& oh)
11   -{
12   - if (auto* ptr = oh.getObjectPtr()) {
13   - return add(ptr->getObjGen());
14   - } else {
15   - throw std::logic_error(
16   - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle");
17   - return false;
18   - }
19   -}
20   -
21   -bool
22   -QPDFObjGen::set::add(QPDFObjectHelper const& helper)
23   -{
24   - if (auto* ptr = helper.getObjectHandle().getObjectPtr()) {
25   - return add(ptr->getObjGen());
26   - } else {
27   - throw std::logic_error(
28   - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle");
29   - return false;
30   - }
31   -}
32   -
33   -void
34   -QPDFObjGen::set::erase(QPDFObjectHandle const& oh)
35   -{
36   - if (auto* ptr = oh.getObjectPtr()) {
37   - erase(ptr->getObjGen());
38   - } else {
39   - throw std::logic_error(
40   - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle");
41   - }
42   -}
43   -
44   -void
45   -QPDFObjGen::set::erase(QPDFObjectHelper const& helper)
46   -{
47   - if (auto* ptr = helper.getObjectHandle().getObjectPtr()) {
48   - erase(ptr->getObjGen());
49   - } else {
50   - throw std::logic_error(
51   - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle");
52   - }
53   -}
libqpdf/QPDFOutlineObjectHelper.cc
... ... @@ -9,8 +9,8 @@ QPDFOutlineObjectHelper::Members::Members(QPDFOutlineDocumentHelper&amp; dh) :
9 9 }
10 10  
11 11 QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
12   - QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth) :
13   - QPDFObjectHelper(oh),
  12 + QPDFObjectHandle a_oh, QPDFOutlineDocumentHelper& dh, int depth) :
  13 + QPDFObjectHelper(a_oh),
14 14 m(new Members(dh))
15 15 {
16 16 if (depth > 50) {
... ... @@ -18,13 +18,13 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper(
18 18 // to 1.
19 19 return;
20 20 }
21   - if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, this->oh.getObjGen())) {
  21 + if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, a_oh.getObjGen())) {
22 22 QTC::TC("qpdf", "QPDFOutlineObjectHelper loop");
23 23 return;
24 24 }
25 25  
26 26 QPDFObjGen::set children;
27   - QPDFObjectHandle cur = oh.getKey("/First");
  27 + QPDFObjectHandle cur = a_oh.getKey("/First");
28 28 while (!cur.isNull() && cur.isIndirect() && children.add(cur)) {
29 29 QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth);
30 30 new_ooh.m->parent = std::make_shared<QPDFOutlineObjectHelper>(*this);
... ... @@ -50,11 +50,11 @@ QPDFOutlineObjectHelper::getDest()
50 50 {
51 51 QPDFObjectHandle dest;
52 52 QPDFObjectHandle A;
53   - if (this->oh.hasKey("/Dest")) {
  53 + if (oh().hasKey("/Dest")) {
54 54 QTC::TC("qpdf", "QPDFOutlineObjectHelper direct dest");
55   - dest = this->oh.getKey("/Dest");
  55 + dest = oh().getKey("/Dest");
56 56 } else if (
57   - (A = this->oh.getKey("/A")).isDictionary() && A.getKey("/S").isName() &&
  57 + (A = oh().getKey("/A")).isDictionary() && A.getKey("/S").isName() &&
58 58 (A.getKey("/S").getName() == "/GoTo") && A.hasKey("/D")) {
59 59 QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest");
60 60 dest = A.getKey("/D");
... ... @@ -85,8 +85,8 @@ int
85 85 QPDFOutlineObjectHelper::getCount()
86 86 {
87 87 int count = 0;
88   - if (this->oh.hasKey("/Count")) {
89   - count = this->oh.getKey("/Count").getIntValueAsInt();
  88 + if (oh().hasKey("/Count")) {
  89 + count = oh().getKey("/Count").getIntValueAsInt();
90 90 }
91 91 return count;
92 92 }
... ... @@ -95,8 +95,8 @@ std::string
95 95 QPDFOutlineObjectHelper::getTitle()
96 96 {
97 97 std::string result;
98   - if (this->oh.hasKey("/Title")) {
99   - result = this->oh.getKey("/Title").getUTF8Value();
  98 + if (oh().hasKey("/Title")) {
  99 + result = oh().getKey("/Title").getUTF8Value();
100 100 }
101 101 return result;
102 102 }
... ...
libqpdf/QPDFPageObjectHelper.cc
... ... @@ -227,9 +227,9 @@ QPDFPageObjectHelper::getAttribute(
227 227 std::function<QPDFObjectHandle()> get_fallback,
228 228 bool copy_if_fallback)
229 229 {
230   - const bool is_form_xobject = this->oh.isFormXObject();
  230 + const bool is_form_xobject = oh().isFormXObject();
231 231 bool inherited = false;
232   - auto dict = is_form_xobject ? oh.getDict() : oh;
  232 + auto dict = is_form_xobject ? oh().getDict() : oh();
233 233 auto result = dict.getKey(name);
234 234  
235 235 if (!is_form_xobject && result.isNull() &&
... ... @@ -324,7 +324,7 @@ QPDFPageObjectHelper::forEachXObject(
324 324 QTC::TC(
325 325 "qpdf",
326 326 "QPDFPageObjectHelper::forEachXObject",
327   - recursive ? (this->oh.isFormXObject() ? 0 : 1) : (this->oh.isFormXObject() ? 2 : 3));
  327 + recursive ? (oh().isFormXObject() ? 0 : 1) : (oh().isFormXObject() ? 2 : 3));
328 328 QPDFObjGen::set seen;
329 329 std::list<QPDFPageObjectHelper> queue;
330 330 queue.push_back(*this);
... ... @@ -402,28 +402,27 @@ QPDFPageObjectHelper::externalizeInlineImages(size_t min_size, bool shallow)
402 402 // Calling mergeResources also ensures that /XObject becomes direct and is not shared with
403 403 // other pages.
404 404 resources.mergeResources("<< /XObject << >> >>"_qpdf);
405   - InlineImageTracker iit(this->oh.getOwningQPDF(), min_size, resources);
  405 + InlineImageTracker iit(oh().getOwningQPDF(), min_size, resources);
406 406 Pl_Buffer b("new page content");
407 407 bool filtered = false;
408 408 try {
409 409 filterContents(&iit, &b);
410 410 filtered = true;
411 411 } catch (std::exception& e) {
412   - this->oh.warnIfPossible(
  412 + oh().warnIfPossible(
413 413 std::string("Unable to filter content stream: ") + e.what() +
414   - "; not attempting to externalize inline images"
415   - " from this stream");
  414 + "; not attempting to externalize inline images from this stream");
416 415 }
417 416 if (filtered && iit.any_images) {
418   - if (this->oh.isFormXObject()) {
419   - this->oh.replaceStreamData(
  417 + if (oh().isFormXObject()) {
  418 + oh().replaceStreamData(
420 419 b.getBufferSharedPointer(),
421 420 QPDFObjectHandle::newNull(),
422 421 QPDFObjectHandle::newNull());
423 422 } else {
424   - this->oh.replaceKey(
  423 + oh().replaceKey(
425 424 "/Contents",
426   - QPDFObjectHandle::newStream(&this->oh.getQPDF(), b.getBufferSharedPointer()));
  425 + QPDFObjectHandle::newStream(&oh().getQPDF(), b.getBufferSharedPointer()));
427 426 }
428 427 }
429 428 } else {
... ... @@ -439,7 +438,7 @@ std::vector&lt;QPDFAnnotationObjectHelper&gt;
439 438 QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype)
440 439 {
441 440 std::vector<QPDFAnnotationObjectHelper> result;
442   - QPDFObjectHandle annots = this->oh.getKey("/Annots");
  441 + QPDFObjectHandle annots = oh().getKey("/Annots");
443 442 if (annots.isArray()) {
444 443 int nannots = annots.getArrayNItems();
445 444 for (int i = 0; i < nannots; ++i) {
... ... @@ -455,25 +454,25 @@ QPDFPageObjectHelper::getAnnotations(std::string const&amp; only_subtype)
455 454 std::vector<QPDFObjectHandle>
456 455 QPDFPageObjectHelper::getPageContents()
457 456 {
458   - return this->oh.getPageContents();
  457 + return oh().getPageContents();
459 458 }
460 459  
461 460 void
462 461 QPDFPageObjectHelper::addPageContents(QPDFObjectHandle contents, bool first)
463 462 {
464   - this->oh.addPageContents(contents, first);
  463 + oh().addPageContents(contents, first);
465 464 }
466 465  
467 466 void
468 467 QPDFPageObjectHelper::rotatePage(int angle, bool relative)
469 468 {
470   - this->oh.rotatePage(angle, relative);
  469 + oh().rotatePage(angle, relative);
471 470 }
472 471  
473 472 void
474 473 QPDFPageObjectHelper::coalesceContentStreams()
475 474 {
476   - this->oh.coalesceContentStreams();
  475 + oh().coalesceContentStreams();
477 476 }
478 477  
479 478 void
... ... @@ -485,10 +484,10 @@ QPDFPageObjectHelper::parsePageContents(QPDFObjectHandle::ParserCallbacks* callb
485 484 void
486 485 QPDFPageObjectHelper::parseContents(QPDFObjectHandle::ParserCallbacks* callbacks)
487 486 {
488   - if (this->oh.isFormXObject()) {
489   - this->oh.parseAsContents(callbacks);
  487 + if (oh().isFormXObject()) {
  488 + oh().parseAsContents(callbacks);
490 489 } else {
491   - this->oh.parsePageContents(callbacks);
  490 + oh().parsePageContents(callbacks);
492 491 }
493 492 }
494 493  
... ... @@ -501,10 +500,10 @@ QPDFPageObjectHelper::filterPageContents(QPDFObjectHandle::TokenFilter* filter,
501 500 void
502 501 QPDFPageObjectHelper::filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next)
503 502 {
504   - if (this->oh.isFormXObject()) {
505   - this->oh.filterAsContents(filter, next);
  503 + if (oh().isFormXObject()) {
  504 + oh().filterAsContents(filter, next);
506 505 } else {
507   - this->oh.filterPageContents(filter, next);
  506 + oh().filterPageContents(filter, next);
508 507 }
509 508 }
510 509  
... ... @@ -517,10 +516,10 @@ QPDFPageObjectHelper::pipePageContents(Pipeline* p)
517 516 void
518 517 QPDFPageObjectHelper::pipeContents(Pipeline* p)
519 518 {
520   - if (this->oh.isFormXObject()) {
521   - this->oh.pipeStreamData(p, 0, qpdf_dl_specialized);
  519 + if (oh().isFormXObject()) {
  520 + oh().pipeStreamData(p, 0, qpdf_dl_specialized);
522 521 } else {
523   - this->oh.pipePageContents(p);
  522 + oh().pipePageContents(p);
524 523 }
525 524 }
526 525  
... ... @@ -528,10 +527,10 @@ void
528 527 QPDFPageObjectHelper::addContentTokenFilter(
529 528 std::shared_ptr<QPDFObjectHandle::TokenFilter> token_filter)
530 529 {
531   - if (this->oh.isFormXObject()) {
532   - this->oh.addTokenFilter(token_filter);
  530 + if (oh().isFormXObject()) {
  531 + oh().addTokenFilter(token_filter);
533 532 } else {
534   - this->oh.addContentTokenFilter(token_filter);
  533 + oh().addContentTokenFilter(token_filter);
535 534 }
536 535 }
537 536  
... ... @@ -539,30 +538,28 @@ bool
539 538 QPDFPageObjectHelper::removeUnreferencedResourcesHelper(
540 539 QPDFPageObjectHelper ph, std::set<std::string>& unresolved)
541 540 {
542   - bool is_page = (!ph.oh.isFormXObject());
  541 + bool is_page = (!ph.oh().isFormXObject());
543 542 if (!is_page) {
544 543 QTC::TC("qpdf", "QPDFPageObjectHelper filter form xobject");
545 544 }
546 545  
547 546 ResourceFinder rf;
548 547 try {
549   - auto q = ph.oh.getOwningQPDF();
  548 + auto q = ph.oh().getOwningQPDF();
550 549 size_t before_nw = (q ? q->numWarnings() : 0);
551 550 ph.parseContents(&rf);
552 551 size_t after_nw = (q ? q->numWarnings() : 0);
553 552 if (after_nw > before_nw) {
554   - ph.oh.warnIfPossible(
  553 + ph.oh().warnIfPossible(
555 554 "Bad token found while scanning content stream; "
556   - "not attempting to remove unreferenced objects from"
557   - " this object");
  555 + "not attempting to remove unreferenced objects from this object");
558 556 return false;
559 557 }
560 558 } catch (std::exception& e) {
561 559 QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names");
562   - ph.oh.warnIfPossible(
  560 + ph.oh().warnIfPossible(
563 561 std::string("Unable to parse content stream: ") + e.what() +
564   - "; not attempting to remove unreferenced objects"
565   - " from this object");
  562 + "; not attempting to remove unreferenced objects from this object");
566 563 return false;
567 564 }
568 565  
... ... @@ -646,7 +643,7 @@ QPDFPageObjectHelper::removeUnreferencedResources()
646 643 any_failures = true;
647 644 }
648 645 });
649   - if (this->oh.isFormXObject() || (!any_failures)) {
  646 + if (oh().isFormXObject() || (!any_failures)) {
650 647 removeUnreferencedResourcesHelper(*this, unresolved);
651 648 }
652 649 }
... ... @@ -654,9 +651,8 @@ QPDFPageObjectHelper::removeUnreferencedResources()
654 651 QPDFPageObjectHelper
655 652 QPDFPageObjectHelper::shallowCopyPage()
656 653 {
657   - QPDF& qpdf =
658   - this->oh.getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object");
659   - QPDFObjectHandle new_page = this->oh.shallowCopy();
  654 + QPDF& qpdf = oh().getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object");
  655 + QPDFObjectHandle new_page = oh().shallowCopy();
660 656 return {qpdf.makeIndirectObject(new_page)};
661 657 }
662 658  
... ... @@ -707,7 +703,7 @@ QPDFObjectHandle
707 703 QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations)
708 704 {
709 705 auto result =
710   - this->oh.getQPDF("QPDFPageObjectHelper::getFormXObjectForPage called with a direct object")
  706 + oh().getQPDF("QPDFPageObjectHelper::getFormXObjectForPage called with a direct object")
711 707 .newStream();
712 708 QPDFObjectHandle newdict = result.getDict();
713 709 newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject"));
... ... @@ -716,13 +712,13 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations)
716 712 newdict.replaceKey("/Group", getAttribute("/Group", false).shallowCopy());
717 713 QPDFObjectHandle bbox = getTrimBox(false).shallowCopy();
718 714 if (!bbox.isRectangle()) {
719   - this->oh.warnIfPossible(
  715 + oh().warnIfPossible(
720 716 "bounding box is invalid; form"
721 717 " XObject created from page will not work");
722 718 }
723 719 newdict.replaceKey("/BBox", bbox);
724 720 auto provider =
725   - std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(new ContentProvider(this->oh));
  721 + std::shared_ptr<QPDFObjectHandle::StreamDataProvider>(new ContentProvider(oh()));
726 722 result.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
727 723 QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false);
728 724 QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false);
... ... @@ -863,9 +859,8 @@ QPDFPageObjectHelper::placeFormXObject(
863 859 void
864 860 QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
865 861 {
866   - QPDF& qpdf =
867   - this->oh.getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object");
868   - auto rotate_oh = this->oh.getKey("/Rotate");
  862 + QPDF& qpdf = oh().getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object");
  863 + auto rotate_oh = oh().getKey("/Rotate");
869 864 int rotate = 0;
870 865 if (rotate_oh.isInteger()) {
871 866 rotate = rotate_oh.getIntValueAsInt();
... ... @@ -873,7 +868,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
873 868 if (!((rotate == 90) || (rotate == 180) || (rotate == 270))) {
874 869 return;
875 870 }
876   - auto mediabox = this->oh.getKey("/MediaBox");
  871 + auto mediabox = oh().getKey("/MediaBox");
877 872 if (!mediabox.isRectangle()) {
878 873 return;
879 874 }
... ... @@ -887,7 +882,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
887 882 "/ArtBox",
888 883 };
889 884 for (auto const& boxkey: boxes) {
890   - auto box = this->oh.getKey(boxkey);
  885 + auto box = oh().getKey(boxkey);
891 886 if (!box.isRectangle()) {
892 887 continue;
893 888 }
... ... @@ -930,7 +925,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
930 925 break;
931 926 }
932 927  
933   - this->oh.replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect));
  928 + oh().replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect));
934 929 }
935 930  
936 931 // When we rotate the page, pivot about the point 0, 0 and then translate so the page is visible
... ... @@ -962,16 +957,16 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
962 957 break;
963 958 }
964 959 std::string cm_str = std::string("q\n") + cm.unparse() + " cm\n";
965   - this->oh.addPageContents(QPDFObjectHandle::newStream(&qpdf, cm_str), true);
966   - this->oh.addPageContents(qpdf.newStream("\nQ\n"), false);
967   - this->oh.removeKey("/Rotate");
  960 + oh().addPageContents(QPDFObjectHandle::newStream(&qpdf, cm_str), true);
  961 + oh().addPageContents(qpdf.newStream("\nQ\n"), false);
  962 + oh().removeKey("/Rotate");
968 963 QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false);
969 964 if (!rotate_obj.isNull()) {
970 965 QTC::TC("qpdf", "QPDFPageObjectHelper flatten inherit rotate");
971   - this->oh.replaceKey("/Rotate", QPDFObjectHandle::newInteger(0));
  966 + oh().replaceKey("/Rotate", QPDFObjectHandle::newInteger(0));
972 967 }
973 968  
974   - QPDFObjectHandle annots = this->oh.getKey("/Annots");
  969 + QPDFObjectHandle annots = oh().getKey("/Annots");
975 970 if (annots.isArray()) {
976 971 std::vector<QPDFObjectHandle> new_annots;
977 972 std::vector<QPDFObjectHandle> new_fields;
... ... @@ -986,7 +981,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh)
986 981 for (auto const& f: new_fields) {
987 982 afdh->addFormField(QPDFFormFieldObjectHelper(f));
988 983 }
989   - this->oh.replaceKey("/Annots", QPDFObjectHandle::newArray(new_annots));
  984 + oh().replaceKey("/Annots", QPDFObjectHandle::newArray(new_annots));
990 985 }
991 986 }
992 987  
... ... @@ -1005,7 +1000,7 @@ QPDFPageObjectHelper::copyAnnotations(
1005 1000 QPDF& from_qpdf = from_page.getObjectHandle().getQPDF(
1006 1001 "QPDFPageObjectHelper::copyAnnotations: from page is a direct object");
1007 1002 QPDF& this_qpdf =
1008   - this->oh.getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object");
  1003 + oh().getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object");
1009 1004  
1010 1005 std::vector<QPDFObjectHandle> new_annots;
1011 1006 std::vector<QPDFObjectHandle> new_fields;
... ... @@ -1032,9 +1027,9 @@ QPDFPageObjectHelper::copyAnnotations(
1032 1027 afdh->transformAnnotations(
1033 1028 old_annots, new_annots, new_fields, old_fields, cm, &from_qpdf, from_afdh);
1034 1029 afdh->addAndRenameFormFields(new_fields);
1035   - auto annots = this->oh.getKey("/Annots");
  1030 + auto annots = oh().getKey("/Annots");
1036 1031 if (!annots.isArray()) {
1037   - annots = this->oh.replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray());
  1032 + annots = oh().replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray());
1038 1033 }
1039 1034 for (auto const& annot: new_annots) {
1040 1035 annots.appendItem(annot);
... ...
qpdf/sizes.cc
... ... @@ -109,7 +109,6 @@ main()
109 109 print_size(QPDFNumberTreeObjectHelper);
110 110 print_size(QPDFNumberTreeObjectHelper::iterator);
111 111 print_size(QPDFObjGen);
112   - print_size(QPDFObjGen::set);
113 112 print_size(QPDFObjectHandle);
114 113 print_size(QPDFObjectHandle::ParserCallbacks);
115 114 print_size(QPDFObjectHandle::QPDFArrayItems);
... ... @@ -118,6 +117,7 @@ main()
118 117 print_size(QPDFObjectHandle::QPDFDictItems::iterator);
119 118 print_size(QPDFObjectHandle::StreamDataProvider);
120 119 print_size(QPDFObjectHandle::TokenFilter);
  120 + print_size(QPDFObjectHelper);
121 121 print_size(QPDFOutlineDocumentHelper);
122 122 print_size(QPDFOutlineObjectHelper);
123 123 print_size(QPDFPageDocumentHelper);
... ...