Remove dependence from cjs_field.cpp to fpdfapi/font

Push some functionality back into the cpdf_formcontrol, which
already has knowlege of CPDF_Font. This removes the last
dependence between fxjs and fpdfapi/font, so update build rules.

Change-Id: I50bc778ca831c95477b4d10fe879a0a47e7a6ba8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58630
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index 5d1efb8..7e8c190 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -202,7 +202,15 @@
   return CPDF_DefaultAppearance(pObj->GetString());
 }
 
-RetainPtr<CPDF_Font> CPDF_FormControl::GetDefaultControlFont() {
+Optional<WideString> CPDF_FormControl::GetDefaultControlFontName() const {
+  RetainPtr<CPDF_Font> pFont = GetDefaultControlFont();
+  if (!pFont)
+    return {};
+
+  return WideString::FromDefANSI(pFont->GetBaseFontName().AsStringView());
+}
+
+RetainPtr<CPDF_Font> CPDF_FormControl::GetDefaultControlFont() const {
   float fFontSize;
   CPDF_DefaultAppearance cDA = GetDefaultAppearance();
   Optional<ByteString> csFontNameTag = cDA.GetFont(&fFontSize);
diff --git a/core/fpdfdoc/cpdf_formcontrol.h b/core/fpdfdoc/cpdf_formcontrol.h
index 18c1f23..8c02d46 100644
--- a/core/fpdfdoc/cpdf_formcontrol.h
+++ b/core/fpdfdoc/cpdf_formcontrol.h
@@ -20,6 +20,7 @@
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxge/fx_dib.h"
+#include "third_party/base/optional.h"
 
 #define TEXTPOS_CAPTION 0
 #define TEXTPOS_ICON 1
@@ -99,13 +100,14 @@
   CPDF_AAction GetAdditionalAction() const;
   CPDF_DefaultAppearance GetDefaultAppearance() const;
 
-  RetainPtr<CPDF_Font> GetDefaultControlFont();
+  Optional<WideString> GetDefaultControlFontName() const;
   int GetControlAlignment() const;
 
   ByteString GetOnStateName() const;
   void CheckControl(bool bChecked);
 
  private:
+  RetainPtr<CPDF_Font> GetDefaultControlFont() const;
   FX_ARGB GetColor(int& iColorType, const ByteString& csEntry);
   float GetOriginalColor(int index, const ByteString& csEntry);
   void GetOriginalColor(int& iColorType,
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index 8d2e7b8..688b5c1 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -104,7 +104,6 @@
     deps += [
       "../constants",
       "../core/fdrm",
-      "../core/fpdfapi/font",
       "../core/fpdfapi/page",
       "../core/fpdfapi/parser",
       "../core/fpdfapi/render",
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index a15781c..45e5ad7 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -12,7 +12,6 @@
 
 #include "constants/annotation_flags.h"
 #include "constants/form_flags.h"
-#include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfdoc/cpdf_formcontrol.h"
 #include "core/fpdfdoc/cpdf_formfield.h"
 #include "core/fpdfdoc/cpdf_interactiveform.h"
@@ -1984,13 +1983,12 @@
     return CJS_Result::Failure(JSMessage::kObjectTypeError);
   }
 
-  RetainPtr<CPDF_Font> pFont = pFormControl->GetDefaultControlFont();
-  if (!pFont)
+  Optional<WideString> wsFontName = pFormControl->GetDefaultControlFontName();
+  if (!wsFontName.has_value())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  return CJS_Result::Success(pRuntime->NewString(
-      WideString::FromDefANSI(pFont->GetBaseFontName().AsStringView())
-          .AsStringView()));
+  return CJS_Result::Success(
+      pRuntime->NewString(wsFontName.value().AsStringView()));
 }
 
 CJS_Result CJS_Field::set_text_font(CJS_Runtime* pRuntime,