| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 "fx_fpf.h" | 7 #include "fx_fpf.h" |
| 8 #if _FX_OS_ == _FX_ANDROID_ | 8 #if _FX_OS_ == _FX_ANDROID_ |
| 9 #define FPF_SKIAMATCHWEIGHT_NAME1 62 | 9 #define FPF_SKIAMATCHWEIGHT_NAME1 62 |
| 10 #define FPF_SKIAMATCHWEIGHT_NAME2 60 | 10 #define FPF_SKIAMATCHWEIGHT_NAME2 60 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 {0xbf85ff26, 0xe1633081}, | 57 {0xbf85ff26, 0xe1633081}, |
| 58 {0xc04fe601, 0xbbeeec72}, | 58 {0xc04fe601, 0xbbeeec72}, |
| 59 {0xca3812d5, 0x59b9f8f1}, | 59 {0xca3812d5, 0x59b9f8f1}, |
| 60 {0xca383e15, 0x59b9f8f1}, | 60 {0xca383e15, 0x59b9f8f1}, |
| 61 {0xcad5eaf6, 0x59b9f8f1}, | 61 {0xcad5eaf6, 0x59b9f8f1}, |
| 62 {0xcb7a04c8, 0xc8d2e345}, | 62 {0xcb7a04c8, 0xc8d2e345}, |
| 63 {0xfb4ce0de, 0xe1633081}, | 63 {0xfb4ce0de, 0xe1633081}, |
| 64 }; | 64 }; |
| 65 FX_DWORD FPF_SkiaGetSubstFont(FX_DWORD dwHash) | 65 FX_DWORD FPF_SkiaGetSubstFont(FX_DWORD dwHash) |
| 66 { | 66 { |
| 67 FX_INT32 iStart = 0; | 67 int32_t iStart = 0; |
| 68 FX_INT32 iEnd = sizeof(g_SkiaFontmap) / sizeof(FPF_SKIAFONTMAP); | 68 int32_t iEnd = sizeof(g_SkiaFontmap) / sizeof(FPF_SKIAFONTMAP); |
| 69 while (iStart <= iEnd) { | 69 while (iStart <= iEnd) { |
| 70 FX_INT32 iMid = (iStart + iEnd) / 2; | 70 int32_t iMid = (iStart + iEnd) / 2; |
| 71 FPF_LPCSKIAFONTMAP pItem = &g_SkiaFontmap[iMid]; | 71 FPF_LPCSKIAFONTMAP pItem = &g_SkiaFontmap[iMid]; |
| 72 if (dwHash < pItem->dwFamily) { | 72 if (dwHash < pItem->dwFamily) { |
| 73 iEnd = iMid - 1; | 73 iEnd = iMid - 1; |
| 74 } else if (dwHash > pItem->dwFamily) { | 74 } else if (dwHash > pItem->dwFamily) { |
| 75 iStart = iMid + 1; | 75 iStart = iMid + 1; |
| 76 } else { | 76 } else { |
| 77 return pItem->dwSubSt; | 77 return pItem->dwSubSt; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 return 0; | 80 return 0; |
| 81 } | 81 } |
| 82 static const FPF_SKIAFONTMAP g_SkiaSansFontMap[] = { | 82 static const FPF_SKIAFONTMAP g_SkiaSansFontMap[] = { |
| 83 {0x58c5083, 0xd5b8d10f}, | 83 {0x58c5083, 0xd5b8d10f}, |
| 84 {0x14ee2d13, 0xd5b8d10f}, | 84 {0x14ee2d13, 0xd5b8d10f}, |
| 85 {0x779ce19d, 0xd5b8d10f}, | 85 {0x779ce19d, 0xd5b8d10f}, |
| 86 {0xcb7a04c8, 0xd5b8d10f}, | 86 {0xcb7a04c8, 0xd5b8d10f}, |
| 87 {0xfb4ce0de, 0xd5b8d10f}, | 87 {0xfb4ce0de, 0xd5b8d10f}, |
| 88 }; | 88 }; |
| 89 FX_DWORD FPF_SkiaGetSansFont(FX_DWORD dwHash) | 89 FX_DWORD FPF_SkiaGetSansFont(FX_DWORD dwHash) |
| 90 { | 90 { |
| 91 FX_INT32 iStart = 0; | 91 int32_t iStart = 0; |
| 92 FX_INT32 iEnd = sizeof(g_SkiaSansFontMap) / sizeof(FPF_SKIAFONTMAP); | 92 int32_t iEnd = sizeof(g_SkiaSansFontMap) / sizeof(FPF_SKIAFONTMAP); |
| 93 while (iStart <= iEnd) { | 93 while (iStart <= iEnd) { |
| 94 FX_INT32 iMid = (iStart + iEnd) / 2; | 94 int32_t iMid = (iStart + iEnd) / 2; |
| 95 FPF_LPCSKIAFONTMAP pItem = &g_SkiaSansFontMap[iMid]; | 95 FPF_LPCSKIAFONTMAP pItem = &g_SkiaSansFontMap[iMid]; |
| 96 if (dwHash < pItem->dwFamily) { | 96 if (dwHash < pItem->dwFamily) { |
| 97 iEnd = iMid - 1; | 97 iEnd = iMid - 1; |
| 98 } else if (dwHash > pItem->dwFamily) { | 98 } else if (dwHash > pItem->dwFamily) { |
| 99 iStart = iMid + 1; | 99 iStart = iMid + 1; |
| 100 } else { | 100 } else { |
| 101 return pItem->dwSubSt; | 101 return pItem->dwSubSt; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 return 0; | 104 return 0; |
| 105 } | 105 } |
| 106 static FX_UINT32 FPF_GetHashCode_StringA(FX_LPCSTR pStr, FX_INT32 iLength, FX_BO
OL bIgnoreCase = FALSE) | 106 static uint32_t FPF_GetHashCode_StringA(FX_LPCSTR pStr, int32_t iLength, FX_BOOL
bIgnoreCase = FALSE) |
| 107 { | 107 { |
| 108 if (!pStr) { | 108 if (!pStr) { |
| 109 return 0; | 109 return 0; |
| 110 } | 110 } |
| 111 if (iLength < 0) { | 111 if (iLength < 0) { |
| 112 iLength = FXSYS_strlen(pStr); | 112 iLength = FXSYS_strlen(pStr); |
| 113 } | 113 } |
| 114 FX_LPCSTR pStrEnd = pStr + iLength; | 114 FX_LPCSTR pStrEnd = pStr + iLength; |
| 115 FX_UINT32 uHashCode = 0; | 115 uint32_t uHashCode = 0; |
| 116 if (bIgnoreCase) { | 116 if (bIgnoreCase) { |
| 117 while (pStr < pStrEnd) { | 117 while (pStr < pStrEnd) { |
| 118 uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++); | 118 uHashCode = 31 * uHashCode + FXSYS_tolower(*pStr++); |
| 119 } | 119 } |
| 120 } else { | 120 } else { |
| 121 while (pStr < pStrEnd) { | 121 while (pStr < pStrEnd) { |
| 122 uHashCode = 31 * uHashCode + *pStr ++; | 122 uHashCode = 31 * uHashCode + *pStr ++; |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return uHashCode; | 125 return uHashCode; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 FPF_SKIACHARSET_Vietnamese = 1 << 10, | 138 FPF_SKIACHARSET_Vietnamese = 1 << 10, |
| 139 FPF_SKIACHARSET_Hebrew = 1 << 11, | 139 FPF_SKIACHARSET_Hebrew = 1 << 11, |
| 140 FPF_SKIACHARSET_Arabic = 1 << 12, | 140 FPF_SKIACHARSET_Arabic = 1 << 12, |
| 141 FPF_SKIACHARSET_Baltic = 1 << 13, | 141 FPF_SKIACHARSET_Baltic = 1 << 13, |
| 142 FPF_SKIACHARSET_Cyrillic = 1 << 14, | 142 FPF_SKIACHARSET_Cyrillic = 1 << 14, |
| 143 FPF_SKIACHARSET_Thai = 1 << 15, | 143 FPF_SKIACHARSET_Thai = 1 << 15, |
| 144 FPF_SKIACHARSET_EeasternEuropean = 1 << 16, | 144 FPF_SKIACHARSET_EeasternEuropean = 1 << 16, |
| 145 FPF_SKIACHARSET_PC = 1 << 17, | 145 FPF_SKIACHARSET_PC = 1 << 17, |
| 146 FPF_SKIACHARSET_OEM = 1 << 18, | 146 FPF_SKIACHARSET_OEM = 1 << 18, |
| 147 }; | 147 }; |
| 148 static FX_DWORD FPF_SkiaGetCharset(FX_BYTE uCharset) | 148 static FX_DWORD FPF_SkiaGetCharset(uint8_t uCharset) |
| 149 { | 149 { |
| 150 switch (uCharset) { | 150 switch (uCharset) { |
| 151 case FXFONT_ANSI_CHARSET: | 151 case FXFONT_ANSI_CHARSET: |
| 152 return FPF_SKIACHARSET_Ansi; | 152 return FPF_SKIACHARSET_Ansi; |
| 153 case FXFONT_DEFAULT_CHARSET: | 153 case FXFONT_DEFAULT_CHARSET: |
| 154 return FPF_SKIACHARSET_Default; | 154 return FPF_SKIACHARSET_Default; |
| 155 case FXFONT_SYMBOL_CHARSET: | 155 case FXFONT_SYMBOL_CHARSET: |
| 156 return FPF_SKIACHARSET_Symbol; | 156 return FPF_SKIACHARSET_Symbol; |
| 157 case FXFONT_SHIFTJIS_CHARSET: | 157 case FXFONT_SHIFTJIS_CHARSET: |
| 158 return FPF_SKIACHARSET_ShiftJIS; | 158 return FPF_SKIACHARSET_ShiftJIS; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 177 case FXFONT_THAI_CHARSET: | 177 case FXFONT_THAI_CHARSET: |
| 178 return FPF_SKIACHARSET_Thai; | 178 return FPF_SKIACHARSET_Thai; |
| 179 case FXFONT_EASTEUROPE_CHARSET: | 179 case FXFONT_EASTEUROPE_CHARSET: |
| 180 return FPF_SKIACHARSET_EeasternEuropean; | 180 return FPF_SKIACHARSET_EeasternEuropean; |
| 181 } | 181 } |
| 182 return FPF_SKIACHARSET_Default; | 182 return FPF_SKIACHARSET_Default; |
| 183 } | 183 } |
| 184 static FX_DWORD FPF_SKIANormalizeFontName(FX_BSTR bsfamily) | 184 static FX_DWORD FPF_SKIANormalizeFontName(FX_BSTR bsfamily) |
| 185 { | 185 { |
| 186 FX_DWORD dwHash = 0; | 186 FX_DWORD dwHash = 0; |
| 187 FX_INT32 iLength = bsfamily.GetLength(); | 187 int32_t iLength = bsfamily.GetLength(); |
| 188 FX_LPCSTR pBuffer = bsfamily.GetCStr(); | 188 FX_LPCSTR pBuffer = bsfamily.GetCStr(); |
| 189 for (FX_INT32 i = 0; i < iLength; i++) { | 189 for (int32_t i = 0; i < iLength; i++) { |
| 190 FX_CHAR ch = pBuffer[i]; | 190 FX_CHAR ch = pBuffer[i]; |
| 191 if (ch == ' ' || ch == '-' || ch == ',') { | 191 if (ch == ' ' || ch == '-' || ch == ',') { |
| 192 continue; | 192 continue; |
| 193 } | 193 } |
| 194 dwHash = 31 * dwHash + FXSYS_tolower(ch); | 194 dwHash = 31 * dwHash + FXSYS_tolower(ch); |
| 195 } | 195 } |
| 196 return dwHash; | 196 return dwHash; |
| 197 } | 197 } |
| 198 static FX_DWORD»FPF_SKIAGetFamilyHash(FX_BSTR bsFamily, FX_DWORD dwStyle, FX_BYT
E uCharset) | 198 static FX_DWORD»FPF_SKIAGetFamilyHash(FX_BSTR bsFamily, FX_DWORD dwStyle, uint8_
t uCharset) |
| 199 { | 199 { |
| 200 CFX_ByteString bsFont(bsFamily); | 200 CFX_ByteString bsFont(bsFamily); |
| 201 if (dwStyle & FXFONT_BOLD) { | 201 if (dwStyle & FXFONT_BOLD) { |
| 202 bsFont += "Bold"; | 202 bsFont += "Bold"; |
| 203 } | 203 } |
| 204 if (dwStyle & FXFONT_ITALIC) { | 204 if (dwStyle & FXFONT_ITALIC) { |
| 205 bsFont += "Italic"; | 205 bsFont += "Italic"; |
| 206 } | 206 } |
| 207 if (dwStyle & FXFONT_SERIF) { | 207 if (dwStyle & FXFONT_SERIF) { |
| 208 bsFont += "Serif"; | 208 bsFont += "Serif"; |
| 209 } | 209 } |
| 210 bsFont += uCharset; | 210 bsFont += uCharset; |
| 211 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); | 211 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); |
| 212 } | 212 } |
| 213 static FX_BOOL FPF_SkiaIsCJK(FX_BYTE uCharset) | 213 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) |
| 214 { | 214 { |
| 215 return (uCharset == FXFONT_GB2312_CHARSET) || (uCharset == FXFONT_CHINESEBIG
5_CHARSET) | 215 return (uCharset == FXFONT_GB2312_CHARSET) || (uCharset == FXFONT_CHINESEBIG
5_CHARSET) |
| 216 || (uCharset == FXFONT_HANGEUL_CHARSET) || (uCharset == FXFONT_SHIFTJ
IS_CHARSET); | 216 || (uCharset == FXFONT_HANGEUL_CHARSET) || (uCharset == FXFONT_SHIFTJ
IS_CHARSET); |
| 217 } | 217 } |
| 218 static FX_BOOL FPF_SkiaMaybeSymbol(FX_BSTR bsFacename) | 218 static FX_BOOL FPF_SkiaMaybeSymbol(FX_BSTR bsFacename) |
| 219 { | 219 { |
| 220 CFX_ByteString bsName = bsFacename; | 220 CFX_ByteString bsName = bsFacename; |
| 221 bsName.MakeLower(); | 221 bsName.MakeLower(); |
| 222 return bsName.Find("symbol") > -1; | 222 return bsName.Find("symbol") > -1; |
| 223 } | 223 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 236 void *pkey = NULL; | 236 void *pkey = NULL; |
| 237 CFPF_SkiaFont *pValue = NULL; | 237 CFPF_SkiaFont *pValue = NULL; |
| 238 FX_POSITION pos = m_FamilyFonts.GetStartPosition(); | 238 FX_POSITION pos = m_FamilyFonts.GetStartPosition(); |
| 239 while (pos) { | 239 while (pos) { |
| 240 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue); | 240 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue); |
| 241 if (pValue) { | 241 if (pValue) { |
| 242 pValue->Release(); | 242 pValue->Release(); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 m_FamilyFonts.RemoveAll(); | 245 m_FamilyFonts.RemoveAll(); |
| 246 for (FX_INT32 i = m_FontFaces.GetUpperBound(); i >= 0; i--) { | 246 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { |
| 247 CFPF_SkiaFontDescriptor *pFont = (CFPF_SkiaFontDescriptor*)m_FontFaces.E
lementAt(i); | 247 CFPF_SkiaFontDescriptor *pFont = (CFPF_SkiaFontDescriptor*)m_FontFaces.E
lementAt(i); |
| 248 if (pFont) { | 248 if (pFont) { |
| 249 delete pFont; | 249 delete pFont; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 m_FontFaces.RemoveAll(); | 252 m_FontFaces.RemoveAll(); |
| 253 if (m_FTLibrary) { | 253 if (m_FTLibrary) { |
| 254 FXFT_Done_FreeType(m_FTLibrary); | 254 FXFT_Done_FreeType(m_FTLibrary); |
| 255 } | 255 } |
| 256 } | 256 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 272 } | 272 } |
| 273 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) | 273 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) |
| 274 { | 274 { |
| 275 } | 275 } |
| 276 void CFPF_SkiaFontMgr::LoadPrivateFont(FX_BSTR bsFileName) | 276 void CFPF_SkiaFontMgr::LoadPrivateFont(FX_BSTR bsFileName) |
| 277 { | 277 { |
| 278 } | 278 } |
| 279 void CFPF_SkiaFontMgr::LoadPrivateFont(FX_LPVOID pBuffer, size_t szBuffer) | 279 void CFPF_SkiaFontMgr::LoadPrivateFont(FX_LPVOID pBuffer, size_t szBuffer) |
| 280 { | 280 { |
| 281 } | 281 } |
| 282 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(FX_BSTR bsFamilyname, FX_BYTE uCharset,
FX_DWORD dwStyle, FX_DWORD dwMatch) | 282 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(FX_BSTR bsFamilyname, uint8_t uCharset,
FX_DWORD dwStyle, FX_DWORD dwMatch) |
| 283 { | 283 { |
| 284 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset); | 284 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset); |
| 285 IFPF_Font *pFont = NULL; | 285 IFPF_Font *pFont = NULL; |
| 286 if (m_FamilyFonts.Lookup((void*)(FX_UINTPTR)dwHash, (void*&)pFont)) { | 286 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { |
| 287 if (pFont) { | 287 if (pFont) { |
| 288 return pFont->Retain(); | 288 return pFont->Retain(); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname); | 291 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname); |
| 292 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName); | 292 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName); |
| 293 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName); | 293 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName); |
| 294 FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname); | 294 FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname); |
| 295 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname))
{ | 295 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname))
{ |
| 296 uCharset = FXFONT_ARABIC_CHARSET; | 296 uCharset = FXFONT_ARABIC_CHARSET; |
| 297 } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLA
CEANSI)) { | 297 } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLA
CEANSI)) { |
| 298 uCharset = FXFONT_DEFAULT_CHARSET; | 298 uCharset = FXFONT_DEFAULT_CHARSET; |
| 299 } | 299 } |
| 300 FX_INT32 nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3
+ FPF_SKIAMATCHWEIGHT_2 * 2; | 300 int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 +
FPF_SKIAMATCHWEIGHT_2 * 2; |
| 301 FX_INT32 nItem = -1; | 301 int32_t nItem = -1; |
| 302 FX_INT32 nMax = -1; | 302 int32_t nMax = -1; |
| 303 FX_INT32 nGlyphNum = 0; | 303 int32_t nGlyphNum = 0; |
| 304 for (FX_INT32 i = m_FontFaces.GetUpperBound(); i >= 0; i--) { | 304 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { |
| 305 CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt(
i); | 305 CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt(
i); |
| 306 if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) { | 306 if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) { |
| 307 continue; | 307 continue; |
| 308 } | 308 } |
| 309 FX_INT32 nFind = 0; | 309 int32_t nFind = 0; |
| 310 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily); | 310 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily); |
| 311 if (dwFaceName == dwSysFontName) { | 311 if (dwFaceName == dwSysFontName) { |
| 312 nFind += FPF_SKIAMATCHWEIGHT_NAME1; | 312 nFind += FPF_SKIAMATCHWEIGHT_NAME1; |
| 313 } | 313 } |
| 314 FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); | 314 FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); |
| 315 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { | 315 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { |
| 316 nFind += FPF_SKIAMATCHWEIGHT_1; | 316 nFind += FPF_SKIAMATCHWEIGHT_1; |
| 317 } | 317 } |
| 318 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC))
{ | 318 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC))
{ |
| 319 nFind += FPF_SKIAMATCHWEIGHT_1; | 319 nFind += FPF_SKIAMATCHWEIGHT_1; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 347 } | 347 } |
| 348 if (nExpectVal <= nFind) { | 348 if (nExpectVal <= nFind) { |
| 349 nItem = i; | 349 nItem = i; |
| 350 break; | 350 break; |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 if (nItem > -1) { | 353 if (nItem > -1) { |
| 354 CFPF_SkiaFontDescriptor *pFontDes = (CFPF_SkiaFontDescriptor*)m_FontFace
s.ElementAt(nItem); | 354 CFPF_SkiaFontDescriptor *pFontDes = (CFPF_SkiaFontDescriptor*)m_FontFace
s.ElementAt(nItem); |
| 355 CFPF_SkiaFont *pFont = new CFPF_SkiaFont; | 355 CFPF_SkiaFont *pFont = new CFPF_SkiaFont; |
| 356 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { | 356 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { |
| 357 m_FamilyFonts.SetAt((void*)(FX_UINTPTR)dwHash, (void*)pFont); | 357 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); |
| 358 return pFont->Retain(); | 358 return pFont->Retain(); |
| 359 } | 359 } |
| 360 pFont->Release(); | 360 pFont->Release(); |
| 361 } | 361 } |
| 362 return NULL; | 362 return NULL; |
| 363 } | 363 } |
| 364 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead *pFileRead, FX_INT32 iFaceI
ndex) | 364 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead *pFileRead, int32_t iFaceIn
dex) |
| 365 { | 365 { |
| 366 if (!pFileRead) { | 366 if (!pFileRead) { |
| 367 return NULL; | 367 return NULL; |
| 368 } | 368 } |
| 369 if (pFileRead->GetSize() == 0) { | 369 if (pFileRead->GetSize() == 0) { |
| 370 return NULL; | 370 return NULL; |
| 371 } | 371 } |
| 372 if (iFaceIndex < 0) { | 372 if (iFaceIndex < 0) { |
| 373 return NULL; | 373 return NULL; |
| 374 } | 374 } |
| 375 FXFT_StreamRec streamRec; | 375 FXFT_StreamRec streamRec; |
| 376 FXSYS_memset32(&streamRec, 0, sizeof(FXFT_StreamRec)); | 376 FXSYS_memset32(&streamRec, 0, sizeof(FXFT_StreamRec)); |
| 377 streamRec.size = pFileRead->GetSize(); | 377 streamRec.size = pFileRead->GetSize(); |
| 378 streamRec.descriptor.pointer = pFileRead; | 378 streamRec.descriptor.pointer = pFileRead; |
| 379 streamRec.read = FPF_SkiaStream_Read; | 379 streamRec.read = FPF_SkiaStream_Read; |
| 380 streamRec.close = FPF_SkiaStream_Close; | 380 streamRec.close = FPF_SkiaStream_Close; |
| 381 FXFT_Open_Args args; | 381 FXFT_Open_Args args; |
| 382 args.flags = FT_OPEN_STREAM; | 382 args.flags = FT_OPEN_STREAM; |
| 383 args.stream = &streamRec; | 383 args.stream = &streamRec; |
| 384 FXFT_Face face; | 384 FXFT_Face face; |
| 385 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 385 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 386 return NULL; | 386 return NULL; |
| 387 } | 387 } |
| 388 FXFT_Set_Pixel_Sizes(face, 0, 64); | 388 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 389 return face; | 389 return face; |
| 390 } | 390 } |
| 391 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(FX_BSTR bsFile, FX_INT32 iFaceIndex ) | 391 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(FX_BSTR bsFile, int32_t iFaceIndex ) |
| 392 { | 392 { |
| 393 if (bsFile.IsEmpty()) { | 393 if (bsFile.IsEmpty()) { |
| 394 return NULL; | 394 return NULL; |
| 395 } | 395 } |
| 396 if (iFaceIndex < 0) { | 396 if (iFaceIndex < 0) { |
| 397 return NULL; | 397 return NULL; |
| 398 } | 398 } |
| 399 FXFT_Open_Args args; | 399 FXFT_Open_Args args; |
| 400 args.flags = FT_OPEN_PATHNAME; | 400 args.flags = FT_OPEN_PATHNAME; |
| 401 args.pathname = (FT_String*)bsFile.GetCStr(); | 401 args.pathname = (FT_String*)bsFile.GetCStr(); |
| 402 FXFT_Face face; | 402 FXFT_Face face; |
| 403 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 403 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 404 return FALSE; | 404 return FALSE; |
| 405 } | 405 } |
| 406 FXFT_Set_Pixel_Sizes(face, 0, 64); | 406 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 407 return face; | 407 return face; |
| 408 } | 408 } |
| 409 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(FX_LPCBYTE pBuffer, size_t szBuffer, FX_
INT32 iFaceIndex ) | 409 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(FX_LPCBYTE pBuffer, size_t szBuffer, int
32_t iFaceIndex ) |
| 410 { | 410 { |
| 411 if (!pBuffer || szBuffer < 1) { | 411 if (!pBuffer || szBuffer < 1) { |
| 412 return NULL; | 412 return NULL; |
| 413 } | 413 } |
| 414 if (iFaceIndex < 0) { | 414 if (iFaceIndex < 0) { |
| 415 return NULL; | 415 return NULL; |
| 416 } | 416 } |
| 417 FXFT_Open_Args args; | 417 FXFT_Open_Args args; |
| 418 args.flags = FT_OPEN_MEMORY; | 418 args.flags = FT_OPEN_MEMORY; |
| 419 args.memory_base = pBuffer; | 419 args.memory_base = pBuffer; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 0, | 498 0, |
| 499 0, | 499 0, |
| 500 0, | 500 0, |
| 501 FPF_SKIACHARSET_OEM, | 501 FPF_SKIACHARSET_OEM, |
| 502 FPF_SKIACHARSET_Symbol, | 502 FPF_SKIACHARSET_Symbol, |
| 503 }; | 503 }; |
| 504 static FX_DWORD FPF_SkiaGetFaceCharset(TT_OS2 *pOS2) | 504 static FX_DWORD FPF_SkiaGetFaceCharset(TT_OS2 *pOS2) |
| 505 { | 505 { |
| 506 FX_DWORD dwCharset = 0; | 506 FX_DWORD dwCharset = 0; |
| 507 if (pOS2) { | 507 if (pOS2) { |
| 508 for (FX_INT32 i = 0; i < 32; i++) { | 508 for (int32_t i = 0; i < 32; i++) { |
| 509 if (pOS2->ulCodePageRange1 & (1 << i)) { | 509 if (pOS2->ulCodePageRange1 & (1 << i)) { |
| 510 dwCharset |= g_FPFSkiaFontCharsets[i]; | 510 dwCharset |= g_FPFSkiaFontCharsets[i]; |
| 511 } | 511 } |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 dwCharset |= FPF_SKIACHARSET_Default; | 514 dwCharset |= FPF_SKIACHARSET_Default; |
| 515 return dwCharset; | 515 return dwCharset; |
| 516 } | 516 } |
| 517 void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor *pFont
Desc) | 517 void CFPF_SkiaFontMgr::ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor *pFont
Desc) |
| 518 { | 518 { |
| 519 if (!face || !pFontDesc) { | 519 if (!face || !pFontDesc) { |
| 520 return; | 520 return; |
| 521 } | 521 } |
| 522 pFontDesc->SetFamily(FXFT_Get_Face_Family_Name(face)); | 522 pFontDesc->SetFamily(FXFT_Get_Face_Family_Name(face)); |
| 523 if (FXFT_Is_Face_Bold(face)) { | 523 if (FXFT_Is_Face_Bold(face)) { |
| 524 pFontDesc->m_dwStyle |= FXFONT_BOLD; | 524 pFontDesc->m_dwStyle |= FXFONT_BOLD; |
| 525 } | 525 } |
| 526 if (FXFT_Is_Face_Italic(face)) { | 526 if (FXFT_Is_Face_Italic(face)) { |
| 527 pFontDesc->m_dwStyle |= FXFONT_ITALIC; | 527 pFontDesc->m_dwStyle |= FXFONT_ITALIC; |
| 528 } | 528 } |
| 529 if (FT_IS_FIXED_WIDTH(face)) { | 529 if (FT_IS_FIXED_WIDTH(face)) { |
| 530 pFontDesc->m_dwStyle |= FXFONT_FIXED_PITCH; | 530 pFontDesc->m_dwStyle |= FXFONT_FIXED_PITCH; |
| 531 } | 531 } |
| 532 TT_OS2 *pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2); | 532 TT_OS2 *pOS2 = (TT_OS2*)FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
| 533 if (pOS2) { | 533 if (pOS2) { |
| 534 if (pOS2->ulCodePageRange1 & (1 << 31)) { | 534 if (pOS2->ulCodePageRange1 & (1 << 31)) { |
| 535 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | 535 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
| 536 } | 536 } |
| 537 if (pOS2->panose[0] == 2) { | 537 if (pOS2->panose[0] == 2) { |
| 538 FX_BYTE uSerif = pOS2->panose[1]; | 538 uint8_t uSerif = pOS2->panose[1]; |
| 539 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { | 539 if ((uSerif > 1 && uSerif < 10) || uSerif > 13) { |
| 540 pFontDesc->m_dwStyle |= FXFONT_SERIF; | 540 pFontDesc->m_dwStyle |= FXFONT_SERIF; |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { | 544 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { |
| 545 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | 545 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
| 546 } | 546 } |
| 547 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); | 547 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); |
| 548 pFontDesc->m_iFaceIndex = face->face_index; | 548 pFontDesc->m_iFaceIndex = face->face_index; |
| 549 pFontDesc->m_iGlyphNum = face->num_glyphs; | 549 pFontDesc->m_iGlyphNum = face->num_glyphs; |
| 550 } | 550 } |
| 551 void CFPF_SkiaFontMgr::OutputSystemFonts() | 551 void CFPF_SkiaFontMgr::OutputSystemFonts() |
| 552 { | 552 { |
| 553 } | 553 } |
| 554 #endif | 554 #endif |
| OLD | NEW |