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 "core/fpdfapi/parser/cpdf_document.h" | 7 #include "core/fpdfapi/parser/cpdf_document.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 return m_pDocPage->GetIccProfile(pStream); | 640 return m_pDocPage->GetIccProfile(pStream); |
641 } | 641 } |
642 | 642 |
643 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { | 643 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { |
644 ASSERT(dwStreamObjNum); | 644 ASSERT(dwStreamObjNum); |
645 return m_pDocPage->GetImage(dwStreamObjNum); | 645 return m_pDocPage->GetImage(dwStreamObjNum); |
646 } | 646 } |
647 | 647 |
648 void CPDF_Document::CreateNewDoc() { | 648 void CPDF_Document::CreateNewDoc() { |
649 ASSERT(!m_pRootDict && !m_pInfoDict); | 649 ASSERT(!m_pRootDict && !m_pInfoDict); |
650 m_pRootDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | 650 m_pRootDict = NewIndirect<CPDF_Dictionary>(); |
651 m_pRootDict->SetNameFor("Type", "Catalog"); | 651 m_pRootDict->SetNameFor("Type", "Catalog"); |
652 | 652 |
653 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | 653 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(); |
654 pPages->SetNameFor("Type", "Pages"); | 654 pPages->SetNameFor("Type", "Pages"); |
655 pPages->SetNumberFor("Count", 0); | 655 pPages->SetNumberFor("Count", 0); |
656 pPages->SetFor("Kids", new CPDF_Array); | 656 pPages->SetFor("Kids", new CPDF_Array); |
657 m_pRootDict->SetReferenceFor("Pages", this, pPages); | 657 m_pRootDict->SetReferenceFor("Pages", this, pPages); |
658 m_pInfoDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | 658 m_pInfoDict = NewIndirect<CPDF_Dictionary>(); |
659 } | 659 } |
660 | 660 |
661 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 661 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
662 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | 662 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(); |
663 pDict->SetNameFor("Type", "Page"); | 663 pDict->SetNameFor("Type", "Page"); |
664 uint32_t dwObjNum = pDict->GetObjNum(); | 664 uint32_t dwObjNum = pDict->GetObjNum(); |
665 if (!InsertNewPage(iPage, pDict)) { | 665 if (!InsertNewPage(iPage, pDict)) { |
666 DeleteIndirectObject(dwObjNum); | 666 DeleteIndirectObject(dwObjNum); |
667 return nullptr; | 667 return nullptr; |
668 } | 668 } |
669 return pDict; | 669 return pDict; |
670 } | 670 } |
671 | 671 |
672 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, | 672 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 size_t CPDF_Document::CalculateEncodingDict(int charset, | 771 size_t CPDF_Document::CalculateEncodingDict(int charset, |
772 CPDF_Dictionary* pBaseDict) { | 772 CPDF_Dictionary* pBaseDict) { |
773 size_t i; | 773 size_t i; |
774 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { | 774 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { |
775 if (g_FX_CharsetUnicodes[i].m_Charset == charset) | 775 if (g_FX_CharsetUnicodes[i].m_Charset == charset) |
776 break; | 776 break; |
777 } | 777 } |
778 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) | 778 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) |
779 return i; | 779 return i; |
780 | 780 |
781 CPDF_Dictionary* pEncodingDict = | 781 CPDF_Dictionary* pEncodingDict = NewIndirect<CPDF_Dictionary>(); |
782 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | |
783 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 782 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); |
784 | 783 |
785 CPDF_Array* pArray = new CPDF_Array; | 784 CPDF_Array* pArray = new CPDF_Array; |
786 pArray->AddNew<CPDF_Number>(128); | 785 pArray->AddNew<CPDF_Number>(128); |
787 | 786 |
788 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 787 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
789 for (int j = 0; j < 128; j++) { | 788 for (int j = 0; j < 128; j++) { |
790 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 789 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
791 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); | 790 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); |
792 } | 791 } |
793 pEncodingDict->SetFor("Differences", pArray); | 792 pEncodingDict->SetFor("Differences", pArray); |
794 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); | 793 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); |
795 return i; | 794 return i; |
796 } | 795 } |
797 | 796 |
798 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 797 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
799 CPDF_Dictionary* pBaseDict, | 798 CPDF_Dictionary* pBaseDict, |
800 int charset, | 799 int charset, |
801 bool bVert, | 800 bool bVert, |
802 CFX_ByteString basefont, | 801 CFX_ByteString basefont, |
803 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 802 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
804 CPDF_Dictionary* pFontDict = | 803 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(); |
805 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | |
806 CFX_ByteString cmap; | 804 CFX_ByteString cmap; |
807 CFX_ByteString ordering; | 805 CFX_ByteString ordering; |
808 int supplement = 0; | 806 int supplement = 0; |
809 CPDF_Array* pWidthArray = new CPDF_Array; | 807 CPDF_Array* pWidthArray = new CPDF_Array; |
810 switch (charset) { | 808 switch (charset) { |
811 case FXFONT_CHINESEBIG5_CHARSET: | 809 case FXFONT_CHINESEBIG5_CHARSET: |
812 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 810 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
813 ordering = "CNS1"; | 811 ordering = "CNS1"; |
814 supplement = 4; | 812 supplement = 4; |
815 pWidthArray->AddNew<CPDF_Number>(1); | 813 pWidthArray->AddNew<CPDF_Number>(1); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 868 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
871 charset == FXFONT_GB2312_CHARSET || | 869 charset == FXFONT_GB2312_CHARSET || |
872 charset == FXFONT_HANGUL_CHARSET || | 870 charset == FXFONT_HANGUL_CHARSET || |
873 charset == FXFONT_SHIFTJIS_CHARSET; | 871 charset == FXFONT_SHIFTJIS_CHARSET; |
874 CFX_ByteString basefont = pFont->GetFamilyName(); | 872 CFX_ByteString basefont = pFont->GetFamilyName(); |
875 basefont.Replace(" ", ""); | 873 basefont.Replace(" ", ""); |
876 int flags = | 874 int flags = |
877 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), | 875 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), |
878 false, false, charset == FXFONT_SYMBOL_CHARSET); | 876 false, false, charset == FXFONT_SYMBOL_CHARSET); |
879 | 877 |
880 CPDF_Dictionary* pBaseDict = | 878 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); |
881 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | |
882 pBaseDict->SetNameFor("Type", "Font"); | 879 pBaseDict->SetNameFor("Type", "Font"); |
883 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( | 880 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
884 new CFX_UnicodeEncoding(pFont)); | 881 new CFX_UnicodeEncoding(pFont)); |
885 CPDF_Dictionary* pFontDict = pBaseDict; | 882 CPDF_Dictionary* pFontDict = pBaseDict; |
886 if (!bCJK) { | 883 if (!bCJK) { |
887 CPDF_Array* pWidths = new CPDF_Array; | 884 CPDF_Array* pWidths = new CPDF_Array; |
888 for (int charcode = 32; charcode < 128; charcode++) { | 885 for (int charcode = 32; charcode < 128; charcode++) { |
889 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 886 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
890 int char_width = pFont->GetGlyphWidth(glyph_index); | 887 int char_width = pFont->GetGlyphWidth(glyph_index); |
891 pWidths->AddNew<CPDF_Number>(char_width); | 888 pWidths->AddNew<CPDF_Number>(char_width); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 basefont = pLogFont->lfFaceName; | 998 basefont = pLogFont->lfFaceName; |
1002 | 999 |
1003 int italicangle = ptm->otmItalicAngle / 10; | 1000 int italicangle = ptm->otmItalicAngle / 10; |
1004 int ascend = ptm->otmrcFontBox.top; | 1001 int ascend = ptm->otmrcFontBox.top; |
1005 int descend = ptm->otmrcFontBox.bottom; | 1002 int descend = ptm->otmrcFontBox.bottom; |
1006 int capheight = ptm->otmsCapEmHeight; | 1003 int capheight = ptm->otmsCapEmHeight; |
1007 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, | 1004 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, |
1008 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; | 1005 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; |
1009 FX_Free(tm_buf); | 1006 FX_Free(tm_buf); |
1010 basefont.Replace(" ", ""); | 1007 basefont.Replace(" ", ""); |
1011 CPDF_Dictionary* pBaseDict = | 1008 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); |
1012 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); | |
1013 pBaseDict->SetNameFor("Type", "Font"); | 1009 pBaseDict->SetNameFor("Type", "Font"); |
1014 CPDF_Dictionary* pFontDict = pBaseDict; | 1010 CPDF_Dictionary* pFontDict = pBaseDict; |
1015 if (!bCJK) { | 1011 if (!bCJK) { |
1016 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || | 1012 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
1017 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || | 1013 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
1018 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { | 1014 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
1019 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 1015 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
1020 } else { | 1016 } else { |
1021 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 1017 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
1022 } | 1018 } |
(...skipping 19 matching lines...) Expand all Loading... |
1042 pBBox, pLogFont->lfWeight / 5); | 1038 pBBox, pLogFont->lfWeight / 5); |
1043 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1039 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1044 pFontDict->SetReferenceFor("FontDescriptor", this, | 1040 pFontDict->SetReferenceFor("FontDescriptor", this, |
1045 AddIndirectObject(std::move(pFontDesc))); | 1041 AddIndirectObject(std::move(pFontDesc))); |
1046 hFont = SelectObject(hDC, hFont); | 1042 hFont = SelectObject(hDC, hFont); |
1047 DeleteObject(hFont); | 1043 DeleteObject(hFont); |
1048 DeleteDC(hDC); | 1044 DeleteDC(hDC); |
1049 return LoadFont(pBaseDict); | 1045 return LoadFont(pBaseDict); |
1050 } | 1046 } |
1051 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1047 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |