Pass face as ByteString in SystemFontInfoIface

-- fix some kConstant naming conventions while at it.

Bug: pdfium:1706
Change-Id: I85ef94c6ff8c775a553a8116d2978ec19bf4de0e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83563
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp
index 17912db..13ef554 100644
--- a/core/fxge/android/cfx_androidfontinfo.cpp
+++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -33,7 +33,7 @@
                                    bool bItalic,
                                    FX_Charset charset,
                                    int pitch_family,
-                                   const char* face) {
+                                   const ByteString& face) {
   if (!m_pFontMgr)
     return nullptr;
 
@@ -48,10 +48,10 @@
     dwStyle |= FXFONT_SCRIPT;
   if (FontFamilyIsRoman(pitch_family))
     dwStyle |= FXFONT_SERIF;
-  return m_pFontMgr->CreateFont(face, charset, dwStyle);
+  return m_pFontMgr->CreateFont(face.AsStringView(), charset, dwStyle);
 }
 
-void* CFX_AndroidFontInfo::GetFont(const char* face) {
+void* CFX_AndroidFontInfo::GetFont(const ByteString& face) {
   return nullptr;
 }
 
diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h
index 3f3001f..d1fcfb3 100644
--- a/core/fxge/android/cfx_androidfontinfo.h
+++ b/core/fxge/android/cfx_androidfontinfo.h
@@ -29,8 +29,8 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* face) override;
-  void* GetFont(const char* face) override;
+                const ByteString& face) override;
+  void* GetFont(const ByteString& face) override;
   uint32_t GetFontData(void* hFont,
                        uint32_t table,
                        pdfium::span<uint8_t> buffer) override;
diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp
index 0021cac..d3bd980 100644
--- a/core/fxge/apple/fx_apple_platform.cpp
+++ b/core/fxge/apple/fx_apple_platform.cpp
@@ -45,34 +45,32 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* family) override;
+                const ByteString& face) override;
 
   bool ParseFontCfg(const char** pUserPaths);
 };
 
-const char JAPAN_GOTHIC[] = "Hiragino Kaku Gothic Pro W6";
-const char JAPAN_MINCHO[] = "Hiragino Mincho Pro W6";
+constexpr char kJapanGothic[] = "Hiragino Kaku Gothic Pro W6";
+constexpr char kJapanMincho[] = "Hiragino Mincho Pro W6";
 
-void GetJapanesePreference(ByteString* face, int weight, int pitch_family) {
-  if (face->Contains("Gothic")) {
-    *face = JAPAN_GOTHIC;
-    return;
-  }
-  *face = (FontFamilyIsRoman(pitch_family) || weight <= 400) ? JAPAN_MINCHO
-                                                             : JAPAN_GOTHIC;
+ByteString GetJapanesePreference(const ByteString& face,
+                                 int weight,
+                                 int pitch_family) {
+  if (face.Contains("Gothic"))
+    return kJapanGothic;
+  if (FontFamilyIsRoman(pitch_family) || weight <= 400)
+    return kJapanMincho;
+  return kJapanGothic;
 }
 
 void* CFX_MacFontInfo::MapFont(int weight,
                                bool bItalic,
                                FX_Charset charset,
                                int pitch_family,
-                               const char* cstr_face) {
-  ByteString face = cstr_face;
+                               const ByteString& face) {
   for (const auto& sub : g_Base14Substs) {
-    if (face == ByteStringView(sub.m_pName)) {
-      face = sub.m_pSubstName;
-      return GetFont(face.c_str());
-    }
+    if (face == ByteStringView(sub.m_pName))
+      return GetFont(sub.m_pSubstName);
   }
 
   // The request may not ask for the bold and/or italic version of a font by
@@ -103,20 +101,25 @@
   if (charset == FX_Charset::kANSI || charset == FX_Charset::kSymbol)
     return nullptr;
 
+  ByteString other_face;
   switch (charset) {
     case FX_Charset::kShiftJIS:
-      GetJapanesePreference(&face, weight, pitch_family);
+      other_face = GetJapanesePreference(face, weight, pitch_family);
       break;
     case FX_Charset::kChineseSimplified:
-      face = "STSong";
+      other_face = "STSong";
       break;
     case FX_Charset::kHangul:
-      face = "AppleMyungjo";
+      other_face = "AppleMyungjo";
       break;
     case FX_Charset::kChineseTraditional:
-      face = "LiSong Pro Light";
+      other_face = "LiSong Pro Light";
+      break;
+    default:
+      other_face = face;
+      break;
   }
-  it = m_FontList.find(face);
+  it = m_FontList.find(other_face);
   return it != m_FontList.end() ? it->second.get() : nullptr;
 }
 
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index d4fd9e2..0cc6794 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -314,13 +314,13 @@
                                    bool bItalic,
                                    FX_Charset charset,
                                    int pitch_family,
-                                   const char* family,
+                                   const ByteString& family,
                                    bool bMatchName) {
   FontFaceInfo* pFind = nullptr;
   if (charset == FX_Charset::kANSI && FontFamilyIsFixedPitch(pitch_family))
     return GetFont("Courier New");
 
-  ByteStringView bsFamily(family);
+  ByteStringView bsFamily = family.AsStringView();
   uint32_t charset_flag = GetCharset(charset);
   int32_t iBestSimilar = 0;
   for (const auto& it : m_FontList) {
@@ -347,11 +347,11 @@
                                   bool bItalic,
                                   FX_Charset charset,
                                   int pitch_family,
-                                  const char* family) {
+                                  const ByteString& face) {
   return nullptr;
 }
 
-void* CFX_FolderFontInfo::GetFont(const char* face) {
+void* CFX_FolderFontInfo::GetFont(const ByteString& face) {
   auto it = m_FontList.find(face);
   return it != m_FontList.end() ? it->second.get() : nullptr;
 }
diff --git a/core/fxge/cfx_folderfontinfo.h b/core/fxge/cfx_folderfontinfo.h
index 1c3875d..3941e67 100644
--- a/core/fxge/cfx_folderfontinfo.h
+++ b/core/fxge/cfx_folderfontinfo.h
@@ -36,8 +36,8 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* family) override;
-  void* GetFont(const char* face) override;
+                const ByteString& face) override;
+  void* GetFont(const ByteString& face) override;
   uint32_t GetFontData(void* hFont,
                        uint32_t table,
                        pdfium::span<uint8_t> buffer) override;
