Add some helper functions in CFX_Font.
Pull out some identical code into their own functions.
Change-Id: Ibaecafa3e76fee08cde2e425079cc0e41a5a6794
Reviewed-on: https://pdfium-review.googlesource.com/c/49654
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp
index 9ce720d..8bb16e5 100644
--- a/core/fxge/cfx_font.cpp
+++ b/core/fxge/cfx_font.cpp
@@ -174,6 +174,10 @@
return 0;
}
+bool ShouldAppendStyle(const ByteString& style) {
+ return !style.IsEmpty() && style != "Regular";
+}
+
} // namespace
const char CFX_Font::s_AngleSkew[] = {
@@ -517,19 +521,21 @@
return ByteString();
if (m_Face)
return ByteString(FXFT_Get_Face_Family_Name(m_Face.Get()));
-
return m_pSubstFont->m_Family;
}
+ByteString CFX_Font::GetFamilyNameOrUntitled() const {
+ ByteString facename = GetFamilyName();
+ return facename.IsEmpty() ? kUntitledFontName : facename;
+}
+
ByteString CFX_Font::GetFaceName() const {
if (!m_Face && !m_pSubstFont)
return ByteString();
if (m_Face) {
ByteString style = ByteString(FXFT_Get_Face_Style_Name(m_Face.Get()));
- ByteString facename = GetFamilyName();
- if (facename.IsEmpty())
- facename = kUntitledFontName;
- if (!style.IsEmpty() && style != "Regular")
+ ByteString facename = GetFamilyNameOrUntitled();
+ if (ShouldAppendStyle(style))
facename += " " + style;
return facename;
}
@@ -544,12 +550,10 @@
return ByteString();
if (m_Face) {
ByteString style = ByteString(FXFT_Get_Face_Style_Name(m_Face.Get()));
- ByteString facename = GetFamilyName();
- if (facename.IsEmpty())
- facename = kUntitledFontName;
+ ByteString facename = GetFamilyNameOrUntitled();
if (IsTTFont())
facename.Remove(' ');
- if (!style.IsEmpty() && style != "Regular")
+ if (ShouldAppendStyle(style))
facename += (IsTTFont() ? "," : " ") + style;
return facename;
}
diff --git a/core/fxge/cfx_font.h b/core/fxge/cfx_font.h
index 8888216..99b2c0e 100644
--- a/core/fxge/cfx_font.h
+++ b/core/fxge/cfx_font.h
@@ -132,6 +132,8 @@
void ReleasePlatformResource();
#endif // _FX_PLATFORM_ == _FX_PLATFORM_APPLE_
+ ByteString GetFamilyNameOrUntitled() const;
+
mutable UnownedPtr<FXFT_FaceRec> m_Face;
mutable UnownedPtr<CFX_FaceCache> m_FaceCache;
std::unique_ptr<CFX_SubstFont> m_pSubstFont;