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