Cleanup CPVT_GenerateAP

This CL moves FPDF_GenerateAP into the anonymous namespace of
CPDF_AnnotList. Several methods are moved into the anonymous namespace
of CPVT_GenerateAP which are only used internally.

Change-Id: I6e8fef54ba3757cc9873ed5ac370dec7eaca5d8b
Reviewed-on: https://pdfium-review.googlesource.com/16070
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index c0f7ae2..c7da676 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -75,6 +75,44 @@
   return pPopupAnnot;
 }
 
+void GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
+  if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget")
+    return;
+
+  CPDF_Object* pFieldTypeObj = FPDF_GetFieldAttr(pAnnotDict, "FT");
+  if (!pFieldTypeObj)
+    return;
+
+  ByteString field_type = pFieldTypeObj->GetString();
+  if (field_type == "Tx") {
+    CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
+    return;
+  }
+
+  CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
+  uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
+  if (field_type == "Ch") {
+    (flags & (1 << 17)) ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
+                        : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
+    return;
+  }
+
+  if (field_type != "Btn")
+    return;
+  if (flags & (1 << 16))
+    return;
+  if (pAnnotDict->KeyExist("AS"))
+    return;
+
+  CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent");
+  if (!pParentDict || !pParentDict->KeyExist("AS"))
+    return;
+
+  pAnnotDict->SetNewFor<CPDF_String>("AS", pParentDict->GetStringFor("AS"),
+                                     false);
+  return;
+}
+
 }  // namespace
 
 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
@@ -103,7 +141,7 @@
     m_AnnotList.push_back(pdfium::MakeUnique<CPDF_Annot>(pDict, m_pDocument));
     if (bRegenerateAP && subtype == "Widget" &&
         CPDF_InterForm::IsUpdateAPEnabled() && !pDict->GetDictFor("AP")) {
-      FPDF_GenerateAP(m_pDocument, pDict);
+      GenerateAP(m_pDocument, pDict);
     }
   }
 
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 34edd0e..b6e89e0 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -631,60 +631,68 @@
   return ByteString(sAppStream);
 }
 
-}  // namespace
-
-bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
-  if (!pAnnotDict || pAnnotDict->GetStringFor("Subtype") != "Widget")
-    return false;
-
-  CPDF_Object* pFieldTypeObj = FPDF_GetFieldAttr(pAnnotDict, "FT");
-  if (!pFieldTypeObj)
-    return false;
-
-  ByteString field_type = pFieldTypeObj->GetString();
-  if (field_type == "Tx")
-    return CPVT_GenerateAP::GenerateTextFieldAP(pDoc, pAnnotDict);
-
-  CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
-  uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
-  if (field_type == "Ch") {
-    return (flags & (1 << 17))
-               ? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
-               : CPVT_GenerateAP::GenerateListBoxAP(pDoc, pAnnotDict);
+ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
+                            int32_t nFontIndex,
+                            uint16_t Word,
+                            uint16_t SubWord) {
+  ByteString sWord;
+  if (SubWord > 0) {
+    sWord.Format("%c", SubWord);
+    return sWord;
   }
 
-  if (field_type == "Btn") {
-    if (!(flags & (1 << 16))) {
-      if (!pAnnotDict->KeyExist("AS")) {
-        if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) {
-          if (pParentDict->KeyExist("AS")) {
-            pAnnotDict->SetNewFor<CPDF_String>(
-                "AS", pParentDict->GetStringFor("AS"), false);
-          }
-        }
-      }
+  if (!pFontMap)
+    return sWord;
+
+  if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
+    if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
+        pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
+      sWord.Format("%c", Word);
+    } else {
+      uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
+      if (dwCharCode != CPDF_Font::kInvalidCharCode)
+        pPDFFont->AppendChar(&sWord, dwCharCode);
     }
   }
-
-  return false;
+  return sWord;
 }
 
+ByteString GetWordRenderString(const ByteString& strWords) {
+  if (strWords.GetLength() > 0)
+    return PDF_EncodeString(strWords, false) + " Tj\n";
+  return "";
+}
+
+ByteString GetFontSetString(IPVT_FontMap* pFontMap,
+                            int32_t nFontIndex,
+                            float fFontSize) {
+  std::ostringstream sRet;
+  if (pFontMap) {
+    ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
+    if (sFontAlias.GetLength() > 0 && fFontSize > 0)
+      sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
+  }
+  return ByteString(sRet);
+}
+
+}  // namespace
+
 // Static.
-bool CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateComboBoxAP(CPDF_Document* pDoc,
                                          CPDF_Dictionary* pAnnotDict) {
-  return GenerateWidgetAP(pDoc, pAnnotDict, 1);
+  GenerateWidgetAP(pDoc, pAnnotDict, 1);
 }
 
 // Static.
