Remove CFX_FontMgr::InitFTLibrary.

Do it as part of the constructor.

Change-Id: Id28c1b62acb77abaccc3ba5d326955dfc482b36e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56411
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 2b2e1c4..35a829a 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -306,8 +306,6 @@
   m_bEmbedded = false;
 
   CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
-  pFontMgr->InitFTLibrary();
-
   std::unique_ptr<FXFT_StreamRec> stream;
   m_Face = LoadFileImp(pFontMgr->GetFTLibrary(), pFile, nFaceIndex, &stream);
   if (!m_Face)
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp
index 34c564b..2cf2626 100644
--- a/core/fxge/cfx_fontmgr.cpp
+++ b/core/fxge/cfx_fontmgr.cpp
@@ -74,24 +74,22 @@
   return index < nfont ? index : 0;
 }
 
+FXFT_LibraryRec* FTLibraryInitHelper() {
+  FXFT_LibraryRec* pLibrary = nullptr;
+  FT_Init_FreeType(&pLibrary);
+  return pLibrary;
+}
+
 }  // namespace
 
 CFX_FontMgr::CFX_FontMgr()
-    : m_pBuiltinMapper(pdfium::MakeUnique<CFX_FontMapper>(this)) {}
+    : m_FTLibrary(FTLibraryInitHelper()),
+      m_pBuiltinMapper(pdfium::MakeUnique<CFX_FontMapper>(this)),
+      m_FTLibrarySupportsHinting(SetLcdFilterMode() ||
+                                 FreeTypeVersionSupportsHinting()) {}
 
 CFX_FontMgr::~CFX_FontMgr() = default;
 
-void CFX_FontMgr::InitFTLibrary() {
-  if (m_FTLibrary)
-    return;
-
-  FXFT_LibraryRec* pLibrary = nullptr;
-  FT_Init_FreeType(&pLibrary);
-  m_FTLibrary.reset(pLibrary);
-  m_FTLibrarySupportsHinting =
-      SetLcdFilterMode() || FreeTypeVersionSupportsHinting();
-}
-
 void CFX_FontMgr::SetSystemFontInfo(
     std::unique_ptr<SystemFontInfoIface> pFontInfo) {
   m_pBuiltinMapper->SetSystemFontInfo(std::move(pFontInfo));
@@ -104,7 +102,6 @@
                                                int italic_angle,
                                                int CharsetCP,
                                                CFX_SubstFont* pSubstFont) {
-  InitFTLibrary();
   return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
                                          italic_angle, CharsetCP, pSubstFont);
 }
@@ -129,8 +126,6 @@
     std::unique_ptr<uint8_t, FxFreeDeleter> pData,
     uint32_t size,
     int face_index) {
-  InitFTLibrary();
-
   RetainPtr<CFX_Face> face =
       CFX_Face::New(m_FTLibrary.get(), {pData.get(), size}, face_index);
   if (!face)
@@ -186,7 +181,6 @@
 
 RetainPtr<CFX_Face> CFX_FontMgr::GetFixedFace(pdfium::span<const uint8_t> span,
                                               int face_index) {
-  InitFTLibrary();
   RetainPtr<CFX_Face> face = CFX_Face::New(m_FTLibrary.get(), span, face_index);
   if (!face)
     return nullptr;
diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h
index 38de56f..bbbad92 100644
--- a/core/fxge/cfx_fontmgr.h
+++ b/core/fxge/cfx_fontmgr.h
@@ -29,8 +29,6 @@
   CFX_FontMgr();
   ~CFX_FontMgr();
 
-  void InitFTLibrary();
-
   RetainPtr<CFX_Face> GetCachedFace(const ByteString& face_name,
                                     int weight,
                                     bool bItalic,
@@ -73,11 +71,10 @@
   bool SetLcdFilterMode() const;
 
   // Must come before |m_pBuiltinMapper| and |m_FaceMap|.
-  ScopedFXFTLibraryRec m_FTLibrary;
-
+  ScopedFXFTLibraryRec const m_FTLibrary;
   std::unique_ptr<CFX_FontMapper> m_pBuiltinMapper;
   std::map<ByteString, std::unique_ptr<CTTFontDesc>> m_FaceMap;
-  bool m_FTLibrarySupportsHinting = false;
+  const bool m_FTLibrarySupportsHinting;
 };
 
 #endif  // CORE_FXGE_CFX_FONTMGR_H_
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp
index e956845..401db99 100644
--- a/xfa/fgas/font/cfgas_fontmgr.cpp
+++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -487,8 +487,6 @@
     return nullptr;
 
   CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
-  pFontMgr->InitFTLibrary();
-
   FXFT_LibraryRec* library = pFontMgr->GetFTLibrary();
   if (!library)
     return nullptr;
@@ -653,7 +651,6 @@
 }
 
 bool CFGAS_FontMgr::EnumFontsFromFiles() {
-  CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
   m_pFontSource->GetNext();
   while (m_pFontSource->HasNext()) {
     RetainPtr<IFX_SeekableStream> stream = m_pFontSource->GetStream();