Generate default AP stream for text annotation.

This patch generates a default AP stream for text annotation. The AP stream
only draws a symbol, which represents the presence of text annotation at the
point.

Also, roll DEPS for testing/corpus to afbac94 to test text annotations.

BUG=62625

Review-Url: https://codereview.chromium.org/2270493002
diff --git a/DEPS b/DEPS
index 37daf56..dcb66d3 100644
--- a/DEPS
+++ b/DEPS
@@ -14,7 +14,7 @@
   'gmock_revision': '29763965ab52f24565299976b936d1265cb6a271',
   'gtest_revision': '8245545b6dc9c4703e6496d1efd19e975ad2b038',
   'icu_revision': 'a5f86adbb0a58d04c035a5d1228747b1823cd485',
-  'pdfium_tests_revision': '1fdec9eaee514481092dd8e066029db71644829a',
+  'pdfium_tests_revision': 'afbac944ba4b41252e4bd16372f27806bc0ed924',
   'skia_revision': '36c38cbb29744e0b5390a38367e47c0c74287c2d',
   'tools_memory_revision': '427f10475e1a8d72424c29d00bf689122b738e5d',
   'trace_event_revision': '54b8455be9505c2cb0cf5c26bb86739c236471aa',
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 617ea0f..df12e9a 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -34,6 +34,8 @@
     CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, m_pAnnotDict);
   else if (m_sSubtype == "StrikeOut")
     CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, m_pAnnotDict);
+  else if (m_sSubtype == "Text")
+    CPVT_GenerateAP::GenerateTextAP(m_pDocument, m_pAnnotDict);
   else if (m_sSubtype == "Underline")
     CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict);
 }
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index da3c052..12ba4ef 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -563,6 +563,56 @@
   return bIsFillRect ? "f" : "n";
 }
 
+CFX_ByteString GenerateTextSymbolAP(const CFX_FloatRect& rect) {
+  CFX_ByteTextBuf sAppStream;
+  sAppStream << CPVT_GenerateAP::GenerateColorAP(
+      CPVT_Color(CPVT_Color::kRGB, 1, 1, 0), PaintOperation::FILL);
+  sAppStream << CPVT_GenerateAP::GenerateColorAP(
+      CPVT_Color(CPVT_Color::kRGB, 0, 0, 0), PaintOperation::STROKE);
+
+  const FX_FLOAT fBorderWidth = 1;
+  sAppStream << fBorderWidth << " w\n";
+
+  const FX_FLOAT fHalfWidth = fBorderWidth / 2;
+  const FX_FLOAT fTipDelta = 4;
+
+  CFX_FloatRect outerRect1 = rect;
+  outerRect1.Deflate(fHalfWidth, fHalfWidth);
+  outerRect1.bottom += fTipDelta;
+
+  CFX_FloatRect outerRect2 = outerRect1;
+  outerRect2.left += fTipDelta;
+  outerRect2.right = outerRect2.left + fTipDelta;
+  outerRect2.top = outerRect2.bottom - fTipDelta;
+  FX_FLOAT outerRect2Middle = (outerRect2.left + outerRect2.right) / 2;
+
+  // Draw outer boxes.
+  sAppStream << outerRect1.left << " " << outerRect1.bottom << " m\n"
+             << outerRect1.left << " " << outerRect1.top << " l\n"
+             << outerRect1.right << " " << outerRect1.top << " l\n"
+             << outerRect1.right << " " << outerRect1.bottom << " l\n"
+             << outerRect2.right << " " << outerRect2.bottom << " l\n"
+             << outerRect2Middle << " " << outerRect2.top << " l\n"
+             << outerRect2.left << " " << outerRect2.bottom << " l\n"
+             << outerRect1.left << " " << outerRect1.bottom << " l\n";
+
+  // Draw inner lines.
+  CFX_FloatRect lineRect = outerRect1;
+  const FX_FLOAT fXDelta = 2;
+  const FX_FLOAT fYDelta = (lineRect.top - lineRect.bottom) / 4;
+
+  lineRect.left += fXDelta;
+  lineRect.right -= fXDelta;
+  for (int i = 0; i < 3; ++i) {
+    lineRect.top -= fYDelta;
+    sAppStream << lineRect.left << " " << lineRect.top << " m\n"
+               << lineRect.right << " " << lineRect.top << " l\n";
+  }
+  sAppStream << "B*\n";
+
+  return sAppStream.MakeString();
+}
+
 bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) {
   // If AP dictionary exists, we use the appearance defined in the
   // existing AP dictionary.
@@ -778,6 +828,30 @@
   return true;
 }
 
+bool CPVT_GenerateAP::GenerateTextAP(CPDF_Document* pDoc,
+                                     CPDF_Dictionary* pAnnotDict) {
+  if (!ShouldGenerateAPForAnnotation(pAnnotDict))
+    return false;
+
+  CFX_ByteTextBuf sAppStream;
+  CFX_ByteString sExtGSDictName = "GS";
+  sAppStream << "/" << sExtGSDictName << " gs ";
+
+  CFX_FloatRect rect = pAnnotDict->GetRectBy("Rect");
+  const FX_FLOAT fNoteLength = 20;
+  CFX_FloatRect noteRect(rect.left, rect.bottom, rect.left + fNoteLength,
+                         rect.bottom + fNoteLength);
+  pAnnotDict->SetAtRect("Rect", noteRect);
+
+  sAppStream << GenerateTextSymbolAP(noteRect);
+
+  CPDF_Dictionary* pExtGStateDict =
+      GenerateExtGStateDict(*pAnnotDict, sExtGSDictName, "Normal");
+  GenerateAndSetAPDict(pDoc, pAnnotDict, sAppStream, pExtGStateDict);
+
+  return true;
+}
+
 bool CPVT_GenerateAP::GenerateUnderlineAP(CPDF_Document* pDoc,
                                           CPDF_Dictionary* pAnnotDict) {
   if (!ShouldGenerateAPForAnnotation(pAnnotDict))
diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h
index e366939..062acf6 100644
--- a/core/fpdfdoc/cpvt_generateap.h
+++ b/core/fpdfdoc/cpvt_generateap.h
@@ -40,6 +40,7 @@
                                  CPDF_Dictionary* pAnnotDict);
   static bool GenerateStrikeOutAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
+  static bool GenerateTextAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
   static bool GenerateTextFieldAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
   static bool GenerateUnderlineAP(CPDF_Document* pDoc,