summaryrefslogtreecommitdiff
path: root/core/fxge
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-01-10 21:23:36 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-10 21:23:36 +0000
commita0157f4b46e6b6253a9185f3b70a5fd22b19c3dd (patch)
treeea0258334dd816054162d32625d0093f55601e75 /core/fxge
parent4afee170f5e26b044236fd1e93c6ae2371a993de (diff)
downloadpdfium-a0157f4b46e6b6253a9185f3b70a5fd22b19c3dd.tar.xz
Move FreeType version check to its own method.
Fix some other nits in CFX_FontMgr as well. Change-Id: I4c15d1cc96c964c452dcab8962885d2b71d54a5d Reviewed-on: https://pdfium-review.googlesource.com/22471 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxge')
-rw-r--r--core/fxge/cfx_fontmgr.cpp57
-rw-r--r--core/fxge/cfx_fontmgr.h3
2 files changed, 31 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;
+}
diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h
index 62ecd84716..5c888a743e 100644
--- a/core/fxge/cfx_fontmgr.h
+++ b/core/fxge/cfx_fontmgr.h
@@ -60,6 +60,9 @@ class CFX_FontMgr {
bool FTLibrarySupportsHinting() const { return m_FTLibrarySupportsHinting; }
private:
+ bool FreeTypeVersionSupportsHinting() const;
+ bool SetLcdFilterMode() const;
+
std::unique_ptr<CFX_FontMapper> m_pBuiltinMapper;
std::map<ByteString, std::unique_ptr<CTTFontDesc>> m_FaceMap;
FXFT_Library m_FTLibrary;