| 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_module.h" | 7 #include "../../../include/fpdfapi/fpdf_module.h" |
| 8 #include "../../../include/fpdfapi/fpdf_page.h" | 8 #include "../../../include/fpdfapi/fpdf_page.h" |
| 9 #include "../../../include/fpdfapi/fpdf_resource.h" | 9 #include "../../../include/fpdfapi/fpdf_resource.h" |
| 10 #include "../../../include/fxcrt/fx_ext.h" |
| 10 #include "../../../include/fxge/fx_freetype.h" | 11 #include "../../../include/fxge/fx_freetype.h" |
| 11 #include "../../../include/fxge/fx_ge.h" | 12 #include "../../../include/fxge/fx_ge.h" |
| 12 #include "../fpdf_cmaps/cmap_int.h" | 13 #include "../fpdf_cmaps/cmap_int.h" |
| 13 #include "font_int.h" | 14 #include "font_int.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = | 18 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = |
| 18 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; | 19 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; |
| 19 | 20 |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 if (CMap_GetCodeRange(range, m_LastWord, word)) { | 692 if (CMap_GetCodeRange(range, m_LastWord, word)) { |
| 692 m_CodeRanges.Add(range); | 693 m_CodeRanges.Add(range); |
| 693 } | 694 } |
| 694 } | 695 } |
| 695 m_CodeSeq++; | 696 m_CodeSeq++; |
| 696 } | 697 } |
| 697 } | 698 } |
| 698 m_LastWord = word; | 699 m_LastWord = word; |
| 699 } | 700 } |
| 700 | 701 |
| 702 // Static. |
| 701 FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { | 703 FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { |
| 702 int num = 0; | 704 int num = 0; |
| 703 if (word.GetAt(0) == '<') { | 705 if (word.GetAt(0) == '<') { |
| 704 for (int i = 1; i < word.GetLength(); i++) { | 706 for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) |
| 705 uint8_t digit = word.GetAt(i); | 707 num = num * 16 + FXSYS_toHexDigit(word.GetAt(i)); |
| 706 if (digit >= '0' && digit <= '9') { | 708 return num; |
| 707 digit = digit - '0'; | |
| 708 } else if (digit >= 'a' && digit <= 'f') { | |
| 709 digit = digit - 'a' + 10; | |
| 710 } else if (digit >= 'A' && digit <= 'F') { | |
| 711 digit = digit - 'A' + 10; | |
| 712 } else { | |
| 713 return num; | |
| 714 } | |
| 715 num = num * 16 + digit; | |
| 716 } | |
| 717 } else { | |
| 718 for (int i = 0; i < word.GetLength(); i++) { | |
| 719 if (word.GetAt(i) < '0' || word.GetAt(i) > '9') { | |
| 720 return num; | |
| 721 } | |
| 722 num = num * 10 + word.GetAt(i) - '0'; | |
| 723 } | |
| 724 } | 709 } |
| 710 |
| 711 for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) |
| 712 num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i)); |
| 725 return num; | 713 return num; |
| 726 } | 714 } |
| 727 | 715 |
| 728 // Static. | 716 // Static. |
| 729 bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, | 717 bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, |
| 730 const CFX_ByteStringC& first, | 718 const CFX_ByteStringC& first, |
| 731 const CFX_ByteStringC& second) { | 719 const CFX_ByteStringC& second) { |
| 732 if (first.GetLength() == 0 || first.GetAt(0) != '<') | 720 if (first.GetLength() == 0 || first.GetAt(0) != '<') |
| 733 return false; | 721 return false; |
| 734 | 722 |
| 735 int i; | 723 int i; |
| 736 for (i = 1; i < first.GetLength(); ++i) { | 724 for (i = 1; i < first.GetLength(); ++i) { |
| 737 if (first.GetAt(i) == '>') { | 725 if (first.GetAt(i) == '>') { |
| 738 break; | 726 break; |
| 739 } | 727 } |
| 740 } | 728 } |
| 741 range.m_CharSize = (i - 1) / 2; | 729 range.m_CharSize = (i - 1) / 2; |
| 742 if (range.m_CharSize > 4) | 730 if (range.m_CharSize > 4) |
| 743 return false; | 731 return false; |
| 744 | 732 |
| 745 for (i = 0; i < range.m_CharSize; ++i) { | 733 for (i = 0; i < range.m_CharSize; ++i) { |
| 746 uint8_t digit1 = first.GetAt(i * 2 + 1); | 734 uint8_t digit1 = first.GetAt(i * 2 + 1); |
| 747 uint8_t digit2 = first.GetAt(i * 2 + 2); | 735 uint8_t digit2 = first.GetAt(i * 2 + 2); |
| 748 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | 736 range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); |
| 749 ? (digit1 - '0') | |
| 750 : ((digit1 & 0xdf) - 'A' + 10); | |
| 751 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') | |
| 752 ? (digit2 - '0') | |
| 753 : ((digit2 & 0xdf) - 'A' + 10)); | |
| 754 range.m_Lower[i] = byte; | |
| 755 } | 737 } |
| 756 | 738 |
| 757 FX_DWORD size = second.GetLength(); | 739 FX_DWORD size = second.GetLength(); |
| 758 for (i = 0; i < range.m_CharSize; ++i) { | 740 for (i = 0; i < range.m_CharSize; ++i) { |
| 759 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) | 741 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) |
| 760 ? second.GetAt((FX_STRSIZE)i * 2 + 1) | 742 ? second.GetAt((FX_STRSIZE)i * 2 + 1) |
| 761 : '0'; | 743 : '0'; |
| 762 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) | 744 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) |
| 763 ? second.GetAt((FX_STRSIZE)i * 2 + 2) | 745 ? second.GetAt((FX_STRSIZE)i * 2 + 2) |
| 764 : '0'; | 746 : '0'; |
| 765 uint8_t byte = (digit1 >= '0' && digit1 <= '9') | 747 range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); |
| 766 ? (digit1 - '0') | |
| 767 : ((digit1 & 0xdf) - 'A' + 10); | |
| 768 byte = byte * 16 + ((digit2 >= '0' && digit2 <= '9') | |
| 769 ? (digit2 - '0') | |
| 770 : ((digit2 & 0xdf) - 'A' + 10)); | |
| 771 range.m_Upper[i] = byte; | |
| 772 } | 748 } |
| 773 return true; | 749 return true; |
| 774 } | 750 } |
| 775 | 751 |
| 776 CPDF_CMap::CPDF_CMap() { | 752 CPDF_CMap::CPDF_CMap() { |
| 777 m_Charset = CIDSET_UNKNOWN; | 753 m_Charset = CIDSET_UNKNOWN; |
| 778 m_Coding = CIDCODING_UNKNOWN; | 754 m_Coding = CIDCODING_UNKNOWN; |
| 779 m_CodingScheme = TwoBytes; | 755 m_CodingScheme = TwoBytes; |
| 780 m_bVertical = 0; | 756 m_bVertical = 0; |
| 781 m_bLoaded = FALSE; | 757 m_bLoaded = FALSE; |
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 | 1721 |
| 1746 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { | 1722 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { |
| 1747 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) | 1723 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) |
| 1748 return nullptr; | 1724 return nullptr; |
| 1749 | 1725 |
| 1750 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( | 1726 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( |
| 1751 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), | 1727 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), |
| 1752 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); | 1728 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); |
| 1753 return found ? &found->a : nullptr; | 1729 return found ? &found->a : nullptr; |
| 1754 } | 1730 } |
| OLD | NEW |