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/fpdf_parser/include/cpdf_document.h" | 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 return nullptr; | 682 return nullptr; |
683 | 683 |
684 ASSERT(pObj->GetObjNum()); | 684 ASSERT(pObj->GetObjNum()); |
685 return m_pDocPage->GetImage(pObj); | 685 return m_pDocPage->GetImage(pObj); |
686 } | 686 } |
687 | 687 |
688 void CPDF_Document::CreateNewDoc() { | 688 void CPDF_Document::CreateNewDoc() { |
689 ASSERT(!m_pRootDict && !m_pInfoDict); | 689 ASSERT(!m_pRootDict && !m_pInfoDict); |
690 m_pRootDict = new CPDF_Dictionary; | 690 m_pRootDict = new CPDF_Dictionary; |
691 m_pRootDict->SetNameFor("Type", "Catalog"); | 691 m_pRootDict->SetNameFor("Type", "Catalog"); |
692 int objnum = AddIndirectObject(m_pRootDict); | 692 AddIndirectObject(m_pRootDict); |
693 CPDF_Dictionary* pPages = new CPDF_Dictionary; | 693 CPDF_Dictionary* pPages = new CPDF_Dictionary; |
694 pPages->SetNameFor("Type", "Pages"); | 694 pPages->SetNameFor("Type", "Pages"); |
695 pPages->SetNumberFor("Count", 0); | 695 pPages->SetNumberFor("Count", 0); |
696 pPages->SetFor("Kids", new CPDF_Array); | 696 pPages->SetFor("Kids", new CPDF_Array); |
697 objnum = AddIndirectObject(pPages); | 697 m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); |
698 m_pRootDict->SetReferenceFor("Pages", this, objnum); | |
699 m_pInfoDict = new CPDF_Dictionary; | 698 m_pInfoDict = new CPDF_Dictionary; |
700 AddIndirectObject(m_pInfoDict); | 699 AddIndirectObject(m_pInfoDict); |
701 } | 700 } |
702 | 701 |
703 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 702 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
704 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 703 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
705 pDict->SetNameFor("Type", "Page"); | 704 pDict->SetNameFor("Type", "Page"); |
706 uint32_t dwObjNum = AddIndirectObject(pDict); | 705 uint32_t dwObjNum = AddIndirectObject(pDict); |
707 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { | 706 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { |
708 ReleaseIndirectObject(dwObjNum); | 707 ReleaseIndirectObject(dwObjNum); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary; | 746 CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary; |
748 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 747 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); |
749 CPDF_Array* pArray = new CPDF_Array; | 748 CPDF_Array* pArray = new CPDF_Array; |
750 pArray->AddInteger(128); | 749 pArray->AddInteger(128); |
751 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 750 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
752 for (int j = 0; j < 128; j++) { | 751 for (int j = 0; j < 128; j++) { |
753 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 752 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
754 pArray->AddName(name.IsEmpty() ? ".notdef" : name); | 753 pArray->AddName(name.IsEmpty() ? ".notdef" : name); |
755 } | 754 } |
756 pEncodingDict->SetFor("Differences", pArray); | 755 pEncodingDict->SetFor("Differences", pArray); |
757 AddIndirectObject(pEncodingDict); | 756 pBaseDict->SetReferenceFor("Encoding", this, |
758 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); | 757 AddIndirectObject(pEncodingDict)); |
| 758 |
759 return i; | 759 return i; |
760 } | 760 } |
761 | 761 |
762 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 762 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
763 CPDF_Dictionary* pBaseDict, | 763 CPDF_Dictionary* pBaseDict, |
764 int charset, | 764 int charset, |
765 FX_BOOL bVert, | 765 FX_BOOL bVert, |
766 CFX_ByteString basefont, | 766 CFX_ByteString basefont, |
767 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 767 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
768 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; | 768 CPDF_Dictionary* pFontDict = new CPDF_Dictionary; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 pFontDict->SetNameFor("Type", "Font"); | 815 pFontDict->SetNameFor("Type", "Font"); |
816 pFontDict->SetNameFor("Subtype", "CIDFontType2"); | 816 pFontDict->SetNameFor("Subtype", "CIDFontType2"); |
817 pFontDict->SetNameFor("BaseFont", basefont); | 817 pFontDict->SetNameFor("BaseFont", basefont); |
818 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary; | 818 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary; |
819 pCIDSysInfo->SetStringFor("Registry", "Adobe"); | 819 pCIDSysInfo->SetStringFor("Registry", "Adobe"); |
820 pCIDSysInfo->SetStringFor("Ordering", ordering); | 820 pCIDSysInfo->SetStringFor("Ordering", ordering); |
821 pCIDSysInfo->SetIntegerFor("Supplement", supplement); | 821 pCIDSysInfo->SetIntegerFor("Supplement", supplement); |
822 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); | 822 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); |
823 CPDF_Array* pArray = new CPDF_Array; | 823 CPDF_Array* pArray = new CPDF_Array; |
824 pBaseDict->SetFor("DescendantFonts", pArray); | 824 pBaseDict->SetFor("DescendantFonts", pArray); |
825 AddIndirectObject(pFontDict); | 825 pArray->AddReference(this, AddIndirectObject(pFontDict)); |
826 pArray->AddReference(this, pFontDict); | |
827 return pFontDict; | 826 return pFontDict; |
828 } | 827 } |
829 | 828 |
830 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { | 829 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { |
831 if (!pFont) | 830 if (!pFont) |
832 return nullptr; | 831 return nullptr; |
833 | 832 |
834 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 833 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
835 charset == FXFONT_GB2312_CHARSET || | 834 charset == FXFONT_GB2312_CHARSET || |
836 charset == FXFONT_HANGUL_CHARSET || | 835 charset == FXFONT_HANGUL_CHARSET || |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 for (size_t i = 1; i < count; i++) { | 902 for (size_t i = 1; i < count; i++) { |
904 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 903 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
905 int width = pFont->GetGlyphWidth(glyph); | 904 int width = pFont->GetGlyphWidth(glyph); |
906 if (width > 0 && width < nStemV) | 905 if (width > 0 && width < nStemV) |
907 nStemV = width; | 906 nStemV = width; |
908 } | 907 } |
909 } | 908 } |
910 CPDF_Dictionary* pFontDesc = | 909 CPDF_Dictionary* pFontDesc = |
911 CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(), | 910 CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(), |
912 pFont->GetDescent(), pBBox, nStemV); | 911 pFont->GetDescent(), pBBox, nStemV); |
913 AddIndirectObject(pFontDesc); | 912 pFontDict->SetReferenceFor("FontDescriptor", this, |
914 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); | 913 AddIndirectObject(pFontDesc)); |
915 return LoadFont(pBaseDict); | 914 return LoadFont(pBaseDict); |
916 } | 915 } |
917 | 916 |
918 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 917 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
919 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, | 918 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, |
920 FX_BOOL bVert, | 919 FX_BOOL bVert, |
921 FX_BOOL bTranslateName) { | 920 FX_BOOL bTranslateName) { |
922 LOGFONTA lfa; | 921 LOGFONTA lfa; |
923 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); | 922 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); |
924 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); | 923 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 }); | 998 }); |
1000 } | 999 } |
1001 AddIndirectObject(pBaseDict); | 1000 AddIndirectObject(pBaseDict); |
1002 CPDF_Array* pBBox = new CPDF_Array; | 1001 CPDF_Array* pBBox = new CPDF_Array; |
1003 for (int i = 0; i < 4; i++) | 1002 for (int i = 0; i < 4; i++) |
1004 pBBox->AddInteger(bbox[i]); | 1003 pBBox->AddInteger(bbox[i]); |
1005 CPDF_Dictionary* pFontDesc = | 1004 CPDF_Dictionary* pFontDesc = |
1006 CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox, | 1005 CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox, |
1007 pLogFont->lfWeight / 5); | 1006 pLogFont->lfWeight / 5); |
1008 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1007 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1009 AddIndirectObject(pFontDesc); | 1008 pFontDict->SetReferenceFor("FontDescriptor", this, |
1010 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); | 1009 AddIndirectObject(pFontDesc)); |
1011 hFont = SelectObject(hDC, hFont); | 1010 hFont = SelectObject(hDC, hFont); |
1012 DeleteObject(hFont); | 1011 DeleteObject(hFont); |
1013 DeleteDC(hDC); | 1012 DeleteDC(hDC); |
1014 return LoadFont(pBaseDict); | 1013 return LoadFont(pBaseDict); |
1015 } | 1014 } |
1016 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1015 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |