| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxge/cfx_fontmgr.h" | 7 #include "core/fxge/cfx_fontmgr.h" |
| 8 | 8 |
| 9 #include "core/fxge/cfx_fontmapper.h" | 9 #include "core/fxge/cfx_fontmapper.h" |
| 10 #include "core/fxge/cfx_substfont.h" | 10 #include "core/fxge/cfx_substfont.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 {g_FoxitDingbatsFontData, 29513}, | 38 {g_FoxitDingbatsFontData, 29513}, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 const BuiltinFont g_MMFonts[2] = { | 41 const BuiltinFont g_MMFonts[2] = { |
| 42 {g_FoxitSerifMMFontData, 113417}, | 42 {g_FoxitSerifMMFontData, 113417}, |
| 43 {g_FoxitSansMMFontData, 66919}, | 43 {g_FoxitSansMMFontData, 66919}, |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 CFX_ByteString KeyNameFromFace(const CFX_ByteString& face_name, | 46 CFX_ByteString KeyNameFromFace(const CFX_ByteString& face_name, |
| 47 int weight, | 47 int weight, |
| 48 FX_BOOL bItalic) { | 48 bool bItalic) { |
| 49 CFX_ByteString key(face_name); | 49 CFX_ByteString key(face_name); |
| 50 key += ','; | 50 key += ','; |
| 51 key += CFX_ByteString::FormatInteger(weight); | 51 key += CFX_ByteString::FormatInteger(weight); |
| 52 key += bItalic ? 'I' : 'N'; | 52 key += bItalic ? 'I' : 'N'; |
| 53 return key; | 53 return key; |
| 54 } | 54 } |
| 55 | 55 |
| 56 CFX_ByteString KeyNameFromSize(int ttc_size, uint32_t checksum) { | 56 CFX_ByteString KeyNameFromSize(int ttc_size, uint32_t checksum) { |
| 57 CFX_ByteString key; | 57 CFX_ByteString key; |
| 58 key.Format("%d:%d", ttc_size, checksum); | 58 key.Format("%d:%d", ttc_size, checksum); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 FXFT_Library_SetLcdFilter(m_FTLibrary, FT_LCD_FILTER_DEFAULT) != | 103 FXFT_Library_SetLcdFilter(m_FTLibrary, FT_LCD_FILTER_DEFAULT) != |
| 104 FT_Err_Unimplemented_Feature; | 104 FT_Err_Unimplemented_Feature; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void CFX_FontMgr::SetSystemFontInfo( | 107 void CFX_FontMgr::SetSystemFontInfo( |
| 108 std::unique_ptr<IFX_SystemFontInfo> pFontInfo) { | 108 std::unique_ptr<IFX_SystemFontInfo> pFontInfo) { |
| 109 m_pBuiltinMapper->SetSystemFontInfo(std::move(pFontInfo)); | 109 m_pBuiltinMapper->SetSystemFontInfo(std::move(pFontInfo)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name, | 112 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name, |
| 113 FX_BOOL bTrueType, | 113 bool bTrueType, |
| 114 uint32_t flags, | 114 uint32_t flags, |
| 115 int weight, | 115 int weight, |
| 116 int italic_angle, | 116 int italic_angle, |
| 117 int CharsetCP, | 117 int CharsetCP, |
| 118 CFX_SubstFont* pSubstFont) { | 118 CFX_SubstFont* pSubstFont) { |
| 119 InitFTLibrary(); | 119 InitFTLibrary(); |
| 120 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight, | 120 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight, |
| 121 italic_angle, CharsetCP, pSubstFont); | 121 italic_angle, CharsetCP, pSubstFont); |
| 122 } | 122 } |
| 123 | 123 |
| 124 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, | 124 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, |
| 125 int weight, | 125 int weight, |
| 126 FX_BOOL bItalic, | 126 bool bItalic, |
| 127 uint8_t*& pFontData) { | 127 uint8_t*& pFontData) { |
| 128 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); | 128 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); |
| 129 if (it == m_FaceMap.end()) | 129 if (it == m_FaceMap.end()) |
| 130 return nullptr; | 130 return nullptr; |
| 131 | 131 |
| 132 CTTFontDesc* pFontDesc = it->second; | 132 CTTFontDesc* pFontDesc = it->second; |
| 133 pFontData = pFontDesc->m_pFontData; | 133 pFontData = pFontDesc->m_pFontData; |
| 134 pFontDesc->m_RefCount++; | 134 pFontDesc->m_RefCount++; |
| 135 return pFontDesc->m_SingleFace; | 135 return pFontDesc->m_SingleFace; |
| 136 } | 136 } |
| 137 | 137 |
| 138 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, | 138 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, |
| 139 int weight, | 139 int weight, |
| 140 FX_BOOL bItalic, | 140 bool bItalic, |
| 141 uint8_t* pData, | 141 uint8_t* pData, |
| 142 uint32_t size, | 142 uint32_t size, |
| 143 int face_index) { | 143 int face_index) { |
| 144 CTTFontDesc* pFontDesc = new CTTFontDesc; | 144 CTTFontDesc* pFontDesc = new CTTFontDesc; |
| 145 pFontDesc->m_Type = 1; | 145 pFontDesc->m_Type = 1; |
| 146 pFontDesc->m_SingleFace = nullptr; | 146 pFontDesc->m_SingleFace = nullptr; |
| 147 pFontDesc->m_pFontData = pData; | 147 pFontDesc->m_pFontData = pData; |
| 148 pFontDesc->m_RefCount = 1; | 148 pFontDesc->m_RefCount = 1; |
| 149 | 149 |
| 150 InitFTLibrary(); | 150 InitFTLibrary(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 FXFT_Library library = m_FTLibrary; | 217 FXFT_Library library = m_FTLibrary; |
| 218 FXFT_Face face = nullptr; | 218 FXFT_Face face = nullptr; |
| 219 if (FXFT_New_Face(library, filename, face_index, &face)) | 219 if (FXFT_New_Face(library, filename, face_index, &face)) |
| 220 return nullptr; | 220 return nullptr; |
| 221 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; | 221 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { | 224 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { |
| 225 if (!face) | 225 if (!face) |
| 226 return; | 226 return; |
| 227 FX_BOOL bNeedFaceDone = TRUE; | 227 bool bNeedFaceDone = true; |
| 228 auto it = m_FaceMap.begin(); | 228 auto it = m_FaceMap.begin(); |
| 229 while (it != m_FaceMap.end()) { | 229 while (it != m_FaceMap.end()) { |
| 230 auto temp = it++; | 230 auto temp = it++; |
| 231 int nRet = temp->second->ReleaseFace(face); | 231 int nRet = temp->second->ReleaseFace(face); |
| 232 if (nRet == -1) | 232 if (nRet == -1) |
| 233 continue; | 233 continue; |
| 234 bNeedFaceDone = FALSE; | 234 bNeedFaceDone = false; |
| 235 if (nRet == 0) | 235 if (nRet == 0) |
| 236 m_FaceMap.erase(temp); | 236 m_FaceMap.erase(temp); |
| 237 break; | 237 break; |
| 238 } | 238 } |
| 239 if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face)) | 239 if (bNeedFaceDone && !m_pBuiltinMapper->IsBuiltinFace(face)) |
| 240 FXFT_Done_Face(face); | 240 FXFT_Done_Face(face); |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool CFX_FontMgr::GetBuiltinFont(size_t index, | 243 bool CFX_FontMgr::GetBuiltinFont(size_t index, |
| 244 const uint8_t** pFontData, | 244 const uint8_t** pFontData, |
| 245 uint32_t* size) { | 245 uint32_t* size) { |
| 246 if (index < FX_ArraySize(g_FoxitFonts)) { | 246 if (index < FX_ArraySize(g_FoxitFonts)) { |
| 247 *pFontData = g_FoxitFonts[index].m_pFontData; | 247 *pFontData = g_FoxitFonts[index].m_pFontData; |
| 248 *size = g_FoxitFonts[index].m_dwSize; | 248 *size = g_FoxitFonts[index].m_dwSize; |
| 249 return true; | 249 return true; |
| 250 } | 250 } |
| 251 index -= FX_ArraySize(g_FoxitFonts); | 251 index -= FX_ArraySize(g_FoxitFonts); |
| 252 if (index < FX_ArraySize(g_MMFonts)) { | 252 if (index < FX_ArraySize(g_MMFonts)) { |
| 253 *pFontData = g_MMFonts[index].m_pFontData; | 253 *pFontData = g_MMFonts[index].m_pFontData; |
| 254 *size = g_MMFonts[index].m_dwSize; | 254 *size = g_MMFonts[index].m_dwSize; |
| 255 return true; | 255 return true; |
| 256 } | 256 } |
| 257 return false; | 257 return false; |
| 258 } | 258 } |
| OLD | NEW |