| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" | 7 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" | 9 #include "core/fpdfapi/fpdf_cmaps/cmap_int.h" |
| 10 #include "core/fpdfapi/fpdf_font/font_int.h" | 10 #include "core/fpdfapi/fpdf_font/font_int.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 int CompareCIDTransform(const void* key, const void* element) { | 199 int CompareCIDTransform(const void* key, const void* element) { |
| 200 uint16_t CID = *static_cast<const uint16_t*>(key); | 200 uint16_t CID = *static_cast<const uint16_t*>(key); |
| 201 return CID - static_cast<const struct CIDTransform*>(element)->CID; | 201 return CID - static_cast<const struct CIDTransform*>(element)->CID; |
| 202 } | 202 } |
| 203 | 203 |
| 204 } // namespace | 204 } // namespace |
| 205 | 205 |
| 206 CPDF_CIDFont::CPDF_CIDFont() | 206 CPDF_CIDFont::CPDF_CIDFont() |
| 207 : m_pCMap(nullptr), | 207 : m_pCMap(nullptr), |
| 208 m_pAllocatedCMap(nullptr), | |
| 209 m_pCID2UnicodeMap(nullptr), | 208 m_pCID2UnicodeMap(nullptr), |
| 210 m_pCIDToGIDMap(nullptr), | |
| 211 m_bCIDIsGID(FALSE), | 209 m_bCIDIsGID(FALSE), |
| 212 m_pAnsiWidths(nullptr), | 210 m_bAnsiWidthsFixed(false), |
| 213 m_bAdobeCourierStd(FALSE), | 211 m_bAdobeCourierStd(FALSE) {} |
| 214 m_pTTGSUBTable(nullptr) {} | |
| 215 | 212 |
| 216 CPDF_CIDFont::~CPDF_CIDFont() { | 213 CPDF_CIDFont::~CPDF_CIDFont() {} |
| 217 if (m_pAnsiWidths) { | |
| 218 FX_Free(m_pAnsiWidths); | |
| 219 } | |
| 220 delete m_pAllocatedCMap; | |
| 221 delete m_pCIDToGIDMap; | |
| 222 delete m_pTTGSUBTable; | |
| 223 } | |
| 224 | 214 |
| 225 bool CPDF_CIDFont::IsCIDFont() const { | 215 bool CPDF_CIDFont::IsCIDFont() const { |
| 226 return true; | 216 return true; |
| 227 } | 217 } |
| 228 | 218 |
| 229 const CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() const { | 219 const CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() const { |
| 230 return this; | 220 return this; |
| 231 } | 221 } |
| 232 | 222 |
| 233 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() { | 223 CPDF_CIDFont* CPDF_CIDFont::AsCIDFont() { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 m_bType1 = (subtype == "CIDFontType0"); | 371 m_bType1 = (subtype == "CIDFontType0"); |
| 382 | 372 |
| 383 if (pEncoding->IsName()) { | 373 if (pEncoding->IsName()) { |
| 384 CFX_ByteString cmap = pEncoding->GetString(); | 374 CFX_ByteString cmap = pEncoding->GetString(); |
| 385 m_pCMap = | 375 m_pCMap = |
| 386 CPDF_ModuleMgr::Get() | 376 CPDF_ModuleMgr::Get() |
| 387 ->GetPageModule() | 377 ->GetPageModule() |
| 388 ->GetFontGlobals() | 378 ->GetFontGlobals() |
| 389 ->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1); | 379 ->m_CMapManager.GetPredefinedCMap(cmap, m_pFontFile && m_bType1); |
| 390 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { | 380 } else if (CPDF_Stream* pStream = pEncoding->AsStream()) { |
| 391 m_pAllocatedCMap = m_pCMap = new CPDF_CMap; | 381 m_pCMap = new CPDF_CMap; |
| 382 m_pAllocatedCMap.reset(m_pCMap); |
| 392 CPDF_StreamAcc acc; | 383 CPDF_StreamAcc acc; |
| 393 acc.LoadAllData(pStream, FALSE); | 384 acc.LoadAllData(pStream, FALSE); |
| 394 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); | 385 m_pCMap->LoadEmbedded(acc.GetData(), acc.GetSize()); |
| 395 } else { | 386 } else { |
| 396 return FALSE; | 387 return FALSE; |
| 397 } | 388 } |
| 398 if (!m_pCMap) { | 389 if (!m_pCMap) { |
| 399 return FALSE; | 390 return FALSE; |
| 400 } | 391 } |
| 401 m_Charset = m_pCMap->m_Charset; | 392 m_Charset = m_pCMap->m_Charset; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 428 LoadMetricsArray(pWidthArray, m_WidthList, 1); | 419 LoadMetricsArray(pWidthArray, m_WidthList, 1); |
| 429 } | 420 } |
| 430 if (!IsEmbedded()) { | 421 if (!IsEmbedded()) { |
| 431 LoadSubstFont(); | 422 LoadSubstFont(); |
| 432 } | 423 } |
| 433 if (1) { | 424 if (1) { |
| 434 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { | 425 if (m_pFontFile || (GetSubstFont()->m_SubstFlags & FXFONT_SUBST_EXACT)) { |
| 435 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectBy("CIDToGIDMap"); | 426 CPDF_Object* pmap = pCIDFontDict->GetDirectObjectBy("CIDToGIDMap"); |
| 436 if (pmap) { | 427 if (pmap) { |
| 437 if (CPDF_Stream* pStream = pmap->AsStream()) { | 428 if (CPDF_Stream* pStream = pmap->AsStream()) { |
| 438 m_pCIDToGIDMap = new CPDF_StreamAcc; | 429 m_pStreamAcc.reset(new CPDF_StreamAcc); |
| 439 m_pCIDToGIDMap->LoadAllData(pStream, FALSE); | 430 m_pStreamAcc->LoadAllData(pStream, FALSE); |
| 440 } else if (pmap->GetString() == "Identity") { | 431 } else if (pmap->GetString() == "Identity") { |
| 441 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 432 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 442 if (m_pFontFile) { | 433 if (m_pFontFile) { |
| 443 m_bCIDIsGID = TRUE; | 434 m_bCIDIsGID = TRUE; |
| 444 } | 435 } |
| 445 #else | 436 #else |
| 446 m_bCIDIsGID = TRUE; | 437 m_bCIDIsGID = TRUE; |
| 447 #endif | 438 #endif |
| 448 } | 439 } |
| 449 } | 440 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 rect_f.Transform(&matrix); | 524 rect_f.Transform(&matrix); |
| 534 rect = rect_f.GetOutterRect(); | 525 rect = rect_f.GetOutterRect(); |
| 535 } | 526 } |
| 536 } | 527 } |
| 537 if (charcode < 256) | 528 if (charcode < 256) |
| 538 m_CharBBox[charcode] = rect.ToSmallRect(); | 529 m_CharBBox[charcode] = rect.ToSmallRect(); |
| 539 | 530 |
| 540 return rect; | 531 return rect; |
| 541 } | 532 } |
| 542 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode, int level) { | 533 int CPDF_CIDFont::GetCharWidthF(uint32_t charcode, int level) { |
| 543 if (m_pAnsiWidths && charcode < 0x80) { | 534 if (charcode < 0x80 && m_bAnsiWidthsFixed) |
| 544 return m_pAnsiWidths[charcode]; | 535 return charcode >= 32 && charcode < 127 ? 500 : 0; |
| 545 } | 536 |
| 546 uint16_t cid = CIDFromCharCode(charcode); | 537 uint16_t cid = CIDFromCharCode(charcode); |
| 547 int size = m_WidthList.GetSize(); | 538 int size = m_WidthList.GetSize(); |
| 548 uint32_t* list = m_WidthList.GetData(); | 539 uint32_t* list = m_WidthList.GetData(); |
| 549 for (int i = 0; i < size; i += 3) { | 540 for (int i = 0; i < size; i += 3) { |
| 550 if (cid >= list[i] && cid <= list[i + 1]) { | 541 if (cid >= list[i] && cid <= list[i + 1]) { |
| 551 return (int)list[i + 2]; | 542 return (int)list[i + 2]; |
| 552 } | 543 } |
| 553 } | 544 } |
| 554 return m_DefaultWidth; | 545 return m_DefaultWidth; |
| 555 } | 546 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 unsigned long length = 0; | 604 unsigned long length = 0; |
| 614 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, | 605 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, |
| 615 NULL, &length); | 606 NULL, &length); |
| 616 if (!error) { | 607 if (!error) { |
| 617 m_Font.SetSubData(FX_Alloc(uint8_t, length)); | 608 m_Font.SetSubData(FX_Alloc(uint8_t, length)); |
| 618 } | 609 } |
| 619 } | 610 } |
| 620 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, | 611 int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, |
| 621 m_Font.GetSubData(), NULL); | 612 m_Font.GetSubData(), NULL); |
| 622 if (!error && m_Font.GetSubData()) { | 613 if (!error && m_Font.GetSubData()) { |
| 623 m_pTTGSUBTable = new CFX_CTTGSUBTable; | 614 m_pTTGSUBTable.reset(new CFX_CTTGSUBTable); |
| 624 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); | 615 m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); |
| 625 uint32_t vindex = 0; | 616 uint32_t vindex = 0; |
| 626 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); | 617 m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); |
| 627 if (vindex) { | 618 if (vindex) { |
| 628 index = vindex; | 619 index = vindex; |
| 629 if (pVertGlyph) { | 620 if (pVertGlyph) { |
| 630 *pVertGlyph = TRUE; | 621 *pVertGlyph = TRUE; |
| 631 } | 622 } |
| 632 } | 623 } |
| 633 } | 624 } |
| 634 return index; | 625 return index; |
| 635 } | 626 } |
| 636 if (pVertGlyph) { | 627 if (pVertGlyph) { |
| 637 *pVertGlyph = FALSE; | 628 *pVertGlyph = FALSE; |
| 638 } | 629 } |
| 639 return index; | 630 return index; |
| 640 } | 631 } |
| 641 int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { | 632 int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { |
| 642 if (pVertGlyph) { | 633 if (pVertGlyph) { |
| 643 *pVertGlyph = FALSE; | 634 *pVertGlyph = FALSE; |
| 644 } | 635 } |
| 645 if (!m_pFontFile && !m_pCIDToGIDMap) { | 636 if (!m_pFontFile && !m_pStreamAcc) { |
| 646 uint16_t cid = CIDFromCharCode(charcode); | 637 uint16_t cid = CIDFromCharCode(charcode); |
| 647 FX_WCHAR unicode = 0; | 638 FX_WCHAR unicode = 0; |
| 648 if (m_bCIDIsGID) { | 639 if (m_bCIDIsGID) { |
| 649 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 640 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
| 650 return cid; | 641 return cid; |
| 651 #else | 642 #else |
| 652 if (m_Flags & PDFFONT_SYMBOLIC) { | 643 if (m_Flags & PDFFONT_SYMBOLIC) { |
| 653 return cid; | 644 return cid; |
| 654 } | 645 } |
| 655 CFX_WideString uni_str = UnicodeFromCharCode(charcode); | 646 CFX_WideString uni_str = UnicodeFromCharCode(charcode); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 return -1; | 739 return -1; |
| 749 return index; | 740 return index; |
| 750 } | 741 } |
| 751 return unicode; | 742 return unicode; |
| 752 } | 743 } |
| 753 if (!m_Font.GetFace()) | 744 if (!m_Font.GetFace()) |
| 754 return -1; | 745 return -1; |
| 755 | 746 |
| 756 uint16_t cid = CIDFromCharCode(charcode); | 747 uint16_t cid = CIDFromCharCode(charcode); |
| 757 if (m_bType1) { | 748 if (m_bType1) { |
| 758 if (!m_pCIDToGIDMap) { | 749 if (!m_pStreamAcc) { |
| 759 return cid; | 750 return cid; |
| 760 } | 751 } |
| 761 } else { | 752 } else { |
| 762 if (!m_pCIDToGIDMap) { | 753 if (!m_pStreamAcc) { |
| 763 if (m_pFontFile && !m_pCMap->m_pMapping) | 754 if (m_pFontFile && !m_pCMap->m_pMapping) |
| 764 return cid; | 755 return cid; |
| 765 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || | 756 if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || |
| 766 !FXFT_Get_Face_Charmap(m_Font.GetFace())) { | 757 !FXFT_Get_Face_Charmap(m_Font.GetFace())) { |
| 767 return cid; | 758 return cid; |
| 768 } | 759 } |
| 769 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) == | 760 if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) == |
| 770 FXFT_ENCODING_UNICODE) { | 761 FXFT_ENCODING_UNICODE) { |
| 771 CFX_WideString unicode_str = UnicodeFromCharCode(charcode); | 762 CFX_WideString unicode_str = UnicodeFromCharCode(charcode); |
| 772 if (unicode_str.IsEmpty()) { | 763 if (unicode_str.IsEmpty()) { |
| 773 return -1; | 764 return -1; |
| 774 } | 765 } |
| 775 charcode = unicode_str.GetAt(0); | 766 charcode = unicode_str.GetAt(0); |
| 776 } | 767 } |
| 777 return GetGlyphIndex(charcode, pVertGlyph); | 768 return GetGlyphIndex(charcode, pVertGlyph); |
| 778 } | 769 } |
| 779 } | 770 } |
| 780 uint32_t byte_pos = cid * 2; | 771 uint32_t byte_pos = cid * 2; |
| 781 if (byte_pos + 2 > m_pCIDToGIDMap->GetSize()) | 772 if (byte_pos + 2 > m_pStreamAcc->GetSize()) |
| 782 return -1; | 773 return -1; |
| 783 | 774 |
| 784 const uint8_t* pdata = m_pCIDToGIDMap->GetData() + byte_pos; | 775 const uint8_t* pdata = m_pStreamAcc->GetData() + byte_pos; |
| 785 return pdata[0] * 256 + pdata[1]; | 776 return pdata[0] * 256 + pdata[1]; |
| 786 } | 777 } |
| 787 uint32_t CPDF_CIDFont::GetNextChar(const FX_CHAR* pString, | 778 uint32_t CPDF_CIDFont::GetNextChar(const FX_CHAR* pString, |
| 788 int nStrLen, | 779 int nStrLen, |
| 789 int& offset) const { | 780 int& offset) const { |
| 790 return m_pCMap->GetNextChar(pString, nStrLen, offset); | 781 return m_pCMap->GetNextChar(pString, nStrLen, offset); |
| 791 } | 782 } |
| 792 int CPDF_CIDFont::GetCharSize(uint32_t charcode) const { | 783 int CPDF_CIDFont::GetCharSize(uint32_t charcode) const { |
| 793 return m_pCMap->GetCharSize(charcode); | 784 return m_pCMap->GetCharSize(charcode); |
| 794 } | 785 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 m_Charset = CIDSET_GB1; | 868 m_Charset = CIDSET_GB1; |
| 878 m_bType1 = FALSE; | 869 m_bType1 = FALSE; |
| 879 m_pCMap = CPDF_ModuleMgr::Get() | 870 m_pCMap = CPDF_ModuleMgr::Get() |
| 880 ->GetPageModule() | 871 ->GetPageModule() |
| 881 ->GetFontGlobals() | 872 ->GetFontGlobals() |
| 882 ->m_CMapManager.GetPredefinedCMap("GBK-EUC-H", FALSE); | 873 ->m_CMapManager.GetPredefinedCMap("GBK-EUC-H", FALSE); |
| 883 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get() | 874 m_pCID2UnicodeMap = CPDF_ModuleMgr::Get() |
| 884 ->GetPageModule() | 875 ->GetPageModule() |
| 885 ->GetFontGlobals() | 876 ->GetFontGlobals() |
| 886 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE); | 877 ->m_CMapManager.GetCID2UnicodeMap(m_Charset, FALSE); |
| 887 if (!IsEmbedded()) { | 878 if (!IsEmbedded()) |
| 888 LoadSubstFont(); | 879 LoadSubstFont(); |
| 889 } | 880 |
| 890 CheckFontMetrics(); | 881 CheckFontMetrics(); |
| 891 m_DefaultWidth = 1000; | 882 m_DefaultWidth = 1000; |
| 892 m_pAnsiWidths = FX_Alloc(uint16_t, 128); | 883 m_bAnsiWidthsFixed = true; |
| 893 for (int i = 32; i < 127; i++) { | |
| 894 m_pAnsiWidths[i] = 500; | |
| 895 } | |
| 896 return TRUE; | 884 return TRUE; |
| 897 } | 885 } |
| 898 | 886 |
| 899 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { | 887 const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const { |
| 900 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 888 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
| 901 return nullptr; | 889 return nullptr; |
| 902 | 890 |
| 903 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( | 891 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( |
| 904 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), | 892 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), |
| 905 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); | 893 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); |
| 906 return found ? &found->a : nullptr; | 894 return found ? &found->a : nullptr; |
| 907 } | 895 } |
| OLD | NEW |