@@ -76,7 +76,7 @@
                  bool bItalic,
                  FX_Charset charset,
                  int pitch_family,
-                 const char* family,
+                 const ByteString& family,
                  bool bMatchName);
 
   std::map<ByteString, std::unique_ptr<FontFaceInfo>> m_FontList;
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index fdb633d..2230030 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -330,7 +330,7 @@
   if (bLocalized) {
     void* hFont = m_pFontInfo->GetFont(name.c_str());
     if (!hFont) {
-      hFont = m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0, name.c_str());
+      hFont = m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0, name);
       if (!hFont)
         return;
     }
@@ -602,8 +602,8 @@
   } else if (FontStyleIsItalic(flags)) {
     bItalic = true;
   }
-  void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
-                                     family.c_str());
+  void* hFont =
+      m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, family);
   if (!hFont) {
     if (bCJK) {
       bItalic = italic_angle != 0;
@@ -734,8 +734,8 @@
   if (!m_pFontInfo)
     return nullptr;
 
-  void* hFont = m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0,
-                                     GetFaceName(index).c_str());
+  void* hFont =
+      m_pFontInfo->MapFont(0, 0, FX_Charset::kDefault, 0, GetFaceName(index));
   if (!hFont)
     return nullptr;
 
diff --git a/core/fxge/linux/fx_linux_impl.cpp b/core/fxge/linux/fx_linux_impl.cpp
index b160060..beb941a 100644
--- a/core/fxge/linux/fx_linux_impl.cpp
+++ b/core/fxge/linux/fx_linux_impl.cpp
@@ -31,33 +31,32 @@
   kCount
 };
 
