Add a test for rendering a transparency onto a white background
Demonstrate an issue where the transparency is not rendered. Use an
embedder test with a specific FPDFBitmap_FillRect() call to trigger the
bug. The bug does not happen in pixel tests and in CompareBitmap().
Bug: chromium:1302355
Change-Id: I01a3dc6eb00810d77082a732aece2239a4744445
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/113210
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index 698a554..617b9cf 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -2160,3 +2160,23 @@
TestRenderPageBitmapWithFlags(page, FPDF_RENDER_NO_SMOOTHTEXT, checksum);
UnloadPage(page);
}
+
+TEST_F(FPDFViewEmbedderTest, RenderTransparencyOnWhiteBackground) {
+ ASSERT_TRUE(OpenDocument("bug_1302355.pdf"));
+ FPDF_PAGE page = LoadPage(0);
+ ASSERT_TRUE(page);
+
+ constexpr int kWidth = 200;
+ constexpr int kHeight = 200;
+ EXPECT_EQ(kWidth, static_cast<int>(FPDF_GetPageWidthF(page)));
+ EXPECT_EQ(kHeight, static_cast<int>(FPDF_GetPageHeightF(page)));
+ EXPECT_TRUE(FPDFPage_HasTransparency(page));
+ ScopedFPDFBitmap bitmap(FPDFBitmap_Create(kWidth, kHeight, /*alpha=*/true));
+ FPDFBitmap_FillRect(bitmap.get(), 0, 0, kWidth, kHeight, 0xFFFFFFFF);
+ FPDF_RenderPageBitmap(bitmap.get(), page, /*start_x=*/0, /*start_y=*/0,
+ kWidth, kHeight, /*rotate=*/0, /*flags=*/0);
+ // TODO(crbug.com/1302355): This page should not render blank.
+ EXPECT_EQ("eee4600ac08b458ac7ac2320e225674c", HashBitmap(bitmap.get()));
+
+ UnloadPage(page);
+}
diff --git a/testing/resources/bug_1302355.in b/testing/resources/bug_1302355.in
new file mode 100644
index 0000000..3ec90ec
--- /dev/null
+++ b/testing/resources/bug_1302355.in
@@ -0,0 +1,66 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+ /MediaBox [0 0 200 200]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Contents 4 0 R
+ /Resources <<
+ /ExtGState <<
+ /GS1 5 0 R
+ >>
+ /XObject <<
+ /Fm1 6 0 R
+ >>
+ >>
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+q
+/GS1 gs
+/Fm1 Do
+Q
+endstream
+endobj
+{{object 5 0}} <<
+ /Type /ExtGState
+ /AIS false
+ /BM /SoftLight
+ /CA 1
+ /OP false
+ /OPM 1
+ /SA true
+ /SMask /None
+ /ca 1
+ /op false
+>>
+endobj
+{{object 6 0}} <<
+ /Type /XObject
+ /Subtype /Form
+ /BBox [50 50 150 150]
+ {{streamlen}}
+>>
+stream
+q
+60 80 50 30 re B*
+Q
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/bug_1302355.pdf b/testing/resources/bug_1302355.pdf
new file mode 100644
index 0000000..1a4d70d
--- /dev/null
+++ b/testing/resources/bug_1302355.pdf
@@ -0,0 +1,79 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+ /MediaBox [0 0 200 200]
+>>
+endobj
+3 0 obj <<
+ /Type /Page
+ /Parent 2 0 R
+ /Contents 4 0 R
+ /Resources <<
+ /ExtGState <<
+ /GS1 5 0 R
+ >>
+ /XObject <<
+ /Fm1 6 0 R
+ >>
+ >>
+>>
+endobj
+4 0 obj <<
+ /Length 20
+>>
+stream
+q
+/GS1 gs
+/Fm1 Do
+Q
+endstream
+endobj
+5 0 obj <<
+ /Type /ExtGState
+ /AIS false
+ /BM /SoftLight
+ /CA 1
+ /OP false
+ /OPM 1
+ /SA true
+ /SMask /None
+ /ca 1
+ /op false
+>>
+endobj
+6 0 obj <<
+ /Type /XObject
+ /Subtype /Form
+ /BBox [50 50 150 150]
+ /Length 22
+>>
+stream
+q
+60 80 50 30 re B*
+Q
+endstream
+endobj
+xref
+0 7
+0000000000 65535 f
+0000000015 00000 n
+0000000068 00000 n
+0000000157 00000 n
+0000000329 00000 n
+0000000400 00000 n
+0000000545 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 7
+>>
+startxref
+676
+%%EOF