Encapsulate FT_Get_Glyph_Name() calls in CFX_Face
Add CFX_Face::GetGlyphName() and switch callers to use that.
Bug: pdfium:2037
Change-Id: Ifac612a30147b98059f22a332c18a9af38887281
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116090
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index cc77cdc..aaad05b 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -214,14 +214,12 @@
SetExtGID(name, charcode);
} else {
m_GlyphIndex[charcode] = face->GetCharIndex(charcode);
- char name_glyph[kInternalTableSize] = {};
- FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode],
- name_glyph, sizeof(name_glyph));
- name_glyph[kInternalTableSize - 1] = 0;
+ ByteString glyph_name = face->GetGlyphName(m_GlyphIndex[charcode]);
const wchar_t unicode =
- name_glyph[0] != 0 ? UnicodeFromAdobeName(name_glyph) : 0;
+ glyph_name.IsEmpty() ? 0
+ : UnicodeFromAdobeName(glyph_name.c_str());
m_Encoding.SetUnicode(charcode, unicode);
- SetExtGID(name_glyph, charcode);
+ SetExtGID(glyph_name.c_str(), charcode);
}
}
return;
@@ -269,12 +267,10 @@
m_GlyphIndex[charcode] =
face->GetCharIndex(static_cast<uint32_t>(charcode));
if (m_GlyphIndex[charcode]) {
- char name_glyph[kInternalTableSize] = {};
- FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode],
- name_glyph, sizeof(name_glyph));
- name_glyph[kInternalTableSize - 1] = 0;
+ ByteString glyph_name = face->GetGlyphName(m_GlyphIndex[charcode]);
const wchar_t unicode =
- name_glyph[0] != 0 ? UnicodeFromAdobeName(name_glyph) : 0;
+ glyph_name.IsEmpty() ? 0
+ : UnicodeFromAdobeName(glyph_name.c_str());
m_Encoding.SetUnicode(charcode, unicode);
}
}
@@ -334,10 +330,8 @@
}
void CPDF_Type1Font::CalcExtGID(uint32_t charcode) {
- char name_glyph[kInternalTableSize] = {};
- FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode], name_glyph,
- sizeof(name_glyph));
- name_glyph[kInternalTableSize - 1] = 0;
- SetExtGID(name_glyph, charcode);
+ ByteString glyph_name =
+ m_Font.GetFace()->GetGlyphName(m_GlyphIndex[charcode]);
+ SetExtGID(glyph_name.c_str(), charcode);
}
#endif // BUILDFLAG(IS_APPLE)
diff --git a/core/fxge/cfx_face.cpp b/core/fxge/cfx_face.cpp
index 8fb25c8..c2ed0af 100644
--- a/core/fxge/cfx_face.cpp
+++ b/core/fxge/cfx_face.cpp
@@ -642,6 +642,13 @@
return static_cast<int>(EM_ADJUST(GetUnitsPerEm(), horizontal_advance));
}
+ByteString CFX_Face::GetGlyphName(uint32_t glyph_index) {
+ char name[256] = {};
+ FT_Get_Glyph_Name(GetRec(), glyph_index, name, sizeof(name));
+ name[255] = 0;
+ return ByteString(name);
+}
+
int CFX_Face::GetCharIndex(uint32_t code) {
return FT_Get_Char_Index(GetRec(), code);
}
diff --git a/core/fxge/cfx_face.h b/core/fxge/cfx_face.h
index f254148..aa0bb93 100644
--- a/core/fxge/cfx_face.h
+++ b/core/fxge/cfx_face.h
@@ -98,6 +98,7 @@
int dest_width,
int weight,
const CFX_SubstFont* subst_font);
+ ByteString GetGlyphName(uint32_t glyph_index);
int GetCharIndex(uint32_t code);
int GetNameIndex(const char* name);