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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) | 336 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) |
337 : CPDF_IndirectObjectHolder(), | 337 : CPDF_IndirectObjectHolder(), |
338 m_pParser(std::move(pParser)), | 338 m_pParser(std::move(pParser)), |
339 m_pRootDict(nullptr), | 339 m_pRootDict(nullptr), |
340 m_pInfoDict(nullptr), | 340 m_pInfoDict(nullptr), |
341 m_iNextPageToTraverse(0), | 341 m_iNextPageToTraverse(0), |
342 m_bLinearized(false), | 342 m_bLinearized(false), |
343 m_iFirstPageNo(0), | 343 m_iFirstPageNo(0), |
344 m_dwFirstPageObjNum(0), | 344 m_dwFirstPageObjNum(0), |
345 m_pDocPage(new CPDF_DocPageData(this)), | 345 m_pDocPage(new CPDF_DocPageData(this)), |
346 m_pDocRender(new CPDF_DocRenderData(this)), | 346 m_pDocRender(new CPDF_DocRenderData(this)) { |
347 m_pByteStringPool(pdfium::MakeUnique<CFX_ByteStringPool>()) { | |
348 if (pParser) | 347 if (pParser) |
349 SetLastObjNum(m_pParser->GetLastObjNum()); | 348 SetLastObjNum(m_pParser->GetLastObjNum()); |
350 } | 349 } |
351 | 350 |
352 CPDF_Document::~CPDF_Document() { | 351 CPDF_Document::~CPDF_Document() { |
353 delete m_pDocPage; | 352 delete m_pDocPage; |
354 CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); | 353 CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); |
355 m_pByteStringPool.DeleteObject(); // Make weak. | |
356 } | 354 } |
357 | 355 |
358 std::unique_ptr<CPDF_Object> CPDF_Document::ParseIndirectObject( | 356 std::unique_ptr<CPDF_Object> CPDF_Document::ParseIndirectObject( |
359 uint32_t objnum) { | 357 uint32_t objnum) { |
360 return m_pParser ? m_pParser->ParseIndirectObject(this, objnum) : nullptr; | 358 return m_pParser ? m_pParser->ParseIndirectObject(this, objnum) : nullptr; |
361 } | 359 } |
362 | 360 |
363 void CPDF_Document::LoadDocInternal() { | 361 void CPDF_Document::LoadDocInternal() { |
364 SetLastObjNum(m_pParser->GetLastObjNum()); | 362 SetLastObjNum(m_pParser->GetLastObjNum()); |
365 | 363 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 return m_pDocPage->GetIccProfile(pStream); | 640 return m_pDocPage->GetIccProfile(pStream); |
643 } | 641 } |
644 | 642 |
645 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { | 643 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { |
646 ASSERT(dwStreamObjNum); | 644 ASSERT(dwStreamObjNum); |
647 return m_pDocPage->GetImage(dwStreamObjNum); | 645 return m_pDocPage->GetImage(dwStreamObjNum); |
648 } | 646 } |
649 | 647 |
650 void CPDF_Document::CreateNewDoc() { | 648 void CPDF_Document::CreateNewDoc() { |
651 ASSERT(!m_pRootDict && !m_pInfoDict); | 649 ASSERT(!m_pRootDict && !m_pInfoDict); |
652 m_pRootDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 650 m_pRootDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
653 m_pRootDict->SetNameFor("Type", "Catalog"); | 651 m_pRootDict->SetNameFor("Type", "Catalog"); |
654 | 652 |
655 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 653 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
656 pPages->SetNameFor("Type", "Pages"); | 654 pPages->SetNameFor("Type", "Pages"); |
657 pPages->SetNumberFor("Count", 0); | 655 pPages->SetNumberFor("Count", 0); |
658 pPages->SetFor("Kids", new CPDF_Array); | 656 pPages->SetFor("Kids", new CPDF_Array); |
659 m_pRootDict->SetReferenceFor("Pages", this, pPages); | 657 m_pRootDict->SetReferenceFor("Pages", this, pPages); |
660 m_pInfoDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 658 m_pInfoDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
661 } | 659 } |
662 | 660 |
663 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 661 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
664 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 662 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
665 pDict->SetNameFor("Type", "Page"); | 663 pDict->SetNameFor("Type", "Page"); |
666 uint32_t dwObjNum = pDict->GetObjNum(); | 664 uint32_t dwObjNum = pDict->GetObjNum(); |
667 if (!InsertNewPage(iPage, pDict)) { | 665 if (!InsertNewPage(iPage, pDict)) { |
668 DeleteIndirectObject(dwObjNum); | 666 DeleteIndirectObject(dwObjNum); |
669 return nullptr; | 667 return nullptr; |
670 } | 668 } |
671 return pDict; | 669 return pDict; |
672 } | 670 } |
673 | 671 |
674 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, | 672 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 CPDF_Dictionary* pBaseDict) { | 772 CPDF_Dictionary* pBaseDict) { |
775 size_t i; | 773 size_t i; |
776 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { | 774 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { |
777 if (g_FX_CharsetUnicodes[i].m_Charset == charset) | 775 if (g_FX_CharsetUnicodes[i].m_Charset == charset) |
778 break; | 776 break; |
779 } | 777 } |
780 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) | 778 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) |
781 return i; | 779 return i; |
782 | 780 |
783 CPDF_Dictionary* pEncodingDict = | 781 CPDF_Dictionary* pEncodingDict = |
784 NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 782 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
785 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 783 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); |
786 | 784 |
787 CPDF_Array* pArray = new CPDF_Array; | 785 CPDF_Array* pArray = new CPDF_Array; |
788 pArray->AddNew<CPDF_Number>(128); | 786 pArray->AddNew<CPDF_Number>(128); |
789 | 787 |
790 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 788 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
791 for (int j = 0; j < 128; j++) { | 789 for (int j = 0; j < 128; j++) { |
792 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 790 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
793 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); | 791 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); |
794 } | 792 } |
795 pEncodingDict->SetFor("Differences", pArray); | 793 pEncodingDict->SetFor("Differences", pArray); |
796 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); | 794 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); |
797 return i; | 795 return i; |
798 } | 796 } |
799 | 797 |
800 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 798 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
801 CPDF_Dictionary* pBaseDict, | 799 CPDF_Dictionary* pBaseDict, |
802 int charset, | 800 int charset, |
803 bool bVert, | 801 bool bVert, |
804 CFX_ByteString basefont, | 802 CFX_ByteString basefont, |
805 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 803 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
806 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 804 CPDF_Dictionary* pFontDict = |
| 805 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
807 CFX_ByteString cmap; | 806 CFX_ByteString cmap; |
808 CFX_ByteString ordering; | 807 CFX_ByteString ordering; |
809 int supplement = 0; | 808 int supplement = 0; |
810 CPDF_Array* pWidthArray = new CPDF_Array; | 809 CPDF_Array* pWidthArray = new CPDF_Array; |
811 switch (charset) { | 810 switch (charset) { |
812 case FXFONT_CHINESEBIG5_CHARSET: | 811 case FXFONT_CHINESEBIG5_CHARSET: |
813 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 812 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
814 ordering = "CNS1"; | 813 ordering = "CNS1"; |
815 supplement = 4; | 814 supplement = 4; |
816 pWidthArray->AddNew<CPDF_Number>(1); | 815 pWidthArray->AddNew<CPDF_Number>(1); |
(...skipping 29 matching lines...) Expand all Loading... |
846 Insert(0x7e, 0x7e, pWidthArray); | 845 Insert(0x7e, 0x7e, pWidthArray); |
847 break; | 846 break; |
848 } | 847 } |
849 pBaseDict->SetNameFor("Subtype", "Type0"); | 848 pBaseDict->SetNameFor("Subtype", "Type0"); |
850 pBaseDict->SetNameFor("BaseFont", basefont); | 849 pBaseDict->SetNameFor("BaseFont", basefont); |
851 pBaseDict->SetNameFor("Encoding", cmap); | 850 pBaseDict->SetNameFor("Encoding", cmap); |
852 pFontDict->SetFor("W", pWidthArray); | 851 pFontDict->SetFor("W", pWidthArray); |
853 pFontDict->SetNameFor("Type", "Font"); | 852 pFontDict->SetNameFor("Type", "Font"); |
854 pFontDict->SetNameFor("Subtype", "CIDFontType2"); | 853 pFontDict->SetNameFor("Subtype", "CIDFontType2"); |
855 pFontDict->SetNameFor("BaseFont", basefont); | 854 pFontDict->SetNameFor("BaseFont", basefont); |
856 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); | 855 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(GetByteStringPool()); |
857 pCIDSysInfo->SetStringFor("Registry", "Adobe"); | 856 pCIDSysInfo->SetStringFor("Registry", "Adobe"); |
858 pCIDSysInfo->SetStringFor("Ordering", ordering); | 857 pCIDSysInfo->SetStringFor("Ordering", ordering); |
859 pCIDSysInfo->SetIntegerFor("Supplement", supplement); | 858 pCIDSysInfo->SetIntegerFor("Supplement", supplement); |
860 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); | 859 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); |
861 CPDF_Array* pArray = new CPDF_Array; | 860 CPDF_Array* pArray = new CPDF_Array; |
862 pBaseDict->SetFor("DescendantFonts", pArray); | 861 pBaseDict->SetFor("DescendantFonts", pArray); |
863 pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum()); | 862 pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum()); |
864 return pFontDict; | 863 return pFontDict; |
865 } | 864 } |
866 | 865 |
867 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { | 866 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { |
868 if (!pFont) | 867 if (!pFont) |
869 return nullptr; | 868 return nullptr; |
870 | 869 |
871 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 870 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
872 charset == FXFONT_GB2312_CHARSET || | 871 charset == FXFONT_GB2312_CHARSET || |
873 charset == FXFONT_HANGUL_CHARSET || | 872 charset == FXFONT_HANGUL_CHARSET || |
874 charset == FXFONT_SHIFTJIS_CHARSET; | 873 charset == FXFONT_SHIFTJIS_CHARSET; |
875 CFX_ByteString basefont = pFont->GetFamilyName(); | 874 CFX_ByteString basefont = pFont->GetFamilyName(); |
876 basefont.Replace(" ", ""); | 875 basefont.Replace(" ", ""); |
877 int flags = | 876 int flags = |
878 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), | 877 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), |
879 false, false, charset == FXFONT_SYMBOL_CHARSET); | 878 false, false, charset == FXFONT_SYMBOL_CHARSET); |
880 | 879 |
881 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 880 CPDF_Dictionary* pBaseDict = |
| 881 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
882 pBaseDict->SetNameFor("Type", "Font"); | 882 pBaseDict->SetNameFor("Type", "Font"); |
883 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( | 883 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
884 new CFX_UnicodeEncoding(pFont)); | 884 new CFX_UnicodeEncoding(pFont)); |
885 CPDF_Dictionary* pFontDict = pBaseDict; | 885 CPDF_Dictionary* pFontDict = pBaseDict; |
886 if (!bCJK) { | 886 if (!bCJK) { |
887 CPDF_Array* pWidths = new CPDF_Array; | 887 CPDF_Array* pWidths = new CPDF_Array; |
888 for (int charcode = 32; charcode < 128; charcode++) { | 888 for (int charcode = 32; charcode < 128; charcode++) { |
889 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 889 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
890 int char_width = pFont->GetGlyphWidth(glyph_index); | 890 int char_width = pFont->GetGlyphWidth(glyph_index); |
891 pWidths->AddNew<CPDF_Number>(char_width); | 891 pWidths->AddNew<CPDF_Number>(char_width); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 basefont = pLogFont->lfFaceName; | 1001 basefont = pLogFont->lfFaceName; |
1002 | 1002 |
1003 int italicangle = ptm->otmItalicAngle / 10; | 1003 int italicangle = ptm->otmItalicAngle / 10; |
1004 int ascend = ptm->otmrcFontBox.top; | 1004 int ascend = ptm->otmrcFontBox.top; |
1005 int descend = ptm->otmrcFontBox.bottom; | 1005 int descend = ptm->otmrcFontBox.bottom; |
1006 int capheight = ptm->otmsCapEmHeight; | 1006 int capheight = ptm->otmsCapEmHeight; |
1007 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, | 1007 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, |
1008 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; | 1008 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; |
1009 FX_Free(tm_buf); | 1009 FX_Free(tm_buf); |
1010 basefont.Replace(" ", ""); | 1010 basefont.Replace(" ", ""); |
1011 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | 1011 CPDF_Dictionary* pBaseDict = |
| 1012 NewIndirect<CPDF_Dictionary>(GetByteStringPool()); |
1012 pBaseDict->SetNameFor("Type", "Font"); | 1013 pBaseDict->SetNameFor("Type", "Font"); |
1013 CPDF_Dictionary* pFontDict = pBaseDict; | 1014 CPDF_Dictionary* pFontDict = pBaseDict; |
1014 if (!bCJK) { | 1015 if (!bCJK) { |
1015 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || | 1016 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
1016 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || | 1017 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
1017 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { | 1018 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
1018 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 1019 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
1019 } else { | 1020 } else { |
1020 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 1021 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
1021 } | 1022 } |
(...skipping 19 matching lines...) Expand all Loading... |
1041 pBBox, pLogFont->lfWeight / 5); | 1042 pBBox, pLogFont->lfWeight / 5); |
1042 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1043 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1043 pFontDict->SetReferenceFor("FontDescriptor", this, | 1044 pFontDict->SetReferenceFor("FontDescriptor", this, |
1044 AddIndirectObject(std::move(pFontDesc))); | 1045 AddIndirectObject(std::move(pFontDesc))); |
1045 hFont = SelectObject(hDC, hFont); | 1046 hFont = SelectObject(hDC, hFont); |
1046 DeleteObject(hFont); | 1047 DeleteObject(hFont); |
1047 DeleteDC(hDC); | 1048 DeleteDC(hDC); |
1048 return LoadFont(pBaseDict); | 1049 return LoadFont(pBaseDict); |
1049 } | 1050 } |
1050 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1051 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |