Add a test case for 2-up PDF generation with rotated pages.
Demonstrate that identical looking pages created with different page
rotations will render differently when converted to a 2-up PDF with
FPDF_ImportNPagesToOne().
Bug: chromium:1229106
Change-Id: I22bf5c05e72cd595a9d0cb167c8fcc1f92e549de
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84071
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Hui Yingst <nigi@chromium.org>
diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp
index e0c11ca..3a2143e 100644
--- a/fpdfsdk/fpdf_ppo_embeddertest.cpp
+++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp
@@ -303,6 +303,37 @@
EXPECT_EQ(1, FPDF_GetPageCount(output_doc_2up.get()));
}
+TEST_F(FPDFPPOEmbedderTest, BUG_1229106) {
+ static constexpr int kPageCount = 4;
+ static constexpr int kTwoUpPageCount = 2;
+ static const char kRectsChecksum[] = "140d629b3c96a07ced2e3e408ea85a1d";
+ static const char kBadTwoUpChecksum[] = "1d12f824e6e1710a91bbb13a903e300a";
+ static const char kGoodTwoUpChecksum[] = "fa4501562301b2e75da354bd067495ec";
+
+ ASSERT_TRUE(OpenDocument("bug_1229106.pdf"));
+
+ // Show all pages render the same.
+ ASSERT_EQ(kPageCount, FPDF_GetPageCount(document()));
+ for (int i = 0; i < kPageCount; ++i) {
+ FPDF_PAGE page = LoadPage(0);
+ ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
+ CompareBitmap(bitmap.get(), 792, 612, kRectsChecksum);
+ UnloadPage(page);
+ }
+
+ // Create a 2-up PDF.
+ ScopedFPDFDocument output_doc_2up(
+ FPDF_ImportNPagesToOne(document(), 612, 792, 1, 2));
+ ASSERT_EQ(kTwoUpPageCount, FPDF_GetPageCount(output_doc_2up.get()));
+ for (int i = 0; i < kTwoUpPageCount; ++i) {
+ ScopedFPDFPage page(FPDF_LoadPage(output_doc_2up.get(), i));
+ ScopedFPDFBitmap bitmap = RenderPage(page.get());
+ // TODO(crbug.com/1229106): Both pages should render the same.
+ CompareBitmap(bitmap.get(), 612, 792,
+ i == 0 ? kBadTwoUpChecksum : kGoodTwoUpChecksum);
+ }
+}
+
TEST_F(FPDFPPOEmbedderTest, BadRepeatViewerPref) {
ASSERT_TRUE(OpenDocument("repeat_viewer_ref.pdf"));
diff --git a/testing/resources/bug_1229106.in b/testing/resources/bug_1229106.in
new file mode 100644
index 0000000..7ffe9bf
--- /dev/null
+++ b/testing/resources/bug_1229106.in
@@ -0,0 +1,68 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 4
+ /Kids [3 0 R 3 0 R 5 0 R 5 0 R]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 612 792]
+ /Rotate 90
+ /Contents 4 0 R
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+q
+0 1 -1 0 792 0 cm
+0 0 0 rg
+100 400 150 50 re f
+1 0 0 rg
+0 180 100 50 re f
+0 1 0 rg
+0 742 100 50 re f
+0 0 1 rg
+692 742 100 50 re f
+1 0 1 rg
+692 180 100 50 re f
+Q
+endstream
+endobj
+{{object 5 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 792 612]
+ /Contents 6 0 R
+>>
+endobj
+{{object 6 0}} <<
+ {{streamlen}}
+>>
+stream
+q
+0 0 0 rg
+100 220 150 50 re f
+1 0 0 rg
+0 0 100 50 re f
+0 1 0 rg
+0 562 100 50 re f
+0 0 1 rg
+692 562 100 50 re f
+1 0 1 rg
+692 0 100 50 re f
+Q
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/bug_1229106.pdf b/testing/resources/bug_1229106.pdf
new file mode 100644
index 0000000..e0d625c
--- /dev/null
+++ b/testing/resources/bug_1229106.pdf
@@ -0,0 +1,81 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 4
+ /Kids [3 0 R 3 0 R 5 0 R 5 0 R]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 612 792]
+ /Rotate 90
+ /Contents 4 0 R
+>>
+endobj
+4 0 obj <<
+ /Length 163
+>>
+stream
+q
+0 1 -1 0 792 0 cm
+0 0 0 rg
+100 400 150 50 re f
+1 0 0 rg
+0 180 100 50 re f
+0 1 0 rg
+0 742 100 50 re f
+0 0 1 rg
+692 742 100 50 re f
+1 0 1 rg
+692 180 100 50 re f
+Q
+endstream
+endobj
+5 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /MediaBox [0 0 792 612]
+ /Contents 6 0 R
+>>
+endobj
+6 0 obj <<
+ /Length 141
+>>
+stream
+q
+0 0 0 rg
+100 220 150 50 re f
+1 0 0 rg
+0 0 100 50 re f
+0 1 0 rg
+0 562 100 50 re f
+0 0 1 rg
+692 562 100 50 re f
+1 0 1 rg
+692 0 100 50 re f
+Q
+endstream
+endobj
+xref
+0 7
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000149 00000 n
+0000000257 00000 n
+0000000472 00000 n
+0000000567 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 7
+>>
+startxref
+760
+%%EOF