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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "core/fpdfapi/cpdf_modulemgr.h" | 13 #include "core/fpdfapi/cpdf_modulemgr.h" |
14 #include "core/fpdfapi/font/cpdf_fontencoding.h" | 14 #include "core/fpdfapi/font/cpdf_fontencoding.h" |
15 #include "core/fpdfapi/page/cpdf_docpagedata.h" | 15 #include "core/fpdfapi/page/cpdf_docpagedata.h" |
16 #include "core/fpdfapi/page/cpdf_pagemodule.h" | 16 #include "core/fpdfapi/page/cpdf_pagemodule.h" |
17 #include "core/fpdfapi/page/pageint.h" | 17 #include "core/fpdfapi/page/pageint.h" |
18 #include "core/fpdfapi/parser/cpdf_array.h" | 18 #include "core/fpdfapi/parser/cpdf_array.h" |
19 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 19 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
20 #include "core/fpdfapi/parser/cpdf_linearized_header.h" | 20 #include "core/fpdfapi/parser/cpdf_linearized_header.h" |
21 #include "core/fpdfapi/parser/cpdf_name.h" | 21 #include "core/fpdfapi/parser/cpdf_name.h" |
22 #include "core/fpdfapi/parser/cpdf_number.h" | 22 #include "core/fpdfapi/parser/cpdf_number.h" |
23 #include "core/fpdfapi/parser/cpdf_parser.h" | 23 #include "core/fpdfapi/parser/cpdf_parser.h" |
24 #include "core/fpdfapi/parser/cpdf_reference.h" | 24 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 25 #include "core/fpdfapi/parser/cpdf_string.h" |
25 #include "core/fpdfapi/parser/cpdf_stream.h" | 26 #include "core/fpdfapi/parser/cpdf_stream.h" |
26 #include "core/fpdfapi/render/render_int.h" | 27 #include "core/fpdfapi/render/render_int.h" |
27 #include "core/fxcodec/JBig2_DocumentContext.h" | 28 #include "core/fxcodec/JBig2_DocumentContext.h" |
28 #include "core/fxge/cfx_unicodeencoding.h" | 29 #include "core/fxge/cfx_unicodeencoding.h" |
29 #include "core/fxge/fx_font.h" | 30 #include "core/fxge/fx_font.h" |
30 #include "third_party/base/ptr_util.h" | 31 #include "third_party/base/ptr_util.h" |
31 #include "third_party/base/stl_util.h" | 32 #include "third_party/base/stl_util.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (pKid->KeyExist("Kids")) { | 258 if (pKid->KeyExist("Kids")) { |
258 // Use |visited_pages| to help detect circular references of pages. | 259 // Use |visited_pages| to help detect circular references of pages. |
259 pdfium::ScopedSetInsertion<CPDF_Dictionary*> local_add(visited_pages, | 260 pdfium::ScopedSetInsertion<CPDF_Dictionary*> local_add(visited_pages, |
260 pKid); | 261 pKid); |
261 count += CountPages(pKid, visited_pages); | 262 count += CountPages(pKid, visited_pages); |
262 } else { | 263 } else { |
263 // This page is a leaf node. | 264 // This page is a leaf node. |
264 count++; | 265 count++; |
265 } | 266 } |
266 } | 267 } |
267 pPages->SetIntegerFor("Count", count); | 268 pPages->SetNewFor<CPDF_Number>("Count", count); |
268 return count; | 269 return count; |
269 } | 270 } |
270 | 271 |
271 int CalculateFlags(bool bold, | 272 int CalculateFlags(bool bold, |
272 bool italic, | 273 bool italic, |
273 bool fixedPitch, | 274 bool fixedPitch, |
274 bool serif, | 275 bool serif, |
275 bool script, | 276 bool script, |
276 bool symbolic) { | 277 bool symbolic) { |
277 int flags = 0; | 278 int flags = 0; |
(...skipping 18 matching lines...) Expand all Loading... |
296 bool bold, | 297 bool bold, |
297 bool italic, | 298 bool italic, |
298 CFX_ByteString basefont, | 299 CFX_ByteString basefont, |
299 CPDF_Array* pWidths) { | 300 CPDF_Array* pWidths) { |
300 if (bold && italic) | 301 if (bold && italic) |
301 basefont += ",BoldItalic"; | 302 basefont += ",BoldItalic"; |
302 else if (bold) | 303 else if (bold) |
303 basefont += ",Bold"; | 304 basefont += ",Bold"; |
304 else if (italic) | 305 else if (italic) |
305 basefont += ",Italic"; | 306 basefont += ",Italic"; |
306 pBaseDict->SetNameFor("Subtype", "TrueType"); | 307 pBaseDict->SetNewFor<CPDF_Name>("Subtype", "TrueType"); |
307 pBaseDict->SetNameFor("BaseFont", basefont); | 308 pBaseDict->SetNewFor<CPDF_Name>("BaseFont", basefont); |
308 pBaseDict->SetNumberFor("FirstChar", 32); | 309 pBaseDict->SetNewFor<CPDF_Number>("FirstChar", 32); |
309 pBaseDict->SetNumberFor("LastChar", 255); | 310 pBaseDict->SetNewFor<CPDF_Number>("LastChar", 255); |
310 pBaseDict->SetFor("Widths", pWidths); | 311 pBaseDict->SetFor("Widths", pdfium::WrapUnique(pWidths)); |
311 } | 312 } |
312 | 313 |
313 std::unique_ptr<CPDF_Dictionary> CalculateFontDesc(CPDF_Document* pDoc, | 314 std::unique_ptr<CPDF_Dictionary> CalculateFontDesc(CPDF_Document* pDoc, |
314 CFX_ByteString basefont, | 315 CFX_ByteString basefont, |
315 int flags, | 316 int flags, |
316 int italicangle, | 317 int italicangle, |
317 int ascend, | 318 int ascend, |
318 int descend, | 319 int descend, |
319 CPDF_Array* bbox, | 320 CPDF_Array* bbox, |
320 int32_t stemV) { | 321 int32_t stemV) { |
321 auto pFontDesc = | 322 auto pFontDesc = |
322 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | 323 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
323 pFontDesc->SetNameFor("Type", "FontDescriptor"); | 324 pFontDesc->SetNewFor<CPDF_Name>("Type", "FontDescriptor"); |
324 pFontDesc->SetNameFor("FontName", basefont); | 325 pFontDesc->SetNewFor<CPDF_Name>("FontName", basefont); |
325 pFontDesc->SetIntegerFor("Flags", flags); | 326 pFontDesc->SetNewFor<CPDF_Number>("Flags", flags); |
326 pFontDesc->SetFor("FontBBox", bbox); | 327 pFontDesc->SetFor("FontBBox", pdfium::WrapUnique(bbox)); |
327 pFontDesc->SetIntegerFor("ItalicAngle", italicangle); | 328 pFontDesc->SetNewFor<CPDF_Number>("ItalicAngle", italicangle); |
328 pFontDesc->SetIntegerFor("Ascent", ascend); | 329 pFontDesc->SetNewFor<CPDF_Number>("Ascent", ascend); |
329 pFontDesc->SetIntegerFor("Descent", descend); | 330 pFontDesc->SetNewFor<CPDF_Number>("Descent", descend); |
330 pFontDesc->SetIntegerFor("StemV", stemV); | 331 pFontDesc->SetNewFor<CPDF_Number>("StemV", stemV); |
331 return pFontDesc; | 332 return pFontDesc; |
332 } | 333 } |
333 | 334 |
334 } // namespace | 335 } // namespace |
335 | 336 |
336 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) | 337 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) |
337 : CPDF_IndirectObjectHolder(), | 338 : CPDF_IndirectObjectHolder(), |
338 m_pParser(std::move(pParser)), | 339 m_pParser(std::move(pParser)), |
339 m_pRootDict(nullptr), | 340 m_pRootDict(nullptr), |
340 m_pInfoDict(nullptr), | 341 m_pInfoDict(nullptr), |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 } | 642 } |
642 | 643 |
643 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { | 644 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { |
644 ASSERT(dwStreamObjNum); | 645 ASSERT(dwStreamObjNum); |
645 return m_pDocPage->GetImage(dwStreamObjNum); | 646 return m_pDocPage->GetImage(dwStreamObjNum); |
646 } | 647 } |
647 | 648 |
648 void CPDF_Document::CreateNewDoc() { | 649 void CPDF_Document::CreateNewDoc() { |
649 ASSERT(!m_pRootDict && !m_pInfoDict); | 650 ASSERT(!m_pRootDict && !m_pInfoDict); |
650 m_pRootDict = NewIndirect<CPDF_Dictionary>(); | 651 m_pRootDict = NewIndirect<CPDF_Dictionary>(); |
651 m_pRootDict->SetNameFor("Type", "Catalog"); | 652 m_pRootDict->SetNewFor<CPDF_Name>("Type", "Catalog"); |
652 | 653 |
653 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(); | 654 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(); |
654 pPages->SetNameFor("Type", "Pages"); | 655 pPages->SetNewFor<CPDF_Name>("Type", "Pages"); |
655 pPages->SetNumberFor("Count", 0); | 656 pPages->SetNewFor<CPDF_Number>("Count", 0); |
656 pPages->SetFor("Kids", new CPDF_Array); | 657 pPages->SetNewFor<CPDF_Array>("Kids"); |
657 m_pRootDict->SetReferenceFor("Pages", this, pPages); | 658 m_pRootDict->SetNewFor<CPDF_Reference>("Pages", this, pPages->GetObjNum()); |
658 m_pInfoDict = NewIndirect<CPDF_Dictionary>(); | 659 m_pInfoDict = NewIndirect<CPDF_Dictionary>(); |
659 } | 660 } |
660 | 661 |
661 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 662 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
662 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(); | 663 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(); |
663 pDict->SetNameFor("Type", "Page"); | 664 pDict->SetNewFor<CPDF_Name>("Type", "Page"); |
664 uint32_t dwObjNum = pDict->GetObjNum(); | 665 uint32_t dwObjNum = pDict->GetObjNum(); |
665 if (!InsertNewPage(iPage, pDict)) { | 666 if (!InsertNewPage(iPage, pDict)) { |
666 DeleteIndirectObject(dwObjNum); | 667 DeleteIndirectObject(dwObjNum); |
667 return nullptr; | 668 return nullptr; |
668 } | 669 } |
669 return pDict; | 670 return pDict; |
670 } | 671 } |
671 | 672 |
672 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, | 673 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, |
673 int nPagesToGo, | 674 int nPagesToGo, |
674 CPDF_Dictionary* pPageDict, | 675 CPDF_Dictionary* pPageDict, |
675 bool bInsert, | 676 bool bInsert, |
676 std::set<CPDF_Dictionary*>* pVisited) { | 677 std::set<CPDF_Dictionary*>* pVisited) { |
677 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); | 678 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); |
678 if (!pKidList) | 679 if (!pKidList) |
679 return false; | 680 return false; |
680 | 681 |
681 for (size_t i = 0; i < pKidList->GetCount(); i++) { | 682 for (size_t i = 0; i < pKidList->GetCount(); i++) { |
682 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 683 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); |
683 if (pKid->GetStringFor("Type") == "Page") { | 684 if (pKid->GetStringFor("Type") == "Page") { |
684 if (nPagesToGo != 0) { | 685 if (nPagesToGo != 0) { |
685 nPagesToGo--; | 686 nPagesToGo--; |
686 continue; | 687 continue; |
687 } | 688 } |
688 if (bInsert) { | 689 if (bInsert) { |
689 pKidList->InsertNewAt<CPDF_Reference>(i, this, pPageDict->GetObjNum()); | 690 pKidList->InsertNewAt<CPDF_Reference>(i, this, pPageDict->GetObjNum()); |
690 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum()); | 691 pPageDict->SetNewFor<CPDF_Reference>("Parent", this, |
| 692 pPages->GetObjNum()); |
691 } else { | 693 } else { |
692 pKidList->RemoveAt(i); | 694 pKidList->RemoveAt(i); |
693 } | 695 } |
694 pPages->SetIntegerFor( | 696 pPages->SetNewFor<CPDF_Number>( |
695 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); | 697 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); |
696 ResetTraversal(); | 698 ResetTraversal(); |
697 break; | 699 break; |
698 } | 700 } |
699 int nPages = pKid->GetIntegerFor("Count"); | 701 int nPages = pKid->GetIntegerFor("Count"); |
700 if (nPagesToGo >= nPages) { | 702 if (nPagesToGo >= nPages) { |
701 nPagesToGo -= nPages; | 703 nPagesToGo -= nPages; |
702 continue; | 704 continue; |
703 } | 705 } |
704 if (pdfium::ContainsKey(*pVisited, pKid)) | 706 if (pdfium::ContainsKey(*pVisited, pKid)) |
705 return false; | 707 return false; |
706 | 708 |
707 pdfium::ScopedSetInsertion<CPDF_Dictionary*> insertion(pVisited, pKid); | 709 pdfium::ScopedSetInsertion<CPDF_Dictionary*> insertion(pVisited, pKid); |
708 if (!InsertDeletePDFPage(pKid, nPagesToGo, pPageDict, bInsert, pVisited)) | 710 if (!InsertDeletePDFPage(pKid, nPagesToGo, pPageDict, bInsert, pVisited)) |
709 return false; | 711 return false; |
710 | 712 |
711 pPages->SetIntegerFor("Count", | 713 pPages->SetNewFor<CPDF_Number>( |
712 pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); | 714 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); |
713 break; | 715 break; |
714 } | 716 } |
715 return true; | 717 return true; |
716 } | 718 } |
717 | 719 |
718 bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { | 720 bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) { |
719 CPDF_Dictionary* pRoot = GetRoot(); | 721 CPDF_Dictionary* pRoot = GetRoot(); |
720 CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr; | 722 CPDF_Dictionary* pPages = pRoot ? pRoot->GetDictFor("Pages") : nullptr; |
721 if (!pPages) | 723 if (!pPages) |
722 return false; | 724 return false; |
723 | 725 |
724 int nPages = GetPageCount(); | 726 int nPages = GetPageCount(); |
725 if (iPage < 0 || iPage > nPages) | 727 if (iPage < 0 || iPage > nPages) |
726 return false; | 728 return false; |
727 | 729 |
728 if (iPage == nPages) { | 730 if (iPage == nPages) { |
729 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); | 731 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); |
730 if (!pPagesList) { | 732 if (!pPagesList) |
731 pPagesList = new CPDF_Array; | 733 pPagesList = pPages->SetNewFor<CPDF_Array>("Kids"); |
732 pPages->SetFor("Kids", pPagesList); | |
733 } | |
734 pPagesList->AddNew<CPDF_Reference>(this, pPageDict->GetObjNum()); | 734 pPagesList->AddNew<CPDF_Reference>(this, pPageDict->GetObjNum()); |
735 pPages->SetIntegerFor("Count", nPages + 1); | 735 pPages->SetNewFor<CPDF_Number>("Count", nPages + 1); |
736 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum()); | 736 pPageDict->SetNewFor<CPDF_Reference>("Parent", this, pPages->GetObjNum()); |
737 ResetTraversal(); | 737 ResetTraversal(); |
738 } else { | 738 } else { |
739 std::set<CPDF_Dictionary*> stack = {pPages}; | 739 std::set<CPDF_Dictionary*> stack = {pPages}; |
740 if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack)) | 740 if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack)) |
741 return false; | 741 return false; |
742 } | 742 } |
743 m_PageList.InsertAt(iPage, pPageDict->GetObjNum()); | 743 m_PageList.InsertAt(iPage, pPageDict->GetObjNum()); |
744 return true; | 744 return true; |
745 } | 745 } |
746 | 746 |
(...skipping 25 matching lines...) Expand all Loading... |
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 = NewIndirect<CPDF_Dictionary>(); | 781 CPDF_Dictionary* pEncodingDict = NewIndirect<CPDF_Dictionary>(); |
782 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 782 pEncodingDict->SetNewFor<CPDF_Name>("BaseEncoding", "WinAnsiEncoding"); |
783 | 783 |
784 CPDF_Array* pArray = new CPDF_Array; | 784 CPDF_Array* pArray = pEncodingDict->SetNewFor<CPDF_Array>("Differences"); |
785 pArray->AddNew<CPDF_Number>(128); | 785 pArray->AddNew<CPDF_Number>(128); |
786 | 786 |
787 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 787 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
788 for (int j = 0; j < 128; j++) { | 788 for (int j = 0; j < 128; j++) { |
789 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 789 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
790 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); | 790 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name); |
791 } | 791 } |
792 pEncodingDict->SetFor("Differences", pArray); | 792 pBaseDict->SetNewFor<CPDF_Reference>("Encoding", this, |
793 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); | 793 pEncodingDict->GetObjNum()); |
794 return i; | 794 return i; |
795 } | 795 } |
796 | 796 |
797 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 797 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
798 CPDF_Dictionary* pBaseDict, | 798 CPDF_Dictionary* pBaseDict, |
799 int charset, | 799 int charset, |
800 bool bVert, | 800 bool bVert, |
801 CFX_ByteString basefont, | 801 CFX_ByteString basefont, |
802 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 802 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
803 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(); | 803 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(); |
804 CFX_ByteString cmap; | 804 CFX_ByteString cmap; |
805 CFX_ByteString ordering; | 805 CFX_ByteString ordering; |
806 int supplement = 0; | 806 int supplement = 0; |
807 CPDF_Array* pWidthArray = new CPDF_Array; | 807 CPDF_Array* pWidthArray = pFontDict->SetNewFor<CPDF_Array>("W"); |
808 switch (charset) { | 808 switch (charset) { |
809 case FXFONT_CHINESEBIG5_CHARSET: | 809 case FXFONT_CHINESEBIG5_CHARSET: |
810 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 810 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
811 ordering = "CNS1"; | 811 ordering = "CNS1"; |
812 supplement = 4; | 812 supplement = 4; |
813 pWidthArray->AddNew<CPDF_Number>(1); | 813 pWidthArray->AddNew<CPDF_Number>(1); |
814 Insert(0x20, 0x7e, pWidthArray); | 814 Insert(0x20, 0x7e, pWidthArray); |
815 break; | 815 break; |
816 case FXFONT_GB2312_CHARSET: | 816 case FXFONT_GB2312_CHARSET: |
817 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; | 817 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; |
(...skipping 18 matching lines...) Expand all Loading... |
836 pWidthArray->AddNew<CPDF_Number>(231); | 836 pWidthArray->AddNew<CPDF_Number>(231); |
837 Insert(0x20, 0x7d, pWidthArray); | 837 Insert(0x20, 0x7d, pWidthArray); |
838 pWidthArray->AddNew<CPDF_Number>(326); | 838 pWidthArray->AddNew<CPDF_Number>(326); |
839 Insert(0xa0, 0xa0, pWidthArray); | 839 Insert(0xa0, 0xa0, pWidthArray); |
840 pWidthArray->AddNew<CPDF_Number>(327); | 840 pWidthArray->AddNew<CPDF_Number>(327); |
841 Insert(0xa1, 0xdf, pWidthArray); | 841 Insert(0xa1, 0xdf, pWidthArray); |
842 pWidthArray->AddNew<CPDF_Number>(631); | 842 pWidthArray->AddNew<CPDF_Number>(631); |
843 Insert(0x7e, 0x7e, pWidthArray); | 843 Insert(0x7e, 0x7e, pWidthArray); |
844 break; | 844 break; |
845 } | 845 } |
846 pBaseDict->SetNameFor("Subtype", "Type0"); | 846 pBaseDict->SetNewFor<CPDF_Name>("Subtype", "Type0"); |
847 pBaseDict->SetNameFor("BaseFont", basefont); | 847 pBaseDict->SetNewFor<CPDF_Name>("BaseFont", basefont); |
848 pBaseDict->SetNameFor("Encoding", cmap); | 848 pBaseDict->SetNewFor<CPDF_Name>("Encoding", cmap); |
849 pFontDict->SetFor("W", pWidthArray); | 849 pFontDict->SetNewFor<CPDF_Name>("Type", "Font"); |
850 pFontDict->SetNameFor("Type", "Font"); | 850 pFontDict->SetNewFor<CPDF_Name>("Subtype", "CIDFontType2"); |
851 pFontDict->SetNameFor("Subtype", "CIDFontType2"); | 851 pFontDict->SetNewFor<CPDF_Name>("BaseFont", basefont); |
852 pFontDict->SetNameFor("BaseFont", basefont); | 852 |
853 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(GetByteStringPool()); | 853 CPDF_Dictionary* pCIDSysInfo = |
854 pCIDSysInfo->SetStringFor("Registry", "Adobe"); | 854 pFontDict->SetNewFor<CPDF_Dictionary>("CIDSystemInfo"); |
855 pCIDSysInfo->SetStringFor("Ordering", ordering); | 855 pCIDSysInfo->SetNewFor<CPDF_String>("Registry", "Adobe", false); |
856 pCIDSysInfo->SetIntegerFor("Supplement", supplement); | 856 pCIDSysInfo->SetNewFor<CPDF_String>("Ordering", ordering, false); |
857 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); | 857 pCIDSysInfo->SetNewFor<CPDF_Number>("Supplement", supplement); |
858 CPDF_Array* pArray = new CPDF_Array; | 858 |
859 pBaseDict->SetFor("DescendantFonts", pArray); | 859 CPDF_Array* pArray = pBaseDict->SetNewFor<CPDF_Array>("DescendantFonts"); |
860 pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum()); | 860 pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum()); |
861 return pFontDict; | 861 return pFontDict; |
862 } | 862 } |
863 | 863 |
864 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { | 864 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { |
865 if (!pFont) | 865 if (!pFont) |
866 return nullptr; | 866 return nullptr; |
867 | 867 |
868 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 868 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
869 charset == FXFONT_GB2312_CHARSET || | 869 charset == FXFONT_GB2312_CHARSET || |
870 charset == FXFONT_HANGUL_CHARSET || | 870 charset == FXFONT_HANGUL_CHARSET || |
871 charset == FXFONT_SHIFTJIS_CHARSET; | 871 charset == FXFONT_SHIFTJIS_CHARSET; |
872 CFX_ByteString basefont = pFont->GetFamilyName(); | 872 CFX_ByteString basefont = pFont->GetFamilyName(); |
873 basefont.Replace(" ", ""); | 873 basefont.Replace(" ", ""); |
874 int flags = | 874 int flags = |
875 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), | 875 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), |
876 false, false, charset == FXFONT_SYMBOL_CHARSET); | 876 false, false, charset == FXFONT_SYMBOL_CHARSET); |
877 | 877 |
878 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); | 878 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); |
879 pBaseDict->SetNameFor("Type", "Font"); | 879 pBaseDict->SetNewFor<CPDF_Name>("Type", "Font"); |
880 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( | 880 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
881 new CFX_UnicodeEncoding(pFont)); | 881 new CFX_UnicodeEncoding(pFont)); |
882 CPDF_Dictionary* pFontDict = pBaseDict; | 882 CPDF_Dictionary* pFontDict = pBaseDict; |
883 if (!bCJK) { | 883 if (!bCJK) { |
884 CPDF_Array* pWidths = new CPDF_Array; | 884 CPDF_Array* pWidths = new CPDF_Array; |
885 for (int charcode = 32; charcode < 128; charcode++) { | 885 for (int charcode = 32; charcode < 128; charcode++) { |
886 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 886 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
887 int char_width = pFont->GetGlyphWidth(glyph_index); | 887 int char_width = pFont->GetGlyphWidth(glyph_index); |
888 pWidths->AddNew<CPDF_Number>(char_width); | 888 pWidths->AddNew<CPDF_Number>(char_width); |
889 } | 889 } |
890 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || | 890 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || |
891 charset == FXFONT_SYMBOL_CHARSET) { | 891 charset == FXFONT_SYMBOL_CHARSET) { |
892 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 892 pBaseDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding"); |
893 for (int charcode = 128; charcode <= 255; charcode++) { | 893 for (int charcode = 128; charcode <= 255; charcode++) { |
894 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 894 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
895 int char_width = pFont->GetGlyphWidth(glyph_index); | 895 int char_width = pFont->GetGlyphWidth(glyph_index); |
896 pWidths->AddNew<CPDF_Number>(char_width); | 896 pWidths->AddNew<CPDF_Number>(char_width); |
897 } | 897 } |
898 } else { | 898 } else { |
899 size_t i = CalculateEncodingDict(charset, pBaseDict); | 899 size_t i = CalculateEncodingDict(charset, pBaseDict); |
900 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { | 900 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { |
901 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 901 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
902 for (int j = 0; j < 128; j++) { | 902 for (int j = 0; j < 128; j++) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 for (size_t i = 1; i < count; i++) { | 936 for (size_t i = 1; i < count; i++) { |
937 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 937 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
938 int width = pFont->GetGlyphWidth(glyph); | 938 int width = pFont->GetGlyphWidth(glyph); |
939 if (width > 0 && width < nStemV) | 939 if (width > 0 && width < nStemV) |
940 nStemV = width; | 940 nStemV = width; |
941 } | 941 } |
942 } | 942 } |
943 CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject( | 943 CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject( |
944 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), | 944 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), |
945 pFont->GetDescent(), pBBox, nStemV))); | 945 pFont->GetDescent(), pBBox, nStemV))); |
946 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); | 946 pFontDict->SetNewFor<CPDF_Reference>("FontDescriptor", this, |
| 947 pFontDesc->GetObjNum()); |
947 return LoadFont(pBaseDict); | 948 return LoadFont(pBaseDict); |
948 } | 949 } |
949 | 950 |
950 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 951 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
951 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, | 952 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, |
952 bool bVert, | 953 bool bVert, |
953 bool bTranslateName) { | 954 bool bTranslateName) { |
954 LOGFONTA lfa; | 955 LOGFONTA lfa; |
955 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); | 956 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); |
956 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); | 957 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 | 1000 |
1000 int italicangle = ptm->otmItalicAngle / 10; | 1001 int italicangle = ptm->otmItalicAngle / 10; |
1001 int ascend = ptm->otmrcFontBox.top; | 1002 int ascend = ptm->otmrcFontBox.top; |
1002 int descend = ptm->otmrcFontBox.bottom; | 1003 int descend = ptm->otmrcFontBox.bottom; |
1003 int capheight = ptm->otmsCapEmHeight; | 1004 int capheight = ptm->otmsCapEmHeight; |
1004 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, | 1005 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, |
1005 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; | 1006 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; |
1006 FX_Free(tm_buf); | 1007 FX_Free(tm_buf); |
1007 basefont.Replace(" ", ""); | 1008 basefont.Replace(" ", ""); |
1008 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); | 1009 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(); |
1009 pBaseDict->SetNameFor("Type", "Font"); | 1010 pBaseDict->SetNewFor<CPDF_Name>("Type", "Font"); |
1010 CPDF_Dictionary* pFontDict = pBaseDict; | 1011 CPDF_Dictionary* pFontDict = pBaseDict; |
1011 if (!bCJK) { | 1012 if (!bCJK) { |
1012 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || | 1013 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
1013 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || | 1014 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
1014 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { | 1015 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
1015 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 1016 pBaseDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding"); |
1016 } else { | 1017 } else { |
1017 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 1018 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
1018 } | 1019 } |
1019 int char_widths[224]; | 1020 int char_widths[224]; |
1020 GetCharWidth(hDC, 32, 255, char_widths); | 1021 GetCharWidth(hDC, 32, 255, char_widths); |
1021 CPDF_Array* pWidths = new CPDF_Array; | 1022 CPDF_Array* pWidths = new CPDF_Array; |
1022 for (size_t i = 0; i < 224; i++) | 1023 for (size_t i = 0; i < 224; i++) |
1023 pWidths->AddNew<CPDF_Number>(char_widths[i]); | 1024 pWidths->AddNew<CPDF_Number>(char_widths[i]); |
1024 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, | 1025 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, |
1025 pLogFont->lfItalic != 0, basefont, pWidths); | 1026 pLogFont->lfItalic != 0, basefont, pWidths); |
1026 } else { | 1027 } else { |
1027 pFontDict = | 1028 pFontDict = |
1028 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, | 1029 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, |
1029 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { | 1030 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { |
1030 InsertWidthArray(hDC, start, end, widthArr); | 1031 InsertWidthArray(hDC, start, end, widthArr); |
1031 }); | 1032 }); |
1032 } | 1033 } |
1033 CPDF_Array* pBBox = new CPDF_Array; | 1034 CPDF_Array* pBBox = new CPDF_Array; |
1034 for (int i = 0; i < 4; i++) | 1035 for (int i = 0; i < 4; i++) |
1035 pBBox->AddNew<CPDF_Number>(bbox[i]); | 1036 pBBox->AddNew<CPDF_Number>(bbox[i]); |
1036 std::unique_ptr<CPDF_Dictionary> pFontDesc = | 1037 std::unique_ptr<CPDF_Dictionary> pFontDesc = |
1037 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, | 1038 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, |
1038 pBBox, pLogFont->lfWeight / 5); | 1039 pBBox, pLogFont->lfWeight / 5); |
1039 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1040 pFontDesc->SetNewFor<CPDF_Number>("CapHeight", capheight); |
1040 pFontDict->SetReferenceFor("FontDescriptor", this, | 1041 pFontDict->SetNewFor<CPDF_Reference>( |
1041 AddIndirectObject(std::move(pFontDesc))); | 1042 "FontDescriptor", this, |
| 1043 AddIndirectObject(std::move(pFontDesc))->GetObjNum()); |
1042 hFont = SelectObject(hDC, hFont); | 1044 hFont = SelectObject(hDC, hFont); |
1043 DeleteObject(hFont); | 1045 DeleteObject(hFont); |
1044 DeleteDC(hDC); | 1046 DeleteDC(hDC); |
1045 return LoadFont(pBaseDict); | 1047 return LoadFont(pBaseDict); |
1046 } | 1048 } |
1047 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1049 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |