summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-21 17:07:24 -0700
committerLei Zhang <thestig@chromium.org>2015-10-21 17:07:24 -0700
commit122ee21e38a15554c8c61edd21fda8c110be6072 (patch)
tree208031600c134d48a8af2488fc337dab2e110bde
parentafaa98eeb161d60e76506a16d8b986203a7ec0b3 (diff)
downloadpdfium-122ee21e38a15554c8c61edd21fda8c110be6072.tar.xz
Merge to XFA: Make CFX_FontMgr member variables private. (try 2)
R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1412733011 . (cherry picked from commit 5a5b6fb3759daf1201ffc9702f626f4b243922d0) Review URL: https://codereview.chromium.org/1414463006 .
-rw-r--r--core/include/fxge/fx_font.h9
-rw-r--r--core/src/fxge/ge/fx_ge_font.cpp40
-rw-r--r--core/src/fxge/ge/fx_ge_fontmap.cpp104
-rw-r--r--core/src/fxge/ge/fx_ge_text.cpp2
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp28
-rw-r--r--xfa/src/fgas/src/font/fx_stdfontmgr.cpp52
6 files changed, 97 insertions, 138 deletions
diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h
index 2314fb3d08..37431203b3 100644
--- a/core/include/fxge/fx_font.h
+++ b/core/include/fxge/fx_font.h
@@ -9,6 +9,7 @@
#include <map>
+#include "../../../third_party/base/nonstd_unique_ptr.h"
#include "../fxcrt/fx_system.h"
#include "fx_dib.h"
@@ -236,6 +237,7 @@ class CFX_FontMgr {
public:
CFX_FontMgr();
~CFX_FontMgr();
+
void InitFTLibrary();
FXFT_Face GetCachedFace(const CFX_ByteString& face_name,
int weight,
@@ -267,13 +269,14 @@ class CFX_FontMgr {
int italic_angle,
int CharsetCP,
CFX_SubstFont* pSubstFont);
- void FreeCache();
FX_BOOL GetStandardFont(const uint8_t*& pFontData, FX_DWORD& size, int index);
+ CFX_FontMapper* GetBuiltinMapper() const { return m_pBuiltinMapper.get(); }
+ FXFT_Library GetFTLibrary() const { return m_FTLibrary; }
- CFX_FontMapper* m_pBuiltinMapper;
+ private:
+ nonstd::unique_ptr<CFX_FontMapper> m_pBuiltinMapper;
std::map<CFX_ByteString, CTTFontDesc*> m_FaceMap;
FXFT_Library m_FTLibrary;
- FoxitFonts m_ExternalFonts[16];
};
class IFX_FontEnumerator {
diff --git a/core/src/fxge/ge/fx_ge_font.cpp b/core/src/fxge/ge/fx_ge_font.cpp
index 468033eb01..7517cf1bed 100644
--- a/core/src/fxge/ge/fx_ge_font.cpp
+++ b/core/src/fxge/ge/fx_ge_font.cpp
@@ -39,6 +39,10 @@ CFX_UnicodeEncodingEx* _FXFM_CreateFontEncoding(CFX_Font* pFont,
return new CFX_UnicodeEncodingEx(pFont, nEncodingID);
}
+FXFT_Face FT_LoadFont(const uint8_t* pData, int size) {
+ return CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(pData, size, 0);
+}
+
} // namespace
CFX_Font::CFX_Font() {
@@ -181,23 +185,27 @@ FX_BOOL _LoadFile(FXFT_Library library,
}
return TRUE;
}
+
FX_BOOL CFX_Font::LoadFile(IFX_FileRead* pFile,
int nFaceIndex,
int* pFaceCount) {
m_bEmbedded = FALSE;
- 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_Stream stream = NULL;
+
+ CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
+ pFontMgr->InitFTLibrary();
+ FXFT_Library library = pFontMgr->GetFTLibrary();
+
+ FXFT_Stream stream = nullptr;
if (!_LoadFile(library, &m_Face, pFile, &stream, nFaceIndex))
return FALSE;
+
if (pFaceCount)
*pFaceCount = (int)m_Face->num_faces;
m_pOwnedStream = stream;
FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
return TRUE;
}
+
int CFX_Font::GetGlyphWidth(FX_DWORD glyph_index) {
if (!m_Face) {
return 0;
@@ -215,28 +223,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 2dfb3c7a17..63cbecd0eb 100644
--- a/core/src/fxge/ge/fx_ge_fontmap.cpp
+++ b/core/src/fxge/ge/fx_ge_fontmap.cpp
@@ -80,31 +80,31 @@ int32_t CTTFontDesc::ReleaseFace(FXFT_Face face) {
delete this;
return 0;
}
+
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) {
- FXFT_Done_FreeType(m_FTLibrary);
- }
+ for (const auto& pair : m_FaceMap)
+ delete pair.second;
+
+ // |m_pBuiltinMapper| references |m_FTLibrary|, so it has to be destroyed
+ // first.
+ m_pBuiltinMapper.reset();
+ 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 +112,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 +143,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,42 +332,27 @@ 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) {
return;
@@ -1066,19 +1048,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 1bb7bbeeea..f2ac7129a2 100644
--- a/core/src/fxge/ge/fx_ge_text.cpp
+++ b/core/src/fxge/ge/fx_ge_text.cpp
@@ -1564,7 +1564,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) {
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 63ed642367..b7de36c7d3 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -146,20 +146,22 @@ FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(
int32_t nCharset,
CFX_ByteString sFontFaceName) {
CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
- if (pFontMgr) {
- CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;
- if (pFontMapper) {
- int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- if (nSize == 0) {
- pFontMapper->LoadInstalledFonts();
- nSize = pFontMapper->m_InstalledTTFonts.GetSize();
- }
+ if (!pFontMgr)
+ return FALSE;
- for (int i = 0; i < nSize; i++) {
- if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
- return TRUE;
- }
- }
+ CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
+ if (!pFontMapper)
+ return FALSE;
+
+ int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
+ if (nSize == 0) {
+ pFontMapper->LoadInstalledFonts();
+ nSize = pFontMapper->m_InstalledTTFonts.GetSize();
+ }
+
+ for (int i = 0; i < nSize; ++i) {
+ if (pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
+ return TRUE;
}
return FALSE;
diff --git a/xfa/src/fgas/src/font/fx_stdfontmgr.cpp b/xfa/src/fgas/src/font/fx_stdfontmgr.cpp
index f339555c6b..83c6dff120 100644
--- a/xfa/src/fgas/src/font/fx_stdfontmgr.cpp
+++ b/xfa/src/fgas/src/font/fx_stdfontmgr.cpp
@@ -610,14 +610,9 @@ CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum,
: m_pFontSource(pFontEnum),
m_pDelegate(pDelegate),
m_pUserData(pUserData) {}
+
FX_BOOL CFX_FontMgrImp::EnumFonts() {
- FXFT_Library& library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary;
- if (library == NULL) {
- FXFT_Init_FreeType(&library);
- }
- if (library == NULL) {
- return FALSE;
- }
+ CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary();
FXFT_Face pFace = NULL;
FX_POSITION pos = m_pFontSource->GetStartPosition();
IFX_FileAccess* pFontSource = NULL;
@@ -1003,45 +998,42 @@ unsigned long _ftStreamRead(FXFT_Stream stream,
}
void _ftStreamClose(FXFT_Stream stream) {}
};
+
FXFT_Face CFX_FontMgrImp::LoadFace(IFX_FileRead* pFontStream,
int32_t iFaceIndex) {
- FXFT_Library& library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary;
- FXFT_Open_Args ftArgs;
+ if (!pFontStream)
+ return nullptr;
+
+ CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
+ pFontMgr->InitFTLibrary();
+ FXFT_Library library = pFontMgr->GetFTLibrary();
+ if (!library)
+ return nullptr;
+
FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1);
- FXFT_Face pFace = NULL;
- if (library == NULL) {
- FXFT_Init_FreeType(&library);
- }
- if (library == NULL) {
- goto BadRet;
- }
- FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args));
- if (NULL == ftStream) {
- goto BadRet;
- }
FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec));
- if (NULL == pFontStream) {
- goto BadRet;
- }
ftStream->base = NULL;
ftStream->descriptor.pointer = pFontStream;
ftStream->pos = 0;
ftStream->size = (unsigned long)pFontStream->GetSize();
ftStream->read = _ftStreamRead;
ftStream->close = _ftStreamClose;
+
+ FXFT_Open_Args ftArgs;
+ FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args));
ftArgs.flags |= FT_OPEN_STREAM;
ftArgs.stream = ftStream;
- if (0 != FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) {
- goto BadRet;
+
+ FXFT_Face pFace = NULL;
+ if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) {
+ FX_Free(ftStream);
+ return nullptr;
}
+
FXFT_Set_Pixel_Sizes(pFace, 0, 64);
return pFace;
-BadRet:
- if (NULL != ftStream) {
- FX_Free(ftStream);
- }
- return NULL;
}
+
int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts,
FX_WORD wCodePage,
FX_DWORD dwFontStyles,