Declare PDF_GetStandardFontName() in the header.
authorLei Zhang <thestig@chromium.org>
Fri, 16 Oct 2015 21:35:18 +0000 (14:35 -0700)
committerLei Zhang <thestig@chromium.org>
Fri, 16 Oct 2015 21:35:18 +0000 (14:35 -0700)
R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1410043003 .

core/include/fxge/fx_font.h
core/src/fpdfapi/fpdf_edit/fpdf_edit_doc.cpp
core/src/fpdfapi/fpdf_font/fpdf_font.cpp
core/src/fxge/ge/fx_ge_fontmap.cpp

index bdaeff7..f368015 100644 (file)
@@ -445,4 +445,6 @@ class IFX_GSUBTable {
 
 CFX_ByteString GetNameFromTT(const uint8_t* name_table, FX_DWORD name);
 
+int PDF_GetStandardFontName(CFX_ByteString* name);
+
 #endif  // CORE_INCLUDE_FXGE_FX_FONT_H_
index a328199..dc79de6 100644 (file)
@@ -1105,15 +1105,15 @@ CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) {
   }
   return pDict;
 }
-int _PDF_GetStandardFontName(CFX_ByteString& name);
+
 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font,
                                           CPDF_FontEncoding* pEncoding) {
   CFX_ByteString name(font, -1);
-  if (_PDF_GetStandardFontName(name) < 0) {
-    return NULL;
-  }
+  if (PDF_GetStandardFontName(&name) < 0)
+    return nullptr;
   return GetPageData()->GetStandardFont(name, pEncoding);
 }
+
 void CPDF_Document::DeletePage(int iPage) {
   CPDF_Dictionary* pRoot = GetRoot();
   if (pRoot == NULL) {
index ed5809c..7a57889 100644 (file)
@@ -370,13 +370,13 @@ int CPDF_Font::GetCharTypeWidth(FX_DWORD charcode) {
   }
   return m_Font.GetGlyphWidth(glyph_index);
 }
-int _PDF_GetStandardFontName(CFX_ByteString& name);
+
 CPDF_Font* CPDF_Font::GetStockFont(CPDF_Document* pDoc,
                                    const CFX_ByteStringC& name) {
   CFX_ByteString fontname(name);
-  int font_id = _PDF_GetStandardFontName(fontname);
+  int font_id = PDF_GetStandardFontName(&fontname);
   if (font_id < 0) {
-    return NULL;
+    return nullptr;
   }
   CPDF_FontGlobals* pFontGlobals =
       CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
@@ -1001,7 +1001,7 @@ CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1) {
   m_Base14Font = -1;
 }
 FX_BOOL CPDF_Type1Font::_Load() {
-  m_Base14Font = _PDF_GetStandardFontName(m_BaseFont);
+  m_Base14Font = PDF_GetStandardFontName(&m_BaseFont);
   if (m_Base14Font >= 0) {
     CPDF_Dictionary* pFontDesc =
         m_pFontDict->GetDict(FX_BSTRC("FontDescriptor"));
index 826caa0..061ad66 100644 (file)
@@ -179,7 +179,7 @@ const FX_CHAR* const g_Base14FontNames[14] = {
     "Symbol",
     "ZapfDingbats",
 };
-const struct _AltFontName {
+const struct AltFontName {
   const FX_CHAR* m_pName;
   int m_Index;
 } g_AltFontNames[] = {
@@ -275,20 +275,10 @@ const struct _AltFontName {
 };
 extern "C" {
 static int compareString(const void* key, const void* element) {
-  return FXSYS_stricmp((const FX_CHAR*)key, ((_AltFontName*)element)->m_pName);
+  return FXSYS_stricmp((const FX_CHAR*)key, ((AltFontName*)element)->m_pName);
 }
 }
-int _PDF_GetStandardFontName(CFX_ByteString& name) {
-  _AltFontName* found =
-      (_AltFontName*)FXSYS_bsearch(name.c_str(), g_AltFontNames,
-                                   sizeof g_AltFontNames / sizeof(_AltFontName),
-                                   sizeof(_AltFontName), compareString);
-  if (found == NULL) {
-    return -1;
-  }
-  name = g_Base14FontNames[found->m_Index];
-  return found->m_Index;
-}
+
 int GetTTCIndex(const uint8_t* pFontData,
                 FX_DWORD ttc_size,
                 FX_DWORD font_offset) {
@@ -846,7 +836,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
       SubstName = name.Mid(1);
     }
   }
-  _PDF_GetStandardFontName(SubstName);
+  PDF_GetStandardFontName(&SubstName);
   if (SubstName == FX_BSTRC("Symbol") && !bTrueType) {
     pSubstFont->m_Family = "Chrome Symbol";
     pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET;
@@ -880,7 +870,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
   int find = SubstName.Find(FX_BSTRC(","), 0);
   if (find >= 0) {
     family = SubstName.Left(find);
-    _PDF_GetStandardFontName(family);
+    PDF_GetStandardFontName(&family);
     style = SubstName.Mid(find + 1);
     bHasComma = TRUE;
   } else {
@@ -1570,3 +1560,14 @@ FX_BOOL CFX_FolderFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) {
 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) {
   return FALSE;
 }
+
+int PDF_GetStandardFontName(CFX_ByteString* name) {
+  AltFontName* found = static_cast<AltFontName*>(
+      FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
+                    sizeof(AltFontName), compareString));
+  if (!found)
+    return -1;
+
+  *name = g_Base14FontNames[found->m_Index];
+  return found->m_Index;
+}