Fix text rendering with patterns and text matrix scaling.
When drawing text using patterns, PDFium renders the combination of font
size 20 and identify text matrix correctly, but renders font size 1 with
a 20X scaling text matrix incorrectly.
Add a pixel test with various combinations of font size and scaling text
matrix to demonstrate the issue. Then adjust the matrices in
CPDF_RenderStatus::DrawTextPathWithPattern() to fix it.
Bug: pdfium:1772
Change-Id: Ie389e8516158833b8d7ce03c68c0448971e0db23
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90610
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index bca567d..0d6155b 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1126,11 +1126,12 @@
}
matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x,
charpos.m_Origin.y));
+ matrix.Concat(mtTextMatrix);
path.set_stroke(stroke);
path.set_filltype(fill ? CFX_FillRenderOptions::FillType::kWinding
: CFX_FillRenderOptions::FillType::kNoFill);
path.path().Append(*pPath, &matrix);
- path.SetPathMatrix(mtTextMatrix);
+ path.SetPathMatrix(CFX_Matrix());
ProcessPath(&path, mtObj2Device);
}
}
diff --git a/testing/resources/pixel/bug_1772.in b/testing/resources/pixel/bug_1772.in
new file mode 100644
index 0000000..026b713
--- /dev/null
+++ b/testing/resources/pixel/bug_1772.in
@@ -0,0 +1,93 @@
+{{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 100 100]
+ /Resources <<
+ /ProcSet [/PDF /Text]
+ /ColorSpace <<
+ /CS1 [/Pattern]
+ >>
+ /Font <<
+ /F1 5 0 R
+ >>
+ /Pattern <<
+ /P1 6 0 R
+ >>
+ >>
+>>
+endobj
+{{object 4 0}} <<
+ {{streamlen}}
+>>
+stream
+BT
+/CS1 CS
+/P1 SCN
+/F1 1 Tf
+1 Tr
+20 0 0 20 20 30 Tm
+(S) Tj
+ET
+BT
+/CS1 CS
+/P1 SCN
+/F1 4 Tf
+1 Tr
+5 0 0 5 50 80 Tm
+(S) Tj
+ET
+BT
+/CS1 CS
+/P1 SCN
+/F1 20 Tf
+1 Tr
+1 0 0 1 70 40 Tm
+(S) Tj
+ET
+endstream
+endobj
+{{object 5 0}} <<
+ /Type /Font
+ /Subtype /Type1
+ /BaseFont /Helvetica
+>>
+endobj
+{{object 6 0}} <<
+ /Type /Pattern
+ /PatternType 2
+ /Shading 7 0 R
+>>
+endobj
+{{object 7 0}} <<
+ /ShadingType 3
+ /ColorSpace /DeviceRGB
+ /Coords [0.0 0.0 0.0 0.0 0.0 0.005] % Concentric circles
+ /Function 8 0 R
+ /Extend [true true]
+ >>
+endobj
+{{object 8 0}} <<
+ /FunctionType 2
+ /Domain [0.0 1.0]
+ /C0 [0 0 0]
+ /C1 [0 1 0]
+ /N 1
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/pixel/bug_1772_expected.pdf.0.png b/testing/resources/pixel/bug_1772_expected.pdf.0.png
new file mode 100644
index 0000000..f7b2703
--- /dev/null
+++ b/testing/resources/pixel/bug_1772_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/bug_1772_expected_skia.pdf.0.png b/testing/resources/pixel/bug_1772_expected_skia.pdf.0.png
new file mode 100644
index 0000000..570d1f1
--- /dev/null
+++ b/testing/resources/pixel/bug_1772_expected_skia.pdf.0.png
Binary files differ