Adding password form flag for text fields in fpdf_annot.h
This CL adds FPDF_FORMFLAG_TEXT_PASSWORD flag in fpdf_annot.h. This
flag can be retrieved for an interactive form annotation using
FPDFAnnot_GetFormFieldFlags API.
The CL also includes tests to validate if this flag is retrieved
correctly for both password and non password text fields.
Bug: pdfium:1464
Change-Id: I5d86c6a3b94a8eb68d8b3aedc89f7c8c58e83d49
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65390
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 1af2a0d..a6cfaf3 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -1194,7 +1194,7 @@
}
TEST_F(FPDFAnnotEmbedderTest, GetNumberValue) {
- // Open a file with three text annotations and load its first page.
+ // Open a file with four text annotations and load its first page.
ASSERT_TRUE(OpenDocument("text_form_multiple.pdf"));
FPDF_PAGE page = LoadPage(0);
ASSERT_TRUE(page);
@@ -1480,6 +1480,7 @@
// Check that the flag values are as expected.
int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_TEXT_PASSWORD);
}
{
@@ -1490,6 +1491,18 @@
// Check that the flag values are as expected.
int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
EXPECT_TRUE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_TEXT_PASSWORD);
+ }
+
+ {
+ // Retrieve the fourth annotation: user-editable password text field.
+ ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 3));
+ ASSERT_TRUE(annot);
+
+ // Check that the flag values are as expected.
+ int flags = FPDFAnnot_GetFormFieldFlags(form_handle(), annot.get());
+ EXPECT_FALSE(flags & FPDF_FORMFLAG_READONLY);
+ EXPECT_TRUE(flags & FPDF_FORMFLAG_TEXT_PASSWORD);
}
UnloadPage(page);
@@ -2022,7 +2035,7 @@
ASSERT_TRUE(page);
{
- // All 3 widgets have Tf font size 12.
+ // All 4 widgets have Tf font size 12.
ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
ASSERT_TRUE(annot);
@@ -2044,6 +2057,10 @@
ASSERT_TRUE(
FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_three));
EXPECT_EQ(12.0, value_three);
+
+ float value_four;
+ ASSERT_TRUE(FPDFAnnot_GetFontSize(form_handle(), annot.get(), &value_four));
+ EXPECT_EQ(12.0, value_four);
}
UnloadPage(page);
diff --git a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
index 4e9327c..8b68afa 100644
--- a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
@@ -48,8 +48,14 @@
ASSERT_TRUE(m_pAnnotCharLimit);
ASSERT_EQ(CPDF_Annot::Subtype::WIDGET,
m_pAnnotCharLimit->GetAnnotSubtype());
+
+ // Password text field.
+ CPDFSDK_Annot* password_annot = iter.GetNextAnnot(m_pAnnotCharLimit);
+ ASSERT_TRUE(password_annot);
+ ASSERT_EQ(CPDF_Annot::Subtype::WIDGET, password_annot->GetAnnotSubtype());
+
CPDFSDK_Annot* pLastAnnot = iter.GetLastAnnot();
- ASSERT_EQ(m_pAnnotCharLimit, pLastAnnot);
+ ASSERT_EQ(password_annot, pLastAnnot);
}
void FormFillerAndWindowSetup(CPDFSDK_Annot* pAnnotTextField) {
diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
index cae6cfd..f458748 100644
--- a/public/fpdf_annot.h
+++ b/public/fpdf_annot.h
@@ -75,6 +75,7 @@
// Refer to PDF Reference version 1.7 table 8.77 for field flags specific to
// interactive form text fields.
#define FPDF_FORMFLAG_TEXT_MULTILINE (1 << 12)
+#define FPDF_FORMFLAG_TEXT_PASSWORD (1 << 13)
// Refer to PDF Reference version 1.7 table 8.79 for field flags specific to
// interactive form choice fields.
diff --git a/testing/resources/text_form_multiple.in b/testing/resources/text_form_multiple.in
index 066ab20..6b3b7a5 100644
--- a/testing/resources/text_form_multiple.in
+++ b/testing/resources/text_form_multiple.in
@@ -3,7 +3,7 @@
<<
/Type /Catalog
/Pages 2 0 R
- /AcroForm << /Fields [ 4 0 R 9 0 R 10 0 R ] /DR 5 0 R >>
+ /AcroForm << /Fields [ 4 0 R 9 0 R 10 0 R 11 0 R ] /DR 5 0 R >>
>>
endobj
{{object 2 0}}
@@ -16,7 +16,7 @@
/Resources 5 0 R
/MediaBox [ 0 0 300 300 ]
/Contents 8 0 R
- /Annots [ 4 0 R 9 0 R 10 0 R ]
+ /Annots [ 4 0 R 9 0 R 10 0 R 11 0 R ]
>>
endobj
{{object 4 0}}
@@ -74,6 +74,16 @@
/Rect [ 100 50 200 75 ]
/Subtype /Widget
>>
+{{object 11 0}}
+<<
+ /Type /Annot
+ /FT /Tx
+ /Ff 8192
+ /T (Password)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 10 200 35 ]
+ /Subtype /Widget
+>>
endobj
{{xref}}
{{trailer}}
diff --git a/testing/resources/text_form_multiple.pdf b/testing/resources/text_form_multiple.pdf
index 172ab5e..cc27c09 100644
--- a/testing/resources/text_form_multiple.pdf
+++ b/testing/resources/text_form_multiple.pdf
@@ -4,7 +4,7 @@
<<
/Type /Catalog
/Pages 2 0 R
- /AcroForm << /Fields [ 4 0 R 9 0 R 10 0 R ] /DR 5 0 R >>
+ /AcroForm << /Fields [ 4 0 R 9 0 R 10 0 R 11 0 R ] /DR 5 0 R >>
>>
endobj
2 0 obj
@@ -17,7 +17,7 @@
/Resources 5 0 R
/MediaBox [ 0 0 300 300 ]
/Contents 8 0 R
- /Annots [ 4 0 R 9 0 R 10 0 R ]
+ /Annots [ 4 0 R 9 0 R 10 0 R 11 0 R ]
>>
endobj
4 0 obj
@@ -75,21 +75,35 @@
/Rect [ 100 50 200 75 ]
/Subtype /Widget
>>
+11 0 obj
+<<
+ /Type /Annot
+ /FT /Tx
+ /Ff 8192
+ /T (Password)
+ /DA (0 0 0 rg /F1 12 Tf)
+ /Rect [ 100 10 200 35 ]
+ /Subtype /Widget
+>>
endobj
xref
-0 11
+0 12
0000000000 65535 f
0000000015 00000 n
-0000000127 00000 n
-0000000186 00000 n
-0000000335 00000 n
-0000000471 00000 n
-0000000504 00000 n
-0000000535 00000 n
-0000000611 00000 n
-0000000711 00000 n
-0000000855 00000 n
-trailer<< /Root 1 0 R /Size 11 >>
+0000000134 00000 n
+0000000193 00000 n
+0000000349 00000 n
+0000000485 00000 n
+0000000518 00000 n
+0000000549 00000 n
+0000000625 00000 n
+0000000725 00000 n
+0000000869 00000 n
+0000001027 00000 n
+trailer <<
+ /Root 1 0 R
+ /Size 12
+>>
startxref
-1020
+1173
%%EOF