FPDFAnnot_GetSubtype: recognize the Redact annotation sub-type

This is new in PDF 1.7, probably that's why it was missing.

Change-Id: If75c0f885ccadc1549085ad30a4c2cd3e8db5ede
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/75730
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 14533f5..405e9b6 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -313,6 +313,8 @@
     return CPDF_Annot::Subtype::RICHMEDIA;
   if (sSubtype == "XFAWidget")
     return CPDF_Annot::Subtype::XFAWIDGET;
+  if (sSubtype == "Redact")
+    return CPDF_Annot::Subtype::REDACT;
   return CPDF_Annot::Subtype::UNKNOWN;
 }
 
@@ -372,6 +374,8 @@
     return "RichMedia";
   if (nSubtype == CPDF_Annot::Subtype::XFAWIDGET)
     return "XFAWidget";
+  if (nSubtype == CPDF_Annot::Subtype::REDACT)
+    return "Redact";
   return ByteString();
 }
 
diff --git a/core/fpdfdoc/cpdf_annot.h b/core/fpdfdoc/cpdf_annot.h
index 72e6bdf..651b0bd 100644
--- a/core/fpdfdoc/cpdf_annot.h
+++ b/core/fpdfdoc/cpdf_annot.h
@@ -57,7 +57,8 @@
     WATERMARK,
     THREED,
     RICHMEDIA,
-    XFAWIDGET
+    XFAWIDGET,
+    REDACT
   };
 
   static CPDF_Annot::Subtype StringToAnnotSubtype(const ByteString& sSubtype);
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 6b53b64..50d39bf 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -48,6 +48,7 @@
     case CPDF_Annot::Subtype::CARET:
     case CPDF_Annot::Subtype::INK:
     case CPDF_Annot::Subtype::FILEATTACHMENT:
+    case CPDF_Annot::Subtype::REDACT:
       return true;
     case CPDF_Annot::Subtype::UNKNOWN:
     case CPDF_Annot::Subtype::LINK:
diff --git a/fpdfsdk/fpdf_annot.cpp b/fpdfsdk/fpdf_annot.cpp
index 98b3e4f..28dbe14 100644
--- a/fpdfsdk/fpdf_annot.cpp
+++ b/fpdfsdk/fpdf_annot.cpp
@@ -115,6 +115,9 @@
 static_assert(static_cast<int>(CPDF_Annot::Subtype::XFAWIDGET) ==
                   FPDF_ANNOT_XFAWIDGET,
               "CPDF_Annot::XFAWIDGET value mismatch");
+static_assert(static_cast<int>(CPDF_Annot::Subtype::REDACT) ==
+                  FPDF_ANNOT_REDACT,
+              "CPDF_Annot::REDACT value mismatch");
 
 // These checks ensure the consistency of annotation appearance mode values
 // across core/ and public.
diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp
index 8ef97a4..2cb76c0 100644
--- a/fpdfsdk/fpdf_annot_embeddertest.cpp
+++ b/fpdfsdk/fpdf_annot_embeddertest.cpp
@@ -3208,3 +3208,18 @@
 
   UnloadPage(page);
 }
+
+TEST_F(FPDFAnnotEmbedderTest, Redactannotation) {
+  ASSERT_TRUE(OpenDocument("redact_annot.pdf"));
+  FPDF_PAGE page = LoadPage(0);
+  ASSERT_TRUE(page);
+  EXPECT_EQ(1, FPDFPage_GetAnnotCount(page));
+
+  {
+    ScopedFPDFAnnotation annot(FPDFPage_GetAnnot(page, 0));
+    ASSERT_TRUE(annot);
+    EXPECT_EQ(FPDF_ANNOT_REDACT, FPDFAnnot_GetSubtype(annot.get()));
+  }
+
+  UnloadPage(page);
+}
diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h
index 9561d84..9306456 100644
--- a/public/fpdf_annot.h
+++ b/public/fpdf_annot.h
@@ -47,6 +47,7 @@
 #define FPDF_ANNOT_THREED 25
 #define FPDF_ANNOT_RICHMEDIA 26
 #define FPDF_ANNOT_XFAWIDGET 27
+#define FPDF_ANNOT_REDACT 28
 
 // Refer to PDF Reference (6th edition) table 8.16 for all annotation flags.
 #define FPDF_ANNOT_FLAG_NONE 0
diff --git a/testing/resources/redact_annot.in b/testing/resources/redact_annot.in
new file mode 100644
index 0000000..99b7b4e
--- /dev/null
+++ b/testing/resources/redact_annot.in
@@ -0,0 +1,44 @@
+{{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 612 792]
+  /Annots [
+    5 0 R
+  ]
+  /Tabs /R
+>>
+endobj
+{{object 4 0}} <<
+  {{streamlen}}
+>>
+stream
+endstream
+endobj
+{{object 5 0}} <<
+  /Type /Annot
+  /Subtype /Redact
+  /NM (Redact-1)
+  /F 4
+  /QuadPoints [293 542 349 542 293 530 349 530]
+  /P 3 0 R
+  /C [1 0.90196 0]
+  /Rect [293 530 349 542]
+>>
+endobj
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/redact_annot.pdf b/testing/resources/redact_annot.pdf
new file mode 100644
index 0000000..76c2607
--- /dev/null
+++ b/testing/resources/redact_annot.pdf
@@ -0,0 +1,56 @@
+%PDF-1.7
+% ò¤ô
+1 0 obj <<
+  /Type /Catalog
+  /Pages 2 0 R
+>>
+endobj
+2 0 obj <<
+  /Type /Pages
+  /Count 1
+  /Kids [3 0 R]
+>>
+endobj
+3 0 obj <<
+  /Type /Page
+  /Parent 2 0 R
+  /Contents 4 0 R
+  /MediaBox [0 0 612 792]
+  /Annots [
+    5 0 R
+  ]
+  /Tabs /R
+>>
+endobj
+4 0 obj <<
+  /Length 0
+>>
+stream
+endstream
+endobj
+5 0 obj <<
+  /Type /Annot
+  /Subtype /Redact
+  /NM (Redact-1)
+  /F 4
+  /QuadPoints [293 542 349 542 293 530 349 530]
+  /P 3 0 R
+  /C [1 0.90196 0]
+  /Rect [293 530 349 542]
+>>
+endobj
+xref
+0 6
+0000000000 65535 f 
+0000000015 00000 n 
+0000000068 00000 n 
+0000000131 00000 n 
+0000000263 00000 n 
+0000000313 00000 n 
+trailer <<
+  /Root 1 0 R
+  /Size 6
+>>
+startxref
+496
+%%EOF