From ef7c9553811c8b45ada69260e9abf5d4444bcd51 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 10 Aug 2018 17:18:09 +0000 Subject: Consolidate const_casts<> in FXFT_Get_Name_Index() There's a missing const in a qualifier in the third party FT library header, so rather than casting on every invocation, consolidate these into our wrapper macro. This may be easier to remove should the API ever get corrected. Part of the war on const_cast<>. Change-Id: I80cdb220730f40297e54aee10acc8bbd2c983b6d Reviewed-on: https://pdfium-review.googlesource.com/39850 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/font/cpdf_cidfont.cpp | 2 +- core/fpdfapi/font/cpdf_truetypefont.cpp | 5 ++--- core/fpdfapi/font/cpdf_type1font.cpp | 15 +++++---------- core/fxge/fx_freetype.h | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index b73e0b8c56..cf2102cd8a 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -661,7 +661,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { uint32_t maccode = FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, name_unicode); index = maccode ? FXFT_Get_Char_Index(face, maccode) - : FXFT_Get_Name_Index(face, const_cast(name)); + : FXFT_Get_Name_Index(face, name); } if (index == 0 || index == 0xffff) return charcode ? static_cast(charcode) : -1; diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp index c77d16c74e..16978f1bda 100644 --- a/core/fpdfapi/font/cpdf_truetypefont.cpp +++ b/core/fpdfapi/font/cpdf_truetypefont.cpp @@ -121,7 +121,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { FXFT_ENCODING_APPLE_ROMAN, m_Encoding.m_Unicodes[charcode]); if (!maccode) { m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); + FXFT_Get_Name_Index(m_Font.GetFace(), name); } else { m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), maccode); @@ -136,8 +136,7 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 32); continue; } - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); + m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), name); if (m_GlyphIndex[charcode] != 0 || !bToUnicode) continue; diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp index 2717ade338..8d0eafcc97 100644 --- a/core/fpdfapi/font/cpdf_type1font.cpp +++ b/core/fpdfapi/font/cpdf_type1font.cpp @@ -197,8 +197,7 @@ void CPDF_Type1Font::LoadGlyphMap() { GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); if (name) { m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), const_cast(name)); + m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), name); SetExtGID(name, charcode); } else { m_GlyphIndex[charcode] = @@ -233,12 +232,10 @@ void CPDF_Type1Font::LoadGlyphMap() { m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); const char* pStrUnicode = GlyphNameRemap(name); - if (pStrUnicode && - FXFT_Get_Name_Index(m_Font.GetFace(), const_cast(name)) == 0) { + if (pStrUnicode && FXFT_Get_Name_Index(m_Font.GetFace(), name) == 0) { name = pStrUnicode; } - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), const_cast(name)); + m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), name); SetExtGID(name, charcode); if (m_GlyphIndex[charcode] != 0) continue; @@ -264,8 +261,7 @@ void CPDF_Type1Font::LoadGlyphMap() { GetAdobeCharName(m_BaseEncoding, m_CharNames, charcode); if (name) { m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), const_cast(name)); + m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), name); } else { m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), charcode); @@ -301,8 +297,7 @@ void CPDF_Type1Font::LoadGlyphMap() { continue; m_Encoding.m_Unicodes[charcode] = PDF_UnicodeFromAdobeName(name); - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), const_cast(name)); + m_GlyphIndex[charcode] = FXFT_Get_Name_Index(m_Font.GetFace(), name); if (m_GlyphIndex[charcode] != 0) continue; diff --git a/core/fxge/fx_freetype.h b/core/fxge/fx_freetype.h index 8a5fd5dda3..4ce9139326 100644 --- a/core/fxge/fx_freetype.h +++ b/core/fxge/fx_freetype.h @@ -90,7 +90,7 @@ using FXFT_Outline_Funcs = FT_Outline_Funcs; #define FXFT_Get_Glyph_Name(face, index, buffer, size) \ FT_Get_Glyph_Name(static_cast(face), index, buffer, size) #define FXFT_Get_Name_Index(face, name) \ - FT_Get_Name_Index(static_cast(face), name) + FT_Get_Name_Index(static_cast(face), const_cast(name)) #define FXFT_Has_Glyph_Names(face) \ (static_cast(face)->face_flags & FT_FACE_FLAG_GLYPH_NAMES) #define FXFT_Get_Postscript_Name(face) \ -- cgit v1.2.3