Update CFX_Face::Open() Callers in CFPF_SkiaFontMgr

This CL creates a new function CFX_Face::OpenFromFilePath() which
constructs FT_Open_Args which is called in CFPF_SkiaFontMgr. This is
done to avoid arg construction in the Callee and is a continuation of
the effort to consolidate CFX_Face::Open() Callers and eventually make
the previously mentioned method private.

Bug: 459848480
Change-Id: Ieeeccb66342a34b6c5826927ce6016449e93dcca
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/138250
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 7ef44f6..4686ed1 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -345,25 +345,7 @@
 
 RetainPtr<CFX_Face> CFPF_SkiaFontMgr::GetFontFace(ByteStringView path,
                                                   int32_t face_index) {
-  if (path.IsEmpty()) {
-    return nullptr;
-  }
-
-  if (face_index < 0) {
-    return nullptr;
-  }
-
-  FT_Open_Args args;
-  args.flags = FT_OPEN_PATHNAME;
-  args.pathname = const_cast<FT_String*>(path.unterminated_c_str());
-  RetainPtr<CFX_Face> face =
-      CFX_Face::Open(ft_library_.get(), &args, face_index);
-  if (!face) {
-    return nullptr;
-  }
-
-  face->SetPixelSize(0, 64);
-  return face;
+  return CFX_Face::OpenFromFilePath(ft_library_.get(), path, face_index);
 }
 
 void CFPF_SkiaFontMgr::ScanPath(const ByteString& path) {
diff --git a/core/fxge/cfx_face.cpp b/core/fxge/cfx_face.cpp
index ecfd21f..5bb2d55 100644
--- a/core/fxge/cfx_face.cpp
+++ b/core/fxge/cfx_face.cpp
@@ -283,7 +283,7 @@
   }
   NOTREACHED();
 }
-#if BUILDFLAG(IS_ANDROID) || defined(PDF_ENABLE_XFA)
+#if defined(PDF_ENABLE_XFA)
 unsigned long FTStreamRead(FXFT_StreamRec* stream,
                            unsigned long offset,
                            unsigned char* buffer,
@@ -334,7 +334,33 @@
   // Private ctor.
   return pdfium::WrapRetain(new CFX_Face(pRec, nullptr));
 }
+#endif
 
+#if BUILDFLAG(IS_ANDROID)
+RetainPtr<CFX_Face> CFX_Face::OpenFromFilePath(FT_Library library,
+                                               ByteStringView path,
+                                               int32_t face_index) {
+  if (path.IsEmpty()) {
+    return nullptr;
+  }
+
+  if (face_index < 0) {
+    return nullptr;
+  }
+
+  FT_Open_Args args;
+  args.flags = FT_OPEN_PATHNAME;
+  args.pathname = const_cast<FT_String*>(path.unterminated_c_str());
+  RetainPtr<CFX_Face> face = Open(library, &args, face_index);
+  if (!face) {
+    return nullptr;
+  }
+  face->SetPixelSize(0, 64);
+  return face;
+}
+#endif
+
+#if defined(PDF_ENABLE_XFA)
 RetainPtr<CFX_Face> CFX_Face::OpenFromStream(
     FT_Library library,
     const RetainPtr<IFX_SeekableReadStream>& font_stream,
diff --git a/core/fxge/cfx_face.h b/core/fxge/cfx_face.h
index d16aeba..803d1be 100644
--- a/core/fxge/cfx_face.h
+++ b/core/fxge/cfx_face.h
@@ -65,16 +65,17 @@
                                  pdfium::span<const FT_Byte> data,
                                  FT_Long face_index);
 
-#if BUILDFLAG(IS_ANDROID) || defined(PDF_ENABLE_XFA)
-  static RetainPtr<CFX_Face> Open(FT_Library library,
-                                  const FT_Open_Args* args,
-                                  FT_Long face_index);
+#if defined(PDF_ENABLE_XFA)
   static RetainPtr<CFX_Face> OpenFromStream(
       FT_Library library,
       const RetainPtr<IFX_SeekableReadStream>& font_stream,
       FT_Long face_index);
 #endif
-
+#if BUILDFLAG(IS_ANDROID)
+  static RetainPtr<CFX_Face> OpenFromFilePath(FT_Library library,
+                                              ByteStringView path,
+                                              int32_t face_index);
+#endif
   bool HasGlyphNames() const;
   bool IsTtOt() const;
   bool IsTricky() const;
@@ -165,6 +166,11 @@
 
   void AdjustVariationParams(int glyph_index, int dest_width, int weight);
   std::optional<std::array<uint8_t, 2>> GetOs2Panose();
+#if BUILDFLAG(IS_ANDROID) || defined(PDF_ENABLE_XFA)
+  static RetainPtr<CFX_Face> Open(FT_Library library,
+                                  const FT_Open_Args* args,
+                                  FT_Long face_index);
+#endif
 
   // `owned_font_stream_` must outlive `owned_stream_rec_`.
   RetainPtr<IFX_SeekableReadStream> owned_font_stream_;