Remove bool argument from CFX_Font::GetBaseFontName().

- simplify and re-order logic.
- add helper function in sole file that calls it.

Change-Id: I623ec3f36c22536ad10b0eda19f72d8f74a5a4c5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82253
Auto-Submit: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 0b8b213..86b6cbe 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -548,12 +548,10 @@
   return m_pSubstFont->m_Family;
 }
 
-ByteString CFX_Font::GetBaseFontName(bool restrict_to_psname) const {
+ByteString CFX_Font::GetBaseFontName() const {
   ByteString psname = GetPsName();
-  if (restrict_to_psname || (!psname.IsEmpty() && psname != kUntitledFontName))
+  if (!psname.IsEmpty() && psname != kUntitledFontName)
     return psname;
-  if (!m_Face && !m_pSubstFont)
-    return ByteString();
   if (m_Face) {
     ByteString style = ByteString(FXFT_Get_Face_Style_Name(m_Face->GetRec()));
     ByteString facename = GetFamilyNameOrUntitled();
@@ -563,7 +561,9 @@
       facename += (IsTTFont() ? "," : " ") + style;
     return facename;
   }
-  return m_pSubstFont->m_Family;
+  if (m_pSubstFont)
+    return m_pSubstFont->m_Family;
+  return ByteString();
 }
 
 Optional<FX_RECT> CFX_Font::GetBBox() {
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index 8fce408..f86bc73 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -108,7 +108,7 @@
   ByteString GetPsName() const;
   ByteString GetFamilyName() const;
   ByteString GetFaceName() const;
-  ByteString GetBaseFontName(bool restrict_to_psname) const;
+  ByteString GetBaseFontName() const;
   bool IsTTFont() const;
   Optional<FX_RECT> GetBBox();
   bool IsEmbedded() const { return m_bEmbedded; }
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 918c909..849bab5 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -65,6 +65,15 @@
 
 namespace {
 
+ByteString BaseFontNameForType(CFX_Font* pFont, int font_type) {
+  ByteString name = font_type == FPDF_FONT_TYPE1 ? pFont->GetPsName()
+                                                 : pFont->GetBaseFontName();
+  if (!name.IsEmpty())
+    return name;
+
+  return CFX_Font::kUntitledFontName;
+}
+
 CPDF_Dictionary* LoadFontDesc(CPDF_Document* pDoc,
                               const ByteString& font_name,
                               CFX_Font* pFont,
@@ -275,9 +284,7 @@
   pFontDict->SetNewFor<CPDF_Name>("Type", "Font");
   pFontDict->SetNewFor<CPDF_Name>(
       "Subtype", font_type == FPDF_FONT_TYPE1 ? "Type1" : "TrueType");
-  ByteString name = pFont->GetBaseFontName(font_type == FPDF_FONT_TYPE1);
-  if (name.IsEmpty())
-    name = CFX_Font::kUntitledFontName;
+  ByteString name = BaseFontNameForType(pFont.get(), font_type);
   pFontDict->SetNewFor<CPDF_Name>("BaseFont", name);
 
   uint32_t dwGlyphIndex;
@@ -322,9 +329,7 @@
   // TODO(npm): Get the correct encoding, if it's not identity.
   ByteString encoding = "Identity-H";
   pFontDict->SetNewFor<CPDF_Name>("Encoding", encoding);
-  ByteString name = pFont->GetBaseFontName(font_type == FPDF_FONT_TYPE1);
-  if (name.IsEmpty())
-    name = CFX_Font::kUntitledFontName;
+  ByteString name = BaseFontNameForType(pFont.get(), font_type);
   pFontDict->SetNewFor<CPDF_Name>(
       "BaseFont", font_type == FPDF_FONT_TYPE1 ? name + "-" + encoding : name);