| 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/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "../../../include/fpdfapi/fpdf_pageobj.h" | 9 #include "../../../include/fpdfapi/fpdf_pageobj.h" |
| 10 #include "font_int.h" | 10 #include "font_int.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 { | 106 { |
| 107 FX_POSITION pos = m_pStockMap.GetStartPosition(); | 107 FX_POSITION pos = m_pStockMap.GetStartPosition(); |
| 108 while (pos) { | 108 while (pos) { |
| 109 void* key = NULL; | 109 void* key = NULL; |
| 110 void* value = NULL; | 110 void* value = NULL; |
| 111 m_pStockMap.GetNextAssoc(pos, key, value); | 111 m_pStockMap.GetNextAssoc(pos, key, value); |
| 112 delete static_cast<CFX_StockFontArray*>(value); | 112 delete static_cast<CFX_StockFontArray*>(value); |
| 113 m_pStockMap.RemoveKey(key); | 113 m_pStockMap.RemoveKey(key); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 CPDF_Font::CPDF_Font() | 116 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) |
| 117 { | 117 { |
| 118 m_FontType = 0; | |
| 119 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; | 118 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; |
| 120 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; | 119 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; |
| 121 m_pFontFile = NULL; | 120 m_pFontFile = NULL; |
| 122 m_Flags = 0; | 121 m_Flags = 0; |
| 123 m_pToUnicodeMap = NULL; | 122 m_pToUnicodeMap = NULL; |
| 124 m_bToUnicodeLoaded = FALSE; | 123 m_bToUnicodeLoaded = FALSE; |
| 125 m_pCharMap = NULL; | |
| 126 } | |
| 127 FX_BOOL CPDF_Font::Initialize() | |
| 128 { | |
| 129 m_pCharMap = new CPDF_FontCharMap(this); | 124 m_pCharMap = new CPDF_FontCharMap(this); |
| 130 return TRUE; | |
| 131 } | 125 } |
| 132 CPDF_Font::~CPDF_Font() | 126 CPDF_Font::~CPDF_Font() |
| 133 { | 127 { |
| 134 delete m_pCharMap; | 128 delete m_pCharMap; |
| 135 m_pCharMap = NULL; | 129 m_pCharMap = NULL; |
| 136 | 130 |
| 137 delete m_pToUnicodeMap; | 131 delete m_pToUnicodeMap; |
| 138 m_pToUnicodeMap = NULL; | 132 m_pToUnicodeMap = NULL; |
| 139 | 133 |
| 140 if (m_pFontFile) { | 134 if (m_pFontFile) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]); | 432 int count = sizeof(ChineseFontNames) / sizeof(ChineseFontNames[0]); |
| 439 for (i = 0; i < count; ++i) { | 433 for (i = 0; i < count; ++i) { |
| 440 if (tag == CFX_ByteString((FX_LPCSTR)ChineseFontNames[i])) { | 434 if (tag == CFX_ByteString((FX_LPCSTR)ChineseFontNames[i])) { |
| 441 break; | 435 break; |
| 442 } | 436 } |
| 443 } | 437 } |
| 444 if (i < count) { | 438 if (i < count) { |
| 445 CPDF_Dictionary* pFontDesc = pFontDict->GetDict(FX_BSTRC("FontDe
scriptor")); | 439 CPDF_Dictionary* pFontDesc = pFontDict->GetDict(FX_BSTRC("FontDe
scriptor")); |
| 446 if (pFontDesc == NULL || !pFontDesc->KeyExist(FX_BSTRC("FontFile
2"))) { | 440 if (pFontDesc == NULL || !pFontDesc->KeyExist(FX_BSTRC("FontFile
2"))) { |
| 447 pFont = new CPDF_CIDFont; | 441 pFont = new CPDF_CIDFont; |
| 448 pFont->Initialize(); | |
| 449 pFont->m_FontType = PDFFONT_CIDFONT; | |
| 450 pFont->m_pFontDict = pFontDict; | 442 pFont->m_pFontDict = pFontDict; |
| 451 pFont->m_pDocument = pDoc; | 443 pFont->m_pDocument = pDoc; |
| 452 if (!pFont->Load()) { | 444 if (!pFont->Load()) { |
| 453 delete pFont; | 445 delete pFont; |
| 454 return NULL; | 446 return NULL; |
| 455 } | 447 } |
| 456 return pFont; | 448 return pFont; |
| 457 } | 449 } |
| 458 } | 450 } |
| 459 #endif | 451 #endif |
| 460 } | 452 } |
| 461 pFont = new CPDF_TrueTypeFont; | 453 pFont = new CPDF_TrueTypeFont; |
| 462 pFont->Initialize(); | |
| 463 pFont->m_FontType = PDFFONT_TRUETYPE; | |
| 464 } else if (type == FX_BSTRC("Type3")) { | 454 } else if (type == FX_BSTRC("Type3")) { |
| 465 pFont = new CPDF_Type3Font; | 455 pFont = new CPDF_Type3Font; |
| 466 pFont->Initialize(); | |
| 467 pFont->m_FontType = PDFFONT_TYPE3; | |
| 468 } else if (type == FX_BSTRC("Type0")) { | 456 } else if (type == FX_BSTRC("Type0")) { |
| 469 pFont = new CPDF_CIDFont; | 457 pFont = new CPDF_CIDFont; |
| 470 pFont->Initialize(); | |
| 471 pFont->m_FontType = PDFFONT_CIDFONT; | |
| 472 } else { | 458 } else { |
| 473 pFont = new CPDF_Type1Font; | 459 pFont = new CPDF_Type1Font; |
| 474 pFont->Initialize(); | |
| 475 pFont->m_FontType = PDFFONT_TYPE1; | |
| 476 } | 460 } |
| 477 pFont->m_pFontDict = pFontDict; | 461 pFont->m_pFontDict = pFontDict; |
| 478 pFont->m_pDocument = pDoc; | 462 pFont->m_pDocument = pDoc; |
| 479 if (!pFont->Load()) { | 463 if (!pFont->Load()) { |
| 480 delete pFont; | 464 delete pFont; |
| 481 return NULL; | 465 return NULL; |
| 482 } | 466 } |
| 483 return pFont; | 467 return pFont; |
| 484 } | 468 } |
| 485 FX_BOOL CPDF_Font::Load() | 469 FX_BOOL CPDF_Font::Load() |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 } | 810 } |
| 827 if (m_pFontFile != NULL) { | 811 if (m_pFontFile != NULL) { |
| 828 return FALSE; | 812 return FALSE; |
| 829 } | 813 } |
| 830 if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) { | 814 if (((CPDF_Type1Font*)this)->GetBase14Font() < 0) { |
| 831 return FALSE; | 815 return FALSE; |
| 832 } | 816 } |
| 833 return TRUE; | 817 return TRUE; |
| 834 } | 818 } |
| 835 extern FX_LPCSTR PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcod
e); | 819 extern FX_LPCSTR PDF_CharNameFromPredefinedCharSet(int encoding, FX_BYTE charcod
e); |
| 836 CPDF_SimpleFont::CPDF_SimpleFont() | 820 CPDF_SimpleFont::CPDF_SimpleFont(int fonttype) : CPDF_Font(fonttype) |
| 837 { | 821 { |
| 838 FXSYS_memset8(m_CharBBox, 0xff, sizeof m_CharBBox); | 822 FXSYS_memset8(m_CharBBox, 0xff, sizeof m_CharBBox); |
| 839 FXSYS_memset8(m_CharWidth, 0xff, sizeof m_CharWidth); | 823 FXSYS_memset8(m_CharWidth, 0xff, sizeof m_CharWidth); |
| 840 FXSYS_memset8(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); | 824 FXSYS_memset8(m_GlyphIndex, 0xff, sizeof m_GlyphIndex); |
| 841 FXSYS_memset8(m_ExtGID, 0xff, sizeof m_ExtGID); | 825 FXSYS_memset8(m_ExtGID, 0xff, sizeof m_ExtGID); |
| 842 m_pCharNames = NULL; | 826 m_pCharNames = NULL; |
| 843 m_BaseEncoding = PDFFONT_ENCODING_BUILTIN; | 827 m_BaseEncoding = PDFFONT_ENCODING_BUILTIN; |
| 844 } | 828 } |
| 845 CPDF_SimpleFont::~CPDF_SimpleFont() | 829 CPDF_SimpleFont::~CPDF_SimpleFont() |
| 846 { | 830 { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 width = m_CharWidth[i]; | 1008 width = m_CharWidth[i]; |
| 1025 } else if (width != m_CharWidth[i]) { | 1009 } else if (width != m_CharWidth[i]) { |
| 1026 break; | 1010 break; |
| 1027 } | 1011 } |
| 1028 } | 1012 } |
| 1029 if (i == 256 && width) { | 1013 if (i == 256 && width) { |
| 1030 m_Flags |= PDFFONT_FIXEDPITCH; | 1014 m_Flags |= PDFFONT_FIXEDPITCH; |
| 1031 } | 1015 } |
| 1032 } | 1016 } |
| 1033 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); | 1017 int weight = m_StemV < 140 ? m_StemV * 5 : (m_StemV * 4 + 140); |
| 1034 m_Font.LoadSubst(m_BaseFont, m_FontType == PDFFONT_TRUETYPE, m_Flags, weight
, m_ItalicAngle, 0); | 1018 m_Font.LoadSubst(m_BaseFont, IsFontType(PDFFONT_TRUETYPE), m_Flags, weight,
m_ItalicAngle, 0); |
| 1035 if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { | 1019 if (m_Font.m_pSubstFont->m_SubstFlags & FXFONT_SUBST_NONSYMBOL) { |
| 1036 } | 1020 } |
| 1037 } | 1021 } |
| 1038 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const | 1022 FX_BOOL CPDF_SimpleFont::IsUnicodeCompatible() const |
| 1039 { | 1023 { |
| 1040 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && m_BaseEncoding != PDFFO
NT_ENCODING_ADOBE_SYMBOL && | 1024 return m_BaseEncoding != PDFFONT_ENCODING_BUILTIN && m_BaseEncoding != PDFFO
NT_ENCODING_ADOBE_SYMBOL && |
| 1041 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; | 1025 m_BaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS; |
| 1042 } | 1026 } |
| 1043 CPDF_Type1Font::CPDF_Type1Font() | 1027 CPDF_Type1Font::CPDF_Type1Font() : CPDF_SimpleFont(PDFFONT_TYPE1) |
| 1044 { | 1028 { |
| 1045 m_Base14Font = -1; | 1029 m_Base14Font = -1; |
| 1046 } | 1030 } |
| 1047 FX_BOOL CPDF_Type1Font::_Load() | 1031 FX_BOOL CPDF_Type1Font::_Load() |
| 1048 { | 1032 { |
| 1049 m_Base14Font = _PDF_GetStandardFontName(m_BaseFont); | 1033 m_Base14Font = _PDF_GetStandardFontName(m_BaseFont); |
| 1050 if (m_Base14Font >= 0) { | 1034 if (m_Base14Font >= 0) { |
| 1051 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescript
or")); | 1035 CPDF_Dictionary* pFontDesc = m_pFontDict->GetDict(FX_BSTRC("FontDescript
or")); |
| 1052 if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("Flags"))) { | 1036 if (pFontDesc && pFontDesc->KeyExist(FX_BSTRC("Flags"))) { |
| 1053 m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags")); | 1037 m_Flags = pFontDesc->GetInteger(FX_BSTRC("Flags")); |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 for (int i = 0; i < 256; i ++) { | 1409 for (int i = 0; i < 256; i ++) { |
| 1426 if (pStandard[i] == m_Unicodes[i]) { | 1410 if (pStandard[i] == m_Unicodes[i]) { |
| 1427 continue; | 1411 continue; |
| 1428 } | 1412 } |
| 1429 pDiff->Add(CPDF_Number::Create(i)); | 1413 pDiff->Add(CPDF_Number::Create(i)); |
| 1430 pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); | 1414 pDiff->Add(CPDF_Name::Create(PDF_AdobeNameFromUnicode(m_Unicodes[i]))); |
| 1431 } | 1415 } |
| 1432 pDict->SetAt(FX_BSTRC("Differences"), pDiff); | 1416 pDict->SetAt(FX_BSTRC("Differences"), pDiff); |
| 1433 return pDict; | 1417 return pDict; |
| 1434 } | 1418 } |
| 1435 CPDF_TrueTypeFont::CPDF_TrueTypeFont() | 1419 CPDF_TrueTypeFont::CPDF_TrueTypeFont() : CPDF_SimpleFont(PDFFONT_TRUETYPE) |
| 1436 { | 1420 { |
| 1437 } | 1421 } |
| 1438 FX_BOOL CPDF_TrueTypeFont::_Load() | 1422 FX_BOOL CPDF_TrueTypeFont::_Load() |
| 1439 { | 1423 { |
| 1440 return LoadCommon(); | 1424 return LoadCommon(); |
| 1441 } | 1425 } |
| 1442 extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode); | 1426 extern FX_DWORD FT_CharCodeFromUnicode(int encoding, FX_WCHAR unicode); |
| 1443 void CPDF_TrueTypeFont::LoadGlyphMap() | 1427 void CPDF_TrueTypeFont::LoadGlyphMap() |
| 1444 { | 1428 { |
| 1445 if (m_Font.m_Face == NULL) { | 1429 if (m_Font.m_Face == NULL) { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 } | 1591 } |
| 1608 } | 1592 } |
| 1609 if (bGotOne) { | 1593 if (bGotOne) { |
| 1610 return; | 1594 return; |
| 1611 } | 1595 } |
| 1612 } | 1596 } |
| 1613 for (int charcode = 0; charcode < 256; charcode ++) { | 1597 for (int charcode = 0; charcode < 256; charcode ++) { |
| 1614 m_GlyphIndex[charcode] = charcode; | 1598 m_GlyphIndex[charcode] = charcode; |
| 1615 } | 1599 } |
| 1616 } | 1600 } |
| 1617 CPDF_Type3Font::CPDF_Type3Font() | 1601 CPDF_Type3Font::CPDF_Type3Font() : CPDF_SimpleFont(PDFFONT_TYPE3) |
| 1618 { | 1602 { |
| 1619 m_pPageResources = NULL; | 1603 m_pPageResources = NULL; |
| 1620 FXSYS_memset32(m_CharWidthL, 0, sizeof m_CharWidthL); | 1604 FXSYS_memset32(m_CharWidthL, 0, sizeof m_CharWidthL); |
| 1621 } | 1605 } |
| 1622 CPDF_Type3Font::~CPDF_Type3Font() | 1606 CPDF_Type3Font::~CPDF_Type3Font() |
| 1623 { | 1607 { |
| 1624 FX_POSITION pos = m_CacheMap.GetStartPosition(); | 1608 FX_POSITION pos = m_CacheMap.GetStartPosition(); |
| 1625 while (pos) { | 1609 while (pos) { |
| 1626 FX_LPVOID key, value; | 1610 FX_LPVOID key, value; |
| 1627 m_CacheMap.GetNextAssoc(pos, key, value); | 1611 m_CacheMap.GetNextAssoc(pos, key, value); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 } | 1746 } |
| 1763 CPDF_Type3Char::~CPDF_Type3Char() | 1747 CPDF_Type3Char::~CPDF_Type3Char() |
| 1764 { | 1748 { |
| 1765 if (m_pForm) { | 1749 if (m_pForm) { |
| 1766 delete m_pForm; | 1750 delete m_pForm; |
| 1767 } | 1751 } |
| 1768 if (m_pBitmap) { | 1752 if (m_pBitmap) { |
| 1769 delete m_pBitmap; | 1753 delete m_pBitmap; |
| 1770 } | 1754 } |
| 1771 } | 1755 } |
| OLD | NEW |