Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: core/src/fpdfapi/fpdf_font/fpdf_font_cid.cpp

Issue 1431683008: Revert "Revert "Revert "Cleanup some numeric code.""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "../../../include/fxge/fx_freetype.h" 10 #include "../../../include/fxge/fx_freetype.h"
12 #include "../../../include/fxge/fx_ge.h" 11 #include "../../../include/fxge/fx_ge.h"
13 #include "../fpdf_cmaps/cmap_int.h" 12 #include "../fpdf_cmaps/cmap_int.h"
14 #include "font_int.h" 13 #include "font_int.h"
15 14
16 namespace { 15 namespace {
17 16
18 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] = 17 const FX_CHAR* const g_CharsetNames[CIDSET_NUM_SETS] =
19 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"}; 18 {nullptr, "GB1", "CNS1", "Japan1", "Korea1", "UCS"};
20 19
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (CMap_GetCodeRange(range, m_LastWord, word)) { 691 if (CMap_GetCodeRange(range, m_LastWord, word)) {
693 m_CodeRanges.Add(range); 692 m_CodeRanges.Add(range);
694 } 693 }
695 } 694 }
696 m_CodeSeq++; 695 m_CodeSeq++;
697 } 696 }
698 } 697 }
699 m_LastWord = word; 698 m_LastWord = word;
700 } 699 }
701 700
702 // Static.
703 FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) { 701 FX_DWORD CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
704 int num = 0; 702 int num = 0;
705 if (word.GetAt(0) == '<') { 703 if (word.GetAt(0) == '<') {
706 for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) 704 for (int i = 1; i < word.GetLength(); i++) {
707 num = num * 16 + FXSYS_toHexDigit(word.GetAt(i)); 705 uint8_t digit = word.GetAt(i);
708 return num; 706 if (digit >= '0' && digit <= '9') {
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 }
709 } 724 }
710
711 for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i)
712 num = num * 10 + FXSYS_toDecimalDigit(word.GetAt(i));
713 return num; 725 return num;
714 } 726 }
715 727
716 // Static. 728 // Static.
717 bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range, 729 bool CPDF_CMapParser::CMap_GetCodeRange(CMap_CodeRange& range,
718 const CFX_ByteStringC& first, 730 const CFX_ByteStringC& first,
719 const CFX_ByteStringC& second) { 731 const CFX_ByteStringC& second) {
720 if (first.GetLength() == 0 || first.GetAt(0) != '<') 732 if (first.GetLength() == 0 || first.GetAt(0) != '<')
721 return false; 733 return false;
722 734
723 int i; 735 int i;
724 for (i = 1; i < first.GetLength(); ++i) { 736 for (i = 1; i < first.GetLength(); ++i) {
725 if (first.GetAt(i) == '>') { 737 if (first.GetAt(i) == '>') {
726 break; 738 break;
727 } 739 }
728 } 740 }
729 range.m_CharSize = (i - 1) / 2; 741 range.m_CharSize = (i - 1) / 2;
730 if (range.m_CharSize > 4) 742 if (range.m_CharSize > 4)
731 return false; 743 return false;
732 744
733 for (i = 0; i < range.m_CharSize; ++i) { 745 for (i = 0; i < range.m_CharSize; ++i) {
734 uint8_t digit1 = first.GetAt(i * 2 + 1); 746 uint8_t digit1 = first.GetAt(i * 2 + 1);
735 uint8_t digit2 = first.GetAt(i * 2 + 2); 747 uint8_t digit2 = first.GetAt(i * 2 + 2);
736 range.m_Lower[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); 748 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
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;
737 } 755 }
738 756
739 FX_DWORD size = second.GetLength(); 757 FX_DWORD size = second.GetLength();
740 for (i = 0; i < range.m_CharSize; ++i) { 758 for (i = 0; i < range.m_CharSize; ++i) {
741 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size) 759 uint8_t digit1 = ((FX_DWORD)i * 2 + 1 < size)
742 ? second.GetAt((FX_STRSIZE)i * 2 + 1) 760 ? second.GetAt((FX_STRSIZE)i * 2 + 1)
743 : '0'; 761 : '0';
744 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size) 762 uint8_t digit2 = ((FX_DWORD)i * 2 + 2 < size)
745 ? second.GetAt((FX_STRSIZE)i * 2 + 2) 763 ? second.GetAt((FX_STRSIZE)i * 2 + 2)
746 : '0'; 764 : '0';
747 range.m_Upper[i] = FXSYS_toHexDigit(digit1) * 16 + FXSYS_toHexDigit(digit2); 765 uint8_t byte = (digit1 >= '0' && digit1 <= '9')
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;
748 } 772 }
749 return true; 773 return true;
750 } 774 }
751 775
752 CPDF_CMap::CPDF_CMap() { 776 CPDF_CMap::CPDF_CMap() {
753 m_Charset = CIDSET_UNKNOWN; 777 m_Charset = CIDSET_UNKNOWN;
754 m_Coding = CIDCODING_UNKNOWN; 778 m_Coding = CIDCODING_UNKNOWN;
755 m_CodingScheme = TwoBytes; 779 m_CodingScheme = TwoBytes;
756 m_bVertical = 0; 780 m_bVertical = 0;
757 m_bLoaded = FALSE; 781 m_bLoaded = FALSE;
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 1745
1722 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const { 1746 const uint8_t* CPDF_CIDFont::GetCIDTransform(FX_WORD CID) const {
1723 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile) 1747 if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
1724 return nullptr; 1748 return nullptr;
1725 1749
1726 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch( 1750 const struct CIDTransform* found = (const struct CIDTransform*)FXSYS_bsearch(
1727 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs), 1751 &CID, g_Japan1_VertCIDs, FX_ArraySize(g_Japan1_VertCIDs),
1728 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform); 1752 sizeof(g_Japan1_VertCIDs[0]), CompareCIDTransform);
1729 return found ? &found->a : nullptr; 1753 return found ? &found->a : nullptr;
1730 } 1754 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_font/fpdf_font.cpp ('k') | core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698