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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 static CFX_ByteString _FontMap_GetByteString(CFX_CharMap* pMap, | 466 static CFX_ByteString _FontMap_GetByteString(CFX_CharMap* pMap, |
467 const CFX_WideString& widestr) { | 467 const CFX_WideString& widestr) { |
468 return ((CPDF_FontCharMap*)pMap)->m_pFont->EncodeString(widestr); | 468 return ((CPDF_FontCharMap*)pMap)->m_pFont->EncodeString(widestr); |
469 } | 469 } |
470 CPDF_FontCharMap::CPDF_FontCharMap(CPDF_Font* pFont) { | 470 CPDF_FontCharMap::CPDF_FontCharMap(CPDF_Font* pFont) { |
471 m_GetByteString = _FontMap_GetByteString; | 471 m_GetByteString = _FontMap_GetByteString; |
472 m_GetWideString = _FontMap_GetWideString; | 472 m_GetWideString = _FontMap_GetWideString; |
473 m_pFont = pFont; | 473 m_pFont = pFont; |
474 } | 474 } |
475 CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { | 475 CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { |
476 FX_DWORD value; | 476 auto it = m_Map.find(charcode); |
477 if (m_Map.Lookup(charcode, value)) { | 477 if (it != m_Map.end()) { |
| 478 FX_DWORD value = it->second; |
478 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); | 479 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); |
479 if (unicode != 0xffff) { | 480 if (unicode != 0xffff) { |
480 return unicode; | 481 return unicode; |
481 } | 482 } |
482 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); | 483 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); |
483 FX_DWORD buf_len = m_MultiCharBuf.GetLength(); | 484 FX_DWORD buf_len = m_MultiCharBuf.GetLength(); |
484 if (buf == NULL || buf_len == 0) { | 485 if (buf == NULL || buf_len == 0) { |
485 return CFX_WideString(); | 486 return CFX_WideString(); |
486 } | 487 } |
487 FX_DWORD index = value >> 16; | 488 FX_DWORD index = value >> 16; |
488 if (index >= buf_len) { | 489 if (index >= buf_len) { |
489 return CFX_WideString(); | 490 return CFX_WideString(); |
490 } | 491 } |
491 FX_DWORD len = buf[index]; | 492 FX_DWORD len = buf[index]; |
492 if (index + len < index || index + len >= buf_len) { | 493 if (index + len < index || index + len >= buf_len) { |
493 return CFX_WideString(); | 494 return CFX_WideString(); |
494 } | 495 } |
495 return CFX_WideString(buf + index + 1, len); | 496 return CFX_WideString(buf + index + 1, len); |
496 } | 497 } |
497 if (m_pBaseMap) { | 498 if (m_pBaseMap) { |
498 return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode); | 499 return m_pBaseMap->UnicodeFromCID((FX_WORD)charcode); |
499 } | 500 } |
500 return CFX_WideString(); | 501 return CFX_WideString(); |
501 } | 502 } |
502 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { | 503 FX_DWORD CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { |
503 FX_POSITION pos = m_Map.GetStartPosition(); | 504 for (const auto& pair : m_Map) { |
504 while (pos) { | 505 if (pair.second == unicode) |
505 FX_DWORD key, value; | 506 return pair.first; |
506 m_Map.GetNextAssoc(pos, key, value); | |
507 if ((FX_WCHAR)value == unicode) { | |
508 return key; | |
509 } | |
510 } | 507 } |
511 return 0; | 508 return 0; |
512 } | 509 } |
513 static FX_DWORD _StringToCode(const CFX_ByteStringC& str) { | 510 static FX_DWORD _StringToCode(const CFX_ByteStringC& str) { |
514 const FX_CHAR* buf = str.GetCStr(); | 511 const FX_CHAR* buf = str.GetCStr(); |
515 int len = str.GetLength(); | 512 int len = str.GetLength(); |
516 if (len == 0) { | 513 if (len == 0) { |
517 return 0; | 514 return 0; |
518 } | 515 } |
519 int result = 0; | 516 int result = 0; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 589 } |
593 if (buf[0] == '(') { | 590 if (buf[0] == '(') { |
594 } | 591 } |
595 return result; | 592 return result; |
596 } | 593 } |
597 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { | 594 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { |
598 int CIDSet = 0; | 595 int CIDSet = 0; |
599 CPDF_StreamAcc stream; | 596 CPDF_StreamAcc stream; |
600 stream.LoadAllData(pStream, FALSE); | 597 stream.LoadAllData(pStream, FALSE); |
601 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); | 598 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); |
602 m_Map.EstimateSize(stream.GetSize() / 8, 1024); | |
603 while (1) { | 599 while (1) { |
604 CFX_ByteStringC word = parser.GetWord(); | 600 CFX_ByteStringC word = parser.GetWord(); |
605 if (word.IsEmpty()) { | 601 if (word.IsEmpty()) { |
606 break; | 602 break; |
607 } | 603 } |
608 if (word == FX_BSTRC("beginbfchar")) { | 604 if (word == FX_BSTRC("beginbfchar")) { |
609 while (1) { | 605 while (1) { |
610 word = parser.GetWord(); | 606 word = parser.GetWord(); |
611 if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) { | 607 if (word.IsEmpty() || word == FX_BSTRC("endbfchar")) { |
612 break; | 608 break; |
613 } | 609 } |
614 FX_DWORD srccode = _StringToCode(word); | 610 FX_DWORD srccode = _StringToCode(word); |
615 word = parser.GetWord(); | 611 word = parser.GetWord(); |
616 CFX_WideString destcode = _StringToWideString(word); | 612 CFX_WideString destcode = _StringToWideString(word); |
617 int len = destcode.GetLength(); | 613 int len = destcode.GetLength(); |
618 if (len == 0) { | 614 if (len == 0) { |
619 continue; | 615 continue; |
620 } | 616 } |
621 if (len == 1) { | 617 if (len == 1) { |
622 m_Map.SetAt(srccode, destcode.GetAt(0)); | 618 m_Map[srccode] = destcode.GetAt(0); |
623 } else { | 619 } else { |
624 m_Map.SetAt(srccode, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff); | 620 m_Map[srccode] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
625 m_MultiCharBuf.AppendChar(destcode.GetLength()); | 621 m_MultiCharBuf.AppendChar(destcode.GetLength()); |
626 m_MultiCharBuf << destcode; | 622 m_MultiCharBuf << destcode; |
627 } | 623 } |
628 } | 624 } |
629 } else if (word == FX_BSTRC("beginbfrange")) { | 625 } else if (word == FX_BSTRC("beginbfrange")) { |
630 while (1) { | 626 while (1) { |
631 CFX_ByteString low, high; | 627 CFX_ByteString low, high; |
632 low = parser.GetWord(); | 628 low = parser.GetWord(); |
633 if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) { | 629 if (low.IsEmpty() || low == FX_BSTRC("endbfrange")) { |
634 break; | 630 break; |
635 } | 631 } |
636 high = parser.GetWord(); | 632 high = parser.GetWord(); |
637 FX_DWORD lowcode = _StringToCode(low); | 633 FX_DWORD lowcode = _StringToCode(low); |
638 FX_DWORD highcode = | 634 FX_DWORD highcode = |
639 (lowcode & 0xffffff00) | (_StringToCode(high) & 0xff); | 635 (lowcode & 0xffffff00) | (_StringToCode(high) & 0xff); |
640 if (highcode == (FX_DWORD)-1) { | 636 if (highcode == (FX_DWORD)-1) { |
641 break; | 637 break; |
642 } | 638 } |
643 CFX_ByteString start = parser.GetWord(); | 639 CFX_ByteString start = parser.GetWord(); |
644 if (start == FX_BSTRC("[")) { | 640 if (start == FX_BSTRC("[")) { |
645 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 641 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
646 CFX_ByteString dest = parser.GetWord(); | 642 CFX_ByteString dest = parser.GetWord(); |
647 CFX_WideString destcode = _StringToWideString(dest); | 643 CFX_WideString destcode = _StringToWideString(dest); |
648 int len = destcode.GetLength(); | 644 int len = destcode.GetLength(); |
649 if (len == 0) { | 645 if (len == 0) { |
650 continue; | 646 continue; |
651 } | 647 } |
652 if (len == 1) { | 648 if (len == 1) { |
653 m_Map.SetAt(code, destcode.GetAt(0)); | 649 m_Map[code] = destcode.GetAt(0); |
654 } else { | 650 } else { |
655 m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff); | 651 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
656 m_MultiCharBuf.AppendChar(destcode.GetLength()); | 652 m_MultiCharBuf.AppendChar(destcode.GetLength()); |
657 m_MultiCharBuf << destcode; | 653 m_MultiCharBuf << destcode; |
658 } | 654 } |
659 } | 655 } |
660 parser.GetWord(); | 656 parser.GetWord(); |
661 } else { | 657 } else { |
662 CFX_WideString destcode = _StringToWideString(start); | 658 CFX_WideString destcode = _StringToWideString(start); |
663 int len = destcode.GetLength(); | 659 int len = destcode.GetLength(); |
664 FX_DWORD value = 0; | 660 FX_DWORD value = 0; |
665 if (len == 1) { | 661 if (len == 1) { |
666 value = _StringToCode(start); | 662 value = _StringToCode(start); |
667 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 663 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
668 m_Map.SetAt(code, value++); | 664 m_Map[code] = value++; |
669 } | 665 } |
670 } else { | 666 } else { |
671 for (FX_DWORD code = lowcode; code <= highcode; code++) { | 667 for (FX_DWORD code = lowcode; code <= highcode; code++) { |
672 CFX_WideString retcode; | 668 CFX_WideString retcode; |
673 if (code == lowcode) { | 669 if (code == lowcode) { |
674 retcode = destcode; | 670 retcode = destcode; |
675 } else { | 671 } else { |
676 retcode = _StringDataAdd(destcode); | 672 retcode = _StringDataAdd(destcode); |
677 } | 673 } |
678 m_Map.SetAt(code, m_MultiCharBuf.GetLength() * 0x10000 + 0xffff); | 674 m_Map[code] = m_MultiCharBuf.GetLength() * 0x10000 + 0xffff; |
679 m_MultiCharBuf.AppendChar(retcode.GetLength()); | 675 m_MultiCharBuf.AppendChar(retcode.GetLength()); |
680 m_MultiCharBuf << retcode; | 676 m_MultiCharBuf << retcode; |
681 destcode = retcode; | 677 destcode = retcode; |
682 } | 678 } |
683 } | 679 } |
684 } | 680 } |
685 } | 681 } |
686 } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) { | 682 } else if (word == FX_BSTRC("/Adobe-Korea1-UCS2")) { |
687 CIDSet = CIDSET_KOREA1; | 683 CIDSet = CIDSET_KOREA1; |
688 } else if (word == FX_BSTRC("/Adobe-Japan1-UCS2")) { | 684 } else if (word == FX_BSTRC("/Adobe-Japan1-UCS2")) { |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 CPDF_Type3Char::CPDF_Type3Char() { | 1782 CPDF_Type3Char::CPDF_Type3Char() { |
1787 m_pForm = NULL; | 1783 m_pForm = NULL; |
1788 m_pBitmap = NULL; | 1784 m_pBitmap = NULL; |
1789 m_bPageRequired = FALSE; | 1785 m_bPageRequired = FALSE; |
1790 m_bColored = FALSE; | 1786 m_bColored = FALSE; |
1791 } | 1787 } |
1792 CPDF_Type3Char::~CPDF_Type3Char() { | 1788 CPDF_Type3Char::~CPDF_Type3Char() { |
1793 delete m_pForm; | 1789 delete m_pForm; |
1794 delete m_pBitmap; | 1790 delete m_pBitmap; |
1795 } | 1791 } |
OLD | NEW |