Commit 7540d2082a97637f334ee882e57afc986ef87116

Authored by Jay Berkenbilt
1 parent e899926e

Explicitly override inherited rotate in flattenRotations

libqpdf/QPDFPageObjectHelper.cc
@@ -1200,4 +1200,10 @@ QPDFPageObjectHelper::flattenRotation() @@ -1200,4 +1200,10 @@ QPDFPageObjectHelper::flattenRotation()
1200 this->oh.addPageContents( 1200 this->oh.addPageContents(
1201 QPDFObjectHandle::newStream(qpdf, "\nQ\n"), false); 1201 QPDFObjectHandle::newStream(qpdf, "\nQ\n"), false);
1202 this->oh.removeKey("/Rotate"); 1202 this->oh.removeKey("/Rotate");
  1203 + QPDFObjectHandle rotate_obj = getAttribute("/Rotate", false);
  1204 + if (! rotate_obj.isNull())
  1205 + {
  1206 + QTC::TC("qpdf", "QPDFPageObjectHelper flatten inherit rotate");
  1207 + this->oh.replaceKey("/Rotate", QPDFObjectHandle::newInteger(0));
  1208 + }
1203 } 1209 }
qpdf/qpdf.testcov
@@ -571,3 +571,4 @@ qpdf password stdin 0 @@ -571,3 +571,4 @@ qpdf password stdin 0
571 qpdf password file 0 571 qpdf password file 0
572 QPDFFileSpecObjectHelper empty compat_name 0 572 QPDFFileSpecObjectHelper empty compat_name 0
573 QPDFFileSpecObjectHelper non-empty compat_name 0 573 QPDFFileSpecObjectHelper non-empty compat_name 0
  574 +QPDFPageObjectHelper flatten inherit rotate 0
qpdf/qtest/qpdf.test
@@ -2248,7 +2248,7 @@ $td->runtest("explicit keep files open = n", @@ -2248,7 +2248,7 @@ $td->runtest("explicit keep files open = n",
2248 show_ntests(); 2248 show_ntests();
2249 # ---------- 2249 # ----------
2250 $td->notify("--- Rotate Pages ---"); 2250 $td->notify("--- Rotate Pages ---");
2251 -$n_tests += 6; 2251 +$n_tests += 8;
2252 # Do absolute, positive, and negative on ranges that include 2252 # Do absolute, positive, and negative on ranges that include
2253 # inherited and non-inherited. 2253 # inherited and non-inherited.
2254 # Pages 11-15 inherit /Rotate 90 2254 # Pages 11-15 inherit /Rotate 90
@@ -2281,6 +2281,15 @@ $td->runtest("check output", @@ -2281,6 +2281,15 @@ $td->runtest("check output",
2281 {$td->FILE => "a.pdf"}, 2281 {$td->FILE => "a.pdf"},
2282 {$td->FILE => "minimal-rotated.pdf"}); 2282 {$td->FILE => "minimal-rotated.pdf"});
2283 2283
  2284 +$td->runtest("flatten with inherited rotate",
  2285 + {$td->COMMAND =>
  2286 + "qpdf --static-id --flatten-rotation" .
  2287 + " inherited-rotate.pdf a.pdf"},
  2288 + {$td->STRING => "", $td->EXIT_STATUS => 0});
  2289 +$td->runtest("check output",
  2290 + {$td->FILE => "a.pdf"},
  2291 + {$td->FILE => "inherited-flattened.pdf"});
  2292 +
2284 show_ntests(); 2293 show_ntests();
2285 # ---------- 2294 # ----------
2286 $td->notify("--- Flatten Form/Annotations ---"); 2295 $td->notify("--- Flatten Form/Annotations ---");
qpdf/qtest/qpdf/inherited-flattened.pdf 0 → 100644
No preview for this file type
qpdf/qtest/qpdf/inherited-rotate.pdf 0 → 100644
  1 +%PDF-1.3
  2 +%¿÷¢þ
  3 +%QDF-1.0
  4 +
  5 +1 0 obj
  6 +<<
  7 + /Pages 2 0 R
  8 + /Type /Catalog
  9 +>>
  10 +endobj
  11 +
  12 +2 0 obj
  13 +<<
  14 + /Count 1
  15 + /Kids [
  16 + 3 0 R
  17 + ]
  18 + /Rotate 270
  19 + /Type /Pages
  20 +>>
  21 +endobj
  22 +
  23 +%% Page 1
  24 +3 0 obj
  25 +<<
  26 + /Contents 4 0 R
  27 + /MediaBox [
  28 + 0
  29 + 0
  30 + 612
  31 + 792
  32 + ]
  33 + /Parent 2 0 R
  34 + /Resources <<
  35 + /Font <<
  36 + /F1 6 0 R
  37 + >>
  38 + /ProcSet 7 0 R
  39 + >>
  40 + /Rotate 90
  41 + /Type /Page
  42 +>>
  43 +endobj
  44 +
  45 +%% Contents for page 1
  46 +4 0 obj
  47 +<<
  48 + /Length 5 0 R
  49 +>>
  50 +stream
  51 +BT
  52 + /F1 24 Tf
  53 + 72 720 Td
  54 + (Potato) Tj
  55 +ET
  56 +endstream
  57 +endobj
  58 +
  59 +5 0 obj
  60 +44
  61 +endobj
  62 +
  63 +6 0 obj
  64 +<<
  65 + /BaseFont /Helvetica
  66 + /Encoding /WinAnsiEncoding
  67 + /Name /F1
  68 + /Subtype /Type1
  69 + /Type /Font
  70 +>>
  71 +endobj
  72 +
  73 +7 0 obj
  74 +[
  75 + /PDF
  76 + /Text
  77 +]
  78 +endobj
  79 +
  80 +xref
  81 +0 8
  82 +0000000000 65535 f
  83 +0000000025 00000 n
  84 +0000000079 00000 n
  85 +0000000175 00000 n
  86 +0000000403 00000 n
  87 +0000000502 00000 n
  88 +0000000521 00000 n
  89 +0000000639 00000 n
  90 +trailer <<
  91 + /Root 1 0 R
  92 + /Size 8
  93 + /ID [<ab4c755c7750297943d9d0473ed27c28><e29efdb11fd4d5afe3f4b707ba817a50>]
  94 +>>
  95 +startxref
  96 +674
  97 +%%EOF