mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-04 11:20:53 +00:00
Have QPDFWriter detect foreign objects while writing
Throw an exception that directs the user to QPDF::copyForeignObject.
This commit is contained in:
parent
11b194a1d0
commit
1c944e4c89
|
@ -1,3 +1,9 @@
|
||||||
|
2012-07-14 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* QPDFWriter: detect if the user has inserted an indirect object
|
||||||
|
from another QPDF object and throw an exception directing the user
|
||||||
|
to copyForeignObject.
|
||||||
|
|
||||||
2012-07-11 Jay Berkenbilt <ejb@ql.org>
|
2012-07-11 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* Added new APIs to copy objects from one QPDF to another. This
|
* Added new APIs to copy objects from one QPDF to another. This
|
||||||
|
|
|
@ -761,6 +761,15 @@ QPDFWriter::enqueueObject(QPDFObjectHandle object)
|
||||||
{
|
{
|
||||||
if (object.isIndirect())
|
if (object.isIndirect())
|
||||||
{
|
{
|
||||||
|
if (object.getOwningQPDF() != &(this->pdf))
|
||||||
|
{
|
||||||
|
QTC::TC("qpdf", "QPDFWriter foreign object");
|
||||||
|
throw std::logic_error(
|
||||||
|
"QPDFObjectHandle from different QPDF found while writing."
|
||||||
|
" Use QPDF::copyForeignObject to add objects from"
|
||||||
|
" another file.");
|
||||||
|
}
|
||||||
|
|
||||||
if (object.isNull())
|
if (object.isNull())
|
||||||
{
|
{
|
||||||
// This is a place-holder object for an object stream
|
// This is a place-holder object for an object stream
|
||||||
|
|
|
@ -233,3 +233,4 @@ QPDF not crossing page boundary 0
|
||||||
QPDF replace foreign indirect with null 0
|
QPDF replace foreign indirect with null 0
|
||||||
QPDF not copying pages object 0
|
QPDF not copying pages object 0
|
||||||
QPDF insert foreign page 0
|
QPDF insert foreign page 0
|
||||||
|
QPDFWriter foreign object 0
|
||||||
|
|
|
@ -149,7 +149,7 @@ $td->runtest("remove page we don't have",
|
||||||
$td->NORMALIZE_NEWLINES);
|
$td->NORMALIZE_NEWLINES);
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Miscellaneous Tests ---");
|
$td->notify("--- Miscellaneous Tests ---");
|
||||||
$n_tests += 43;
|
$n_tests += 44;
|
||||||
|
|
||||||
$td->runtest("qpdf version",
|
$td->runtest("qpdf version",
|
||||||
{$td->COMMAND => "qpdf --version"},
|
{$td->COMMAND => "qpdf --version"},
|
||||||
|
@ -365,6 +365,10 @@ $td->runtest("reserved objects",
|
||||||
$td->runtest("check output",
|
$td->runtest("check output",
|
||||||
{$td->FILE => "a.pdf"},
|
{$td->FILE => "a.pdf"},
|
||||||
{$td->FILE => "reserved-objects.pdf"});
|
{$td->FILE => "reserved-objects.pdf"});
|
||||||
|
$td->runtest("detect foreign object in write",
|
||||||
|
{$td->COMMAND => "test_driver 29 copy-foreign-objects-in.pdf"},
|
||||||
|
{$td->FILE => "foreign-in-write.out", $td->EXIT_STATUS => 0},
|
||||||
|
$td->NORMALIZE_NEWLINES);
|
||||||
|
|
||||||
show_ntests();
|
show_ntests();
|
||||||
# ----------
|
# ----------
|
||||||
|
|
2
qpdf/qtest/qpdf/foreign-in-write.out
Normal file
2
qpdf/qtest/qpdf/foreign-in-write.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
logic error: QPDFObjectHandle from different QPDF found while writing. Use QPDF::copyForeignObject to add objects from another file.
|
||||||
|
test 29 done
|
|
@ -999,6 +999,26 @@ void runtest(int n, char const* filename)
|
||||||
std::cout << "logic error: " << e.what() << std::endl;
|
std::cout << "logic error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (n == 29)
|
||||||
|
{
|
||||||
|
// Detect mixed objects in QPDFWriter
|
||||||
|
QPDF other;
|
||||||
|
other.processFile("minimal.pdf");
|
||||||
|
// Should use copyForeignObject instead
|
||||||
|
other.getTrailer().replaceKey(
|
||||||
|
"/QTest", pdf.getTrailer().getKey("/QTest"));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QPDFWriter w(other, "a.pdf");
|
||||||
|
w.write();
|
||||||
|
std::cout << "oops -- didn't throw" << std::endl;
|
||||||
|
}
|
||||||
|
catch (std::logic_error e)
|
||||||
|
{
|
||||||
|
std::cout << "logic error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::runtime_error(std::string("invalid test ") +
|
throw std::runtime_error(std::string("invalid test ") +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user