summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2023-11-03 15:30:15 +0100
committerOliver Sander <oliver.sander@tu-dresden.de>2023-11-03 16:00:10 +0100
commit6d37f787abc05a658d342d42995c5df167c5e5b9 (patch)
treea2ecd18f8bab80b930a4e3e68c395afbcf5d28ed
parent975d6998b0ad979e81ea133be493bbf7be113fc7 (diff)
Object: Add constructor from r-value std::string
This can simplify the calling code when the string to use is stack-allocated. Unfortunately, the new constructor has to do a heap allocation internally, because Object stores a pointer to a string, not a string value. With the new constructor, construction of Object objects from std::initializer_list is now ambiguous. This leads to compiler errors in a few places where {num, gen} is used to initialize an Object with a Ref object. The patch replaces this construction by Ref{num, gen}, which fixes the problem.
-rw-r--r--poppler/Object.h5
-rw-r--r--qt5/tests/check_optcontent.cpp4
-rw-r--r--qt6/tests/check_optcontent.cpp4
-rw-r--r--utils/pdfunite.cc8
4 files changed, 13 insertions, 8 deletions
diff --git a/poppler/Object.h b/poppler/Object.h
index 3eb6216c..23e968c0 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -214,6 +214,11 @@ public:
type = objString;
string = stringA;
}
+ explicit Object(std::string &&stringA)
+ {
+ type = objString;
+ string = new GooString(stringA);
+ }
Object(ObjType typeA, GooString *stringA)
{
assert(typeA == objHexString);
diff --git a/qt5/tests/check_optcontent.cpp b/qt5/tests/check_optcontent.cpp
index b254cdb1..e38b9b69 100644
--- a/qt5/tests/check_optcontent.cpp
+++ b/qt5/tests/check_optcontent.cpp
@@ -173,7 +173,7 @@ void TestOptionalContent::checkVisibilitySetting()
// In this test, both Ref(21,0) and Ref(28,0) start On,
// based on the file settings
- Object ref21obj({ 21, 0 });
+ Object ref21obj(Ref { 21, 0 });
Ref ref21 = ref21obj.getRef();
OptionalContentGroup *ocgA = ocgs->findOcgByRef(ref21);
QVERIFY(ocgA);
@@ -181,7 +181,7 @@ void TestOptionalContent::checkVisibilitySetting()
QVERIFY((ocgA->getName()->cmp("A")) == 0);
QCOMPARE(ocgA->getState(), OptionalContentGroup::On);
- Object ref28obj({ 28, 0 });
+ Object ref28obj(Ref { 28, 0 });
Ref ref28 = ref28obj.getRef();
OptionalContentGroup *ocgB = ocgs->findOcgByRef(ref28);
QVERIFY(ocgB);
diff --git a/qt6/tests/check_optcontent.cpp b/qt6/tests/check_optcontent.cpp
index 5f9294bc..37a737ba 100644
--- a/qt6/tests/check_optcontent.cpp
+++ b/qt6/tests/check_optcontent.cpp
@@ -164,7 +164,7 @@ void TestOptionalContent::checkVisibilitySetting()
// In this test, both Ref(21,0) and Ref(28,0) start On,
// based on the file settings
- Object ref21obj({ 21, 0 });
+ Object ref21obj(Ref { 21, 0 });
Ref ref21 = ref21obj.getRef();
OptionalContentGroup *ocgA = ocgs->findOcgByRef(ref21);
QVERIFY(ocgA);
@@ -172,7 +172,7 @@ void TestOptionalContent::checkVisibilitySetting()
QVERIFY((ocgA->getName()->cmp("A")) == 0);
QCOMPARE(ocgA->getState(), OptionalContentGroup::On);
- Object ref28obj({ 28, 0 });
+ Object ref28obj(Ref { 28, 0 });
Ref ref28 = ref28obj.getRef();
OptionalContentGroup *ocgB = ocgs->findOcgByRef(ref28);
QVERIFY(ocgB);
diff --git a/utils/pdfunite.cc b/utils/pdfunite.cc
index 83082542..07d57ac2 100644
--- a/utils/pdfunite.cc
+++ b/utils/pdfunite.cc
@@ -49,7 +49,7 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
if (mkey.isString() && mvalue.isRef()) {
if (mkey.getString()->cmp(key.getString()) < 0) {
newNameArray->add(Object(new GooString(mkey.getString()->c_str())));
- newNameArray->add(Object({ mvalue.getRef().num + numOffset, mvalue.getRef().gen }));
+ newNameArray->add(Object(Ref { mvalue.getRef().num + numOffset, mvalue.getRef().gen }));
j += 2;
} else if (mkey.getString()->cmp(key.getString()) == 0) {
j += 2;
@@ -69,7 +69,7 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
const Object &mvalue = mergeNameArray.arrayGetNF(j + 1);
if (mkey.isString() && mvalue.isRef()) {
newNameArray->add(Object(new GooString(mkey.getString()->c_str())));
- newNameArray->add(Object({ mvalue.getRef().num + numOffset, mvalue.getRef().gen }));
+ newNameArray->add(Object(Ref { mvalue.getRef().num + numOffset, mvalue.getRef().gen }));
}
j += 2;
}
@@ -82,7 +82,7 @@ static void doMergeNameTree(PDFDoc *doc, XRef *srcXRef, XRef *countRef, int oldR
const Object &value = mergeNameArray.arrayGetNF(i + 1);
if (key.isString() && value.isRef()) {
newNameArray->add(Object(new GooString(key.getString()->c_str())));
- newNameArray->add(Object({ value.getRef().num + numOffset, value.getRef().gen }));
+ newNameArray->add(Object(Ref { value.getRef().num + numOffset, value.getRef().gen }));
}
}
srcNameTree->add("Names", Object(newNameArray));
@@ -117,7 +117,7 @@ static bool doMergeFormDict(Dict *srcFormDict, Dict *mergeFormDict, int numOffse
error(errSyntaxError, -1, "Fields object is not a Ref.");
return false;
}
- srcFields.arrayAdd(Object({ value.getRef().num + numOffset, value.getRef().gen }));
+ srcFields.arrayAdd(Object(Ref { value.getRef().num + numOffset, value.getRef().gen }));
}
}
return true;