aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDFObjectHandle.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-11-14 23:06:04 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2022-11-20 18:07:22 +0100
commitb1eb1a958438025efbf90f7a7f45dbe33c746d91 (patch)
treef9ff3400204d1ca1e878c94b240eb0d1e1704e3f /libqpdf/QPDFObjectHandle.cc
parent3e3b79a774a294ca2020a7bad8ee6ddd2c0179de (diff)
downloadqpdf-b1eb1a958438025efbf90f7a7f45dbe33c746d91.tar.zst
Refactor QPDFObjectHandle::copyObject1
Diffstat (limited to 'libqpdf/QPDFObjectHandle.cc')
-rw-r--r--libqpdf/QPDFObjectHandle.cc37
1 files changed, 9 insertions, 28 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 3e37a966..2990b019 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -2211,8 +2211,7 @@ QPDFObjectHandle::shallowCopyInternal1(QPDFObjectHandle& new_obj)
assertInitialized();
if (isStream()) {
- QTC::TC("qpdf", "QPDFObjectHandle ERR shallow copy stream");
- throw std::runtime_error("attempt to make a shallow copy of a stream");
+ // Handled bt QPDF_Stream::copy()
}
new_obj = QPDFObjectHandle(obj->copy(true));
@@ -2225,9 +2224,10 @@ QPDFObjectHandle::copyObject1(std::set<QPDFObjGen>& visited)
{
assertInitialized();
+ std::shared_ptr<QPDFObject> new_obj;
+
if (isStream()) {
- throw std::runtime_error(
- "attempt to make a stream into a direct object");
+ new_obj = obj->copy();
}
auto cur_og = getObjGen();
@@ -2241,36 +2241,17 @@ QPDFObjectHandle::copyObject1(std::set<QPDFObjGen>& visited)
}
if (isReserved()) {
- throw std::logic_error("QPDFObjectHandle: attempting to make a"
- " reserved object handle direct");
+ new_obj = obj->copy();
}
- std::shared_ptr<QPDFObject> new_obj;
-
if (isBool() || isInteger() || isName() || isNull() || isReal() ||
isString()) {
- new_obj = obj->copy(true);
+ // copy(true) and copy(false) are the same
+ new_obj = obj->copy();
} else if (isArray()) {
- std::vector<QPDFObjectHandle> items;
- auto array = asArray();
- int n = array->getNItems();
- for (int i = 0; i < n; ++i) {
- items.push_back(array->getItem(i));
- if (!items.back().isIndirect()) {
- items.back().copyObject1(visited);
- }
- }
- new_obj = QPDF_Array::create(items);
+ new_obj = obj->copy();
} else if (isDictionary()) {
- std::map<std::string, QPDFObjectHandle> items;
- auto dict = asDictionary();
- for (auto const& key: getKeys()) {
- items[key] = dict->getKey(key);
- if (!items[key].isIndirect()) {
- items[key].copyObject1(visited);
- }
- }
- new_obj = QPDF_Dictionary::create(items);
+ new_obj = obj->copy();
} else {
throw std::logic_error("QPDFObjectHandle::makeDirectInternal: "
"unknown object type");