| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "../../../include/fxge/fx_ge.h" | 9 #include "../../../include/fxge/fx_ge.h" |
| 10 #include "../../../include/fxge/fx_freetype.h" | 10 #include "../../../include/fxge/fx_freetype.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 FXFT_Face face = m_pExtMapper->FindSubstFont(face_name, bTrueType, flags
, weight, italic_angle, | 110 FXFT_Face face = m_pExtMapper->FindSubstFont(face_name, bTrueType, flags
, weight, italic_angle, |
| 111 CharsetCP, pSubstFont); | 111 CharsetCP, pSubstFont); |
| 112 if (face) { | 112 if (face) { |
| 113 return face; | 113 return face; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
italic_angle, | 116 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
italic_angle, |
| 117 CharsetCP, pSubstFont); | 117 CharsetCP, pSubstFont); |
| 118 } | 118 } |
| 119 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, | 119 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, |
| 120 int weight, FX_BOOL bItalic, FX_LPBYTE& pFo
ntData) | 120 int weight, FX_BOOL bItalic, uint8_t*& pFon
tData) |
| 121 { | 121 { |
| 122 CFX_ByteString key(face_name); | 122 CFX_ByteString key(face_name); |
| 123 key += ','; | 123 key += ','; |
| 124 key += CFX_ByteString::FormatInteger(weight); | 124 key += CFX_ByteString::FormatInteger(weight); |
| 125 key += bItalic ? 'I' : 'N'; | 125 key += bItalic ? 'I' : 'N'; |
| 126 CTTFontDesc* pFontDesc = NULL; | 126 CTTFontDesc* pFontDesc = NULL; |
| 127 m_FaceMap.Lookup(key, (void*&)pFontDesc); | 127 m_FaceMap.Lookup(key, (void*&)pFontDesc); |
| 128 if(pFontDesc) { | 128 if(pFontDesc) { |
| 129 pFontData = pFontDesc->m_pFontData; | 129 pFontData = pFontDesc->m_pFontData; |
| 130 pFontDesc->m_RefCount ++; | 130 pFontDesc->m_RefCount ++; |
| 131 return pFontDesc->m_SingleFace.m_pFace; | 131 return pFontDesc->m_SingleFace.m_pFace; |
| 132 } | 132 } |
| 133 return NULL; | 133 return NULL; |
| 134 } | 134 } |
| 135 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, | 135 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, |
| 136 int weight, FX_BOOL bItalic, FX_LPBYTE pDat
a, FX_DWORD size, int face_index) | 136 int weight, FX_BOOL bItalic, uint8_t* pData
, FX_DWORD size, int face_index) |
| 137 { | 137 { |
| 138 CTTFontDesc* pFontDesc = new CTTFontDesc; | 138 CTTFontDesc* pFontDesc = new CTTFontDesc; |
| 139 pFontDesc->m_Type = 1; | 139 pFontDesc->m_Type = 1; |
| 140 pFontDesc->m_SingleFace.m_pFace = NULL; | 140 pFontDesc->m_SingleFace.m_pFace = NULL; |
| 141 pFontDesc->m_SingleFace.m_bBold = weight; | 141 pFontDesc->m_SingleFace.m_bBold = weight; |
| 142 pFontDesc->m_SingleFace.m_bItalic = bItalic; | 142 pFontDesc->m_SingleFace.m_bItalic = bItalic; |
| 143 pFontDesc->m_pFontData = pData; | 143 pFontDesc->m_pFontData = pData; |
| 144 pFontDesc->m_RefCount = 1; | 144 pFontDesc->m_RefCount = 1; |
| 145 FXFT_Library library; | 145 FXFT_Library library; |
| 146 if (m_FTLibrary == NULL) { | 146 if (m_FTLibrary == NULL) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 157 delete pFontDesc; | 157 delete pFontDesc; |
| 158 return NULL; | 158 return NULL; |
| 159 } | 159 } |
| 160 CFX_ByteString key(face_name); | 160 CFX_ByteString key(face_name); |
| 161 key += ','; | 161 key += ','; |
| 162 key += CFX_ByteString::FormatInteger(weight); | 162 key += CFX_ByteString::FormatInteger(weight); |
| 163 key += bItalic ? 'I' : 'N'; | 163 key += bItalic ? 'I' : 'N'; |
| 164 m_FaceMap.SetAt(key, pFontDesc); | 164 m_FaceMap.SetAt(key, pFontDesc); |
| 165 return pFontDesc->m_SingleFace.m_pFace; | 165 return pFontDesc->m_SingleFace.m_pFace; |
| 166 } | 166 } |
| 167 const FX_LPCSTR g_Base14FontNames[14] = { | 167 const FX_CHAR* const g_Base14FontNames[14] = { |
| 168 "Courier", | 168 "Courier", |
| 169 "Courier-Bold", | 169 "Courier-Bold", |
| 170 "Courier-BoldOblique", | 170 "Courier-BoldOblique", |
| 171 "Courier-Oblique", | 171 "Courier-Oblique", |
| 172 "Helvetica", | 172 "Helvetica", |
| 173 "Helvetica-Bold", | 173 "Helvetica-Bold", |
| 174 "Helvetica-BoldOblique", | 174 "Helvetica-BoldOblique", |
| 175 "Helvetica-Oblique", | 175 "Helvetica-Oblique", |
| 176 "Times-Roman", | 176 "Times-Roman", |
| 177 "Times-Bold", | 177 "Times-Bold", |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 {"TimesNewRomanPS-ItalicMT", 11}, | 271 {"TimesNewRomanPS-ItalicMT", 11}, |
| 272 {"TimesNewRomanPSMT", 8}, | 272 {"TimesNewRomanPSMT", 8}, |
| 273 {"TimesNewRomanPSMT,Bold", 9}, | 273 {"TimesNewRomanPSMT,Bold", 9}, |
| 274 {"TimesNewRomanPSMT,BoldItalic", 10}, | 274 {"TimesNewRomanPSMT,BoldItalic", 10}, |
| 275 {"TimesNewRomanPSMT,Italic", 11}, | 275 {"TimesNewRomanPSMT,Italic", 11}, |
| 276 {"ZapfDingbats", 13}, | 276 {"ZapfDingbats", 13}, |
| 277 }; | 277 }; |
| 278 extern "C" { | 278 extern "C" { |
| 279 static int compareString(const void* key, const void* element) | 279 static int compareString(const void* key, const void* element) |
| 280 { | 280 { |
| 281 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontName*)element)->m_pName); | 281 return FXSYS_stricmp((const FX_CHAR*)key, ((_AltFontName*)element)->m_pN
ame); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 int _PDF_GetStandardFontName(CFX_ByteString& name) | 284 int _PDF_GetStandardFontName(CFX_ByteString& name) |
| 285 { | 285 { |
| 286 _AltFontName* found = (_AltFontName*)FXSYS_bsearch(name.c_str(), g_AltFontNa
mes, | 286 _AltFontName* found = (_AltFontName*)FXSYS_bsearch(name.c_str(), g_AltFontNa
mes, |
| 287 sizeof g_AltFontNames / sizeof (_AltFontName), sizeof
(_AltFontName), compareString); | 287 sizeof g_AltFontNames / sizeof (_AltFontName), sizeof
(_AltFontName), compareString); |
| 288 if (found == NULL) { | 288 if (found == NULL) { |
| 289 return -1; | 289 return -1; |
| 290 } | 290 } |
| 291 name = g_Base14FontNames[found->m_Index]; | 291 name = g_Base14FontNames[found->m_Index]; |
| 292 return found->m_Index; | 292 return found->m_Index; |
| 293 } | 293 } |
| 294 int GetTTCIndex(FX_LPCBYTE pFontData, FX_DWORD ttc_size, FX_DWORD font_offset) | 294 int GetTTCIndex(const uint8_t* pFontData, FX_DWORD ttc_size, FX_DWORD font_offse
t) |
| 295 { | 295 { |
| 296 int face_index = 0; | 296 int face_index = 0; |
| 297 FX_LPCBYTE p = pFontData + 8; | 297 const uint8_t* p = pFontData + 8; |
| 298 FX_DWORD nfont = GET_TT_LONG(p); | 298 FX_DWORD nfont = GET_TT_LONG(p); |
| 299 FX_DWORD index; | 299 FX_DWORD index; |
| 300 for (index = 0; index < nfont; index ++) { | 300 for (index = 0; index < nfont; index ++) { |
| 301 p = pFontData + 12 + index * 4; | 301 p = pFontData + 12 + index * 4; |
| 302 if (GET_TT_LONG(p) == font_offset) { | 302 if (GET_TT_LONG(p) == font_offset) { |
| 303 break; | 303 break; |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 if(index >= nfont) { | 306 if(index >= nfont) { |
| 307 face_index = 0; | 307 face_index = 0; |
| 308 } else { | 308 } else { |
| 309 face_index = index; | 309 face_index = index; |
| 310 } | 310 } |
| 311 return face_index; | 311 return face_index; |
| 312 } | 312 } |
| 313 FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, FX_DWORD checksum, | 313 FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, FX_DWORD checksum, |
| 314 int font_offset, FX_LPBYTE& pFontData) | 314 int font_offset, uint8_t*& pFontData) |
| 315 { | 315 { |
| 316 CFX_ByteString key; | 316 CFX_ByteString key; |
| 317 key.Format("%d:%d", ttc_size, checksum); | 317 key.Format("%d:%d", ttc_size, checksum); |
| 318 CTTFontDesc* pFontDesc = NULL; | 318 CTTFontDesc* pFontDesc = NULL; |
| 319 m_FaceMap.Lookup(key, (void*&)pFontDesc); | 319 m_FaceMap.Lookup(key, (void*&)pFontDesc); |
| 320 if (pFontDesc == NULL) { | 320 if (pFontDesc == NULL) { |
| 321 return NULL; | 321 return NULL; |
| 322 } | 322 } |
| 323 pFontData = pFontDesc->m_pFontData; | 323 pFontData = pFontDesc->m_pFontData; |
| 324 pFontDesc->m_RefCount ++; | 324 pFontDesc->m_RefCount ++; |
| 325 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); | 325 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); |
| 326 if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) { | 326 if (pFontDesc->m_TTCFace.m_pFaces[face_index] == NULL) { |
| 327 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pF
ontData, ttc_size, face_index); | 327 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pF
ontData, ttc_size, face_index); |
| 328 } | 328 } |
| 329 return pFontDesc->m_TTCFace.m_pFaces[face_index]; | 329 return pFontDesc->m_TTCFace.m_pFaces[face_index]; |
| 330 } | 330 } |
| 331 FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, FX_DWORD checksum, | 331 FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, FX_DWORD checksum, |
| 332 FX_LPBYTE pData, FX_DWORD size, int font
_offset) | 332 uint8_t* pData, FX_DWORD size, int font_
offset) |
| 333 { | 333 { |
| 334 CFX_ByteString key; | 334 CFX_ByteString key; |
| 335 key.Format("%d:%d", ttc_size, checksum); | 335 key.Format("%d:%d", ttc_size, checksum); |
| 336 CTTFontDesc* pFontDesc = new CTTFontDesc; | 336 CTTFontDesc* pFontDesc = new CTTFontDesc; |
| 337 pFontDesc->m_Type = 2; | 337 pFontDesc->m_Type = 2; |
| 338 pFontDesc->m_pFontData = pData; | 338 pFontDesc->m_pFontData = pData; |
| 339 for (int i = 0; i < 16; i ++) { | 339 for (int i = 0; i < 16; i ++) { |
| 340 pFontDesc->m_TTCFace.m_pFaces[i] = NULL; | 340 pFontDesc->m_TTCFace.m_pFaces[i] = NULL; |
| 341 } | 341 } |
| 342 pFontDesc->m_RefCount ++; | 342 pFontDesc->m_RefCount ++; |
| 343 key.Format("%d:%d", ttc_size, checksum); | 343 key.Format("%d:%d", ttc_size, checksum); |
| 344 m_FaceMap.SetAt(key, pFontDesc); | 344 m_FaceMap.SetAt(key, pFontDesc); |
| 345 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); | 345 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); |
| 346 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pFontD
ata, ttc_size, face_index); | 346 pFontDesc->m_TTCFace.m_pFaces[face_index] = GetFixedFace(pFontDesc->m_pFontD
ata, ttc_size, face_index); |
| 347 return pFontDesc->m_TTCFace.m_pFaces[face_index]; | 347 return pFontDesc->m_TTCFace.m_pFaces[face_index]; |
| 348 } | 348 } |
| 349 FXFT_Face CFX_FontMgr::GetFixedFace(FX_LPCBYTE pData, FX_DWORD size, int face_in
dex) | 349 FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData, FX_DWORD size, int fac
e_index) |
| 350 { | 350 { |
| 351 FXFT_Library library; | 351 FXFT_Library library; |
| 352 if (m_FTLibrary == NULL) { | 352 if (m_FTLibrary == NULL) { |
| 353 FXFT_Init_FreeType(&m_FTLibrary); | 353 FXFT_Init_FreeType(&m_FTLibrary); |
| 354 } | 354 } |
| 355 library = m_FTLibrary; | 355 library = m_FTLibrary; |
| 356 FXFT_Face face = NULL; | 356 FXFT_Face face = NULL; |
| 357 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face); | 357 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face); |
| 358 if (ret) { | 358 if (ret) { |
| 359 return NULL; | 359 return NULL; |
| 360 } | 360 } |
| 361 ret = FXFT_Set_Pixel_Sizes(face, 64, 64); | 361 ret = FXFT_Set_Pixel_Sizes(face, 64, 64); |
| 362 if (ret) { | 362 if (ret) { |
| 363 return NULL; | 363 return NULL; |
| 364 } | 364 } |
| 365 return face; | 365 return face; |
| 366 } | 366 } |
| 367 FXFT_Face CFX_FontMgr::GetFileFace(FX_LPCSTR filename, int face_index) | 367 FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) |
| 368 { | 368 { |
| 369 FXFT_Library library; | 369 FXFT_Library library; |
| 370 if (m_FTLibrary == NULL) { | 370 if (m_FTLibrary == NULL) { |
| 371 FXFT_Init_FreeType(&m_FTLibrary); | 371 FXFT_Init_FreeType(&m_FTLibrary); |
| 372 } | 372 } |
| 373 library = m_FTLibrary; | 373 library = m_FTLibrary; |
| 374 FXFT_Face face = NULL; | 374 FXFT_Face face = NULL; |
| 375 int ret = FXFT_New_Face(library, filename, face_index, &face); | 375 int ret = FXFT_New_Face(library, filename, face_index, &face); |
| 376 if (ret) { | 376 if (ret) { |
| 377 return NULL; | 377 return NULL; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 {g_FoxitSansBoldFontData, 16344}, | 424 {g_FoxitSansBoldFontData, 16344}, |
| 425 {g_FoxitSansBoldItalicFontData, 16418}, | 425 {g_FoxitSansBoldItalicFontData, 16418}, |
| 426 {g_FoxitSansItalicFontData, 16339}, | 426 {g_FoxitSansItalicFontData, 16339}, |
| 427 {g_FoxitSerifFontData, 19469}, | 427 {g_FoxitSerifFontData, 19469}, |
| 428 {g_FoxitSerifBoldFontData, 19395}, | 428 {g_FoxitSerifBoldFontData, 19395}, |
| 429 {g_FoxitSerifBoldItalicFontData, 20733}, | 429 {g_FoxitSerifBoldItalicFontData, 20733}, |
| 430 {g_FoxitSerifItalicFontData, 21227}, | 430 {g_FoxitSerifItalicFontData, 21227}, |
| 431 {g_FoxitSymbolFontData, 16729}, | 431 {g_FoxitSymbolFontData, 16729}, |
| 432 {g_FoxitDingbatsFontData, 29513}, | 432 {g_FoxitDingbatsFontData, 29513}, |
| 433 }; | 433 }; |
| 434 void _FPDFAPI_GetInternalFontData(int id, FX_LPCBYTE& data, FX_DWORD& size) | 434 void _FPDFAPI_GetInternalFontData(int id, const uint8_t*& data, FX_DWORD& size) |
| 435 { | 435 { |
| 436 CFX_GEModule::Get()->GetFontMgr()->GetStandardFont(data, size, id); | 436 CFX_GEModule::Get()->GetFontMgr()->GetStandardFont(data, size, id); |
| 437 } | 437 } |
| 438 FX_BOOL CFX_FontMgr::GetStandardFont(FX_LPCBYTE& pFontData, FX_DWORD& size, int
index) | 438 FX_BOOL CFX_FontMgr::GetStandardFont(const uint8_t*& pFontData, FX_DWORD& size,
int index) |
| 439 { | 439 { |
| 440 if (index > 15 || index < 0) { | 440 if (index > 15 || index < 0) { |
| 441 return FALSE; | 441 return FALSE; |
| 442 } | 442 } |
| 443 { | 443 { |
| 444 if (index >= 14) { | 444 if (index >= 14) { |
| 445 if (index == 14) { | 445 if (index == 14) { |
| 446 pFontData = g_FoxitSerifMMFontData; | 446 pFontData = g_FoxitSerifMMFontData; |
| 447 size = 113417; | 447 size = 113417; |
| 448 } else { | 448 } else { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 void CFX_FontMapper::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) | 483 void CFX_FontMapper::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) |
| 484 { | 484 { |
| 485 if (pFontInfo == NULL) { | 485 if (pFontInfo == NULL) { |
| 486 return; | 486 return; |
| 487 } | 487 } |
| 488 if (m_pFontInfo) { | 488 if (m_pFontInfo) { |
| 489 m_pFontInfo->Release(); | 489 m_pFontInfo->Release(); |
| 490 } | 490 } |
| 491 m_pFontInfo = pFontInfo; | 491 m_pFontInfo = pFontInfo; |
| 492 } | 492 } |
| 493 static CFX_ByteString _TT_NormalizeName(FX_LPCSTR family) | 493 static CFX_ByteString _TT_NormalizeName(const FX_CHAR* family) |
| 494 { | 494 { |
| 495 CFX_ByteString norm(family, -1); | 495 CFX_ByteString norm(family, -1); |
| 496 norm.Remove(' '); | 496 norm.Remove(' '); |
| 497 norm.Remove('-'); | 497 norm.Remove('-'); |
| 498 norm.Remove(','); | 498 norm.Remove(','); |
| 499 int pos = norm.Find('+'); | 499 int pos = norm.Find('+'); |
| 500 if (pos > 0) { | 500 if (pos > 0) { |
| 501 norm = norm.Left(pos); | 501 norm = norm.Left(pos); |
| 502 } | 502 } |
| 503 norm.MakeLower(); | 503 norm.MakeLower(); |
| 504 return norm; | 504 return norm; |
| 505 } | 505 } |
| 506 CFX_ByteString _FPDF_GetNameFromTT(FX_LPCBYTE name_table, FX_DWORD name_id) | 506 CFX_ByteString _FPDF_GetNameFromTT(const uint8_t* name_table, FX_DWORD name_id) |
| 507 { | 507 { |
| 508 FX_LPCBYTE ptr = name_table + 2; | 508 const uint8_t* ptr = name_table + 2; |
| 509 int name_count = GET_TT_SHORT(ptr); | 509 int name_count = GET_TT_SHORT(ptr); |
| 510 int string_offset = GET_TT_SHORT(ptr + 2); | 510 int string_offset = GET_TT_SHORT(ptr + 2); |
| 511 FX_LPCBYTE string_ptr = name_table + string_offset; | 511 const uint8_t* string_ptr = name_table + string_offset; |
| 512 ptr += 4; | 512 ptr += 4; |
| 513 for (int i = 0; i < name_count; i ++) { | 513 for (int i = 0; i < name_count; i ++) { |
| 514 if (GET_TT_SHORT(ptr + 6) == name_id && GET_TT_SHORT(ptr) == 1 && GET_TT
_SHORT(ptr + 2) == 0) { | 514 if (GET_TT_SHORT(ptr + 6) == name_id && GET_TT_SHORT(ptr) == 1 && GET_TT
_SHORT(ptr + 2) == 0) { |
| 515 return CFX_ByteStringC(string_ptr + GET_TT_SHORT(ptr + 10), GET_TT_S
HORT(ptr + 8)); | 515 return CFX_ByteStringC(string_ptr + GET_TT_SHORT(ptr + 10), GET_TT_S
HORT(ptr + 8)); |
| 516 } | 516 } |
| 517 ptr += 12; | 517 ptr += 12; |
| 518 } | 518 } |
| 519 return CFX_ByteString(); | 519 return CFX_ByteString(); |
| 520 } | 520 } |
| 521 static CFX_ByteString _FPDF_ReadStringFromFile(FXSYS_FILE* pFile, FX_DWORD size) | 521 static CFX_ByteString _FPDF_ReadStringFromFile(FXSYS_FILE* pFile, FX_DWORD size) |
| 522 { | 522 { |
| 523 CFX_ByteString buffer; | 523 CFX_ByteString buffer; |
| 524 if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile)) { | 524 if (!FXSYS_fread(buffer.GetBuffer(size), size, 1, pFile)) { |
| 525 return CFX_ByteString(); | 525 return CFX_ByteString(); |
| 526 } | 526 } |
| 527 buffer.ReleaseBuffer(size); | 527 buffer.ReleaseBuffer(size); |
| 528 return buffer; | 528 return buffer; |
| 529 } | 529 } |
| 530 CFX_ByteString _FPDF_LoadTableFromTT(FXSYS_FILE* pFile, FX_LPCBYTE pTables, FX_D
WORD nTables, FX_DWORD tag) | 530 CFX_ByteString _FPDF_LoadTableFromTT(FXSYS_FILE* pFile, const uint8_t* pTables,
FX_DWORD nTables, FX_DWORD tag) |
| 531 { | 531 { |
| 532 for (FX_DWORD i = 0; i < nTables; i ++) { | 532 for (FX_DWORD i = 0; i < nTables; i ++) { |
| 533 FX_LPCBYTE p = pTables + i * 16; | 533 const uint8_t* p = pTables + i * 16; |
| 534 if (GET_TT_LONG(p) == tag) { | 534 if (GET_TT_LONG(p) == tag) { |
| 535 FX_DWORD offset = GET_TT_LONG(p + 8); | 535 FX_DWORD offset = GET_TT_LONG(p + 8); |
| 536 FX_DWORD size = GET_TT_LONG(p + 12); | 536 FX_DWORD size = GET_TT_LONG(p + 12); |
| 537 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); | 537 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); |
| 538 return _FPDF_ReadStringFromFile(pFile, size); | 538 return _FPDF_ReadStringFromFile(pFile, size); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 return CFX_ByteString(); | 541 return CFX_ByteString(); |
| 542 } | 542 } |
| 543 CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile, FX_LPCBYTE
pTables, FX_DWORD nTables, FX_DWORD tag) | 543 CFX_ByteString _FPDF_LoadTableFromTTStreamFile(IFX_FileStream* pFile, const uint
8_t* pTables, FX_DWORD nTables, FX_DWORD tag) |
| 544 { | 544 { |
| 545 for (FX_DWORD i = 0; i < nTables; i ++) { | 545 for (FX_DWORD i = 0; i < nTables; i ++) { |
| 546 FX_LPCBYTE p = pTables + i * 16; | 546 const uint8_t* p = pTables + i * 16; |
| 547 if (GET_TT_LONG(p) == tag) { | 547 if (GET_TT_LONG(p) == tag) { |
| 548 FX_DWORD offset = GET_TT_LONG(p + 8); | 548 FX_DWORD offset = GET_TT_LONG(p + 8); |
| 549 FX_DWORD size = GET_TT_LONG(p + 12); | 549 FX_DWORD size = GET_TT_LONG(p + 12); |
| 550 CFX_ByteString buffer; | 550 CFX_ByteString buffer; |
| 551 if (!pFile->ReadBlock(buffer.GetBuffer(size), offset, size)) { | 551 if (!pFile->ReadBlock(buffer.GetBuffer(size), offset, size)) { |
| 552 return CFX_ByteString(); | 552 return CFX_ByteString(); |
| 553 } | 553 } |
| 554 buffer.ReleaseBuffer(size); | 554 buffer.ReleaseBuffer(size); |
| 555 return buffer; | 555 return buffer; |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 return CFX_ByteString(); | 558 return CFX_ByteString(); |
| 559 } | 559 } |
| 560 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) | 560 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) |
| 561 { | 561 { |
| 562 if (m_pFontInfo == NULL) { | 562 if (m_pFontInfo == NULL) { |
| 563 CFX_ByteString(); | 563 CFX_ByteString(); |
| 564 } | 564 } |
| 565 CFX_ByteString result; | 565 CFX_ByteString result; |
| 566 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); | 566 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); |
| 567 if (size) { | 567 if (size) { |
| 568 FX_LPBYTE buffer = FX_Alloc(uint8_t, size); | 568 uint8_t* buffer = FX_Alloc(uint8_t, size); |
| 569 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); | 569 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); |
| 570 result = _FPDF_GetNameFromTT(buffer, 6); | 570 result = _FPDF_GetNameFromTT(buffer, 6); |
| 571 FX_Free(buffer); | 571 FX_Free(buffer); |
| 572 } | 572 } |
| 573 return result; | 573 return result; |
| 574 } | 574 } |
| 575 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) | 575 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) |
| 576 { | 576 { |
| 577 if (m_pFontInfo == NULL) { | 577 if (m_pFontInfo == NULL) { |
| 578 return; | 578 return; |
| 579 } | 579 } |
| 580 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) { | 580 if (m_CharsetArray.Find((FX_DWORD)charset) == -1) { |
| 581 m_CharsetArray.Add((FX_DWORD)charset); | 581 m_CharsetArray.Add((FX_DWORD)charset); |
| 582 m_FaceArray.Add(name); | 582 m_FaceArray.Add(name); |
| 583 } | 583 } |
| 584 if (name == m_LastFamily) { | 584 if (name == m_LastFamily) { |
| 585 return; | 585 return; |
| 586 } | 586 } |
| 587 FX_LPCBYTE ptr = name; | 587 const uint8_t* ptr = name; |
| 588 FX_BOOL bLocalized = FALSE; | 588 FX_BOOL bLocalized = FALSE; |
| 589 for (int i = 0; i < name.GetLength(); i ++) | 589 for (int i = 0; i < name.GetLength(); i ++) |
| 590 if (ptr[i] > 0x80) { | 590 if (ptr[i] > 0x80) { |
| 591 bLocalized = TRUE; | 591 bLocalized = TRUE; |
| 592 break; | 592 break; |
| 593 } | 593 } |
| 594 if (bLocalized) { | 594 if (bLocalized) { |
| 595 void* hFont = m_pFontInfo->GetFont(name); | 595 void* hFont = m_pFontInfo->GetFont(name); |
| 596 if (hFont == NULL) { | 596 if (hFont == NULL) { |
| 597 FX_BOOL bExact; | 597 FX_BOOL bExact; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 return 1 << 31; | 737 return 1 << 31; |
| 738 } | 738 } |
| 739 return 1 << 21; | 739 return 1 << 21; |
| 740 } | 740 } |
| 741 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseF
ont, int italic_angle, int weight, int picthfamily) | 741 FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, int iBaseF
ont, int italic_angle, int weight, int picthfamily) |
| 742 { | 742 { |
| 743 if (iBaseFont < 12) { | 743 if (iBaseFont < 12) { |
| 744 if (m_FoxitFaces[iBaseFont]) { | 744 if (m_FoxitFaces[iBaseFont]) { |
| 745 return m_FoxitFaces[iBaseFont]; | 745 return m_FoxitFaces[iBaseFont]; |
| 746 } | 746 } |
| 747 FX_LPCBYTE pFontData = NULL; | 747 const uint8_t* pFontData = NULL; |
| 748 FX_DWORD size = 0; | 748 FX_DWORD size = 0; |
| 749 if (m_pFontMgr->GetStandardFont(pFontData, size, iBaseFont)) { | 749 if (m_pFontMgr->GetStandardFont(pFontData, size, iBaseFont)) { |
| 750 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size,
0); | 750 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size,
0); |
| 751 return m_FoxitFaces[iBaseFont]; | 751 return m_FoxitFaces[iBaseFont]; |
| 752 } | 752 } |
| 753 } | 753 } |
| 754 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM; | 754 pSubstFont->m_SubstFlags |= FXFONT_SUBST_MM; |
| 755 pSubstFont->m_ItalicAngle = italic_angle; | 755 pSubstFont->m_ItalicAngle = italic_angle; |
| 756 if (weight) { | 756 if (weight) { |
| 757 pSubstFont->m_Weight = weight; | 757 pSubstFont->m_Weight = weight; |
| 758 } | 758 } |
| 759 if (picthfamily & FXFONT_FF_ROMAN) { | 759 if (picthfamily & FXFONT_FF_ROMAN) { |
| 760 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; | 760 pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; |
| 761 pSubstFont->m_Family = "Chrome Serif"; | 761 pSubstFont->m_Family = "Chrome Serif"; |
| 762 if (m_MMFaces[1]) { | 762 if (m_MMFaces[1]) { |
| 763 return m_MMFaces[1]; | 763 return m_MMFaces[1]; |
| 764 } | 764 } |
| 765 FX_LPCBYTE pFontData = NULL; | 765 const uint8_t* pFontData = NULL; |
| 766 FX_DWORD size; | 766 FX_DWORD size; |
| 767 m_pFontMgr->GetStandardFont(pFontData, size, 14); | 767 m_pFontMgr->GetStandardFont(pFontData, size, 14); |
| 768 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 768 m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
| 769 return m_MMFaces[1]; | 769 return m_MMFaces[1]; |
| 770 } | 770 } |
| 771 pSubstFont->m_Family = "Chrome Sans"; | 771 pSubstFont->m_Family = "Chrome Sans"; |
| 772 if (m_MMFaces[0]) { | 772 if (m_MMFaces[0]) { |
| 773 return m_MMFaces[0]; | 773 return m_MMFaces[0]; |
| 774 } | 774 } |
| 775 FX_LPCBYTE pFontData = NULL; | 775 const uint8_t* pFontData = NULL; |
| 776 FX_DWORD size = 0; | 776 FX_DWORD size = 0; |
| 777 m_pFontMgr->GetStandardFont(pFontData, size, 15); | 777 m_pFontMgr->GetStandardFont(pFontData, size, 15); |
| 778 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 778 m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
| 779 return m_MMFaces[0]; | 779 return m_MMFaces[0]; |
| 780 } | 780 } |
| 781 const struct _AltFontFamily { | 781 const struct _AltFontFamily { |
| 782 FX_LPCSTR m_pFontName; | 782 const FX_CHAR* m_pFontName; |
| 783 FX_LPCSTR m_pFontFamily; | 783 const FX_CHAR* m_pFontFamily; |
| 784 } | 784 } |
| 785 g_AltFontFamilies[] = { | 785 g_AltFontFamilies[] = { |
| 786 {"AGaramondPro", "Adobe Garamond Pro"}, | 786 {"AGaramondPro", "Adobe Garamond Pro"}, |
| 787 {"BankGothicBT-Medium", "BankGothic Md BT"}, | 787 {"BankGothicBT-Medium", "BankGothic Md BT"}, |
| 788 {"ForteMT", "Forte"}, | 788 {"ForteMT", "Forte"}, |
| 789 }; | 789 }; |
| 790 extern "C" { | 790 extern "C" { |
| 791 static int compareFontFamilyString(const void* key, const void* element) | 791 static int compareFontFamilyString(const void* key, const void* element) |
| 792 { | 792 { |
| 793 CFX_ByteString str_key((FX_LPCSTR)key); | 793 CFX_ByteString str_key((const FX_CHAR*)key); |
| 794 if (str_key.Find(((_AltFontFamily*)element)->m_pFontName) != -1) { | 794 if (str_key.Find(((_AltFontFamily*)element)->m_pFontName) != -1) { |
| 795 return 0; | 795 return 0; |
| 796 } | 796 } |
| 797 return FXSYS_stricmp((FX_LPCSTR)key, ((_AltFontFamily*)element)->m_pFont
Name); | 797 return FXSYS_stricmp((const FX_CHAR*)key, ((_AltFontFamily*)element)->m_
pFontName); |
| 798 } | 798 } |
| 799 } | 799 } |
| 800 #define FX_FONT_STYLE_None 0x00 | 800 #define FX_FONT_STYLE_None 0x00 |
| 801 #define FX_FONT_STYLE_Bold 0x01 | 801 #define FX_FONT_STYLE_Bold 0x01 |
| 802 #define FX_FONT_STYLE_Italic 0x02 | 802 #define FX_FONT_STYLE_Italic 0x02 |
| 803 #define FX_FONT_STYLE_BoldBold 0x04 | 803 #define FX_FONT_STYLE_BoldBold 0x04 |
| 804 static CFX_ByteString _GetFontFamily(CFX_ByteString fontName, int nStyle) | 804 static CFX_ByteString _GetFontFamily(CFX_ByteString fontName, int nStyle) |
| 805 { | 805 { |
| 806 if (fontName.Find("Script") >= 0) { | 806 if (fontName.Find("Script") >= 0) { |
| 807 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) { | 807 if ((nStyle & FX_FONT_STYLE_Bold) == FX_FONT_STYLE_Bold) { |
| 808 fontName = "ScriptMTBold"; | 808 fontName = "ScriptMTBold"; |
| 809 } else if (fontName.Find("Palace") >= 0) { | 809 } else if (fontName.Find("Palace") >= 0) { |
| 810 fontName = "PalaceScriptMT"; | 810 fontName = "PalaceScriptMT"; |
| 811 } else if (fontName.Find("French") >= 0) { | 811 } else if (fontName.Find("French") >= 0) { |
| 812 fontName = "FrenchScriptMT"; | 812 fontName = "FrenchScriptMT"; |
| 813 } else if (fontName.Find("FreeStyle") >= 0) { | 813 } else if (fontName.Find("FreeStyle") >= 0) { |
| 814 fontName = "FreeStyleScript"; | 814 fontName = "FreeStyleScript"; |
| 815 } | 815 } |
| 816 return fontName; | 816 return fontName; |
| 817 } | 817 } |
| 818 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch(fontName.c_str(), g_A
ltFontFamilies, | 818 _AltFontFamily* found = (_AltFontFamily*)FXSYS_bsearch(fontName.c_str(), g_A
ltFontFamilies, |
| 819 sizeof g_AltFontFamilies / sizeof (_AltFontFamily),
sizeof (_AltFontFamily), compareFontFamilyString); | 819 sizeof g_AltFontFamilies / sizeof (_AltFontFamily),
sizeof (_AltFontFamily), compareFontFamilyString); |
| 820 if (found == NULL) { | 820 if (found == NULL) { |
| 821 return fontName; | 821 return fontName; |
| 822 } | 822 } |
| 823 return found->m_pFontFamily; | 823 return found->m_pFontFamily; |
| 824 }; | 824 }; |
| 825 typedef struct _FX_FontStyle { | 825 typedef struct _FX_FontStyle { |
| 826 FX_LPCSTR style; | 826 const FX_CHAR* style; |
| 827 int32_t len; | 827 int32_t len; |
| 828 } FX_FontStyle; | 828 } FX_FontStyle; |
| 829 const FX_FontStyle g_FontStyles[] = { | 829 const FX_FontStyle g_FontStyles[] = { |
| 830 { "Bold", 4 }, | 830 { "Bold", 4 }, |
| 831 { "Italic", 6 }, | 831 { "Italic", 6 }, |
| 832 { "BoldItalic", 10 }, | 832 { "BoldItalic", 10 }, |
| 833 { "Reg", 3 }, | 833 { "Reg", 3 }, |
| 834 { "Regular", 7 }, | 834 { "Regular", 7 }, |
| 835 }; | 835 }; |
| 836 CFX_ByteString ParseStyle(FX_LPCSTR pStyle, int iLen, int iIndex) | 836 CFX_ByteString ParseStyle(const FX_CHAR* pStyle, int iLen, int iIndex) |
| 837 { | 837 { |
| 838 CFX_ByteTextBuf buf; | 838 CFX_ByteTextBuf buf; |
| 839 if (!iLen || iLen <= iIndex) { | 839 if (!iLen || iLen <= iIndex) { |
| 840 return buf.GetByteString(); | 840 return buf.GetByteString(); |
| 841 } | 841 } |
| 842 while (iIndex < iLen) { | 842 while (iIndex < iLen) { |
| 843 if (pStyle[iIndex] == ',') { | 843 if (pStyle[iIndex] == ',') { |
| 844 break; | 844 break; |
| 845 } | 845 } |
| 846 buf.AppendChar(pStyle[iIndex]); | 846 buf.AppendChar(pStyle[iIndex]); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 } | 896 } |
| 897 } | 897 } |
| 898 _PDF_GetStandardFontName(SubstName); | 898 _PDF_GetStandardFontName(SubstName); |
| 899 if (SubstName == FX_BSTRC("Symbol") && !bTrueType) { | 899 if (SubstName == FX_BSTRC("Symbol") && !bTrueType) { |
| 900 pSubstFont->m_Family = "Chrome Symbol"; | 900 pSubstFont->m_Family = "Chrome Symbol"; |
| 901 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 901 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
| 902 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 902 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
| 903 if (m_FoxitFaces[12]) { | 903 if (m_FoxitFaces[12]) { |
| 904 return m_FoxitFaces[12]; | 904 return m_FoxitFaces[12]; |
| 905 } | 905 } |
| 906 FX_LPCBYTE pFontData = NULL; | 906 const uint8_t* pFontData = NULL; |
| 907 FX_DWORD size = 0; | 907 FX_DWORD size = 0; |
| 908 m_pFontMgr->GetStandardFont(pFontData, size, 12); | 908 m_pFontMgr->GetStandardFont(pFontData, size, 12); |
| 909 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 909 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
| 910 return m_FoxitFaces[12]; | 910 return m_FoxitFaces[12]; |
| 911 } | 911 } |
| 912 if (SubstName == FX_BSTRC("ZapfDingbats")) { | 912 if (SubstName == FX_BSTRC("ZapfDingbats")) { |
| 913 pSubstFont->m_Family = "Chrome Dingbats"; | 913 pSubstFont->m_Family = "Chrome Dingbats"; |
| 914 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 914 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
| 915 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 915 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
| 916 if (m_FoxitFaces[13]) { | 916 if (m_FoxitFaces[13]) { |
| 917 return m_FoxitFaces[13]; | 917 return m_FoxitFaces[13]; |
| 918 } | 918 } |
| 919 FX_LPCBYTE pFontData = NULL; | 919 const uint8_t* pFontData = NULL; |
| 920 FX_DWORD size = 0; | 920 FX_DWORD size = 0; |
| 921 m_pFontMgr->GetStandardFont(pFontData, size, 13); | 921 m_pFontMgr->GetStandardFont(pFontData, size, 13); |
| 922 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); | 922 m_FoxitFaces[13] = m_pFontMgr->GetFixedFace(pFontData, size, 0); |
| 923 return m_FoxitFaces[13]; | 923 return m_FoxitFaces[13]; |
| 924 } | 924 } |
| 925 int iBaseFont = 0; | 925 int iBaseFont = 0; |
| 926 CFX_ByteString family, style; | 926 CFX_ByteString family, style; |
| 927 FX_BOOL bHasComma = FALSE; | 927 FX_BOOL bHasComma = FALSE; |
| 928 FX_BOOL bHasHypen = FALSE; | 928 FX_BOOL bHasHypen = FALSE; |
| 929 int find = SubstName.Find(FX_BSTRC(","), 0); | 929 int find = SubstName.Find(FX_BSTRC(","), 0); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 } | 987 } |
| 988 if (flags & FXFONT_SCRIPT) { | 988 if (flags & FXFONT_SCRIPT) { |
| 989 PitchFamily |= FXFONT_FF_SCRIPT; | 989 PitchFamily |= FXFONT_FF_SCRIPT; |
| 990 } | 990 } |
| 991 if (flags & FXFONT_FIXED_PITCH) { | 991 if (flags & FXFONT_FIXED_PITCH) { |
| 992 PitchFamily |= FXFONT_FF_FIXEDPITCH; | 992 PitchFamily |= FXFONT_FF_FIXEDPITCH; |
| 993 } | 993 } |
| 994 } | 994 } |
| 995 if (!style.IsEmpty()) { | 995 if (!style.IsEmpty()) { |
| 996 int nLen = style.GetLength(); | 996 int nLen = style.GetLength(); |
| 997 FX_LPCSTR pStyle = style; | 997 const FX_CHAR* pStyle = style; |
| 998 int i = 0; | 998 int i = 0; |
| 999 FX_BOOL bFirstItem = TRUE; | 999 FX_BOOL bFirstItem = TRUE; |
| 1000 CFX_ByteString buf; | 1000 CFX_ByteString buf; |
| 1001 while (i < nLen) { | 1001 while (i < nLen) { |
| 1002 buf = ParseStyle(pStyle, nLen, i); | 1002 buf = ParseStyle(pStyle, nLen, i); |
| 1003 int32_t nRet = GetStyleType(buf, FALSE); | 1003 int32_t nRet = GetStyleType(buf, FALSE); |
| 1004 if ((i && !bStyleAvail) || (!i && nRet < 0)) { | 1004 if ((i && !bStyleAvail) || (!i && nRet < 0)) { |
| 1005 family = SubstName; | 1005 family = SubstName; |
| 1006 iBaseFont = 12; | 1006 iBaseFont = 12; |
| 1007 break; | 1007 break; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 } else { | 1149 } else { |
| 1150 if (Charset == FXFONT_SYMBOL_CHARSET) { | 1150 if (Charset == FXFONT_SYMBOL_CHARSET) { |
| 1151 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_
ANDROID_ | 1151 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || _FXM_PLATFORM_ == _FXM_PLATFORM_
ANDROID_ |
| 1152 if (SubstName == FX_BSTRC("Symbol")) { | 1152 if (SubstName == FX_BSTRC("Symbol")) { |
| 1153 pSubstFont->m_Family = "Chrome Symbol"; | 1153 pSubstFont->m_Family = "Chrome Symbol"; |
| 1154 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; | 1154 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; |
| 1155 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; | 1155 pSubstFont->m_Charset = FXFONT_SYMBOL_CHARSET; |
| 1156 if (m_FoxitFaces[12]) { | 1156 if (m_FoxitFaces[12]) { |
| 1157 return m_FoxitFaces[12]; | 1157 return m_FoxitFaces[12]; |
| 1158 } | 1158 } |
| 1159 FX_LPCBYTE pFontData = NULL; | 1159 const uint8_t* pFontData = NULL; |
| 1160 FX_DWORD size = 0; | 1160 FX_DWORD size = 0; |
| 1161 m_pFontMgr->GetStandardFont(pFontData, size, 12); | 1161 m_pFontMgr->GetStandardFont(pFontData, size, 12); |
| 1162 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size,
0); | 1162 m_FoxitFaces[12] = m_pFontMgr->GetFixedFace(pFontData, size,
0); |
| 1163 return m_FoxitFaces[12]; | 1163 return m_FoxitFaces[12]; |
| 1164 } else { | 1164 } else { |
| 1165 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; | 1165 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; |
| 1166 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMB
OLIC, weight, italic_angle, 0, pSubstFont); | 1166 return FindSubstFont(family, bTrueType, flags & ~FXFONT_SYMB
OLIC, weight, italic_angle, 0, pSubstFont); |
| 1167 } | 1167 } |
| 1168 #else | 1168 #else |
| 1169 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; | 1169 pSubstFont->m_SubstFlags |= FXFONT_SUBST_NONSYMBOL; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1197 return NULL; | 1197 return NULL; |
| 1198 } | 1198 } |
| 1199 FXFT_Face face = NULL; | 1199 FXFT_Face face = NULL; |
| 1200 if (ttc_size) { | 1200 if (ttc_size) { |
| 1201 uint8_t temp[1024]; | 1201 uint8_t temp[1024]; |
| 1202 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); | 1202 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); |
| 1203 FX_DWORD checksum = 0; | 1203 FX_DWORD checksum = 0; |
| 1204 for (int i = 0; i < 256; i ++) { | 1204 for (int i = 0; i < 256; i ++) { |
| 1205 checksum += ((FX_DWORD*)temp)[i]; | 1205 checksum += ((FX_DWORD*)temp)[i]; |
| 1206 } | 1206 } |
| 1207 FX_LPBYTE pFontData; | 1207 uint8_t* pFontData; |
| 1208 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_
size, pFontData); | 1208 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_
size, pFontData); |
| 1209 if (face == NULL) { | 1209 if (face == NULL) { |
| 1210 pFontData = FX_Alloc(uint8_t, ttc_size); | 1210 pFontData = FX_Alloc(uint8_t, ttc_size); |
| 1211 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); | 1211 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); |
| 1212 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t
tc_size, | 1212 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t
tc_size, |
| 1213 ttc_size - font_size); | 1213 ttc_size - font_size); |
| 1214 } | 1214 } |
| 1215 } else { | 1215 } else { |
| 1216 FX_LPBYTE pFontData; | 1216 uint8_t* pFontData; |
| 1217 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); | 1217 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); |
| 1218 if (face == NULL) { | 1218 if (face == NULL) { |
| 1219 pFontData = FX_Alloc(uint8_t, font_size); | 1219 pFontData = FX_Alloc(uint8_t, font_size); |
| 1220 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); | 1220 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); |
| 1221 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa
ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); | 1221 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa
ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); |
| 1222 } | 1222 } |
| 1223 } | 1223 } |
| 1224 if (face == NULL) { | 1224 if (face == NULL) { |
| 1225 m_pFontInfo->DeleteFont(hFont); | 1225 m_pFontInfo->DeleteFont(hFont); |
| 1226 return NULL; | 1226 return NULL; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 } | 1286 } |
| 1287 #endif | 1287 #endif |
| 1288 CFX_FolderFontInfo::CFX_FolderFontInfo() | 1288 CFX_FolderFontInfo::CFX_FolderFontInfo() |
| 1289 { | 1289 { |
| 1290 } | 1290 } |
| 1291 CFX_FolderFontInfo::~CFX_FolderFontInfo() | 1291 CFX_FolderFontInfo::~CFX_FolderFontInfo() |
| 1292 { | 1292 { |
| 1293 FX_POSITION pos = m_FontList.GetStartPosition(); | 1293 FX_POSITION pos = m_FontList.GetStartPosition(); |
| 1294 while (pos) { | 1294 while (pos) { |
| 1295 CFX_ByteString key; | 1295 CFX_ByteString key; |
| 1296 FX_LPVOID value; | 1296 void* value; |
| 1297 m_FontList.GetNextAssoc(pos, key, value); | 1297 m_FontList.GetNextAssoc(pos, key, value); |
| 1298 delete (CFontFaceInfo*)value; | 1298 delete (CFontFaceInfo*)value; |
| 1299 } | 1299 } |
| 1300 } | 1300 } |
| 1301 void CFX_FolderFontInfo::AddPath(FX_BSTR path) | 1301 void CFX_FolderFontInfo::AddPath(FX_BSTR path) |
| 1302 { | 1302 { |
| 1303 m_PathList.Add(path); | 1303 m_PathList.Add(path); |
| 1304 } | 1304 } |
| 1305 void CFX_FolderFontInfo::Release() | 1305 void CFX_FolderFontInfo::Release() |
| 1306 { | 1306 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 return; | 1365 return; |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 if (GET_TT_LONG(buffer) == 0x74746366) { | 1368 if (GET_TT_LONG(buffer) == 0x74746366) { |
| 1369 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); | 1369 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); |
| 1370 if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) { | 1370 if (nFaces > std::numeric_limits<FX_DWORD>::max() / 4) { |
| 1371 FXSYS_fclose(pFile); | 1371 FXSYS_fclose(pFile); |
| 1372 return; | 1372 return; |
| 1373 } | 1373 } |
| 1374 FX_DWORD face_bytes = nFaces * 4; | 1374 FX_DWORD face_bytes = nFaces * 4; |
| 1375 FX_LPBYTE offsets = FX_Alloc(uint8_t, face_bytes); | 1375 uint8_t* offsets = FX_Alloc(uint8_t, face_bytes); |
| 1376 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); | 1376 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); |
| 1377 if (readCnt != face_bytes) { | 1377 if (readCnt != face_bytes) { |
| 1378 FX_Free(offsets); | 1378 FX_Free(offsets); |
| 1379 FXSYS_fclose(pFile); | 1379 FXSYS_fclose(pFile); |
| 1380 return; | 1380 return; |
| 1381 } | 1381 } |
| 1382 for (FX_DWORD i = 0; i < nFaces; i ++) { | 1382 for (FX_DWORD i = 0; i < nFaces; i ++) { |
| 1383 FX_LPBYTE p = offsets + i * 4; | 1383 uint8_t* p = offsets + i * 4; |
| 1384 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); | 1384 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); |
| 1385 } | 1385 } |
| 1386 FX_Free(offsets); | 1386 FX_Free(offsets); |
| 1387 } else { | 1387 } else { |
| 1388 ReportFace(path, pFile, filesize, 0); | 1388 ReportFace(path, pFile, filesize, 0); |
| 1389 } | 1389 } |
| 1390 FXSYS_fclose(pFile); | 1390 FXSYS_fclose(pFile); |
| 1391 } | 1391 } |
| 1392 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_
DWORD filesize, FX_DWORD offset) | 1392 void CFX_FolderFontInfo::ReportFace(CFX_ByteString& path, FXSYS_FILE* pFile, FX_
DWORD filesize, FX_DWORD offset) |
| 1393 { | 1393 { |
| 1394 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); | 1394 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); |
| 1395 char buffer[16]; | 1395 char buffer[16]; |
| 1396 if (!FXSYS_fread(buffer, 12, 1, pFile)) { | 1396 if (!FXSYS_fread(buffer, 12, 1, pFile)) { |
| 1397 return; | 1397 return; |
| 1398 } | 1398 } |
| 1399 FX_DWORD nTables = GET_TT_SHORT(buffer + 4); | 1399 FX_DWORD nTables = GET_TT_SHORT(buffer + 4); |
| 1400 CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16); | 1400 CFX_ByteString tables = _FPDF_ReadStringFromFile(pFile, nTables * 16); |
| 1401 if (tables.IsEmpty()) { | 1401 if (tables.IsEmpty()) { |
| 1402 return; | 1402 return; |
| 1403 } | 1403 } |
| 1404 CFX_ByteString names = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616
d65); | 1404 CFX_ByteString names = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x6e616
d65); |
| 1405 CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1); | 1405 CFX_ByteString facename = _FPDF_GetNameFromTT(names, 1); |
| 1406 CFX_ByteString style = _FPDF_GetNameFromTT(names, 2); | 1406 CFX_ByteString style = _FPDF_GetNameFromTT(names, 2); |
| 1407 if (style != "Regular") { | 1407 if (style != "Regular") { |
| 1408 facename += " " + style; | 1408 facename += " " + style; |
| 1409 } | 1409 } |
| 1410 FX_LPVOID p; | 1410 void* p; |
| 1411 if (m_FontList.Lookup(facename, p)) { | 1411 if (m_FontList.Lookup(facename, p)) { |
| 1412 return; | 1412 return; |
| 1413 } | 1413 } |
| 1414 CFontFaceInfo* pInfo = new CFontFaceInfo; | 1414 CFontFaceInfo* pInfo = new CFontFaceInfo; |
| 1415 pInfo->m_FilePath = path; | 1415 pInfo->m_FilePath = path; |
| 1416 pInfo->m_FaceName = facename; | 1416 pInfo->m_FaceName = facename; |
| 1417 pInfo->m_FontTables = tables; | 1417 pInfo->m_FontTables = tables; |
| 1418 pInfo->m_FontOffset = offset; | 1418 pInfo->m_FontOffset = offset; |
| 1419 pInfo->m_FileSize = filesize; | 1419 pInfo->m_FileSize = filesize; |
| 1420 pInfo->m_Charsets = 0; | 1420 pInfo->m_Charsets = 0; |
| 1421 CFX_ByteString os2 = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f3
2); | 1421 CFX_ByteString os2 = _FPDF_LoadTableFromTT(pFile, tables, nTables, 0x4f532f3
2); |
| 1422 if (os2.GetLength() >= 86) { | 1422 if (os2.GetLength() >= 86) { |
| 1423 FX_LPCBYTE p = (FX_LPCBYTE)os2 + 78; | 1423 const uint8_t* p = (const uint8_t*)os2 + 78; |
| 1424 FX_DWORD codepages = GET_TT_LONG(p); | 1424 FX_DWORD codepages = GET_TT_LONG(p); |
| 1425 if (codepages & (1 << 17)) { | 1425 if (codepages & (1 << 17)) { |
| 1426 m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET); | 1426 m_pMapper->AddInstalledFont(facename, FXFONT_SHIFTJIS_CHARSET); |
| 1427 pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS; | 1427 pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS; |
| 1428 } | 1428 } |
| 1429 if (codepages & (1 << 18)) { | 1429 if (codepages & (1 << 18)) { |
| 1430 m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET); | 1430 m_pMapper->AddInstalledFont(facename, FXFONT_GB2312_CHARSET); |
| 1431 pInfo->m_Charsets |= CHARSET_FLAG_GB; | 1431 pInfo->m_Charsets |= CHARSET_FLAG_GB; |
| 1432 } | 1432 } |
| 1433 if (codepages & (1 << 20)) { | 1433 if (codepages & (1 << 20)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1450 pInfo->m_Styles |= FXFONT_BOLD; | 1450 pInfo->m_Styles |= FXFONT_BOLD; |
| 1451 } | 1451 } |
| 1452 if (style.Find(FX_BSTRC("Italic")) > -1 || style.Find(FX_BSTRC("Oblique")) >
-1) { | 1452 if (style.Find(FX_BSTRC("Italic")) > -1 || style.Find(FX_BSTRC("Oblique")) >
-1) { |
| 1453 pInfo->m_Styles |= FXFONT_ITALIC; | 1453 pInfo->m_Styles |= FXFONT_ITALIC; |
| 1454 } | 1454 } |
| 1455 if (facename.Find(FX_BSTRC("Serif")) > -1) { | 1455 if (facename.Find(FX_BSTRC("Serif")) > -1) { |
| 1456 pInfo->m_Styles |= FXFONT_SERIF; | 1456 pInfo->m_Styles |= FXFONT_SERIF; |
| 1457 } | 1457 } |
| 1458 m_FontList.SetAt(facename, pInfo); | 1458 m_FontList.SetAt(facename, pInfo); |
| 1459 } | 1459 } |
| 1460 void* CFX_FolderFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int
pitch_family, FX_LPCSTR family, FX_BOOL& bExact) | 1460 void* CFX_FolderFontInfo::MapFont(int weight, FX_BOOL bItalic, int charset, int
pitch_family, const FX_CHAR* family, FX_BOOL& bExact) |
| 1461 { | 1461 { |
| 1462 return NULL; | 1462 return NULL; |
| 1463 } | 1463 } |
| 1464 void* CFX_FolderFontInfo::GetFont(FX_LPCSTR face) | 1464 void* CFX_FolderFontInfo::GetFont(const FX_CHAR* face) |
| 1465 { | 1465 { |
| 1466 FX_LPVOID p; | 1466 void* p; |
| 1467 if (!m_FontList.Lookup(face, p)) { | 1467 if (!m_FontList.Lookup(face, p)) { |
| 1468 return NULL; | 1468 return NULL; |
| 1469 } | 1469 } |
| 1470 return p; | 1470 return p; |
| 1471 } | 1471 } |
| 1472 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, FX_LPBYTE
buffer, FX_DWORD size) | 1472 FX_DWORD CFX_FolderFontInfo::GetFontData(void* hFont, FX_DWORD table, uint8_t* b
uffer, FX_DWORD size) |
| 1473 { | 1473 { |
| 1474 if (hFont == NULL) { | 1474 if (hFont == NULL) { |
| 1475 return 0; | 1475 return 0; |
| 1476 } | 1476 } |
| 1477 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; | 1477 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; |
| 1478 FXSYS_FILE* pFile = NULL; | 1478 FXSYS_FILE* pFile = NULL; |
| 1479 if (size > 0) { | 1479 if (size > 0) { |
| 1480 pFile = FXSYS_fopen(pFont->m_FilePath, "rb"); | 1480 pFile = FXSYS_fopen(pFont->m_FilePath, "rb"); |
| 1481 if (pFile == NULL) { | 1481 if (pFile == NULL) { |
| 1482 return 0; | 1482 return 0; |
| 1483 } | 1483 } |
| 1484 } | 1484 } |
| 1485 FX_DWORD datasize = 0; | 1485 FX_DWORD datasize = 0; |
| 1486 FX_DWORD offset; | 1486 FX_DWORD offset; |
| 1487 if (table == 0) { | 1487 if (table == 0) { |
| 1488 datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize; | 1488 datasize = pFont->m_FontOffset ? 0 : pFont->m_FileSize; |
| 1489 offset = 0; | 1489 offset = 0; |
| 1490 } else if (table == 0x74746366) { | 1490 } else if (table == 0x74746366) { |
| 1491 datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0; | 1491 datasize = pFont->m_FontOffset ? pFont->m_FileSize : 0; |
| 1492 offset = 0; | 1492 offset = 0; |
| 1493 } else { | 1493 } else { |
| 1494 FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16; | 1494 FX_DWORD nTables = pFont->m_FontTables.GetLength() / 16; |
| 1495 for (FX_DWORD i = 0; i < nTables; i ++) { | 1495 for (FX_DWORD i = 0; i < nTables; i ++) { |
| 1496 FX_LPCBYTE p = (FX_LPCBYTE)pFont->m_FontTables + i * 16; | 1496 const uint8_t* p = (const uint8_t*)pFont->m_FontTables + i * 16; |
| 1497 if (GET_TT_LONG(p) == table) { | 1497 if (GET_TT_LONG(p) == table) { |
| 1498 offset = GET_TT_LONG(p + 8); | 1498 offset = GET_TT_LONG(p + 8); |
| 1499 datasize = GET_TT_LONG(p + 12); | 1499 datasize = GET_TT_LONG(p + 12); |
| 1500 } | 1500 } |
| 1501 } | 1501 } |
| 1502 } | 1502 } |
| 1503 if (datasize && size >= datasize && pFile) { | 1503 if (datasize && size >= datasize && pFile) { |
| 1504 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); | 1504 FXSYS_fseek(pFile, offset, FXSYS_SEEK_SET); |
| 1505 FXSYS_fread(buffer, datasize, 1, pFile); | 1505 FXSYS_fread(buffer, datasize, 1, pFile); |
| 1506 } | 1506 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1518 return FALSE; | 1518 return FALSE; |
| 1519 } | 1519 } |
| 1520 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; | 1520 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; |
| 1521 name = pFont->m_FaceName; | 1521 name = pFont->m_FaceName; |
| 1522 return TRUE; | 1522 return TRUE; |
| 1523 } | 1523 } |
| 1524 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) | 1524 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) |
| 1525 { | 1525 { |
| 1526 return FALSE; | 1526 return FALSE; |
| 1527 } | 1527 } |
| OLD | NEW |