Introduce ref-counted CFX_Face class.

The class wraps the FXFT_FaceRec usage, and removes the ad-hoc
refcounting from CTTFontDesc.

This imposes some requirements upon the time at which the underling
FT library is created. These have been resolved as of 78f6819.

Change-Id: I6f0dac16aa0d8e629555af66acc9a34e20eba264
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54790
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 7b9b00b..532448a 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -12,7 +12,7 @@
 #include <vector>
 
 #include "core/fxcrt/fx_string.h"
-#include "core/fxge/fx_freetype.h"
+#include "core/fxge/cfx_face.h"
 
 class CFX_FontMgr;
 class CFX_SubstFont;
@@ -30,15 +30,15 @@
   void AddInstalledFont(const ByteString& name, int charset);
   void LoadInstalledFonts();
 
-  FXFT_FaceRec* FindSubstFont(const ByteString& face_name,
-                              bool bTrueType,
-                              uint32_t flags,
-                              int weight,
-                              int italic_angle,
-                              int CharsetCP,
-                              CFX_SubstFont* pSubstFont);
+  RetainPtr<CFX_Face> FindSubstFont(const ByteString& face_name,
+                                    bool bTrueType,
+                                    uint32_t flags,
+                                    int weight,
+                                    int italic_angle,
+                                    int CharsetCP,
+                                    CFX_SubstFont* pSubstFont);
 
-  bool IsBuiltinFace(const FXFT_FaceRec* face) const;
+  bool IsBuiltinFace(const RetainPtr<CFX_Face>& face) const;
   int GetFaceSize() const;
   ByteString GetFaceName(int index) const { return m_FaceArray[index].name; }
 
@@ -51,20 +51,20 @@
 
   ByteString GetPSNameFromTT(void* hFont);
   ByteString MatchInstalledFonts(const ByteString& norm_name);
-  FXFT_FaceRec* UseInternalSubst(CFX_SubstFont* pSubstFont,
-                                 int iBaseFont,
-                                 int italic_angle,
-                                 int weight,
-                                 int picthfamily);
-  FXFT_FaceRec* GetCachedTTCFace(void* hFont,
-                                 const uint32_t tableTTCF,
-                                 uint32_t ttc_size,
-                                 uint32_t font_size);
-  FXFT_FaceRec* GetCachedFace(void* hFont,
-                              ByteString SubstName,
-                              int weight,
-                              bool bItalic,
-                              uint32_t font_size);
+  RetainPtr<CFX_Face> UseInternalSubst(CFX_SubstFont* pSubstFont,
+                                       int iBaseFont,
+                                       int italic_angle,
+                                       int weight,
+                                       int picthfamily);
+  RetainPtr<CFX_Face> GetCachedTTCFace(void* hFont,
+                                       const uint32_t tableTTCF,
+                                       uint32_t ttc_size,
+                                       uint32_t font_size);
+  RetainPtr<CFX_Face> GetCachedFace(void* hFont,
+                                    ByteString SubstName,
+                                    int weight,
+                                    bool bItalic,
+                                    uint32_t font_size);
 
   struct FaceData {
     ByteString name;
@@ -76,8 +76,8 @@
   std::vector<FaceData> m_FaceArray;
   std::unique_ptr<SystemFontInfoIface> m_pFontInfo;
   UnownedPtr<CFX_FontMgr> const m_pFontMgr;
-  ScopedFXFTFaceRec m_MMFaces[MM_FACE_COUNT];
-  ScopedFXFTFaceRec m_FoxitFaces[FOXIT_FACE_COUNT];
+  RetainPtr<CFX_Face> m_MMFaces[MM_FACE_COUNT];
+  RetainPtr<CFX_Face> m_FoxitFaces[FOXIT_FACE_COUNT];
 };
 
 #endif  // CORE_FXGE_CFX_FONTMAPPER_H_