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

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

Issue 1405253007: 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_pageobj.h" 9 #include "../../../include/fpdfapi/fpdf_pageobj.h"
10 #include "../../../include/fpdfapi/fpdf_resource.h" 10 #include "../../../include/fpdfapi/fpdf_resource.h"
11 #include "../../../include/fxcrt/fx_ext.h"
11 #include "../../../include/fxge/fx_freetype.h" 12 #include "../../../include/fxge/fx_freetype.h"
12 #include "../fpdf_page/pageint.h" 13 #include "../fpdf_page/pageint.h"
13 #include "font_int.h" 14 #include "font_int.h"
14 15
15 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { 16 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) {
16 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { 17 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
17 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == 18 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) ==
18 platform_id && 19 platform_id &&
19 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) == 20 FXFT_Get_Charmap_EncodingID(FXFT_Get_Face_Charmaps(face)[i]) ==
20 encoding_id) { 21 encoding_id) {
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { 505 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) {
505 for (const auto& pair : m_Map) { 506 for (const auto& pair : m_Map) {
506 if (pair.second == unicode) 507 if (pair.second == unicode)
507 return pair.first; 508 return pair.first;
508 } 509 }
509 return 0; 510 return 0;
510 } 511 }
511 static FX_DWORD _StringToCode(const CFX_ByteStringC& str) { 512 static FX_DWORD _StringToCode(const CFX_ByteStringC& str) {
512 const FX_CHAR* buf = str.GetCStr(); 513 const FX_CHAR* buf = str.GetCStr();
513 int len = str.GetLength(); 514 int len = str.GetLength();
514 if (len == 0) { 515 if (len == 0)
515 return 0; 516 return 0;
516 } 517
517 int result = 0; 518 int result = 0;
518 if (buf[0] == '<') { 519 if (buf[0] == '<') {
519 for (int i = 1; i < len; i++) { 520 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i)
520 int digit; 521 result = result * 16 + FXSYS_toHexDigit(buf[i]);
521 if (buf[i] >= '0' && buf[i] <= '9') {
522 digit = buf[i] - '0';
523 } else if (buf[i] >= 'a' && buf[i] <= 'f') {
524 digit = buf[i] - 'a' + 10;
525 } else if (buf[i] >= 'A' && buf[i] <= 'F') {
526 digit = buf[i] - 'A' + 10;
527 } else {
528 break;
529 }
530 result = result * 16 + digit;
531 }
532 return result; 522 return result;
533 } 523 }
534 for (int i = 0; i < len; i++) { 524
535 if (buf[i] < '0' || buf[i] > '9') { 525 for (int i = 0; i < len && std::isdigit(buf[i]); ++i)
536 break; 526 result = result * 10 + FXSYS_toDecimalDigit(buf[i]);
537 } 527
538 result = result * 10 + buf[i] - '0';
539 }
540 return result; 528 return result;
541 } 529 }
542 static CFX_WideString _StringDataAdd(CFX_WideString str) { 530 static CFX_WideString _StringDataAdd(CFX_WideString str) {
543 CFX_WideString ret; 531 CFX_WideString ret;
544 int len = str.GetLength(); 532 int len = str.GetLength();
545 FX_WCHAR value = 1; 533 FX_WCHAR value = 1;
546 for (int i = len - 1; i >= 0; --i) { 534 for (int i = len - 1; i >= 0; --i) {
547 FX_WCHAR ch = str[i] + value; 535 FX_WCHAR ch = str[i] + value;
548 if (ch < str[i]) { 536 if (ch < str[i]) {
549 ret.Insert(0, 0); 537 ret.Insert(0, 0);
550 } else { 538 } else {
551 ret.Insert(0, ch); 539 ret.Insert(0, ch);
552 value = 0; 540 value = 0;
553 } 541 }
554 } 542 }
555 if (value) { 543 if (value) {
556 ret.Insert(0, value); 544 ret.Insert(0, value);
557 } 545 }
558 return ret; 546 return ret;
559 } 547 }
560 static CFX_WideString _StringToWideString(const CFX_ByteStringC& str) { 548 static CFX_WideString _StringToWideString(const CFX_ByteStringC& str) {
561 const FX_CHAR* buf = str.GetCStr(); 549 const FX_CHAR* buf = str.GetCStr();
562 int len = str.GetLength(); 550 int len = str.GetLength();
563 if (len == 0) { 551 if (len == 0)
564 return CFX_WideString(); 552 return CFX_WideString();
565 } 553
566 CFX_WideString result; 554 CFX_WideString result;
567 if (buf[0] == '<') { 555 if (buf[0] == '<') {
568 int byte_pos = 0; 556 int byte_pos = 0;
569 FX_WCHAR ch = 0; 557 FX_WCHAR ch = 0;
570 for (int i = 1; i < len; i++) { 558 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) {
571 int digit; 559 ch = ch * 16 + FXSYS_toHexDigit(buf[i]);
572 if (buf[i] >= '0' && buf[i] <= '9') {
573 digit = buf[i] - '0';
574 } else if (buf[i] >= 'a' && buf[i] <= 'f') {
575 digit = buf[i] - 'a' + 10;
576 } else if (buf[i] >= 'A' && buf[i] <= 'F') {
577 digit = buf[i] - 'A' + 10;
578 } else {
579 break;
580 }
581 ch = ch * 16 + digit;
582 byte_pos++; 560 byte_pos++;
583 if (byte_pos == 4) { 561 if (byte_pos == 4) {
584 result += ch; 562 result += ch;
585 byte_pos = 0; 563 byte_pos = 0;
586 ch = 0; 564 ch = 0;
587 } 565 }
588 } 566 }
589 return result; 567 return result;
590 } 568 }
591 if (buf[0] == '(') {
592 }
593 return result; 569 return result;
594 } 570 }
595 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { 571 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) {
596 CIDSet cid_set = CIDSET_UNKNOWN; 572 CIDSet cid_set = CIDSET_UNKNOWN;
597 CPDF_StreamAcc stream; 573 CPDF_StreamAcc stream;
598 stream.LoadAllData(pStream, FALSE); 574 stream.LoadAllData(pStream, FALSE);
599 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); 575 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize());
600 while (1) { 576 while (1) {
601 CFX_ByteStringC word = parser.GetWord(); 577 CFX_ByteStringC word = parser.GetWord();
602 if (word.IsEmpty()) { 578 if (word.IsEmpty()) {
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 CPDF_Type3Char::CPDF_Type3Char() { 1757 CPDF_Type3Char::CPDF_Type3Char() {
1782 m_pForm = NULL; 1758 m_pForm = NULL;
1783 m_pBitmap = NULL; 1759 m_pBitmap = NULL;
1784 m_bPageRequired = FALSE; 1760 m_bPageRequired = FALSE;
1785 m_bColored = FALSE; 1761 m_bColored = FALSE;
1786 } 1762 }
1787 CPDF_Type3Char::~CPDF_Type3Char() { 1763 CPDF_Type3Char::~CPDF_Type3Char() {
1788 delete m_pForm; 1764 delete m_pForm;
1789 delete m_pBitmap; 1765 delete m_pBitmap;
1790 } 1766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698