| 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/src/fpdfapi/fpdf_page/pageint.h" | 9 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
| 10 #include "core/include/fpdfapi/fpdf_module.h" | 10 #include "core/include/fpdfapi/fpdf_module.h" |
| 11 #include "core/include/fpdfapi/fpdf_page.h" | 11 #include "core/include/fpdfapi/fpdf_page.h" |
| 12 #include "core/include/fpdfapi/fpdf_pageobj.h" | 12 #include "core/include/fpdfapi/fpdf_pageobj.h" |
| 13 #include "core/include/fpdfapi/fpdf_resource.h" | 13 #include "core/include/fpdfapi/fpdf_resource.h" |
| 14 #include "core/include/fxcrt/fx_ext.h" |
| 14 #include "core/include/fxge/fx_freetype.h" | 15 #include "core/include/fxge/fx_freetype.h" |
| 15 | 16 |
| 16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 17 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 17 #include "core/src/fxge/apple/apple_int.h" | 18 #include "core/src/fxge/apple/apple_int.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { | 21 FX_BOOL FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) { |
| 21 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { | 22 for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { |
| 22 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == | 23 if (FXFT_Get_Charmap_PlatformID(FXFT_Get_Face_Charmaps(face)[i]) == |
| 23 platform_id && | 24 platform_id && |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (pair.second == unicode) | 512 if (pair.second == unicode) |
| 512 return pair.first; | 513 return pair.first; |
| 513 } | 514 } |
| 514 return 0; | 515 return 0; |
| 515 } | 516 } |
| 516 | 517 |
| 517 // Static. | 518 // Static. |
| 518 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { | 519 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { |
| 519 const FX_CHAR* buf = str.GetCStr(); | 520 const FX_CHAR* buf = str.GetCStr(); |
| 520 int len = str.GetLength(); | 521 int len = str.GetLength(); |
| 521 if (len == 0) { | 522 if (len == 0) |
| 522 return 0; | 523 return 0; |
| 523 } | 524 |
| 524 int result = 0; | 525 int result = 0; |
| 525 if (buf[0] == '<') { | 526 if (buf[0] == '<') { |
| 526 for (int i = 1; i < len; i++) { | 527 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) |
| 527 int digit; | 528 result = result * 16 + FXSYS_toHexDigit(buf[i]); |
| 528 if (buf[i] >= '0' && buf[i] <= '9') { | |
| 529 digit = buf[i] - '0'; | |
| 530 } else if (buf[i] >= 'a' && buf[i] <= 'f') { | |
| 531 digit = buf[i] - 'a' + 10; | |
| 532 } else if (buf[i] >= 'A' && buf[i] <= 'F') { | |
| 533 digit = buf[i] - 'A' + 10; | |
| 534 } else { | |
| 535 break; | |
| 536 } | |
| 537 result = result * 16 + digit; | |
| 538 } | |
| 539 return result; | 529 return result; |
| 540 } | 530 } |
| 541 for (int i = 0; i < len; i++) { | 531 |
| 542 if (buf[i] < '0' || buf[i] > '9') { | 532 for (int i = 0; i < len && std::isdigit(buf[i]); ++i) |
| 543 break; | 533 result = result * 10 + FXSYS_toDecimalDigit(buf[i]); |
| 544 } | 534 |
| 545 result = result * 10 + buf[i] - '0'; | |
| 546 } | |
| 547 return result; | 535 return result; |
| 548 } | 536 } |
| 549 static CFX_WideString StringDataAdd(CFX_WideString str) { | 537 static CFX_WideString StringDataAdd(CFX_WideString str) { |
| 550 CFX_WideString ret; | 538 CFX_WideString ret; |
| 551 int len = str.GetLength(); | 539 int len = str.GetLength(); |
| 552 FX_WCHAR value = 1; | 540 FX_WCHAR value = 1; |
| 553 for (int i = len - 1; i >= 0; --i) { | 541 for (int i = len - 1; i >= 0; --i) { |
| 554 FX_WCHAR ch = str[i] + value; | 542 FX_WCHAR ch = str[i] + value; |
| 555 if (ch < str[i]) { | 543 if (ch < str[i]) { |
| 556 ret.Insert(0, 0); | 544 ret.Insert(0, 0); |
| 557 } else { | 545 } else { |
| 558 ret.Insert(0, ch); | 546 ret.Insert(0, ch); |
| 559 value = 0; | 547 value = 0; |
| 560 } | 548 } |
| 561 } | 549 } |
| 562 if (value) { | 550 if (value) { |
| 563 ret.Insert(0, value); | 551 ret.Insert(0, value); |
| 564 } | 552 } |
| 565 return ret; | 553 return ret; |
| 566 } | 554 } |
| 567 | 555 |
| 568 // Static. | 556 // Static. |
| 569 CFX_WideString CPDF_ToUnicodeMap::StringToWideString( | 557 CFX_WideString CPDF_ToUnicodeMap::StringToWideString( |
| 570 const CFX_ByteStringC& str) { | 558 const CFX_ByteStringC& str) { |
| 571 const FX_CHAR* buf = str.GetCStr(); | 559 const FX_CHAR* buf = str.GetCStr(); |
| 572 int len = str.GetLength(); | 560 int len = str.GetLength(); |
| 573 if (len == 0) { | 561 if (len == 0) |
| 574 return CFX_WideString(); | 562 return CFX_WideString(); |
| 575 } | 563 |
| 576 CFX_WideString result; | 564 CFX_WideString result; |
| 577 if (buf[0] == '<') { | 565 if (buf[0] == '<') { |
| 578 int byte_pos = 0; | 566 int byte_pos = 0; |
| 579 FX_WCHAR ch = 0; | 567 FX_WCHAR ch = 0; |
| 580 for (int i = 1; i < len; i++) { | 568 for (int i = 1; i < len && std::isxdigit(buf[i]); ++i) { |
| 581 int digit; | 569 ch = ch * 16 + FXSYS_toHexDigit(buf[i]); |
| 582 if (buf[i] >= '0' && buf[i] <= '9') { | |
| 583 digit = buf[i] - '0'; | |
| 584 } else if (buf[i] >= 'a' && buf[i] <= 'f') { | |
| 585 digit = buf[i] - 'a' + 10; | |
| 586 } else if (buf[i] >= 'A' && buf[i] <= 'F') { | |
| 587 digit = buf[i] - 'A' + 10; | |
| 588 } else { | |
| 589 break; | |
| 590 } | |
| 591 ch = ch * 16 + digit; | |
| 592 | |
| 593 byte_pos++; | 570 byte_pos++; |
| 594 if (byte_pos == 4) { | 571 if (byte_pos == 4) { |
| 595 result += ch; | 572 result += ch; |
| 596 byte_pos = 0; | 573 byte_pos = 0; |
| 597 ch = 0; | 574 ch = 0; |
| 598 } | 575 } |
| 599 } | 576 } |
| 600 return result; | 577 return result; |
| 601 } | 578 } |
| 602 if (buf[0] == '(') { | |
| 603 } | |
| 604 return result; | 579 return result; |
| 605 } | 580 } |
| 606 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { | 581 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { |
| 607 CIDSet cid_set = CIDSET_UNKNOWN; | 582 CIDSet cid_set = CIDSET_UNKNOWN; |
| 608 CPDF_StreamAcc stream; | 583 CPDF_StreamAcc stream; |
| 609 stream.LoadAllData(pStream, FALSE); | 584 stream.LoadAllData(pStream, FALSE); |
| 610 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); | 585 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); |
| 611 while (1) { | 586 while (1) { |
| 612 CFX_ByteStringC word = parser.GetWord(); | 587 CFX_ByteStringC word = parser.GetWord(); |
| 613 if (word.IsEmpty()) { | 588 if (word.IsEmpty()) { |
| (...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 rect = pChar->m_BBox; | 1764 rect = pChar->m_BBox; |
| 1790 } | 1765 } |
| 1791 | 1766 |
| 1792 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) | 1767 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) |
| 1793 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} | 1768 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} |
| 1794 | 1769 |
| 1795 CPDF_Type3Char::~CPDF_Type3Char() { | 1770 CPDF_Type3Char::~CPDF_Type3Char() { |
| 1796 delete m_pForm; | 1771 delete m_pForm; |
| 1797 delete m_pBitmap; | 1772 delete m_pBitmap; |
| 1798 } | 1773 } |
| OLD | NEW |