summaryrefslogtreecommitdiff
path: root/core/fxge/cfx_fontmgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/cfx_fontmgr.cpp')
-rw-r--r--core/fxge/cfx_fontmgr.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp
index c6521175fb..29902049cd 100644
--- a/core/fxge/cfx_fontmgr.cpp
+++ b/core/fxge/cfx_fontmgr.cpp
@@ -63,7 +63,6 @@ ByteString KeyNameFromSize(int ttc_size, uint32_t checksum) {
int GetTTCIndex(const uint8_t* pFontData,
uint32_t ttc_size,
uint32_t font_offset) {
- int face_index = 0;
const uint8_t* p = pFontData + 8;
uint32_t nfont = GET_TT_LONG(p);
uint32_t index;
@@ -72,11 +71,7 @@ int GetTTCIndex(const uint8_t* pFontData,
if (GET_TT_LONG(p) == font_offset)
break;
}
- if (index >= nfont)
- face_index = 0;
- else
- face_index = index;
- return face_index;
+ return index < nfont ? index : 0;
}
} // namespace
@@ -97,18 +92,10 @@ CFX_FontMgr::~CFX_FontMgr() {
void CFX_FontMgr::InitFTLibrary() {
if (m_FTLibrary)
return;
+
FXFT_Init_FreeType(&m_FTLibrary);
- FT_Int major;
- FT_Int minor;
- FT_Int patch;
- FXFT_Library_Version(m_FTLibrary, &major, &minor, &patch);
- // Freetype versions >= 2.8.1 support hinting even if subpixel rendering is
- // disabled. https://sourceforge.net/projects/freetype/files/freetype2/2.8.1/
m_FTLibrarySupportsHinting =
- FXFT_Library_SetLcdFilter(m_FTLibrary, FT_LCD_FILTER_DEFAULT) !=
- FT_Err_Unimplemented_Feature ||
- major > 2 || (major >= 2 && minor > 8) ||
- (major >= 2 && minor >= 8 && patch >= 1);
+ SetLcdFilterMode() || FreeTypeVersionSupportsHinting();
}
void CFX_FontMgr::SetSystemFontInfo(
@@ -212,18 +199,16 @@ FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData,
uint32_t 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))
+ if (FXFT_New_Memory_Face(m_FTLibrary, pData, size, face_index, &face))
return nullptr;
return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
}
FXFT_Face CFX_FontMgr::GetFileFace(const char* filename, int face_index) {
InitFTLibrary();
- FXFT_Library library = m_FTLibrary;
FXFT_Face face = nullptr;
- if (FXFT_New_Face(library, filename, face_index, &face))
+ if (FXFT_New_Face(m_FTLibrary, filename, face_index, &face))
return nullptr;
return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
}
@@ -232,15 +217,13 @@ void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
if (!face)
return;
bool bNeedFaceDone = true;
- auto it = m_FaceMap.begin();
- while (it != m_FaceMap.end()) {
- auto temp = it++;
- int nRet = temp->second->ReleaseFace(face);
+ for (auto it = m_FaceMap.begin(); it != m_FaceMap.end(); ++it) {
+ int nRet = it->second->ReleaseFace(face);
if (nRet == -1)
continue;
bNeedFaceDone = false;
if (nRet == 0)
- m_FaceMap.erase(temp);
+ m_FaceMap.erase(it);
break;
}
if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face))
@@ -255,11 +238,27 @@ bool CFX_FontMgr::GetBuiltinFont(size_t index,
*size = g_FoxitFonts[index].m_dwSize;
return true;
}
- index -= FX_ArraySize(g_FoxitFonts);
- if (index < FX_ArraySize(g_MMFonts)) {
- *pFontData = g_MMFonts[index].m_pFontData;
- *size = g_MMFonts[index].m_dwSize;
+ size_t mm_index = index - FX_ArraySize(g_FoxitFonts);
+ if (mm_index < FX_ArraySize(g_MMFonts)) {
+ *pFontData = g_MMFonts[mm_index].m_pFontData;
+ *size = g_MMFonts[mm_index].m_dwSize;
return true;
}
return false;
}
+
+bool CFX_FontMgr::FreeTypeVersionSupportsHinting() const {
+ FT_Int major;
+ FT_Int minor;
+ FT_Int patch;
+ FXFT_Library_Version(m_FTLibrary, &major, &minor, &patch);
+ // Freetype versions >= 2.8.1 support hinting even if subpixel rendering is
+ // disabled. https://sourceforge.net/projects/freetype/files/freetype2/2.8.1/
+ return major > 2 || (major == 2 && minor > 8) ||
+ (major == 2 && minor == 8 && patch >= 1);
+}
+
+bool CFX_FontMgr::SetLcdFilterMode() const {
+ return FXFT_Library_SetLcdFilter(m_FTLibrary, FT_LCD_FILTER_DEFAULT) !=
+ FT_Err_Unimplemented_Feature;
+}