From 7540d2082a97637f334ee882e57afc986ef87116 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 21 Feb 2021 07:54:09 -0500 Subject: [PATCH] Explicitly override inherited rotate in flattenRotations --- libqpdf/QPDFPageObjectHelper.cc | 6 ++ qpdf/qpdf.testcov | 1 + qpdf/qtest/qpdf.test | 11 ++- qpdf/qtest/qpdf/inherited-flattened.pdf | Bin 0 -> 1054 bytes qpdf/qtest/qpdf/inherited-rotate.pdf | 97 ++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 qpdf/qtest/qpdf/inherited-flattened.pdf create mode 100644 qpdf/qtest/qpdf/inherited-rotate.pdf diff --git a/libqpdf/QPDFPageObjectHelper.cc b/libqpdf/QPDFPageObjectHelper.cc index b7f96dc0..748d865d 100644 --- a/libqpdf/QPDFPageObjectHelper.cc +++ b/libqpdf/QPDFPageObjectHelper.cc @@ -1200,4 +1200,10 @@ QPDFPageObjectHelper::flattenRotation() this->oh.addPageContents( QPDFObjectHandle::newStream(qpdf, "\nQ\n"), false); this->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)); + } } diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index a2d2b71f..057e2734 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -571,3 +571,4 @@ qpdf password stdin 0 qpdf password file 0 QPDFFileSpecObjectHelper empty compat_name 0 QPDFFileSpecObjectHelper non-empty compat_name 0 +QPDFPageObjectHelper flatten inherit rotate 0 diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 100520f3..a0985f07 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -2248,7 +2248,7 @@ $td->runtest("explicit keep files open = n", show_ntests(); # ---------- $td->notify("--- Rotate Pages ---"); -$n_tests += 6; +$n_tests += 8; # Do absolute, positive, and negative on ranges that include # inherited and non-inherited. # Pages 11-15 inherit /Rotate 90 @@ -2281,6 +2281,15 @@ $td->runtest("check output", {$td->FILE => "a.pdf"}, {$td->FILE => "minimal-rotated.pdf"}); +$td->runtest("flatten with inherited rotate", + {$td->COMMAND => + "qpdf --static-id --flatten-rotation" . + " inherited-rotate.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "inherited-flattened.pdf"}); + show_ntests(); # ---------- $td->notify("--- Flatten Form/Annotations ---"); diff --git a/qpdf/qtest/qpdf/inherited-flattened.pdf b/qpdf/qtest/qpdf/inherited-flattened.pdf new file mode 100644 index 0000000000000000000000000000000000000000..bf00e4d8583fbdf17ca82ff491c4d7c9fdff02f5 GIT binary patch literal 1054 zcmah|J&)5s5H)u~3YPc}gCI1(+1~Z16j_kuA|k#*5{V+D*w~w3l(Uh&fj~t=$v>dt zC(u#R=7bJi1@%Gx107=4i4$;&v!&R1JM(7d&2zQWY~3;rs9OE<`{N(g03DLibG23j zt-~ff1A<5wwEpWC9JB@#Y?@5K_f;N;GEg2D35{eH3ot;t7lj!Nfaa+~(7K6Wf&+2% zf@sCPrIDdqnpp5yNCq=!u<~EKV0*yBh}Dxhp6hr!9s%1RfOR@7#l)iJF3*x#8sH3a znpT1*`HKNgPUZWUktRWp3vf5cy4U|Y{byd;QPJpq9#6zGAU3i`Q^8YwPI1sC50a3} zq)eoo9jWsVHbvFB1LgYX{cot^I%ch>oVCPny65v}>RGpQ`ik~- z^0?C8|8(;H?c(;8YZn*aD+{fC^Y}-Mx1UU>n!8B`r2JSeaS@>FwhQT)F_H4pgoD=J8>3mfrsn}t=7W&z1c|QzLW05 z|0@&bTwCkN)yYx=+-9?dL3}P?Som|E^0BIer|O#vY|Ek+jA4TrsJgr$-eNXxx`Y{+ zRmP~k8)qU@InFY$&k~>Ic{`Y+<1UIgk+Nutwvx8(CW-vE@{h3>z2V@2)^5U}#ztn~ zSXSUTmQFm!Gim6By6I3J5+@+8U!#U;SRS!)Y8L}2p{{8Y+oaT`#PKYDxbiAXMJ|^^ MZM9lGeAH6^0@!ILY5)KL literal 0 HcmV?d00001 diff --git a/qpdf/qtest/qpdf/inherited-rotate.pdf b/qpdf/qtest/qpdf/inherited-rotate.pdf new file mode 100644 index 00000000..eb392a4c --- /dev/null +++ b/qpdf/qtest/qpdf/inherited-rotate.pdf @@ -0,0 +1,97 @@ +%PDF-1.3 +%¿÷¢þ +%QDF-1.0 + +1 0 obj +<< + /Pages 2 0 R + /Type /Catalog +>> +endobj + +2 0 obj +<< + /Count 1 + /Kids [ + 3 0 R + ] + /Rotate 270 + /Type /Pages +>> +endobj + +%% Page 1 +3 0 obj +<< + /Contents 4 0 R + /MediaBox [ + 0 + 0 + 612 + 792 + ] + /Parent 2 0 R + /Resources << + /Font << + /F1 6 0 R + >> + /ProcSet 7 0 R + >> + /Rotate 90 + /Type /Page +>> +endobj + +%% Contents for page 1 +4 0 obj +<< + /Length 5 0 R +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +44 +endobj + +6 0 obj +<< + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding + /Name /F1 + /Subtype /Type1 + /Type /Font +>> +endobj + +7 0 obj +[ + /PDF + /Text +] +endobj + +xref +0 8 +0000000000 65535 f +0000000025 00000 n +0000000079 00000 n +0000000175 00000 n +0000000403 00000 n +0000000502 00000 n +0000000521 00000 n +0000000639 00000 n +trailer << + /Root 1 0 R + /Size 8 + /ID [] +>> +startxref +674 +%%EOF