Restore previous transparency rendering behavior
Fix a regression in transparency rendering by revert the C++ code in CL
[1] and suppressing the test added in that CL. Then add a pixel test to
demonstrate the PDF that regressed now renders correctly.
[1] https://pdfium-review.googlesource.com/118830
Bug: 42271122, 346598551
Change-Id: I5b86ed5e28522d9c0cc74f500be5151155678357
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120351
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 8e4d72f..9c2dd94 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -584,7 +584,6 @@
}
RetainPtr<const CPDF_Dictionary> pFormResource;
float group_alpha = 1.0f;
- float initial_alpha = 1.0f;
CPDF_Transparency transparency = m_Transparency;
bool bGroupTransparent = false;
const CPDF_FormObject* pFormObj = pPageObj->AsForm();
@@ -593,14 +592,13 @@
transparency = pFormObj->form()->GetTransparency();
bGroupTransparent = transparency.IsIsolated();
pFormResource = pFormObj->form()->GetDict()->GetDictFor("Resources");
- initial_alpha = m_InitialStates.general_state().GetFillAlpha();
}
bool bTextClip =
(pPageObj->clip_path().HasRef() &&
pPageObj->clip_path().GetTextCount() > 0 && !m_bPrint &&
!(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP));
if (!pSMaskDict && group_alpha == 1.0f && blend_type == BlendMode::kNormal &&
- !bTextClip && !bGroupTransparent && initial_alpha == 1.0f) {
+ !bTextClip && !bGroupTransparent) {
return false;
}
if (m_bPrint) {
@@ -695,9 +693,6 @@
bitmap_device.MultiplyAlpha(group_alpha);
}
transparency = m_Transparency;
- if (initial_alpha != 1.0f) {
- bitmap_device.MultiplyAlpha(initial_alpha);
- }
if (pPageObj->IsForm()) {
transparency.SetGroup();
}
diff --git a/core/fpdfapi/render/cpdf_rendertiling.cpp b/core/fpdfapi/render/cpdf_rendertiling.cpp
index 6b50893..cd906cd 100644
--- a/core/fpdfapi/render/cpdf_rendertiling.cpp
+++ b/core/fpdfapi/render/cpdf_rendertiling.cpp
@@ -125,11 +125,6 @@
if (!pPattern->colored()) {
pStates = CPDF_RenderStatus::CloneObjStates(&pPageObj->graphic_states(),
bStroke);
- } else if (pPageObj->AsPath()) {
- pStates = std::make_unique<CPDF_GraphicStates>();
- pStates->SetDefaultStates();
- pStates->mutable_general_state().SetFillAlpha(
- pPageObj->general_state().GetFillAlpha());
}
RetainPtr<const CPDF_Dictionary> pFormResource =
diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS
index 96c84d12..a625d0b 100644
--- a/testing/SUPPRESSIONS
+++ b/testing/SUPPRESSIONS
@@ -659,6 +659,9 @@
# TODO(pdfium:2001): Remove after associated bug is fixed
bug_2001.pdf * * * *
+# TODO(crbug.com/42271122): Remove after associated bug is fixed
+bug_2106.in * * * *
+
# TODO(chromium:237527): Remove after associated bug is fixed
bug_237527_1.in * * * *
diff --git a/testing/resources/pixel/bug_346598551.in b/testing/resources/pixel/bug_346598551.in
new file mode 100644
index 0000000..0c0443a
--- /dev/null
+++ b/testing/resources/pixel/bug_346598551.in
@@ -0,0 +1,81 @@
+{{header}}
+{{object 1 0}} <<
+ /Type /Catalog
+ /Pages 2 0 R
+>>
+endobj
+{{object 2 0}} <<
+ /Type /Pages
+ /Count 1
+ /Kids [3 0 R]
+>>
+endobj
+{{object 3 0}} <<
+ /Type /Page
+ /Parent 2 0 R
+ /Contents 4 0 R
+ /MediaBox [0 0 200 200]
+ /Resources <<
+ /ExtGState <<
+ /GS0 <<
+ /ca 0.5
+ >>
+ >>
+ /XObject <<
+ /FM0 5 0 R
+ >>
+ >>
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+q
+20 0 0 20 0 0 cm
+/GS0 gs
+/FM0 Do
+Q
+endstream
+endobj
+{{object 5 0}} <<
+ /Type /XObject
+ /Subtype /Form
+ /FormType 1
+ /BBox [0 0 10 10]
+ /Group <<
+ /S /Transparency
+ /I true
+ /K false
+ >>
+ /Resources <<
+ /XObject <<
+ /IM0 6 0 R
+ >>
+ >>
+ {{streamlen}}
+>>
+stream
+q
+/IM0 Do
+Q
+endstream
+endobj
+{{object 6 0}} <<
+ /Type /XObject
+ /Subtype /Form
+ /FormType 1
+ /BBox [0 0 10 10]
+ {{streamlen}}
+>>
+stream
+q
+0 1 0 rg
+0 0 10 10 re f
+Q
+endstream
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/pixel/bug_346598551_expected.pdf.0.png b/testing/resources/pixel/bug_346598551_expected.pdf.0.png
new file mode 100644
index 0000000..12ae8b7
--- /dev/null
+++ b/testing/resources/pixel/bug_346598551_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_346598551_expected_gdi_skia.pdf.0.png b/testing/resources/pixel/bug_346598551_expected_gdi_skia.pdf.0.png
new file mode 100644
index 0000000..25dd318
--- /dev/null
+++ b/testing/resources/pixel/bug_346598551_expected_gdi_skia.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_346598551_expected_skia.pdf.0.png b/testing/resources/pixel/bug_346598551_expected_skia.pdf.0.png
new file mode 100644
index 0000000..25dd318
--- /dev/null
+++ b/testing/resources/pixel/bug_346598551_expected_skia.pdf.0.png
Binary files differ