-const char* const g_LinuxJpFontList[][JpFontFamily::kCount] = {
+const char* const kLinuxJpFontList[][JpFontFamily::kCount] = {
     {"TakaoPGothic", "VL PGothic", "IPAPGothic", "VL Gothic"},
     {"TakaoGothic", "VL Gothic", "IPAGothic", "Kochi Gothic"},
     {"TakaoPMincho", "IPAPMincho", "VL Gothic", "Kochi Mincho"},
     {"TakaoMincho", "IPAMincho", "VL Gothic", "Kochi Mincho"},
 };
 
-const char* const g_LinuxGbFontList[] = {
+const char* const kLinuxGbFontList[] = {
     "AR PL UMing CN Light",
     "WenQuanYi Micro Hei",
     "AR PL UKai CN",
 };
 
-const char* const g_LinuxB5FontList[] = {
+const char* const kLinuxB5FontList[] = {
     "AR PL UMing TW Light",
     "WenQuanYi Micro Hei",
     "AR PL UKai TW",
 };
 
-const char* const g_LinuxHGFontList[] = {
+const char* const kLinuxHGFontList[] = {
     "UnDotum",
 };
 
-uint8_t GetJapanesePreference(const char* facearr,
-                              int weight,
-                              int pitch_family) {
-  ByteString face = facearr;
+JpFontFamily GetJapanesePreference(const ByteString& face,
+                                   int weight,
+                                   int pitch_family) {
   if (face.Contains("Gothic") ||
       face.Contains("\x83\x53\x83\x56\x83\x62\x83\x4e")) {
     if (face.Contains("PGothic") ||
@@ -88,7 +87,7 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* family) override;
+                const ByteString& face) override;
 
   bool ParseFontCfg(const char** pUserPaths);
 };
@@ -97,17 +96,17 @@
                                  bool bItalic,
                                  FX_Charset charset,
                                  int pitch_family,
-                                 const char* family) {
-  void* font = GetSubstFont(family);
+                                 const ByteString& face) {
+  void* font = GetSubstFont(face);
   if (font)
     return font;
 
   bool bCJK = true;
   switch (charset) {
     case FX_Charset::kShiftJIS: {
-      uint8_t index = GetJapanesePreference(family, weight, pitch_family);
-      DCHECK(index < pdfium::size(g_LinuxJpFontList));
-      for (const char* name : g_LinuxJpFontList[index]) {
+      JpFontFamily index = GetJapanesePreference(face, weight, pitch_family);
+      DCHECK(index < pdfium::size(kLinuxJpFontList));
+      for (const char* name : kLinuxJpFontList[index]) {
         auto it = m_FontList.find(name);
         if (it != m_FontList.end())
           return it->second.get();
@@ -115,7 +114,7 @@
       break;
     }
     case FX_Charset::kChineseSimplified: {
-      for (const char* name : g_LinuxGbFontList) {
+      for (const char* name : kLinuxGbFontList) {
         auto it = m_FontList.find(name);
         if (it != m_FontList.end())
           return it->second.get();
@@ -123,7 +122,7 @@
       break;
     }
     case FX_Charset::kChineseTraditional: {
-      for (const char* name : g_LinuxB5FontList) {
+      for (const char* name : kLinuxB5FontList) {
         auto it = m_FontList.find(name);
         if (it != m_FontList.end())
           return it->second.get();
@@ -131,7 +130,7 @@
       break;
     }
     case FX_Charset::kHangul: {
-      for (const char* name : g_LinuxHGFontList) {
+      for (const char* name : kLinuxHGFontList) {
         auto it = m_FontList.find(name);
         if (it != m_FontList.end())
           return it->second.get();
@@ -142,7 +141,7 @@
       bCJK = false;
       break;
   }
-  return FindFont(weight, bItalic, charset, pitch_family, family, !bCJK);
+  return FindFont(weight, bItalic, charset, pitch_family, face, !bCJK);
 }
 
 bool CFX_LinuxFontInfo::ParseFontCfg(const char** pUserPaths) {
diff --git a/core/fxge/systemfontinfo_iface.h b/core/fxge/systemfontinfo_iface.h
index 222872b..f6c3623 100644
--- a/core/fxge/systemfontinfo_iface.h
+++ b/core/fxge/systemfontinfo_iface.h
@@ -7,6 +7,7 @@
 #ifndef CORE_FXGE_SYSTEMFONTINFO_IFACE_H_
 #define CORE_FXGE_SYSTEMFONTINFO_IFACE_H_
 
+#include "core/fxcrt/bytestring.h"
 #include "core/fxcrt/fx_codepage_forward.h"
 #include "core/fxge/cfx_fontmapper.h"
 #include "third_party/base/span.h"
@@ -23,8 +24,8 @@
                         bool bItalic,
                         FX_Charset charset,
                         int pitch_family,
-                        const char* face) = 0;
-  virtual void* GetFont(const char* face) = 0;
+                        const ByteString& face) = 0;
+  virtual void* GetFont(const ByteString& face) = 0;
   virtual uint32_t GetFontData(void* hFont,
                                uint32_t table,
                                pdfium::span<uint8_t> buffer) = 0;
diff --git a/core/fxge/win32/cwin32_platform.cpp b/core/fxge/win32/cwin32_platform.cpp
index d8e853e..8977d34 100644
--- a/core/fxge/win32/cwin32_platform.cpp
+++ b/core/fxge/win32/cwin32_platform.cpp
@@ -73,7 +73,7 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* family) override;
+                const ByteString& face) override;
 };
 
 class CFX_Win32FontInfo final : public SystemFontInfoIface {
@@ -87,8 +87,8 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* face) override;
-  void* GetFont(const char* face) override { return nullptr; }
+                const ByteString& face) override;
+  void* GetFont(const ByteString& face) override { return nullptr; }
   uint32_t GetFontData(void* hFont,
                        uint32_t table,
                        pdfium::span<uint8_t> buffer) override;
@@ -221,8 +221,8 @@
                                          bool bItalic,
                                          FX_Charset charset,
                                          int pitch_family,
-                                         const char* cstr_face) {
-  void* font = GetSubstFont(cstr_face);
+                                         const ByteString& face) {
+  void* font = GetSubstFont(face);
   if (font)
     return font;
 
@@ -237,7 +237,7 @@
       bCJK = false;
       break;
   }
-  return FindFont(weight, bItalic, charset, pitch_family, cstr_face, !bCJK);
+  return FindFont(weight, bItalic, charset, pitch_family, face, !bCJK);
 }
 
 void CFX_Win32FontInfo::GetGBPreference(ByteString& face,
@@ -311,12 +311,11 @@
                                  bool bItalic,
                                  FX_Charset charset,
                                  int pitch_family,
-                                 const char* cstr_face) {
-  ByteString face = cstr_face;
-  int iBaseFont;
-  for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) {
-    if (face == ByteStringView(g_Base14Substs[iBaseFont].m_pName)) {
-      face = g_Base14Substs[iBaseFont].m_pWinName;
+                                 const ByteString& face) {
+  ByteString new_face = face;
+  for (int iBaseFont = 0; iBaseFont < 12; iBaseFont++) {
+    if (new_face == ByteStringView(g_Base14Substs[iBaseFont].m_pName)) {
+      new_face = g_Base14Substs[iBaseFont].m_pWinName;
       weight = g_Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL;
       bItalic = g_Base14Substs[iBaseFont].m_bItalic;
       break;
@@ -338,17 +337,17 @@
   }
   HFONT hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0,
                               static_cast<int>(charset), OUT_TT_ONLY_PRECIS, 0,
-                              0, subst_pitch_family, face.c_str());
+                              0, subst_pitch_family, new_face.c_str());
   char facebuf[100];
   HFONT hOldFont = (HFONT)::SelectObject(m_hDC, hFont);
   ::GetTextFaceA(m_hDC, 100, facebuf);
   ::SelectObject(m_hDC, hOldFont);
-  if (face.EqualNoCase(facebuf))
+  if (new_face.EqualNoCase(facebuf))
     return hFont;
 
   WideString wsFace = WideString::FromDefANSI(facebuf);
   for (size_t i = 0; i < pdfium::size(g_VariantNames); ++i) {
-    if (face != g_VariantNames[i].m_pFaceName)
+    if (new_face != g_VariantNames[i].m_pFaceName)
       continue;
 
     const unsigned short* pName = reinterpret_cast<const unsigned short*>(
@@ -364,25 +363,25 @@
 
   switch (charset) {
     case FX_Charset::kShiftJIS:
-      GetJapanesePreference(face, weight, pitch_family);
+      GetJapanesePreference(new_face, weight, pitch_family);
       break;
     case FX_Charset::kChineseSimplified:
-      GetGBPreference(face, weight, pitch_family);
+      GetGBPreference(new_face, weight, pitch_family);
       break;
     case FX_Charset::kHangul:
-      face = "Gulim";
+      new_face = "Gulim";
       break;
     case FX_Charset::kChineseTraditional:
-      if (face.Contains("MSung")) {
-        face = "MingLiU";
+      if (new_face.Contains("MSung")) {
+        new_face = "MingLiU";
       } else {
-        face = "PMingLiU";
+        new_face = "PMingLiU";
       }
       break;
   }
   hFont = ::CreateFontA(-10, 0, 0, 0, weight, bItalic, 0, 0,
                         static_cast<int>(charset), OUT_TT_ONLY_PRECIS, 0, 0,
-                        subst_pitch_family, face.c_str());
+                        subst_pitch_family, new_face.c_str());
   return hFont;
 }
 
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index caf4761..3fc4543 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -74,19 +74,19 @@
                 bool bItalic,
                 FX_Charset charset,
                 int pitch_family,
-                const char* family) override {
+                const ByteString& face) override {
     if (!m_pInfo->MapFont)
       return nullptr;
 
     int iExact;
     return m_pInfo->MapFont(m_pInfo, weight, bItalic, static_cast<int>(charset),
-                            pitch_family, family, &iExact);
+                            pitch_family, face.c_str(), &iExact);
   }
 
-  void* GetFont(const char* family) override {
+  void* GetFont(const ByteString& family) override {
     if (!m_pInfo->GetFont)
       return nullptr;
-    return m_pInfo->GetFont(m_pInfo, family);
+    return m_pInfo->GetFont(m_pInfo, family.c_str());
   }
 
   uint32_t GetFontData(void* hFont,