summaryrefslogtreecommitdiff
path: root/core/src/fxge
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-20 10:22:56 -0700
committerLei Zhang <thestig@chromium.org>2015-10-20 10:22:56 -0700
commitc29bee029cd5fe3f8a4ceb580235ac2d0e5ce8fd (patch)
tree037f934729035eb708ca20bc1798382c3b0376c6 /core/src/fxge
parent4816432671eef6467354aa252f22bb80acc315b7 (diff)
downloadpdfium-c29bee029cd5fe3f8a4ceb580235ac2d0e5ce8fd.tar.xz
Make CFX_FontMgr member variables private.
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1405213003 .
Diffstat (limited to 'core/src/fxge')
-rw-r--r--core/src/fxge/ge/fx_ge_font.cpp32
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp99
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp2
3 files changed, 47 insertions, 86 deletions
diff --git a/core/src/fxge/ge/fx_ge_font.cpp b/core/src/fxge/ge/fx_ge_font.cpp
index a6ababf572..fed80e6165 100644
--- a/core/src/fxge/ge/fx_ge_font.cpp
+++ b/core/src/fxge/ge/fx_ge_font.cpp
@@ -7,7 +7,17 @@
#include "../../../include/fxge/fx_ge.h"
#include "../../../include/fxge/fx_freetype.h"
#include "text_int.h"
+
#define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em)
+
+namespace {
+
+FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
+ return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
+}
+
+} // namespace
+
CFX_Font::CFX_Font() {
m_pSubstFont = NULL;
m_Face = NULL;
@@ -90,28 +100,12 @@ int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) {
FXFT_Get_Glyph_HoriAdvance(m_Face));
return width;
}
-static FXFT_Face FT_LoadFont(uint8_t* pData, int size) {
- FXFT_Library library;
- if (CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary == NULL) {
- FXFT_Init_FreeType(&CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary);
- }
- library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary;
- FXFT_Face face = NULL;
- int error = FXFT_New_Memory_Face(library, pData, size, 0, &face);
- if (error) {
- return NULL;
- }
- error = FXFT_Set_Pixel_Sizes(face, 64, 64);
- if (error) {
- return NULL;
- }
- return face;
-}
+
FX_BOOL CFX_Font::LoadEmbedded(const uint8_t* data, FX_DWORD size) {
m_pFontDataAllocation = FX_Alloc(uint8_t, size);
FXSYS_memcpy(m_pFontDataAllocation, data, size);
- m_Face = FT_LoadFont((uint8_t*)m_pFontDataAllocation, size);
- m_pFontData = (uint8_t*)m_pFontDataAllocation;
+ m_Face = FT_LoadFont(m_pFontDataAllocation, size);
+ m_pFontData = m_pFontDataAllocation;
m_bEmbedded = TRUE;
m_dwSize = size;
return m_Face != NULL;
diff --git a/core/src/fxge/ge/fx_ge_fontmap.cpp b/core/src/fxge/ge/fx_ge_fontmap.cpp
index e88791aac5..d135ffb531 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -80,31 +80,28 @@ FX_BOOL CTTFontDesc::ReleaseFace(FXFT_Face face) {
delete this;
return TRUE;
}
+
CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) {
- m_pBuiltinMapper = new CFX_FontMapper(this);
- FXSYS_memset(m_ExternalFonts, 0, sizeof m_ExternalFonts);
+ m_pBuiltinMapper.reset(new CFX_FontMapper(this));
}
+
CFX_FontMgr::~CFX_FontMgr() {
- delete m_pBuiltinMapper;
- FreeCache();
- if (m_FTLibrary) {
+ for (const auto& pair : m_FaceMap)
+ delete pair.second;
+ if (m_FTLibrary)
FXFT_Done_FreeType(m_FTLibrary);
- }
}
+
void CFX_FontMgr::InitFTLibrary() {
- 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();
+ if (m_FTLibrary)
+ return;
+ FXFT_Init_FreeType(&m_FTLibrary);
}
+
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,
@@ -112,12 +109,11 @@ FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
int italic_angle,
int CharsetCP,
CFX_SubstFont* pSubstFont) {
- if (!m_FTLibrary) {
- FXFT_Init_FreeType(&m_FTLibrary);
- }
+ InitFTLibrary();
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,
@@ -144,11 +140,9 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name,
pFontDesc->m_SingleFace.m_bItalic = bItalic;
pFontDesc->m_pFontData = pData;
pFontDesc->m_RefCount = 1;
- FXFT_Library library;
- if (m_FTLibrary == NULL) {
- FXFT_Init_FreeType(&m_FTLibrary);
- }
- library = m_FTLibrary;
+
+ InitFTLibrary();
+ FXFT_Library library = m_FTLibrary;
int ret = FXFT_New_Memory_Face(library, pData, size, face_index,
&pFontDesc->m_SingleFace.m_pFace);
if (ret) {
@@ -335,41 +329,26 @@ 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) {
- 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;
+ 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_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) {
- 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;
+ 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;
}
void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
if (!face) {
@@ -1058,19 +1037,7 @@ FXFT_Face CFX_FontMapper::FindSubstFont(const CFX_ByteString& name,
iBaseFont += 2;
}
}
- 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];
- }
+ family = g_Base14FontNames[iBaseFont];
pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
}
} else {
diff --git a/core/src/fxge/ge/fx_ge_text.cpp b/core/src/fxge/ge/fx_ge_text.cpp
index 6938bb975d..11bc29ef5b 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1592,7 +1592,7 @@ CFX_GlyphBitmap* CFX_FaceCache::RenderGlyph(CFX_Font* pFont,
}
FXFT_Outline_Embolden(FXFT_Get_Glyph_Outline(m_Face), level);
}
- FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary,
+ FXFT_Library_SetLcdFilter(CFX_GEModule::Get()->GetFontMgr()->GetFTLibrary(),
FT_LCD_FILTER_DEFAULT);
error = FXFT_Render_Glyph(m_Face, anti_alias);
if (error) {