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