| 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 "../../../include/fxge/fx_ge.h" | 7 #include "../../../include/fxge/fx_ge.h" |
| 8 #include "../../../include/fxge/fx_freetype.h" | 8 #include "../../../include/fxge/fx_freetype.h" |
| 9 #include "text_int.h" | 9 #include "text_int.h" |
| 10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) | 10 #define GET_TT_SHORT(w) (FX_WORD)(((w)[0] << 8) | (w)[1]) |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 } | 574 } |
| 575 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) | 575 CFX_ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) |
| 576 { | 576 { |
| 577 if (m_pFontInfo == NULL) { | 577 if (m_pFontInfo == NULL) { |
| 578 CFX_ByteString(); | 578 CFX_ByteString(); |
| 579 } | 579 } |
| 580 CFX_ByteString result; | 580 CFX_ByteString result; |
| 581 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); | 581 FX_DWORD size = m_pFontInfo->GetFontData(hFont, 0x6e616d65, NULL, 0); |
| 582 if (size) { | 582 if (size) { |
| 583 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size); | 583 FX_LPBYTE buffer = FX_Alloc(FX_BYTE, size); |
| 584 if (!buffer) { | |
| 585 return result; | |
| 586 } | |
| 587 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); | 584 m_pFontInfo->GetFontData(hFont, 0x6e616d65, buffer, size); |
| 588 result = _FPDF_GetNameFromTT(buffer, 6); | 585 result = _FPDF_GetNameFromTT(buffer, 6); |
| 589 FX_Free(buffer); | 586 FX_Free(buffer); |
| 590 } | 587 } |
| 591 return result; | 588 return result; |
| 592 } | 589 } |
| 593 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) | 590 void CFX_FontMapper::AddInstalledFont(const CFX_ByteString& name, int charset) |
| 594 { | 591 { |
| 595 if (m_pFontInfo == NULL) { | 592 if (m_pFontInfo == NULL) { |
| 596 return; | 593 return; |
| (...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 FX_BYTE temp[1024]; | 1219 FX_BYTE temp[1024]; |
| 1223 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); | 1220 m_pFontInfo->GetFontData(hFont, 0x74746366, temp, 1024); |
| 1224 FX_DWORD checksum = 0; | 1221 FX_DWORD checksum = 0; |
| 1225 for (int i = 0; i < 256; i ++) { | 1222 for (int i = 0; i < 256; i ++) { |
| 1226 checksum += ((FX_DWORD*)temp)[i]; | 1223 checksum += ((FX_DWORD*)temp)[i]; |
| 1227 } | 1224 } |
| 1228 FX_LPBYTE pFontData; | 1225 FX_LPBYTE pFontData; |
| 1229 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_
size, pFontData); | 1226 face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, ttc_size - font_
size, pFontData); |
| 1230 if (face == NULL) { | 1227 if (face == NULL) { |
| 1231 pFontData = FX_Alloc(FX_BYTE, ttc_size); | 1228 pFontData = FX_Alloc(FX_BYTE, ttc_size); |
| 1232 if (pFontData) { | 1229 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size); |
| 1233 m_pFontInfo->GetFontData(hFont, 0x74746366, pFontData, ttc_size)
; | 1230 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, t
tc_size, |
| 1234 face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontDat
a, ttc_size, | 1231 ttc_size - font_size); |
| 1235 ttc_size - font_size); | |
| 1236 } | |
| 1237 } | 1232 } |
| 1238 } else { | 1233 } else { |
| 1239 FX_LPBYTE pFontData; | 1234 FX_LPBYTE pFontData; |
| 1240 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); | 1235 face = m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, pFontData); |
| 1241 if (face == NULL) { | 1236 if (face == NULL) { |
| 1242 pFontData = FX_Alloc(FX_BYTE, font_size); | 1237 pFontData = FX_Alloc(FX_BYTE, font_size); |
| 1243 if (!pFontData) { | |
| 1244 m_pFontInfo->DeleteFont(hFont); | |
| 1245 return NULL; | |
| 1246 } | |
| 1247 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); | 1238 m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); |
| 1248 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa
ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); | 1239 face = m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontDa
ta, font_size, m_pFontInfo->GetFaceIndex(hFont)); |
| 1249 } | 1240 } |
| 1250 } | 1241 } |
| 1251 if (face == NULL) { | 1242 if (face == NULL) { |
| 1252 m_pFontInfo->DeleteFont(hFont); | 1243 m_pFontInfo->DeleteFont(hFont); |
| 1253 return NULL; | 1244 return NULL; |
| 1254 } | 1245 } |
| 1255 pSubstFont->m_Family = SubstName; | 1246 pSubstFont->m_Family = SubstName; |
| 1256 pSubstFont->m_Charset = Charset; | 1247 pSubstFont->m_Charset = Charset; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 } | 1461 } |
| 1471 | 1462 |
| 1472 if (GET_TT_LONG(buffer) == 0x74746366) { | 1463 if (GET_TT_LONG(buffer) == 0x74746366) { |
| 1473 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); | 1464 FX_DWORD nFaces = GET_TT_LONG(buffer + 8); |
| 1474 if (nFaces > FX_DWORD_MAX / 4) { | 1465 if (nFaces > FX_DWORD_MAX / 4) { |
| 1475 FXSYS_fclose(pFile); | 1466 FXSYS_fclose(pFile); |
| 1476 return; | 1467 return; |
| 1477 } | 1468 } |
| 1478 FX_DWORD face_bytes = nFaces * 4; | 1469 FX_DWORD face_bytes = nFaces * 4; |
| 1479 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes); | 1470 FX_LPBYTE offsets = FX_Alloc(FX_BYTE, face_bytes); |
| 1480 if (!offsets) { | |
| 1481 FXSYS_fclose(pFile); | |
| 1482 return; | |
| 1483 } | |
| 1484 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); | 1471 readCnt = FXSYS_fread(offsets, face_bytes, 1, pFile); |
| 1485 if (readCnt != face_bytes) { | 1472 if (readCnt != face_bytes) { |
| 1486 FX_Free(offsets); | 1473 FX_Free(offsets); |
| 1487 FXSYS_fclose(pFile); | 1474 FXSYS_fclose(pFile); |
| 1488 return; | 1475 return; |
| 1489 } | 1476 } |
| 1490 for (FX_DWORD i = 0; i < nFaces; i ++) { | 1477 for (FX_DWORD i = 0; i < nFaces; i ++) { |
| 1491 FX_LPBYTE p = offsets + i * 4; | 1478 FX_LPBYTE p = offsets + i * 4; |
| 1492 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); | 1479 ReportFace(path, pFile, filesize, GET_TT_LONG(p)); |
| 1493 } | 1480 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 return FALSE; | 1620 return FALSE; |
| 1634 } | 1621 } |
| 1635 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; | 1622 CFontFaceInfo* pFont = (CFontFaceInfo*)hFont; |
| 1636 name = pFont->m_FaceName; | 1623 name = pFont->m_FaceName; |
| 1637 return TRUE; | 1624 return TRUE; |
| 1638 } | 1625 } |
| 1639 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) | 1626 FX_BOOL CFX_FolderFontInfo::GetFontCharset(void* hFont, int& charset) |
| 1640 { | 1627 { |
| 1641 return FALSE; | 1628 return FALSE; |
| 1642 } | 1629 } |
| OLD | NEW |