diff --git a/include/qpdf/QPDFObjGen.hh b/include/qpdf/QPDFObjGen.hh index 3553ff3..5c38665 100644 --- a/include/qpdf/QPDFObjGen.hh +++ b/include/qpdf/QPDFObjGen.hh @@ -130,12 +130,6 @@ class QPDFObjGen } QPDF_DLL - bool add(QPDFObjectHandle const& oh); - - QPDF_DLL - bool add(QPDFObjectHelper const& oh); - - QPDF_DLL void erase(QPDFObjGen og) { @@ -143,12 +137,6 @@ class QPDFObjGen std::set::erase(og); } } - - QPDF_DLL - void erase(QPDFObjectHandle const& oh); - - QPDF_DLL - void erase(QPDFObjectHelper const& oh); }; private: diff --git a/include/qpdf/QPDFObjectHelper.hh b/include/qpdf/QPDFObjectHelper.hh index ebd2e80..648b0f7 100644 --- a/include/qpdf/QPDFObjectHelper.hh +++ b/include/qpdf/QPDFObjectHelper.hh @@ -31,13 +31,12 @@ // underlying QPDF objects unless there is a specific comment in a specific helper method that says // otherwise. The pattern of using helper objects was introduced to allow creation of higher level // helper functions without polluting the public interface of QPDFObjectHandle. - -class QPDF_DLL_CLASS QPDFObjectHelper +class QPDF_DLL_CLASS QPDFObjectHelper: public qpdf::BaseHandle { public: QPDF_DLL QPDFObjectHelper(QPDFObjectHandle oh) : - oh(oh) + qpdf::BaseHandle(oh.getObj()) { } QPDF_DLL @@ -46,17 +45,29 @@ class QPDF_DLL_CLASS QPDFObjectHelper QPDFObjectHandle getObjectHandle() { - return this->oh; + return {obj}; } QPDF_DLL QPDFObjectHandle const getObjectHandle() const { - return this->oh; + return {obj}; } protected: - QPDFObjectHandle oh; + QPDF_DLL_PRIVATE + QPDFObjectHandle + oh() + { + return {obj}; + } + QPDF_DLL_PRIVATE + QPDFObjectHandle const + oh() const + { + return {obj}; + } + QPDFObjectHandle oh_; }; #endif // QPDFOBJECTHELPER_HH diff --git a/libqpdf/CMakeLists.txt b/libqpdf/CMakeLists.txt index 91344a5..5480f12 100644 --- a/libqpdf/CMakeLists.txt +++ b/libqpdf/CMakeLists.txt @@ -76,7 +76,6 @@ set(libqpdf_SOURCES QPDFObject.cc QPDFObjectHandle.cc QPDFObjectHelper.cc - QPDFObjGen.cc QPDFOutlineDocumentHelper.cc QPDFOutlineObjectHelper.cc QPDFPageDocumentHelper.cc diff --git a/libqpdf/QPDFAnnotationObjectHelper.cc b/libqpdf/QPDFAnnotationObjectHelper.cc index 1878c0e..573273c 100644 --- a/libqpdf/QPDFAnnotationObjectHelper.cc +++ b/libqpdf/QPDFAnnotationObjectHelper.cc @@ -13,27 +13,27 @@ QPDFAnnotationObjectHelper::QPDFAnnotationObjectHelper(QPDFObjectHandle oh) : std::string QPDFAnnotationObjectHelper::getSubtype() { - return this->oh.getKey("/Subtype").getName(); + return oh().getKey("/Subtype").getName(); } QPDFObjectHandle::Rectangle QPDFAnnotationObjectHelper::getRect() { - return this->oh.getKey("/Rect").getArrayAsRectangle(); + return oh().getKey("/Rect").getArrayAsRectangle(); } QPDFObjectHandle QPDFAnnotationObjectHelper::getAppearanceDictionary() { - return this->oh.getKey("/AP"); + return oh().getKey("/AP"); } std::string QPDFAnnotationObjectHelper::getAppearanceState() { - if (this->oh.getKey("/AS").isName()) { + if (oh().getKey("/AS").isName()) { QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS present"); - return this->oh.getKey("/AS").getName(); + return oh().getKey("/AS").getName(); } QTC::TC("qpdf", "QPDFAnnotationObjectHelper AS absent"); return ""; @@ -42,7 +42,7 @@ QPDFAnnotationObjectHelper::getAppearanceState() int QPDFAnnotationObjectHelper::getFlags() { - QPDFObjectHandle flags_obj = this->oh.getKey("/F"); + QPDFObjectHandle flags_obj = oh().getKey("/F"); return flags_obj.isInteger() ? flags_obj.getIntValueAsInt() : 0; } @@ -143,7 +143,7 @@ QPDFAnnotationObjectHelper::getPageContentForAppearance( // 3. Apply the rotation to A as computed above to get the final appearance matrix. - QPDFObjectHandle rect_obj = this->oh.getKey("/Rect"); + QPDFObjectHandle rect_obj = oh().getKey("/Rect"); QPDFObjectHandle as = getAppearanceStream("/N").getDict(); QPDFObjectHandle bbox_obj = as.getKey("/BBox"); QPDFObjectHandle matrix_obj = as.getKey("/Matrix"); diff --git a/libqpdf/QPDFEFStreamObjectHelper.cc b/libqpdf/QPDFEFStreamObjectHelper.cc index b21c898..8728617 100644 --- a/libqpdf/QPDFEFStreamObjectHelper.cc +++ b/libqpdf/QPDFEFStreamObjectHelper.cc @@ -16,7 +16,7 @@ QPDFEFStreamObjectHelper::QPDFEFStreamObjectHelper(QPDFObjectHandle oh) : QPDFObjectHandle QPDFEFStreamObjectHelper::getParam(std::string const& pkey) { - auto params = this->oh.getDict().getKey("/Params"); + auto params = oh().getDict().getKey("/Params"); if (params.isDictionary()) { return params.getKey(pkey); } @@ -26,10 +26,9 @@ QPDFEFStreamObjectHelper::getParam(std::string const& pkey) void QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval) { - auto params = this->oh.getDict().getKey("/Params"); + auto params = oh().getDict().getKey("/Params"); if (!params.isDictionary()) { - params = - this->oh.getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary()); + params = oh().getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary()); } params.replaceKey(pkey, pval); } @@ -67,7 +66,7 @@ QPDFEFStreamObjectHelper::getSize() std::string QPDFEFStreamObjectHelper::getSubtype() { - auto val = this->oh.getDict().getKey("/Subtype"); + auto val = oh().getDict().getKey("/Subtype"); if (val.isName()) { auto n = val.getName(); if (n.length() > 1) { @@ -124,7 +123,7 @@ QPDFEFStreamObjectHelper::setModDate(std::string const& date) QPDFEFStreamObjectHelper& QPDFEFStreamObjectHelper::setSubtype(std::string const& subtype) { - this->oh.getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype)); + oh().getDict().replaceKey("/Subtype", QPDFObjectHandle::newName("/" + subtype)); return *this; } diff --git a/libqpdf/QPDFFileSpecObjectHelper.cc b/libqpdf/QPDFFileSpecObjectHelper.cc index eada461..8fac3ba 100644 --- a/libqpdf/QPDFFileSpecObjectHelper.cc +++ b/libqpdf/QPDFFileSpecObjectHelper.cc @@ -25,7 +25,7 @@ std::string QPDFFileSpecObjectHelper::getDescription() { std::string result; - auto desc = this->oh.getKey("/Desc"); + auto desc = oh().getKey("/Desc"); if (desc.isString()) { result = desc.getUTF8Value(); } @@ -36,7 +36,7 @@ std::string QPDFFileSpecObjectHelper::getFilename() { for (auto const& i: name_keys) { - auto k = this->oh.getKey(i); + auto k = oh().getKey(i); if (k.isString()) { return k.getUTF8Value(); } @@ -49,7 +49,7 @@ QPDFFileSpecObjectHelper::getFilenames() { std::map result; for (auto const& i: name_keys) { - auto k = this->oh.getKey(i); + auto k = oh().getKey(i); if (k.isString()) { result[i] = k.getUTF8Value(); } @@ -60,7 +60,7 @@ QPDFFileSpecObjectHelper::getFilenames() QPDFObjectHandle QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const& key) { - auto ef = this->oh.getKey("/EF"); + auto ef = oh().getKey("/EF"); if (!ef.isDictionary()) { return QPDFObjectHandle::newNull(); } @@ -79,7 +79,7 @@ QPDFFileSpecObjectHelper::getEmbeddedFileStream(std::string const& key) QPDFObjectHandle QPDFFileSpecObjectHelper::getEmbeddedFileStreams() { - return this->oh.getKey("/EF"); + return oh().getKey("/EF"); } QPDFFileSpecObjectHelper @@ -110,7 +110,7 @@ QPDFFileSpecObjectHelper::createFileSpec( QPDFFileSpecObjectHelper& QPDFFileSpecObjectHelper::setDescription(std::string const& desc) { - this->oh.replaceKey("/Desc", QPDFObjectHandle::newUnicodeString(desc)); + oh().replaceKey("/Desc", QPDFObjectHandle::newUnicodeString(desc)); return *this; } @@ -119,13 +119,13 @@ QPDFFileSpecObjectHelper::setFilename( std::string const& unicode_name, std::string const& compat_name) { auto uf = QPDFObjectHandle::newUnicodeString(unicode_name); - this->oh.replaceKey("/UF", uf); + oh().replaceKey("/UF", uf); if (compat_name.empty()) { QTC::TC("qpdf", "QPDFFileSpecObjectHelper empty compat_name"); - this->oh.replaceKey("/F", uf); + oh().replaceKey("/F", uf); } else { QTC::TC("qpdf", "QPDFFileSpecObjectHelper non-empty compat_name"); - this->oh.replaceKey("/F", QPDFObjectHandle::newString(compat_name)); + oh().replaceKey("/F", QPDFObjectHandle::newString(compat_name)); } return *this; } diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index 8e5b2d8..0f9c936 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -23,19 +23,19 @@ QPDFFormFieldObjectHelper::QPDFFormFieldObjectHelper() : bool QPDFFormFieldObjectHelper::isNull() { - return this->oh.isNull(); + return oh().isNull(); } QPDFFormFieldObjectHelper QPDFFormFieldObjectHelper::getParent() { - return this->oh.getKey("/Parent"); // may be null + return oh().getKey("/Parent"); // may be null } QPDFFormFieldObjectHelper QPDFFormFieldObjectHelper::getTopLevelField(bool* is_different) { - auto top_field = this->oh; + auto top_field = oh(); QPDFObjGen::set seen; while (seen.add(top_field) && !top_field.getKeyIfDict("/Parent").isNull()) { top_field = top_field.getKey("/Parent"); @@ -51,7 +51,7 @@ QPDFFormFieldObjectHelper::getFieldFromAcroForm(std::string const& name) { QPDFObjectHandle result = QPDFObjectHandle::newNull(); // Fields are supposed to be indirect, so this should work. - QPDF* q = this->oh.getOwningQPDF(); + QPDF* q = oh().getOwningQPDF(); if (!q) { return result; } @@ -65,7 +65,7 @@ QPDFFormFieldObjectHelper::getFieldFromAcroForm(std::string const& name) QPDFObjectHandle QPDFFormFieldObjectHelper::getInheritableFieldValue(std::string const& name) { - QPDFObjectHandle node = this->oh; + QPDFObjectHandle node = oh(); if (!node.isDictionary()) { return QPDFObjectHandle::newNull(); } @@ -116,7 +116,7 @@ std::string QPDFFormFieldObjectHelper::getFullyQualifiedName() { std::string result; - QPDFObjectHandle node = this->oh; + QPDFObjectHandle node = oh(); QPDFObjGen::set seen; while (!node.isNull() && seen.add(node)) { if (node.getKey("/T").isString()) { @@ -135,8 +135,8 @@ std::string QPDFFormFieldObjectHelper::getPartialName() { std::string result; - if (this->oh.getKey("/T").isString()) { - result = this->oh.getKey("/T").getUTF8Value(); + if (oh().getKey("/T").isString()) { + result = oh().getKey("/T").getUTF8Value(); } return result; } @@ -144,9 +144,9 @@ QPDFFormFieldObjectHelper::getPartialName() std::string QPDFFormFieldObjectHelper::getAlternativeName() { - if (this->oh.getKey("/TU").isString()) { + if (oh().getKey("/TU").isString()) { QTC::TC("qpdf", "QPDFFormFieldObjectHelper TU present"); - return this->oh.getKey("/TU").getUTF8Value(); + return oh().getKey("/TU").getUTF8Value(); } QTC::TC("qpdf", "QPDFFormFieldObjectHelper TU absent"); return getFullyQualifiedName(); @@ -155,9 +155,9 @@ QPDFFormFieldObjectHelper::getAlternativeName() std::string QPDFFormFieldObjectHelper::getMappingName() { - if (this->oh.getKey("/TM").isString()) { + if (oh().getKey("/TM").isString()) { QTC::TC("qpdf", "QPDFFormFieldObjectHelper TM present"); - return this->oh.getKey("/TM").getUTF8Value(); + return oh().getKey("/TM").getUTF8Value(); } QTC::TC("qpdf", "QPDFFormFieldObjectHelper TM absent"); return getAlternativeName(); @@ -287,13 +287,13 @@ QPDFFormFieldObjectHelper::getChoices() void QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, QPDFObjectHandle value) { - this->oh.replaceKey(key, value); + oh().replaceKey(key, value); } void QPDFFormFieldObjectHelper::setFieldAttribute(std::string const& key, std::string const& utf8_value) { - this->oh.replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value)); + oh().replaceKey(key, QPDFObjectHandle::newUnicodeString(utf8_value)); } void @@ -310,18 +310,18 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) setCheckBoxValue((name != "/Off")); } if (!okay) { - this->oh.warnIfPossible( + oh().warnIfPossible( "ignoring attempt to set a checkbox field to a value whose type is not name"); } } else if (isRadioButton()) { if (value.isName()) { setRadioButtonValue(value); } else { - this->oh.warnIfPossible( + oh().warnIfPossible( "ignoring attempt to set a radio button field to an object that is not a name"); } } else if (isPushbutton()) { - this->oh.warnIfPossible("ignoring attempt set the value of a pushbutton field"); + oh().warnIfPossible("ignoring attempt set the value of a pushbutton field"); } return; } @@ -331,7 +331,7 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) setFieldAttribute("/V", value); } if (need_appearances) { - QPDF& qpdf = this->oh.getQPDF( + QPDF& qpdf = oh().getQPDF( "QPDFFormFieldObjectHelper::setV called with need_appearances = " "true on an object that is not associated with an owning QPDF"); QPDFAcroFormDocumentHelper(qpdf).setNeedAppearances(true); @@ -355,7 +355,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) // its /AP (i.e. its normal appearance stream dictionary), set /AS to name; otherwise, if /Off // is a member, set /AS to /Off. // Note that we never turn on /NeedAppearances when setting a radio button field. - QPDFObjectHandle parent = this->oh.getKey("/Parent"); + QPDFObjectHandle parent = oh().getKey("/Parent"); if (parent.isDictionary() && parent.getKey("/Parent").isNull()) { QPDFFormFieldObjectHelper ph(parent); if (ph.isRadioButton()) { @@ -366,9 +366,9 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) } } - QPDFObjectHandle kids = this->oh.getKey("/Kids"); + QPDFObjectHandle kids = oh().getKey("/Kids"); if (!(isRadioButton() && parent.isNull() && kids.isArray())) { - this->oh.warnIfPossible( + oh().warnIfPossible( "don't know how to set the value" " of this field as a radio button"); return; @@ -399,7 +399,7 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) } if (!annot) { QTC::TC("qpdf", "QPDFObjectHandle broken radio button"); - this->oh.warnIfPossible("unable to set the value of this radio button"); + oh().warnIfPossible("unable to set the value of this radio button"); continue; } if (AP.isDictionary() && AP.getKey("/N").isDictionary() && @@ -416,12 +416,12 @@ QPDFFormFieldObjectHelper::setRadioButtonValue(QPDFObjectHandle name) void QPDFFormFieldObjectHelper::setCheckBoxValue(bool value) { - QPDFObjectHandle AP = this->oh.getKey("/AP"); + QPDFObjectHandle AP = oh().getKey("/AP"); QPDFObjectHandle annot; if (AP.isNull()) { // The widget may be below. If there is more than one, just // find the first one. - QPDFObjectHandle kids = this->oh.getKey("/Kids"); + QPDFObjectHandle kids = oh().getKey("/Kids"); if (kids.isArray()) { int nkids = kids.getArrayNItems(); for (int i = 0; i < nkids; ++i) { @@ -435,7 +435,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value) } } } else { - annot = this->oh; + annot = oh(); } std::string on_value; if (value) { @@ -462,7 +462,7 @@ QPDFFormFieldObjectHelper::setCheckBoxValue(bool value) setFieldAttribute("/V", name); if (!annot) { QTC::TC("qpdf", "QPDFObjectHandle broken checkbox"); - this->oh.warnIfPossible("unable to set the value of this checkbox"); + oh().warnIfPossible("unable to set the value of this checkbox"); return; } QTC::TC("qpdf", "QPDFFormFieldObjectHelper set checkbox AS"); @@ -775,7 +775,7 @@ QPDFFormFieldObjectHelper::generateTextAppearance(QPDFAnnotationObjectHelper& ao "<< /Resources << /ProcSet [ /PDF /Text ] >>" " /Type /XObject /Subtype /Form >>"); dict.replaceKey("/BBox", QPDFObjectHandle::newFromRectangle(bbox)); - AS = QPDFObjectHandle::newStream(this->oh.getOwningQPDF(), "/Tx BMC\nEMC\n"); + AS = QPDFObjectHandle::newStream(oh().getOwningQPDF(), "/Tx BMC\nEMC\n"); AS.replaceDict(dict); QPDFObjectHandle AP = aoh.getAppearanceDictionary(); if (AP.isNull()) { diff --git a/libqpdf/QPDFObjGen.cc b/libqpdf/QPDFObjGen.cc deleted file mode 100644 index 5242f4f..0000000 --- a/libqpdf/QPDFObjGen.cc +++ /dev/null @@ -1,53 +0,0 @@ -#include - -#include -#include -#include - -#include - -bool -QPDFObjGen::set::add(QPDFObjectHandle const& oh) -{ - if (auto* ptr = oh.getObjectPtr()) { - return add(ptr->getObjGen()); - } else { - throw std::logic_error( - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle"); - return false; - } -} - -bool -QPDFObjGen::set::add(QPDFObjectHelper const& helper) -{ - if (auto* ptr = helper.getObjectHandle().getObjectPtr()) { - return add(ptr->getObjGen()); - } else { - throw std::logic_error( - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle"); - return false; - } -} - -void -QPDFObjGen::set::erase(QPDFObjectHandle const& oh) -{ - if (auto* ptr = oh.getObjectPtr()) { - erase(ptr->getObjGen()); - } else { - throw std::logic_error( - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle"); - } -} - -void -QPDFObjGen::set::erase(QPDFObjectHelper const& helper) -{ - if (auto* ptr = helper.getObjectHandle().getObjectPtr()) { - erase(ptr->getObjGen()); - } else { - throw std::logic_error( - "attempt to retrieve QPDFObjGen from uninitialized QPDFObjectHandle"); - } -} diff --git a/libqpdf/QPDFOutlineObjectHelper.cc b/libqpdf/QPDFOutlineObjectHelper.cc index 4da38b8..8d561f8 100644 --- a/libqpdf/QPDFOutlineObjectHelper.cc +++ b/libqpdf/QPDFOutlineObjectHelper.cc @@ -9,8 +9,8 @@ QPDFOutlineObjectHelper::Members::Members(QPDFOutlineDocumentHelper& dh) : } QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( - QPDFObjectHandle oh, QPDFOutlineDocumentHelper& dh, int depth) : - QPDFObjectHelper(oh), + QPDFObjectHandle a_oh, QPDFOutlineDocumentHelper& dh, int depth) : + QPDFObjectHelper(a_oh), m(new Members(dh)) { if (depth > 50) { @@ -18,13 +18,13 @@ QPDFOutlineObjectHelper::QPDFOutlineObjectHelper( // to 1. return; } - if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, this->oh.getObjGen())) { + if (QPDFOutlineDocumentHelper::Accessor::checkSeen(m->dh, a_oh.getObjGen())) { QTC::TC("qpdf", "QPDFOutlineObjectHelper loop"); return; } QPDFObjGen::set children; - QPDFObjectHandle cur = oh.getKey("/First"); + QPDFObjectHandle cur = a_oh.getKey("/First"); while (!cur.isNull() && cur.isIndirect() && children.add(cur)) { QPDFOutlineObjectHelper new_ooh(cur, dh, 1 + depth); new_ooh.m->parent = std::make_shared(*this); @@ -50,11 +50,11 @@ QPDFOutlineObjectHelper::getDest() { QPDFObjectHandle dest; QPDFObjectHandle A; - if (this->oh.hasKey("/Dest")) { + if (oh().hasKey("/Dest")) { QTC::TC("qpdf", "QPDFOutlineObjectHelper direct dest"); - dest = this->oh.getKey("/Dest"); + dest = oh().getKey("/Dest"); } else if ( - (A = this->oh.getKey("/A")).isDictionary() && A.getKey("/S").isName() && + (A = oh().getKey("/A")).isDictionary() && A.getKey("/S").isName() && (A.getKey("/S").getName() == "/GoTo") && A.hasKey("/D")) { QTC::TC("qpdf", "QPDFOutlineObjectHelper action dest"); dest = A.getKey("/D"); @@ -85,8 +85,8 @@ int QPDFOutlineObjectHelper::getCount() { int count = 0; - if (this->oh.hasKey("/Count")) { - count = this->oh.getKey("/Count").getIntValueAsInt(); + if (oh().hasKey("/Count")) { + count = oh().getKey("/Count").getIntValueAsInt(); } return count; } @@ -95,8 +95,8 @@ std::string QPDFOutlineObjectHelper::getTitle() { std::string result; - if (this->oh.hasKey("/Title")) { - result = this->oh.getKey("/Title").getUTF8Value(); + if (oh().hasKey("/Title")) { + result = oh().getKey("/Title").getUTF8Value(); } return result; } diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index f474e1c..858b63a 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -227,9 +227,9 @@ QPDFPageObjectHelper::getAttribute( std::function get_fallback, bool copy_if_fallback) { - const bool is_form_xobject = this->oh.isFormXObject(); + const bool is_form_xobject = oh().isFormXObject(); bool inherited = false; - auto dict = is_form_xobject ? oh.getDict() : oh; + auto dict = is_form_xobject ? oh().getDict() : oh(); auto result = dict.getKey(name); if (!is_form_xobject && result.isNull() && @@ -324,7 +324,7 @@ QPDFPageObjectHelper::forEachXObject( QTC::TC( "qpdf", "QPDFPageObjectHelper::forEachXObject", - recursive ? (this->oh.isFormXObject() ? 0 : 1) : (this->oh.isFormXObject() ? 2 : 3)); + recursive ? (oh().isFormXObject() ? 0 : 1) : (oh().isFormXObject() ? 2 : 3)); QPDFObjGen::set seen; std::list queue; queue.push_back(*this); @@ -402,28 +402,27 @@ QPDFPageObjectHelper::externalizeInlineImages(size_t min_size, bool shallow) // Calling mergeResources also ensures that /XObject becomes direct and is not shared with // other pages. resources.mergeResources("<< /XObject << >> >>"_qpdf); - InlineImageTracker iit(this->oh.getOwningQPDF(), min_size, resources); + InlineImageTracker iit(oh().getOwningQPDF(), min_size, resources); Pl_Buffer b("new page content"); bool filtered = false; try { filterContents(&iit, &b); filtered = true; } catch (std::exception& e) { - this->oh.warnIfPossible( + oh().warnIfPossible( std::string("Unable to filter content stream: ") + e.what() + - "; not attempting to externalize inline images" - " from this stream"); + "; not attempting to externalize inline images from this stream"); } if (filtered && iit.any_images) { - if (this->oh.isFormXObject()) { - this->oh.replaceStreamData( + if (oh().isFormXObject()) { + oh().replaceStreamData( b.getBufferSharedPointer(), QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); } else { - this->oh.replaceKey( + oh().replaceKey( "/Contents", - QPDFObjectHandle::newStream(&this->oh.getQPDF(), b.getBufferSharedPointer())); + QPDFObjectHandle::newStream(&oh().getQPDF(), b.getBufferSharedPointer())); } } } else { @@ -439,7 +438,7 @@ std::vector QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype) { std::vector result; - QPDFObjectHandle annots = this->oh.getKey("/Annots"); + QPDFObjectHandle annots = oh().getKey("/Annots"); if (annots.isArray()) { int nannots = annots.getArrayNItems(); for (int i = 0; i < nannots; ++i) { @@ -455,25 +454,25 @@ QPDFPageObjectHelper::getAnnotations(std::string const& only_subtype) std::vector QPDFPageObjectHelper::getPageContents() { - return this->oh.getPageContents(); + return oh().getPageContents(); } void QPDFPageObjectHelper::addPageContents(QPDFObjectHandle contents, bool first) { - this->oh.addPageContents(contents, first); + oh().addPageContents(contents, first); } void QPDFPageObjectHelper::rotatePage(int angle, bool relative) { - this->oh.rotatePage(angle, relative); + oh().rotatePage(angle, relative); } void QPDFPageObjectHelper::coalesceContentStreams() { - this->oh.coalesceContentStreams(); + oh().coalesceContentStreams(); } void @@ -485,10 +484,10 @@ QPDFPageObjectHelper::parsePageContents(QPDFObjectHandle::ParserCallbacks* callb void QPDFPageObjectHelper::parseContents(QPDFObjectHandle::ParserCallbacks* callbacks) { - if (this->oh.isFormXObject()) { - this->oh.parseAsContents(callbacks); + if (oh().isFormXObject()) { + oh().parseAsContents(callbacks); } else { - this->oh.parsePageContents(callbacks); + oh().parsePageContents(callbacks); } } @@ -501,10 +500,10 @@ QPDFPageObjectHelper::filterPageContents(QPDFObjectHandle::TokenFilter* filter, void QPDFPageObjectHelper::filterContents(QPDFObjectHandle::TokenFilter* filter, Pipeline* next) { - if (this->oh.isFormXObject()) { - this->oh.filterAsContents(filter, next); + if (oh().isFormXObject()) { + oh().filterAsContents(filter, next); } else { - this->oh.filterPageContents(filter, next); + oh().filterPageContents(filter, next); } } @@ -517,10 +516,10 @@ QPDFPageObjectHelper::pipePageContents(Pipeline* p) void QPDFPageObjectHelper::pipeContents(Pipeline* p) { - if (this->oh.isFormXObject()) { - this->oh.pipeStreamData(p, 0, qpdf_dl_specialized); + if (oh().isFormXObject()) { + oh().pipeStreamData(p, 0, qpdf_dl_specialized); } else { - this->oh.pipePageContents(p); + oh().pipePageContents(p); } } @@ -528,10 +527,10 @@ void QPDFPageObjectHelper::addContentTokenFilter( std::shared_ptr token_filter) { - if (this->oh.isFormXObject()) { - this->oh.addTokenFilter(token_filter); + if (oh().isFormXObject()) { + oh().addTokenFilter(token_filter); } else { - this->oh.addContentTokenFilter(token_filter); + oh().addContentTokenFilter(token_filter); } } @@ -539,30 +538,28 @@ bool QPDFPageObjectHelper::removeUnreferencedResourcesHelper( QPDFPageObjectHelper ph, std::set& unresolved) { - bool is_page = (!ph.oh.isFormXObject()); + bool is_page = (!ph.oh().isFormXObject()); if (!is_page) { QTC::TC("qpdf", "QPDFPageObjectHelper filter form xobject"); } ResourceFinder rf; try { - auto q = ph.oh.getOwningQPDF(); + auto q = ph.oh().getOwningQPDF(); size_t before_nw = (q ? q->numWarnings() : 0); ph.parseContents(&rf); size_t after_nw = (q ? q->numWarnings() : 0); if (after_nw > before_nw) { - ph.oh.warnIfPossible( + ph.oh().warnIfPossible( "Bad token found while scanning content stream; " - "not attempting to remove unreferenced objects from" - " this object"); + "not attempting to remove unreferenced objects from this object"); return false; } } catch (std::exception& e) { QTC::TC("qpdf", "QPDFPageObjectHelper bad token finding names"); - ph.oh.warnIfPossible( + ph.oh().warnIfPossible( std::string("Unable to parse content stream: ") + e.what() + - "; not attempting to remove unreferenced objects" - " from this object"); + "; not attempting to remove unreferenced objects from this object"); return false; } @@ -646,7 +643,7 @@ QPDFPageObjectHelper::removeUnreferencedResources() any_failures = true; } }); - if (this->oh.isFormXObject() || (!any_failures)) { + if (oh().isFormXObject() || (!any_failures)) { removeUnreferencedResourcesHelper(*this, unresolved); } } @@ -654,9 +651,8 @@ QPDFPageObjectHelper::removeUnreferencedResources() QPDFPageObjectHelper QPDFPageObjectHelper::shallowCopyPage() { - QPDF& qpdf = - this->oh.getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object"); - QPDFObjectHandle new_page = this->oh.shallowCopy(); + QPDF& qpdf = oh().getQPDF("QPDFPageObjectHelper::shallowCopyPage called with a direct object"); + QPDFObjectHandle new_page = oh().shallowCopy(); return {qpdf.makeIndirectObject(new_page)}; } @@ -707,7 +703,7 @@ QPDFObjectHandle QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) { auto result = - this->oh.getQPDF("QPDFPageObjectHelper::getFormXObjectForPage called with a direct object") + oh().getQPDF("QPDFPageObjectHelper::getFormXObjectForPage called with a direct object") .newStream(); QPDFObjectHandle newdict = result.getDict(); newdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); @@ -716,13 +712,13 @@ QPDFPageObjectHelper::getFormXObjectForPage(bool handle_transformations) newdict.replaceKey("/Group", getAttribute("/Group", false).shallowCopy()); QPDFObjectHandle bbox = getTrimBox(false).shallowCopy(); if (!bbox.isRectangle()) { - this->oh.warnIfPossible( + oh().warnIfPossible( "bounding box is invalid; form" " XObject created from page will not work"); } newdict.replaceKey("/BBox", bbox); auto provider = - std::shared_ptr(new ContentProvider(this->oh)); + std::shared_ptr(new ContentProvider(oh())); result.replaceStreamData(provider, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); QPDFObjectHandle scale_obj = getAttribute("/UserUnit", false); @@ -863,9 +859,8 @@ QPDFPageObjectHelper::placeFormXObject( void QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) { - QPDF& qpdf = - this->oh.getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object"); - auto rotate_oh = this->oh.getKey("/Rotate"); + QPDF& qpdf = oh().getQPDF("QPDFPageObjectHelper::flattenRotation called with a direct object"); + auto rotate_oh = oh().getKey("/Rotate"); int rotate = 0; if (rotate_oh.isInteger()) { rotate = rotate_oh.getIntValueAsInt(); @@ -873,7 +868,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) if (!((rotate == 90) || (rotate == 180) || (rotate == 270))) { return; } - auto mediabox = this->oh.getKey("/MediaBox"); + auto mediabox = oh().getKey("/MediaBox"); if (!mediabox.isRectangle()) { return; } @@ -887,7 +882,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) "/ArtBox", }; for (auto const& boxkey: boxes) { - auto box = this->oh.getKey(boxkey); + auto box = oh().getKey(boxkey); if (!box.isRectangle()) { continue; } @@ -930,7 +925,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) break; } - this->oh.replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect)); + oh().replaceKey(boxkey, QPDFObjectHandle::newFromRectangle(new_rect)); } // 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) break; } std::string cm_str = std::string("q\n") + cm.unparse() + " cm\n"; - this->oh.addPageContents(QPDFObjectHandle::newStream(&qpdf, cm_str), true); - this->oh.addPageContents(qpdf.newStream("\nQ\n"), false); - this->oh.removeKey("/Rotate"); + oh().addPageContents(QPDFObjectHandle::newStream(&qpdf, cm_str), true); + oh().addPageContents(qpdf.newStream("\nQ\n"), false); + oh().removeKey("/Rotate"); QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false); if (!rotate_obj.isNull()) { QTC::TC("qpdf", "QPDFPageObjectHelper flatten inherit rotate"); - this->oh.replaceKey("/Rotate", QPDFObjectHandle::newInteger(0)); + oh().replaceKey("/Rotate", QPDFObjectHandle::newInteger(0)); } - QPDFObjectHandle annots = this->oh.getKey("/Annots"); + QPDFObjectHandle annots = oh().getKey("/Annots"); if (annots.isArray()) { std::vector new_annots; std::vector new_fields; @@ -986,7 +981,7 @@ QPDFPageObjectHelper::flattenRotation(QPDFAcroFormDocumentHelper* afdh) for (auto const& f: new_fields) { afdh->addFormField(QPDFFormFieldObjectHelper(f)); } - this->oh.replaceKey("/Annots", QPDFObjectHandle::newArray(new_annots)); + oh().replaceKey("/Annots", QPDFObjectHandle::newArray(new_annots)); } } @@ -1005,7 +1000,7 @@ QPDFPageObjectHelper::copyAnnotations( QPDF& from_qpdf = from_page.getObjectHandle().getQPDF( "QPDFPageObjectHelper::copyAnnotations: from page is a direct object"); QPDF& this_qpdf = - this->oh.getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object"); + oh().getQPDF("QPDFPageObjectHelper::copyAnnotations: this page is a direct object"); std::vector new_annots; std::vector new_fields; @@ -1032,9 +1027,9 @@ QPDFPageObjectHelper::copyAnnotations( afdh->transformAnnotations( old_annots, new_annots, new_fields, old_fields, cm, &from_qpdf, from_afdh); afdh->addAndRenameFormFields(new_fields); - auto annots = this->oh.getKey("/Annots"); + auto annots = oh().getKey("/Annots"); if (!annots.isArray()) { - annots = this->oh.replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray()); + annots = oh().replaceKeyAndGetNew("/Annots", QPDFObjectHandle::newArray()); } for (auto const& annot: new_annots) { annots.appendItem(annot); diff --git a/qpdf/sizes.cc b/qpdf/sizes.cc index 6512187..6075712 100644 --- a/qpdf/sizes.cc +++ b/qpdf/sizes.cc @@ -109,7 +109,6 @@ main() print_size(QPDFNumberTreeObjectHelper); print_size(QPDFNumberTreeObjectHelper::iterator); print_size(QPDFObjGen); - print_size(QPDFObjGen::set); print_size(QPDFObjectHandle); print_size(QPDFObjectHandle::ParserCallbacks); print_size(QPDFObjectHandle::QPDFArrayItems); @@ -118,6 +117,7 @@ main() print_size(QPDFObjectHandle::QPDFDictItems::iterator); print_size(QPDFObjectHandle::StreamDataProvider); print_size(QPDFObjectHandle::TokenFilter); + print_size(QPDFObjectHelper); print_size(QPDFOutlineDocumentHelper); print_size(QPDFOutlineObjectHelper); print_size(QPDFPageDocumentHelper);