| 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_pageobj.h" | 9 #include "../../../include/fpdfapi/fpdf_pageobj.h" |
| 10 #include "../../../include/fpdfapi/fpdf_resource.h" | 10 #include "../../../include/fpdfapi/fpdf_resource.h" |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 501 } |
| 502 return CFX_WideString(); | 502 return CFX_WideString(); |
| 503 } | 503 } |
| 504 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { | 504 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { |
| 505 for (const auto& pair : m_Map) { | 505 for (const auto& pair : m_Map) { |
| 506 if (pair.second == unicode) | 506 if (pair.second == unicode) |
| 507 return pair.first; | 507 return pair.first; |
| 508 } | 508 } |
| 509 return 0; | 509 return 0; |
| 510 } | 510 } |
| 511 static FX_DWORD _StringToCode(const CFX_ByteStringC& str) { | 511 |
| 512 // Static. |
| 513 FX_DWORD CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { |
| 512 const FX_CHAR* buf = str.GetCStr(); | 514 const FX_CHAR* buf = str.GetCStr(); |
| 513 int len = str.GetLength(); | 515 int len = str.GetLength(); |
| 514 if (len == 0) { | 516 if (len == 0) { |
| 515 return 0; | 517 return 0; |
| 516 } | 518 } |
| 517 int result = 0; | 519 int result = 0; |
| 518 if (buf[0] == '<') { | 520 if (buf[0] == '<') { |
| 519 for (int i = 1; i < len; i++) { | 521 for (int i = 1; i < len; i++) { |
| 520 int digit; | 522 int digit; |
| 521 if (buf[i] >= '0' && buf[i] <= '9') { | 523 if (buf[i] >= '0' && buf[i] <= '9') { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 532 return result; | 534 return result; |
| 533 } | 535 } |
| 534 for (int i = 0; i < len; i++) { | 536 for (int i = 0; i < len; i++) { |
| 535 if (buf[i] < '0' || buf[i] > '9') { | 537 if (buf[i] < '0' || buf[i] > '9') { |
| 536 break; | 538 break; |
| 537 } | 539 } |
| 538 result = result * 10 + buf[i] - '0'; | 540 result = result * 10 + buf[i] - '0'; |
| 539 } | 541 } |
| 540 return result; | 542 return result; |
| 541 } | 543 } |
| 542 static CFX_WideString _StringDataAdd(CFX_WideString str) { | 544 static CFX_WideString StringDataAdd(CFX_WideString str) { |
| 543 CFX_WideString ret; | 545 CFX_WideString ret; |
| 544 int len = str.GetLength(); | 546 int len = str.GetLength(); |
| 545 FX_WCHAR value = 1; | 547 FX_WCHAR value = 1; |
| 546 for (int i = len - 1; i >= 0; --i) { | 548 for (int i = len - 1; i >= 0; --i) { |
| 547 FX_WCHAR ch = str[i] + value; | 549 FX_WCHAR ch = str[i] + value; |
| 548 if (ch < str[i]) { | 550 if (ch < str[i]) { |
| 549 ret.Insert(0, 0); | 551 ret.Insert(0, 0); |
| 550 } else { | 552 } else { |
| 551 ret.Insert(0, ch); | 553 ret.Insert(0, ch); |
| 552 value = 0; | 554 value = 0; |
| 553 } | 555 } |
| 554 } | 556 } |
| 555 if (value) { | 557 if (value) { |
| 556 ret.Insert(0, value); | 558 ret.Insert(0, value); |
| 557 } | 559 } |
| 558 return ret; | 560 return ret; |
| 559 } | 561 } |
| 560 static CFX_WideString _StringToWideString(const CFX_ByteStringC& str) { | 562 |
| 563 // Static. |
| 564 CFX_WideString CPDF_ToUnicodeMap::StringToWideString( |
| 565 const CFX_ByteStringC& str) { |
| 561 const FX_CHAR* buf = str.GetCStr(); | 566 const FX_CHAR* buf = str.GetCStr(); |
| 562 int len = str.GetLength(); | 567 int len = str.GetLength(); |
| 563 if (len == 0) { | 568 if (len == 0) { |
| 564 return CFX_WideString(); | 569 return CFX_WideString(); |
| 565 } | 570 } |
| 566 CFX_WideString result; | 571 CFX_WideString result; |
| 567 if (buf[0] == '<') { | 572 if (buf[0] == '<') { |
| 568 int byte_pos = 0; | 573 int byte_pos = 0; |
| 569 FX_WCHAR ch = 0; | 574 FX_WCHAR ch = 0; |
| 570 for (int i = 1; i < len; i++) { | 575 for (int i = 1; i < len; i++) { |
| 571 int digit; | 576 int digit; |
| 572 if (buf[i] >= '0' && buf[i] <= '9') { | 577 if (buf[i] >= '0' && buf[i] <= '9') { |
| 573 digit = buf[i] - '0'; | 578 digit = buf[i] - '0'; |
| 574 } else if (buf[i] >= 'a' && buf[i] <= 'f') { | 579 } else if (buf[i] >= 'a' && buf[i] <= 'f') { |
| 575 digit = buf[i] - 'a' + 10; | 580 digit = buf[i] - 'a' + 10; |
| 576 } else if (buf[i] >= 'A' && buf[i] <= 'F') { | 581 } else if (buf[i] >= 'A' && buf[i] <= 'F') { |
| 577 digit = buf[i] - 'A' + 10; | 582 digit = buf[i] - 'A' + 10; |
| 578 } else { | 583 } else { |
| 579 break; | 584 break; |
| 580 } | 585 } |
| 581 ch = ch * 16 + digit; | 586 ch = ch * 16 + digit; |
| 587 |
| 582 byte_pos++; | 588 byte_pos++; |
| 583 if (byte_pos == 4) { | 589 if (byte_pos == 4) { |
| 584 result += ch; | 590 result += ch; |
| 585 byte_pos = 0; | 591 byte_pos = 0; |
| 586 ch = 0; | 592 ch = 0; |
| 587 } | 593 } |
| 588 } | 594 } |
| 589 return result; | 595 return result; |
| 590 } | 596 } |
| 591 if (buf[0] == '(') { | 597 if (buf[0] == '(') { |
| 592 } | 598 } |
| 593 return result; | 599 return result; |
| 594 } | 600 } |
| 595 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { | 601 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { |
| 596 CIDSet cid_set = CIDSET_UNKNOWN; | 602 CIDSet cid_set = CIDSET_UNKNOWN; |
| 597 CPDF_StreamAcc stream; | 603 CPDF_StreamAcc stream; |
| 598 stream.LoadAllData(pStream, FALSE); | 604 stream.LoadAllData(pStream, FALSE); |
| 599 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); | 605 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); |
| 600 while (1) { | 606 while (1) { |
| 601 CFX_ByteStringC word = parser.GetWord(); | 607 CFX_ByteStringC word = parser.GetWord(); |
| 602 if (word.IsEmpty()) { | 608 if (word.IsEmpty()) { |
| 603 break; | 609 break; |
| 604 } | 610 } |
| 605 if (word == FX_BSTRC("beginbfchar")) { | 611 if (word == FX_BSTRC("beginbfchar")) { |
| 606 while (1) { | 612 while (1) { |
| 607 word = parser.GetWord(); | 613 word = parser.GetWord(); |
| 608 if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) { | 614 if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) { |
| 609 break; | 615 break; |
| 610 } | 616 } |
| 611 FX_DWORD srccode = _StringToCode(word); | 617 FX_DWORD srccode = StringToCode(word); |
| 612 word = parser.GetWord(); | 618 word = parser.GetWord(); |
| 613 CFX_WideString destcode = _StringToWideString(word); | 619 CFX_WideString destcode = StringToWideString(word); |
| 614 int len = destcode.GetLength(); | 620 int len = destcode.GetLength(); |
| 615 if (len == 0) { | 621 if (len == 0) { |
| 616 continue; | 622 continue; |
| 617 } | 623 } |
| 618 if (len == 1) { | 624 if (len == 1) { |
| 619 m_Map[srccode] = destcode.GetAt(0); | 625 m_Map[srccode] = destcode.GetAt(0); |
| 620 } else { | 626 } else { |
| 621 m_Map[srccode] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; | 627 m_Map[srccode] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
| 622 m_MultiCharBuf.AppendChar(destcode.GetLength()); | 628 m_MultiCharBuf.AppendChar(destcode.GetLength()); |
| 623 m_MultiCharBuf << destcode; | 629 m_MultiCharBuf << destcode; |
| 624 } | 630 } |
| 625 } | 631 } |
| 626 } else if (word == FX_BSTRC("beginbfrange")) { | 632 } else if (word == FX_BSTRC("beginbfrange")) { |
| 627 while (1) { | 633 while (1) { |
| 628 CFX_ByteString low, high; | 634 CFX_ByteString low, high; |
| 629 low = parser.GetWord(); | 635 low = parser.GetWord(); |
| 630 if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) { | 636 if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) { |
| 631 break; | 637 break; |
| 632 } | 638 } |
| 633 high = parser.GetWord(); | 639 high = parser.GetWord(); |
| 634 FX_DWORD lowcode = _StringToCode(low); | 640 FX_DWORD lowcode = StringToCode(low); |
| 635 FX_DWORD highcode = | 641 FX_DWORD highcode = |
| 636 (lowcode & 0xffffff00) | (_StringToCode(high) & 0xff); | 642 (lowcode & 0xffffff00) | (StringToCode(high) & 0xff); |
| 637 if (highcode == (FX_DWORD)-1) { | 643 if (highcode == (FX_DWORD)-1) { |
| 638 break; | 644 break; |
| 639 } | 645 } |
| 640 CFX_ByteString start = parser.GetWord(); | 646 CFX_ByteString start = parser.GetWord(); |
| 641 if (start == FX_BSTRC("[")) { | 647 if (start == FX_BSTRC("[")) { |
| 642 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 648 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
| 643 CFX_ByteString dest = parser.GetWord(); | 649 CFX_ByteString dest = parser.GetWord(); |
| 644 CFX_WideString destcode = _StringToWideString(dest); | 650 CFX_WideString destcode = StringToWideString(dest); |
| 645 int len = destcode.GetLength(); | 651 int len = destcode.GetLength(); |
| 646 if (len == 0) { | 652 if (len == 0) { |
| 647 continue; | 653 continue; |
| 648 } | 654 } |
| 649 if (len == 1) { | 655 if (len == 1) { |
| 650 m_Map[code] = destcode.GetAt(0); | 656 m_Map[code] = destcode.GetAt(0); |
| 651 } else { | 657 } else { |
| 652 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; | 658 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
| 653 m_MultiCharBuf.AppendChar(destcode.GetLength()); | 659 m_MultiCharBuf.AppendChar(destcode.GetLength()); |
| 654 m_MultiCharBuf << destcode; | 660 m_MultiCharBuf << destcode; |
| 655 } | 661 } |
| 656 } | 662 } |
| 657 parser.GetWord(); | 663 parser.GetWord(); |
| 658 } else { | 664 } else { |
| 659 CFX_WideString destcode = _StringToWideString(start); | 665 CFX_WideString destcode = StringToWideString(start); |
| 660 int len = destcode.GetLength(); | 666 int len = destcode.GetLength(); |
| 661 FX_DWORD value = 0; | 667 FX_DWORD value = 0; |
| 662 if (len == 1) { | 668 if (len == 1) { |
| 663 value = _StringToCode(start); | 669 value = StringToCode(start); |
| 664 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 670 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
| 665 m_Map[code] = value++; | 671 m_Map[code] = value++; |
| 666 } | 672 } |
| 667 } else { | 673 } else { |
| 668 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 674 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
| 669 CFX_WideString retcode; | 675 CFX_WideString retcode; |
| 670 if (code == lowcode) { | 676 if (code == lowcode) { |
| 671 retcode = destcode; | 677 retcode = destcode; |
| 672 } else { | 678 } else { |
| 673 retcode = _StringDataAdd(destcode); | 679 retcode = StringDataAdd(destcode); |
| 674 } | 680 } |
| 675 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; | 681 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
| 676 m_MultiCharBuf.AppendChar(retcode.GetLength()); | 682 m_MultiCharBuf.AppendChar(retcode.GetLength()); |
| 677 m_MultiCharBuf << retcode; | 683 m_MultiCharBuf << retcode; |
| 678 destcode = retcode; | 684 destcode = retcode; |
| 679 } | 685 } |
| 680 } | 686 } |
| 681 } | 687 } |
| 682 } | 688 } |
| 683 } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) { | 689 } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) { |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 CPDF_Type3Char::CPDF_Type3Char() { | 1787 CPDF_Type3Char::CPDF_Type3Char() { |
| 1782 m_pForm = NULL; | 1788 m_pForm = NULL; |
| 1783 m_pBitmap = NULL; | 1789 m_pBitmap = NULL; |
| 1784 m_bPageRequired = FALSE; | 1790 m_bPageRequired = FALSE; |
| 1785 m_bColored = FALSE; | 1791 m_bColored = FALSE; |
| 1786 } | 1792 } |
| 1787 CPDF_Type3Char::~CPDF_Type3Char() { | 1793 CPDF_Type3Char::~CPDF_Type3Char() { |
| 1788 delete m_pForm; | 1794 delete m_pForm; |
| 1789 delete m_pBitmap; | 1795 delete m_pBitmap; |
| 1790 } | 1796 } |
| OLD | NEW |