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