Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1531)

Unified Diff: core/fpdfapi/font/cpdf_type1font.cpp

Issue 2412483006: Reduce code duplication in CPDF_Type1Font::LoadGlyphMap (Closed)
Patch Set: Fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/font/cpdf_type1font.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/font/cpdf_type1font.cpp
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 127ec281ec4f8e3c81ff4df1a99bb80f3994680e..9ef45100d4e762d104885f92ed26c51452f8b6ec 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -140,18 +140,7 @@ void CPDF_Type1Font::LoadGlyphMap() {
m_GlyphIndex[charcode] =
FXFT_Get_Char_Index(m_Font.GetFace(), unicode);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
- name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ CalcExtGID(charcode);
#endif
if (m_GlyphIndex[charcode]) {
bGotOne = true;
@@ -181,35 +170,13 @@ void CPDF_Type1Font::LoadGlyphMap() {
m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
m_Font.GetFace(), m_Encoding.m_Unicodes[charcode]);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], name_glyph,
- 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ CalcExtGID(charcode);
#endif
if (m_GlyphIndex[charcode] == 0 && FXSYS_strcmp(name, ".notdef") == 0) {
m_Encoding.m_Unicodes[charcode] = 0x20;
m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 0x20);
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
- name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ CalcExtGID(charcode);
#endif
}
}
@@ -230,14 +197,7 @@ void CPDF_Type1Font::LoadGlyphMap() {
m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name);
m_GlyphIndex[charcode] =
FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ SetExtGID(name, charcode);
} else {
m_GlyphIndex[charcode] =
FXFT_Get_Char_Index(m_Font.GetFace(), charcode);
@@ -255,14 +215,7 @@ void CPDF_Type1Font::LoadGlyphMap() {
unicode = PDF_UnicodeFromAdobeName(name_glyph);
}
m_Encoding.m_Unicodes[charcode] = unicode;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ SetExtGID(name_glyph, charcode);
}
}
return;
@@ -285,47 +238,19 @@ void CPDF_Type1Font::LoadGlyphMap() {
}
m_GlyphIndex[charcode] =
FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name);
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ SetExtGID(name, charcode);
if (m_GlyphIndex[charcode] == 0) {
if (FXSYS_strcmp(name, ".notdef") != 0 &&
FXSYS_strcmp(name, "space") != 0) {
m_GlyphIndex[charcode] = FXFT_Get_Char_Index(
m_Font.GetFace(),
bUnicode ? m_Encoding.m_Unicodes[charcode] : charcode);
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
- name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ CalcExtGID(charcode);
} else {
m_Encoding.m_Unicodes[charcode] = 0x20;
m_GlyphIndex[charcode] =
bUnicode ? FXFT_Get_Char_Index(m_Font.GetFace(), 0x20) : 0xffff;
- FX_CHAR name_glyph[256];
- FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode],
- name_glyph, 256);
- name_glyph[255] = 0;
- CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
- kCFAllocatorDefault, name_glyph, kCFStringEncodingASCII,
- kCFAllocatorNull);
- m_ExtGID[charcode] = CGFontGetGlyphWithGlyphName(
- (CGFontRef)m_Font.GetPlatformFont(), name_ct);
- if (name_ct) {
- CFRelease(name_ct);
- }
+ CalcExtGID(charcode);
}
}
}
@@ -396,3 +321,22 @@ void CPDF_Type1Font::LoadGlyphMap() {
FXSYS_memcpy(m_ExtGID, m_GlyphIndex, 256);
#endif
}
+
+#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
+void CPDF_Type1Font::SetExtGID(const FX_CHAR* name, int charcode) {
+ CFStringRef name_ct = CFStringCreateWithCStringNoCopy(
+ kCFAllocatorDefault, name, kCFStringEncodingASCII, kCFAllocatorNull);
+ m_ExtGID[charcode] =
+ CGFontGetGlyphWithGlyphName((CGFontRef)m_Font.GetPlatformFont(), name_ct);
+ if (name_ct)
+ CFRelease(name_ct);
+}
+
+void CPDF_Type1Font::CalcExtGID(int charcode) {
+ FX_CHAR name_glyph[256];
+ FXFT_Get_Glyph_Name(m_Font.GetFace(), m_GlyphIndex[charcode], name_glyph,
+ 256);
+ name_glyph[255] = 0;
+ SetExtGID(name_glyph, charcode);
+}
+#endif // _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
« no previous file with comments | « core/fpdfapi/font/cpdf_type1font.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698