Move CFGAS_PDFFontMgr to the CXFA_FFDoc

This CL removes the map of CXFA_FFDoc -> CFGAS_PDFFontMgr from the
CXFA_FontMgr and moves the storage of the PDFFontMgr into the CXFA_FFDoc
itself.

Change-Id: Ia725ddd94b1ac2c9504bfd6370040ab6ac01e272
Reviewed-on: https://pdfium-review.googlesource.com/14590
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index b3ff3c9..316987f 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -241,7 +241,9 @@
 }
 
 void CXFA_FFDoc::StopLoad() {
-  m_pApp->GetXFAFontMgr()->LoadDocFonts(this);
+  m_pPDFFontMgr = pdfium::MakeUnique<CFGAS_PDFFontMgr>(
+      GetPDFDoc(), GetApp()->GetFDEFontMgr());
+
   m_dwDocType = XFA_DocType::Static;
   CXFA_Node* pConfig = ToNode(
       m_pDocumentParser->GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
@@ -327,7 +329,7 @@
     doc->ClearLayoutData();
 
   m_pNotify.reset();
-  m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this);
+  m_pPDFFontMgr.reset();
   m_HashToDibDpiMap.clear();
   m_pApp->ClearEventTargets();
 }
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index 7984d74..1d35c66 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -15,6 +15,7 @@
 #include "xfa/fxfa/parser/cxfa_document.h"
 #include "xfa/fxfa/parser/cxfa_document_parser.h"
 
+class CFGAS_PDFFontMgr;
 class CFX_ChecksumContext;
 class CXFA_FFApp;
 class CXFA_FFNotify;
@@ -72,6 +73,7 @@
   CFX_RetainPtr<CFX_DIBitmap> GetPDFNamedImage(const WideStringView& wsName,
                                                int32_t& iImageXDpi,
                                                int32_t& iImageYDpi);
+  CFGAS_PDFFontMgr* GetPDFFontMgr() const { return m_pPDFFontMgr.get(); }
 
   bool SavePackage(XFA_HashCode code,
                    const CFX_RetainPtr<IFX_SeekableStream>& pFile,
@@ -88,6 +90,7 @@
   CFX_UnownedPtr<CPDF_Document> m_pPDFDoc;
   std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap;
   std::unique_ptr<CXFA_FFDocView> m_DocView;
+  std::unique_ptr<CFGAS_PDFFontMgr> m_pPDFFontMgr;
   XFA_DocType m_dwDocType;
 };
 
diff --git a/xfa/fxfa/cxfa_fontmgr.cpp b/xfa/fxfa/cxfa_fontmgr.cpp
index d5ba2ea..5a11dd5 100644
--- a/xfa/fxfa/cxfa_fontmgr.cpp
+++ b/xfa/fxfa/cxfa_fontmgr.cpp
@@ -36,9 +36,8 @@
     return iter->second;
 
   WideString wsEnglishName = FGAS_FontNameToEnglishName(wsFontFamily);
-  auto it = m_PDFFontMgrMap.find(hDoc);
-  CFGAS_PDFFontMgr* pMgr =
-      it != m_PDFFontMgrMap.end() ? it->second.get() : nullptr;
+
+  CFGAS_PDFFontMgr* pMgr = hDoc->GetPDFFontMgr();
   CPDF_Font* pPDFFont = nullptr;
   CFX_RetainPtr<CFGAS_GEFont> pFont;
   if (pMgr) {
@@ -62,6 +61,7 @@
     pFont = m_pDefFontMgr->GetDefaultFont(
         hDoc->GetApp()->GetFDEFontMgr(), wsFontFamily, dwFontStyles, wCodePage);
   }
+
   if (pFont) {
     if (pPDFFont) {
       pMgr->SetFont(pFont, pPDFFont);
@@ -72,16 +72,6 @@
   return pFont;
 }
 
-void CXFA_FontMgr::LoadDocFonts(CXFA_FFDoc* hDoc) {
-  if (!m_PDFFontMgrMap[hDoc])
-    m_PDFFontMgrMap[hDoc] = pdfium::MakeUnique<CFGAS_PDFFontMgr>(
-        hDoc->GetPDFDoc(), hDoc->GetApp()->GetFDEFontMgr());
-}
-
-void CXFA_FontMgr::ReleaseDocFonts(CXFA_FFDoc* hDoc) {
-  m_PDFFontMgrMap.erase(hDoc);
-}
-
 void CXFA_FontMgr::SetDefFontMgr(
     std::unique_ptr<CFGAS_DefaultFontManager> pFontMgr) {
   m_pDefFontMgr = std::move(pFontMgr);
diff --git a/xfa/fxfa/cxfa_fontmgr.h b/xfa/fxfa/cxfa_fontmgr.h
index 988964d..b7d1f51 100644
--- a/xfa/fxfa/cxfa_fontmgr.h
+++ b/xfa/fxfa/cxfa_fontmgr.h
@@ -30,13 +30,10 @@
                                       const WideStringView& wsFontFamily,
                                       uint32_t dwFontStyles,
                                       uint16_t wCodePage = 0xFFFF);
-  void LoadDocFonts(CXFA_FFDoc* hDoc);
-  void ReleaseDocFonts(CXFA_FFDoc* hDoc);
   void SetDefFontMgr(std::unique_ptr<CFGAS_DefaultFontManager> pFontMgr);
 
  private:
   std::unique_ptr<CFGAS_DefaultFontManager> m_pDefFontMgr;
-  std::map<CXFA_FFDoc*, std::unique_ptr<CFGAS_PDFFontMgr>> m_PDFFontMgrMap;
   std::map<ByteString, CFX_RetainPtr<CFGAS_GEFont>> m_FontMap;
 };