-bool CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateListBoxAP(CPDF_Document* pDoc,
                                         CPDF_Dictionary* pAnnotDict) {
-  return GenerateWidgetAP(pDoc, pAnnotDict, 2);
+  GenerateWidgetAP(pDoc, pAnnotDict, 2);
 }
 
 // Static.
-bool CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
+void CPVT_GenerateAP::GenerateTextFieldAP(CPDF_Document* pDoc,
                                           CPDF_Dictionary* pAnnotDict) {
-  return GenerateWidgetAP(pDoc, pAnnotDict, 0);
+  GenerateWidgetAP(pDoc, pAnnotDict, 0);
 }
 
 bool CPVT_GenerateAP::GenerateCircleAP(CPDF_Document* pDoc,
@@ -1335,50 +1343,3 @@
   pStreamDict->SetRectFor("BBox", rect);
   pStreamDict->SetFor("Resources", std::move(pResourceDict));
 }
-
-// Static.
-ByteString CPVT_GenerateAP::GetPDFWordString(IPVT_FontMap* pFontMap,
-                                             int32_t nFontIndex,
-                                             uint16_t Word,
-                                             uint16_t SubWord) {
-  ByteString sWord;
-  if (SubWord > 0) {
-    sWord.Format("%c", SubWord);
-    return sWord;
-  }
-
-  if (!pFontMap)
-    return sWord;
-
-  if (CPDF_Font* pPDFFont = pFontMap->GetPDFFont(nFontIndex)) {
-    if (pPDFFont->GetBaseFont().Compare("Symbol") == 0 ||
-        pPDFFont->GetBaseFont().Compare("ZapfDingbats") == 0) {
-      sWord.Format("%c", Word);
-    } else {
-      uint32_t dwCharCode = pPDFFont->CharCodeFromUnicode(Word);
-      if (dwCharCode != CPDF_Font::kInvalidCharCode)
-        pPDFFont->AppendChar(&sWord, dwCharCode);
-    }
-  }
-  return sWord;
-}
-
-// Static.
-ByteString CPVT_GenerateAP::GetWordRenderString(const ByteString& strWords) {
-  if (strWords.GetLength() > 0)
-    return PDF_EncodeString(strWords, false) + " Tj\n";
-  return "";
-}
-
-// Static.
-ByteString CPVT_GenerateAP::GetFontSetString(IPVT_FontMap* pFontMap,
-                                             int32_t nFontIndex,
-                                             float fFontSize) {
-  std::ostringstream sRet;
-  if (pFontMap) {
-    ByteString sFontAlias = pFontMap->GetPDFFontAlias(nFontIndex);
-    if (sFontAlias.GetLength() > 0 && fFontSize > 0)
-      sRet << "/" << sFontAlias << " " << fFontSize << " Tf\n";
-  }
-  return ByteString(sRet);
-}
diff --git a/core/fpdfdoc/cpvt_generateap.h b/core/fpdfdoc/cpvt_generateap.h
index 6f63b10..42ff339 100644
--- a/core/fpdfdoc/cpvt_generateap.h
+++ b/core/fpdfdoc/cpvt_generateap.h
@@ -21,20 +21,16 @@
 struct CPVT_Dash;
 class IPVT_FontMap;
 
-struct CPVT_WordRange;
-
-bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
-
 class CPVT_GenerateAP {
  public:
   static bool GenerateCircleAP(CPDF_Document* pDoc,
                                CPDF_Dictionary* pAnnotDict);
-  static bool GenerateComboBoxAP(CPDF_Document* pDoc,
+  static void GenerateComboBoxAP(CPDF_Document* pDoc,
                                  CPDF_Dictionary* pAnnotDict);
   static bool GenerateHighlightAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
   static bool GenerateInkAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
-  static bool GenerateListBoxAP(CPDF_Document* pDoc,
+  static void GenerateListBoxAP(CPDF_Document* pDoc,
                                 CPDF_Dictionary* pAnnotDict);
   static bool GeneratePopupAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
   static bool GenerateSquareAP(CPDF_Document* pDoc,
@@ -44,7 +40,7 @@
   static bool GenerateStrikeOutAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
   static bool GenerateTextAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict);
-  static bool GenerateTextFieldAP(CPDF_Document* pDoc,
+  static void GenerateTextFieldAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
   static bool GenerateUnderlineAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);
@@ -76,15 +72,6 @@
       std::ostringstream* psAppStream,
       std::unique_ptr<CPDF_Dictionary> pResourceDict,
       bool bIsTextMarkupAnnotation);
-
-  static ByteString GetPDFWordString(IPVT_FontMap* pFontMap,
-                                     int32_t nFontIndex,
-                                     uint16_t Word,
-                                     uint16_t SubWord);
-  static ByteString GetWordRenderString(const ByteString& strWords);
-  static ByteString GetFontSetString(IPVT_FontMap* pFontMap,
-                                     int32_t nFontIndex,
-                                     float fFontSize);
 };
 
 #endif  // CORE_FPDFDOC_CPVT_GENERATEAP_H_