From e7b8f297ba92f4cadf88efcb394830dc24d54738 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 11 Jul 2012 15:29:41 -0400 Subject: Support copying objects from another QPDF object This includes QPDF::copyForeignObject and supporting foreign objects as arguments to addPage*. --- libqpdf/QPDFObjectHandle.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'libqpdf/QPDFObjectHandle.cc') diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index 25298bee..4f43aa89 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -355,6 +355,14 @@ QPDFObjectHandle::isOrHasName(std::string const& value) return false; } +// Indirect object accessors +QPDF* +QPDFObjectHandle::getOwningQPDF() +{ + // Will be null for direct objects + return this->qpdf; +} + // Dictionary mutators void @@ -784,6 +792,7 @@ QPDFObjectHandle::makeDirectInternal(std::set& visited) } dereference(); + this->qpdf = 0; this->objid = 0; this->generation = 0; @@ -945,6 +954,16 @@ QPDFObjectHandle::assertReserved() assertType("Reserved", isReserved()); } +void +QPDFObjectHandle::assertIndirect() +{ + if (! isIndirect()) + { + throw std::logic_error( + "operation for indirect object attempted on direct object"); + } +} + void QPDFObjectHandle::assertScalar() { @@ -957,11 +976,24 @@ QPDFObjectHandle::assertNumber() assertType("Number", isNumber()); } +bool +QPDFObjectHandle::isPageObject() +{ + return (this->isDictionary() && this->hasKey("/Type") && + (this->getKey("/Type").getName() == "/Page")); +} + +bool +QPDFObjectHandle::isPagesObject() +{ + return (this->isDictionary() && this->hasKey("/Type") && + (this->getKey("/Type").getName() == "/Pages")); +} + void QPDFObjectHandle::assertPageObject() { - if (! (this->isDictionary() && this->hasKey("/Type") && - (this->getKey("/Type").getName() == "/Page"))) + if (! isPageObject()) { throw std::logic_error("page operation called on non-Page object"); } -- cgit v1.2.3-54-g00ecf