Fix rendering for freetext_annotation_without_da.in
Change GenerateFreeTextAP() to initialize the /AcroForm dictionary if it
does not exist. Reuse InitDict() from cpdf_interactiveform.cpp to do
this by exposing it publicly. To make InitDict() work as expected and
create a reasonable default appearance entry:
- Change its font selection logic to avoid overwriting the "standard"
font with the "native" font, if there is no "native" font.
- Use a font size of 12 instead of 0.
Also update DEPS with new corpus test expectations to match this change:
https://pdfium.googlesource.com/pdfium_tests/+log/0d854e64bed7..039b875bf673
Bug: 380434959
Change-Id: I7131488d8f184bfb1bd4fc698a048fd9781d99f6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/130031
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/DEPS b/DEPS
index 6a63c7e..8bf433e 100644
--- a/DEPS
+++ b/DEPS
@@ -192,7 +192,7 @@
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling pdfium_tests
# and whatever else without interference from each other.
- 'pdfium_tests_revision': '0d854e64bed7be71f32de54f1e81377a7cb7caab',
+ 'pdfium_tests_revision': '039b875bf67383c6da78426a9cb75732b38d5dbb',
# Three lines of non-changing comments so that
# the commit queue can handle CLs rolling resultdb
# and whatever else without interference from each other.
diff --git a/core/fpdfdoc/cpdf_generateap.cpp b/core/fpdfdoc/cpdf_generateap.cpp
index 4ea0b2b..7cadb2b 100644
--- a/core/fpdfdoc/cpdf_generateap.cpp
+++ b/core/fpdfdoc/cpdf_generateap.cpp
@@ -32,6 +32,7 @@
#include "core/fpdfdoc/cpdf_color_utils.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
#include "core/fpdfdoc/cpdf_formfield.h"
+#include "core/fpdfdoc/cpdf_interactiveform.h"
#include "core/fpdfdoc/cpvt_fontmap.h"
#include "core/fpdfdoc/cpvt_variabletext.h"
#include "core/fpdfdoc/cpvt_word.h"
@@ -1051,7 +1052,8 @@
RetainPtr<CPDF_Dictionary> form_dict =
root_dict->GetMutableDictFor("AcroForm");
if (!form_dict) {
- return false;
+ form_dict = CPDF_InteractiveForm::InitAcroFormDict(doc);
+ CHECK(form_dict);
}
std::optional<DefaultAppearanceInfo> default_appearance_info =
diff --git a/core/fpdfdoc/cpdf_interactiveform.cpp b/core/fpdfdoc/cpdf_interactiveform.cpp
index 2868aaa..347c592 100644
--- a/core/fpdfdoc/cpdf_interactiveform.cpp
+++ b/core/fpdfdoc/cpdf_interactiveform.cpp
@@ -300,18 +300,20 @@
if (charSet != FX_Charset::kANSI) {
ByteString csFontName = GetNativeFontName(charSet, nullptr);
if (!pFont || csFontName != CFX_Font::kDefaultAnsiFontName) {
- pFont = AddNativeFont(charSet, pDocument);
- if (pFont) {
+ RetainPtr<CPDF_Font> native_font = AddNativeFont(charSet, pDocument);
+ if (native_font) {
csBaseName.clear();
- AddFont(pFormDict.Get(), pDocument, pFont, &csBaseName);
+ AddFont(pFormDict.Get(), pDocument, native_font, &csBaseName);
+ pFont = std::move(native_font);
}
}
}
ByteString csDA;
- if (pFont)
- csDA = "/" + PDF_NameEncode(csBaseName) + " 0 Tf ";
+ if (pFont) {
+ csDA = "/" + PDF_NameEncode(csBaseName) + " 12 Tf ";
+ }
csDA += "0 g";
- pFormDict->SetNewFor<CPDF_String>("DA", csDA);
+ pFormDict->SetNewFor<CPDF_String>("DA", std::move(csDA));
return pFormDict;
}
@@ -610,6 +612,12 @@
return pFont;
}
+// static
+RetainPtr<CPDF_Dictionary> CPDF_InteractiveForm::InitAcroFormDict(
+ CPDF_Document* document) {
+ return InitDict(document);
+}
+
size_t CPDF_InteractiveForm::CountFields(const WideString& csFieldName) const {
if (csFieldName.IsEmpty())
return m_pFieldTree->GetRoot()->CountFields();
diff --git a/core/fpdfdoc/cpdf_interactiveform.h b/core/fpdfdoc/cpdf_interactiveform.h
index 4e5d18a..4152301 100644
--- a/core/fpdfdoc/cpdf_interactiveform.h
+++ b/core/fpdfdoc/cpdf_interactiveform.h
@@ -56,6 +56,9 @@
static RetainPtr<CPDF_Font> AddNativeInteractiveFormFont(
CPDF_Document* pDocument,
ByteString* csNameTag);
+ // Adds a new /AcroForm dictionary to the root dictionary of `document`.
+ // Returns the newly created dictionary.
+ static RetainPtr<CPDF_Dictionary> InitAcroFormDict(CPDF_Document* document);
size_t CountFields(const WideString& csFieldName) const;
CPDF_FormField* GetField(size_t index, const WideString& csFieldName) const;
diff --git a/testing/resources/pixel/freetext_annotation_without_da_expected.pdf.0.png b/testing/resources/pixel/freetext_annotation_without_da_expected.pdf.0.png
index f97e340..2c83767 100644
--- a/testing/resources/pixel/freetext_annotation_without_da_expected.pdf.0.png
+++ b/testing/resources/pixel/freetext_annotation_without_da_expected.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/freetext_annotation_without_da_expected_mac.pdf.0.png b/testing/resources/pixel/freetext_annotation_without_da_expected_mac.pdf.0.png
new file mode 100644
index 0000000..a33b8eb
--- /dev/null
+++ b/testing/resources/pixel/freetext_annotation_without_da_expected_mac.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/freetext_annotation_without_da_expected_skia.pdf.0.png b/testing/resources/pixel/freetext_annotation_without_da_expected_skia.pdf.0.png
new file mode 100644
index 0000000..71f5ee7
--- /dev/null
+++ b/testing/resources/pixel/freetext_annotation_without_da_expected_skia.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/freetext_annotation_without_da_expected_skia_mac.pdf.0.png b/testing/resources/pixel/freetext_annotation_without_da_expected_skia_mac.pdf.0.png
new file mode 100644
index 0000000..7f2ab0f
--- /dev/null
+++ b/testing/resources/pixel/freetext_annotation_without_da_expected_skia_mac.pdf.0.png
Binary files differ
diff --git a/testing/resources/pixel/freetext_annotation_without_da_expected_skia_win.pdf.0.png b/testing/resources/pixel/freetext_annotation_without_da_expected_skia_win.pdf.0.png
new file mode 100644
index 0000000..1ad08ca
--- /dev/null
+++ b/testing/resources/pixel/freetext_annotation_without_da_expected_skia_win.pdf.0.png
Binary files differ