Remove xfa/fxfa dependence on fpdfapi/font

Pushes interaction with CPDF_Fonts down into CFGAS_GEFont

Change-Id: I667130a0074f1087c1154d0f32eec9774ad1d83b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/59219
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp
index 246fee1..3f4c886 100644
--- a/xfa/fgas/font/cfgas_gefont.cpp
+++ b/xfa/fgas/font/cfgas_gefont.cpp
@@ -57,6 +57,16 @@
   return pFont;
 }
 
+// static
+RetainPtr<CFGAS_GEFont> CFGAS_GEFont::LoadStockFont(
+    CPDF_Document* pDoc,
+    CFGAS_FontMgr* pMgr,
+    const ByteString& font_family) {
+  RetainPtr<CPDF_Font> stock_font =
+      CPDF_Font::GetStockFont(pDoc, font_family.AsStringView());
+  return stock_font ? CFGAS_GEFont::LoadFont(stock_font, pMgr) : nullptr;
+}
+
 CFGAS_GEFont::CFGAS_GEFont(CFGAS_FontMgr* pFontMgr) : m_pFontMgr(pFontMgr) {}
 
 CFGAS_GEFont::~CFGAS_GEFont() = default;
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index b7988db..7e021e1 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -22,6 +22,7 @@
 
 class CFX_Font;
 class CFX_UnicodeEncodingEx;
+class CPDF_Document;
 class CPDF_Font;
 
 class CFGAS_GEFont final : public Retainable {
@@ -39,6 +40,10 @@
       std::unique_ptr<CFX_Font> pInternalFont,
       CFGAS_FontMgr* pFontMgr);
 
+  static RetainPtr<CFGAS_GEFont> LoadStockFont(CPDF_Document* pDoc,
+                                               CFGAS_FontMgr* pMgr,
+                                               const ByteString& font_family);
+
   uint32_t GetFontStyles() const;
   bool GetCharWidth(wchar_t wUnicode, int32_t* pWidth);
   int32_t GetGlyphIndex(wchar_t wUnicode);
diff --git a/xfa/fxfa/BUILD.gn b/xfa/fxfa/BUILD.gn
index f3c132d..06fb256 100644
--- a/xfa/fxfa/BUILD.gn
+++ b/xfa/fxfa/BUILD.gn
@@ -96,7 +96,6 @@
     "fxfa_basic.h",
   ]
   deps = [
-    "../../core/fpdfapi/font",
     "../../core/fpdfapi/parser",
     "../../core/fpdfdoc",
     "../../core/fxcodec",
diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp
index c7ced0c..7259f6cf 100644
--- a/xfa/fxfa/cxfa_fontmgr.cpp
+++ b/xfa/fxfa/cxfa_fontmgr.cpp
@@ -10,7 +10,6 @@
 #include <memory>
 #include <utility>
 
-#include "core/fpdfapi/font/cpdf_font.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fxge/cfx_fontmgr.h"
@@ -35,7 +34,6 @@
     return iter->second;
 
   WideString wsEnglishName = FGAS_FontNameToEnglishName(wsFontFamily);
-
   CFGAS_PDFFontMgr* pMgr = hDoc->GetPDFFontMgr();
   RetainPtr<CFGAS_GEFont> pFont;
   if (pMgr) {
@@ -47,27 +45,19 @@
     pFont = CFGAS_DefaultFontManager::GetFont(hDoc->GetApp()->GetFDEFontMgr(),
                                               wsFontFamily, dwFontStyles);
   }
-
   if (!pFont && pMgr) {
     pFont = pMgr->GetFont(wsEnglishName.AsStringView(), dwFontStyles, false);
     if (pFont)
       return pFont;
   }
-
   if (!pFont) {
     pFont = CFGAS_DefaultFontManager::GetDefaultFont(
         hDoc->GetApp()->GetFDEFontMgr(), wsFontFamily, dwFontStyles);
   }
-
   if (!pFont) {
-    ByteString font_family =
-        ByteString::Format("%ls", WideString(wsFontFamily).c_str());
-    RetainPtr<CPDF_Font> stock_font =
-        CPDF_Font::GetStockFont(hDoc->GetPDFDoc(), font_family.AsStringView());
-    if (stock_font) {
-      pFont =
-          CFGAS_GEFont::LoadFont(stock_font, hDoc->GetApp()->GetFDEFontMgr());
-    }
+    pFont = CFGAS_GEFont::LoadStockFont(
+        hDoc->GetPDFDoc(), hDoc->GetApp()->GetFDEFontMgr(),
+        ByteString::Format("%ls", WideString(wsFontFamily).c_str()));
   }
   if (pFont)
     m_FontMap[bsKey] = pFont;