Encapsulate SystemFontInfoIface operations behind CFX_FontMapper.

- fix IWYU exposed by removing header.

Change-Id: I364d4eb6b1a4510e8b3eee08abdc11714fda7ba6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/65572
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index f16b9be..04fb77d 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -667,6 +667,30 @@
   return pdfium::CollectionSize<int>(m_FaceArray);
 }
 
+#ifdef PDF_ENABLE_XFA
+std::unique_ptr<uint8_t, FxFreeDeleter> CFX_FontMapper::RawBytesForIndex(
+    uint32_t index,
+    size_t* returned_length) {
+  if (!m_pFontInfo)
+    return nullptr;
+
+  void* hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0,
+                                     GetFaceName(index).c_str());
+  if (!hFont)
+    return nullptr;
+
+  uint32_t required_size = m_pFontInfo->GetFontData(hFont, 0, {});
+  if (required_size == 0)
+    return nullptr;
+
+  std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer(
+      FX_Alloc(uint8_t, required_size + 1));
+  *returned_length =
+      m_pFontInfo->GetFontData(hFont, 0, {pBuffer.get(), required_size});
+  return pBuffer;
+}
+#endif  // PDF_ENABLE_XFA
+
 bool CFX_FontMapper::IsBuiltinFace(const RetainPtr<CFX_Face>& face) const {
   for (size_t i = 0; i < MM_FACE_COUNT; ++i) {
     if (m_MMFaces[i] == face)
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 3ce0c29..c21c6cb 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -11,6 +11,7 @@
 #include <utility>
 #include <vector>
 
+#include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxge/cfx_face.h"
 #include "third_party/base/optional.h"
@@ -50,7 +51,6 @@
   }
 
   void SetSystemFontInfo(std::unique_ptr<SystemFontInfoIface> pFontInfo);
-  SystemFontInfoIface* GetSystemFontInfo() { return m_pFontInfo.get(); }
   void AddInstalledFont(const ByteString& name, int charset);
   void LoadInstalledFonts();
 
@@ -66,6 +66,12 @@
   int GetFaceSize() const;
   ByteString GetFaceName(int index) const { return m_FaceArray[index].name; }
 
+#ifdef PDF_ENABLE_XFA
+  std::unique_ptr<uint8_t, FxFreeDeleter> RawBytesForIndex(
+      uint32_t index,
+      size_t* returned_length);
+#endif  // PDF_ENABLE_XFA
+
   std::vector<ByteString> m_InstalledTTFonts;
   std::vector<std::pair<ByteString, ByteString>> m_LocalizedTTFonts;
 
diff --git a/testing/xfa_unit_test_support.cpp b/testing/xfa_unit_test_support.cpp
index 8d8460f..8cc2d6c 100644
--- a/testing/xfa_unit_test_support.cpp
+++ b/testing/xfa_unit_test_support.cpp
@@ -9,6 +9,7 @@
 
 #include "core/fxge/cfx_fontmgr.h"
 #include "core/fxge/cfx_gemodule.h"
+#include "core/fxge/systemfontinfo_iface.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index c50d9e7..96407f3 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -19,7 +19,6 @@
 #include "core/fxge/cfx_fontmgr.h"
 #include "core/fxge/cfx_gemodule.h"
 #include "core/fxge/fx_font.h"
-#include "core/fxge/systemfontinfo_iface.h"
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
@@ -447,21 +446,13 @@
 
 RetainPtr<IFX_SeekableReadStream> CreateFontStream(
     CFX_FontMapper* pFontMapper,
-    SystemFontInfoIface* pSystemFontInfo,
     uint32_t index) {
-  void* hFont = pSystemFontInfo->MapFont(
-      0, 0, FX_CHARSET_Default, 0, pFontMapper->GetFaceName(index).c_str());
-  if (!hFont)
+  size_t dwFileSize = 0;
+  std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer =
+      pFontMapper->RawBytesForIndex(index, &dwFileSize);
+  if (!pBuffer)
     return nullptr;
 
-  uint32_t dwFileSize = pSystemFontInfo->GetFontData(hFont, 0, {});
-  if (dwFileSize == 0)
-    return nullptr;
-
-  std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer(
-      FX_Alloc(uint8_t, dwFileSize + 1));
-  dwFileSize =
-      pSystemFontInfo->GetFontData(hFont, 0, {pBuffer.get(), dwFileSize});
   return pdfium::MakeRetain<CFX_MemoryStream>(std::move(pBuffer), dwFileSize);
 }
 
@@ -471,13 +462,9 @@
   CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
   pFontMapper->LoadInstalledFonts();
 
-  SystemFontInfoIface* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
-  if (!pSystemFontInfo)
-    return nullptr;
-
   for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
     if (pFontMapper->GetFaceName(i) == bsFaceName)
-      return CreateFontStream(pFontMapper, pSystemFontInfo, i);
+      return CreateFontStream(pFontMapper, i);
   }
   return nullptr;
 }
@@ -633,13 +620,9 @@
       CFX_GEModule::Get()->GetFontMgr()->GetBuiltinMapper();
   pFontMapper->LoadInstalledFonts();
 
-  SystemFontInfoIface* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
-  if (!pSystemFontInfo)
-    return false;
-
   for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) {
     RetainPtr<IFX_SeekableReadStream> pFontStream =
-        CreateFontStream(pFontMapper, pSystemFontInfo, i);
+        CreateFontStream(pFontMapper, i);
     if (!pFontStream)
       continue;
 
@@ -702,12 +685,6 @@
 RetainPtr<CFGAS_GEFont> CFGAS_FontMgr::LoadFontInternal(
     const WideString& wsFaceName,
     int32_t iFaceIndex) {
-  CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
-  CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
-  SystemFontInfoIface* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
-  if (!pSystemFontInfo)
-    return nullptr;
-
   RetainPtr<IFX_SeekableReadStream> pFontStream =
       CreateFontStream(wsFaceName.ToUTF8());
   if (!pFontStream)
diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h
index ff2050b..bc7768e 100644
--- a/xfa/fgas/font/cfgas_fontmgr.h
+++ b/xfa/fgas/font/cfgas_fontmgr.h
@@ -17,8 +17,8 @@
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/observed_ptr.h"
 #include "core/fxcrt/retain_ptr.h"
+#include "core/fxge/cfx_face.h"
 #include "core/fxge/fx_freetype.h"
-#include "core/fxge/systemfontinfo_iface.h"
 #include "xfa/fgas/font/cfgas_pdffontmgr.h"
 
 class CFGAS_GEFont;