summaryrefslogtreecommitdiff
path: root/core/src/fxge/ge/fx_ge_fontmap.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-20 10:43:15 -0700
committerLei Zhang <thestig@chromium.org>2015-10-20 10:43:15 -0700
commit444ed783c014bbbde2eda7a25cf42bfc2234d7a8 (patch)
tree8acd0842faeed065ef12e1a528293c87222e82d4 /core/src/fxge/ge/fx_ge_fontmap.cpp
parent937840e1722d1f2b77d80575d6e710d760662c9c (diff)
downloadpdfium-444ed783c014bbbde2eda7a25cf42bfc2234d7a8.tar.xz
Revert "Make CFX_FontMgr member variables private."
This reverts commit c29bee029cd5fe3f8a4ceb580235ac2d0e5ce8fd. because it broke corpus tests. TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1410733005 .
Diffstat (limited to 'core/src/fxge/ge/fx_ge_fontmap.cpp')
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp99
1 files changed, 66 insertions, 33 deletions
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index d135ffb531..e88791aac5 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -80,28 +80,31 @@ FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) {
delete this;
return TRUE;
}
-
CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) {
- m_pBuiltinMapper.reset(new CFX_FontMapper(this));
+ m_pBuiltinMapper = new CFX_FontMapper(this);
+ FXSYS_memset(m_ExternalFonts, 0, sizeof m_ExternalFonts);
}
-
CFX_FontMgr::~CFX_FontMgr() {
- for (const auto& pair : m_FaceMap)
- delete pair.second;
- if (m_FTLibrary)
+ delete m_pBuiltinMapper;
+ FreeCache();
+ if (m_FTLibrary) {
FXFT_Done_FreeType(m_FTLibrary);
+ }
}
-
void CFX_FontMgr::InitFTLibrary() {
- if (m_FTLibrary)
- return;
- FXFT_Init_FreeType(&m_FTLibrary);
+ if (m_FTLibrary == NULL) {
+ FXFT_Init_FreeType(&m_FTLibrary);
+ }
+}
+void CFX_FontMgr::FreeCache() {
+ for (const auto& pair : m_FaceMap) {
+ delete pair.second;
+ }
+ m_FaceMap.clear();
}
-
void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
m_pBuiltinMapper->SetSystemFontInfo(pFontInfo);
}
-
FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
FX_BOOL bTrueType,
FX_DWORD flags,
@@ -109,11 +112,12 @@ FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
int italic_angle,
int CharsetCP,
CFX_SubstFont* pSubstFont) {
- InitFTLibrary();
+ if (!m_FTLibrary) {
+ FXFT_Init_FreeType(&m_FTLibrary);
+ }
return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
italic_angle, CharsetCP, pSubstFont);
}
-
FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name,
int weight,
FX_BOOL bItalic,
@@ -140,9 +144,11 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name,
pFontDesc->m_SingleFace.m_bItalic = bItalic;
pFontDesc->m_pFontData = pData;
pFontDesc->m_RefCount = 1;
-
- InitFTLibrary();
- FXFT_Library library = m_FTLibrary;
+ FXFT_Library library;
+ if (m_FTLibrary == NULL) {
+ FXFT_Init_FreeType(&m_FTLibrary);
+ }
+ library = m_FTLibrary;
int ret = FXFT_New_Memory_Face(library, pData, size, face_index,
&pFontDesc->m_SingleFace.m_pFace);
if (ret) {
@@ -329,26 +335,41 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size,
GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index);
return pFontDesc->m_TTCFace.m_pFaces[face_index];
}
-
FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData,
FX_DWORD size,
int face_index) {
- InitFTLibrary();
- FXFT_Library library = m_FTLibrary;
- FXFT_Face face = nullptr;
- if (FXFT_New_Memory_Face(library, pData, size, face_index, &face))
- return nullptr;
- return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
+ FXFT_Library library;
+ if (m_FTLibrary == NULL) {
+ FXFT_Init_FreeType(&m_FTLibrary);
+ }
+ library = m_FTLibrary;
+ FXFT_Face face = NULL;
+ int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face);
+ if (ret) {
+ return NULL;
+ }
+ ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
+ if (ret) {
+ return NULL;
+ }
+ return face;
}
-
FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) {
- InitFTLibrary();
- FXFT_Library library = m_FTLibrary;
- FXFT_Face face = nullptr;
- if (FXFT_New_Face(library, filename, face_index, &face))
- return nullptr;
-
- return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
+ FXFT_Library library;
+ if (m_FTLibrary == NULL) {
+ FXFT_Init_FreeType(&m_FTLibrary);
+ }
+ library = m_FTLibrary;
+ FXFT_Face face = NULL;
+ int ret = FXFT_New_Face(library, filename, face_index, &face);
+ if (ret) {
+ return NULL;
+ }
+ ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
+ if (ret) {
+ return NULL;
+ }
+ return face;
}
void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
if (!face) {
@@ -1037,7 +1058,19 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
iBaseFont += 2;
}
}
- family = g_Base14FontNames[iBaseFont];
+ if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) {
+ if (m_FoxitFaces[iBaseFont]) {
+ return m_FoxitFaces[iBaseFont];
+ }
+ m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(
+ m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData,
+ m_pFontMgr->m_ExternalFonts[iBaseFont].m_dwSize, 0);
+ if (m_FoxitFaces[iBaseFont]) {
+ return m_FoxitFaces[iBaseFont];
+ }
+ } else {
+ family = g_Base14FontNames[iBaseFont];
+ }
pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
}
} else {