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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 basefont += ",Bold"; | 303 basefont += ",Bold"; |
304 else if (italic) | 304 else if (italic) |
305 basefont += ",Italic"; | 305 basefont += ",Italic"; |
306 pBaseDict->SetNameFor("Subtype", "TrueType"); | 306 pBaseDict->SetNameFor("Subtype", "TrueType"); |
307 pBaseDict->SetNameFor("BaseFont", basefont); | 307 pBaseDict->SetNameFor("BaseFont", basefont); |
308 pBaseDict->SetNumberFor("FirstChar", 32); | 308 pBaseDict->SetNumberFor("FirstChar", 32); |
309 pBaseDict->SetNumberFor("LastChar", 255); | 309 pBaseDict->SetNumberFor("LastChar", 255); |
310 pBaseDict->SetFor("Widths", pWidths); | 310 pBaseDict->SetFor("Widths", pWidths); |
311 } | 311 } |
312 | 312 |
313 CPDF_Dictionary* CalculateFontDesc(CPDF_Document* pDoc, | 313 std::unique_ptr<CPDF_Dictionary> CalculateFontDesc(CPDF_Document* pDoc, |
314 CFX_ByteString basefont, | 314 CFX_ByteString basefont, |
315 int flags, | 315 int flags, |
316 int italicangle, | 316 int italicangle, |
317 int ascend, | 317 int ascend, |
318 int descend, | 318 int descend, |
319 CPDF_Array* bbox, | 319 CPDF_Array* bbox, |
320 int32_t stemV) { | 320 int32_t stemV) { |
321 CPDF_Dictionary* pFontDesc = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 321 auto pFontDesc = |
322 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); | |
322 pFontDesc->SetNameFor("Type", "FontDescriptor"); | 323 pFontDesc->SetNameFor("Type", "FontDescriptor"); |
323 pFontDesc->SetNameFor("FontName", basefont); | 324 pFontDesc->SetNameFor("FontName", basefont); |
324 pFontDesc->SetIntegerFor("Flags", flags); | 325 pFontDesc->SetIntegerFor("Flags", flags); |
325 pFontDesc->SetFor("FontBBox", bbox); | 326 pFontDesc->SetFor("FontBBox", bbox); |
326 pFontDesc->SetIntegerFor("ItalicAngle", italicangle); | 327 pFontDesc->SetIntegerFor("ItalicAngle", italicangle); |
327 pFontDesc->SetIntegerFor("Ascent", ascend); | 328 pFontDesc->SetIntegerFor("Ascent", ascend); |
328 pFontDesc->SetIntegerFor("Descent", descend); | 329 pFontDesc->SetIntegerFor("Descent", descend); |
329 pFontDesc->SetIntegerFor("StemV", stemV); | 330 pFontDesc->SetIntegerFor("StemV", stemV); |
330 return pFontDesc; | 331 return pFontDesc; |
331 } | 332 } |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 return m_pDocPage->GetIccProfile(pStream); | 642 return m_pDocPage->GetIccProfile(pStream); |
642 } | 643 } |
643 | 644 |
644 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { | 645 CPDF_Image* CPDF_Document::LoadImageFromPageData(uint32_t dwStreamObjNum) { |
645 ASSERT(dwStreamObjNum); | 646 ASSERT(dwStreamObjNum); |
646 return m_pDocPage->GetImage(dwStreamObjNum); | 647 return m_pDocPage->GetImage(dwStreamObjNum); |
647 } | 648 } |
648 | 649 |
649 void CPDF_Document::CreateNewDoc() { | 650 void CPDF_Document::CreateNewDoc() { |
650 ASSERT(!m_pRootDict && !m_pInfoDict); | 651 ASSERT(!m_pRootDict && !m_pInfoDict); |
651 m_pRootDict = new CPDF_Dictionary(m_pByteStringPool); | 652 m_pRootDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); |
652 m_pRootDict->SetNameFor("Type", "Catalog"); | 653 m_pRootDict->SetNameFor("Type", "Catalog"); |
653 AddIndirectObject(m_pRootDict); | |
654 | 654 |
655 CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool); | 655 CPDF_Dictionary* pPages = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); |
656 pPages->SetNameFor("Type", "Pages"); | 656 pPages->SetNameFor("Type", "Pages"); |
657 pPages->SetNumberFor("Count", 0); | 657 pPages->SetNumberFor("Count", 0); |
658 pPages->SetFor("Kids", new CPDF_Array); | 658 pPages->SetFor("Kids", new CPDF_Array); |
659 m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); | 659 m_pRootDict->SetReferenceFor("Pages", this, pPages); |
660 m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); | 660 m_pInfoDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); |
661 AddIndirectObject(m_pInfoDict); | |
662 } | 661 } |
663 | 662 |
664 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 663 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
665 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); | 664 CPDF_Dictionary* pDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); |
666 pDict->SetNameFor("Type", "Page"); | 665 pDict->SetNameFor("Type", "Page"); |
667 uint32_t dwObjNum = AddIndirectObject(pDict); | 666 uint32_t dwObjNum = pDict->GetObjNum(); |
668 if (!InsertNewPage(iPage, pDict)) { | 667 if (!InsertNewPage(iPage, pDict)) { |
669 DeleteIndirectObject(dwObjNum); | 668 DeleteIndirectObject(dwObjNum); |
670 return nullptr; | 669 return nullptr; |
671 } | 670 } |
672 return pDict; | 671 return pDict; |
673 } | 672 } |
674 | 673 |
675 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, | 674 bool CPDF_Document::InsertDeletePDFPage(CPDF_Dictionary* pPages, |
676 int nPagesToGo, | 675 int nPagesToGo, |
677 CPDF_Dictionary* pPageDict, | 676 CPDF_Dictionary* pPageDict, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 | 772 |
774 size_t CPDF_Document::CalculateEncodingDict(int charset, | 773 size_t CPDF_Document::CalculateEncodingDict(int charset, |
775 CPDF_Dictionary* pBaseDict) { | 774 CPDF_Dictionary* pBaseDict) { |
776 size_t i; | 775 size_t i; |
777 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { | 776 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { |
778 if (g_FX_CharsetUnicodes[i].m_Charset == charset) | 777 if (g_FX_CharsetUnicodes[i].m_Charset == charset) |
779 break; | 778 break; |
780 } | 779 } |
781 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) | 780 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) |
782 return i; | 781 return i; |
783 CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary(m_pByteStringPool); | 782 |
783 CPDF_Dictionary* pEncodingDict = | |
784 NewIndirect<CPDF_Dictionary>(m_pByteStringPool); | |
784 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 785 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); |
786 | |
785 CPDF_Array* pArray = new CPDF_Array; | 787 CPDF_Array* pArray = new CPDF_Array; |
786 pArray->AddInteger(128); | 788 pArray->AddInteger(128); |
789 | |
787 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 790 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
788 for (int j = 0; j < 128; j++) { | 791 for (int j = 0; j < 128; j++) { |
789 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 792 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
790 pArray->AddName(name.IsEmpty() ? ".notdef" : name); | 793 pArray->AddName(name.IsEmpty() ? ".notdef" : name); |
791 } | 794 } |
792 pEncodingDict->SetFor("Differences", pArray); | 795 pEncodingDict->SetFor("Differences", pArray); |
793 pBaseDict->SetReferenceFor("Encoding", this, | 796 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); |
794 AddIndirectObject(pEncodingDict)); | |
795 | |
796 return i; | 797 return i; |
797 } | 798 } |
798 | 799 |
799 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 800 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
800 CPDF_Dictionary* pBaseDict, | 801 CPDF_Dictionary* pBaseDict, |
801 int charset, | 802 int charset, |
802 bool bVert, | 803 bool bVert, |
803 CFX_ByteString basefont, | 804 CFX_ByteString basefont, |
804 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 805 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
805 CPDF_Dictionary* pFontDict = new CPDF_Dictionary(m_pByteStringPool); | 806 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); |
806 CFX_ByteString cmap; | 807 CFX_ByteString cmap; |
807 CFX_ByteString ordering; | 808 CFX_ByteString ordering; |
808 int supplement = 0; | 809 int supplement = 0; |
809 CPDF_Array* pWidthArray = new CPDF_Array; | 810 CPDF_Array* pWidthArray = new CPDF_Array; |
810 switch (charset) { | 811 switch (charset) { |
811 case FXFONT_CHINESEBIG5_CHARSET: | 812 case FXFONT_CHINESEBIG5_CHARSET: |
812 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 813 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
813 ordering = "CNS1"; | 814 ordering = "CNS1"; |
814 supplement = 4; | 815 supplement = 4; |
815 pWidthArray->AddInteger(1); | 816 pWidthArray->AddInteger(1); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 pFontDict->SetNameFor("Type", "Font"); | 853 pFontDict->SetNameFor("Type", "Font"); |
853 pFontDict->SetNameFor("Subtype", "CIDFontType2"); | 854 pFontDict->SetNameFor("Subtype", "CIDFontType2"); |
854 pFontDict->SetNameFor("BaseFont", basefont); | 855 pFontDict->SetNameFor("BaseFont", basefont); |
855 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); | 856 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); |
856 pCIDSysInfo->SetStringFor("Registry", "Adobe"); | 857 pCIDSysInfo->SetStringFor("Registry", "Adobe"); |
857 pCIDSysInfo->SetStringFor("Ordering", ordering); | 858 pCIDSysInfo->SetStringFor("Ordering", ordering); |
858 pCIDSysInfo->SetIntegerFor("Supplement", supplement); | 859 pCIDSysInfo->SetIntegerFor("Supplement", supplement); |
859 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); | 860 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); |
860 CPDF_Array* pArray = new CPDF_Array; | 861 CPDF_Array* pArray = new CPDF_Array; |
861 pBaseDict->SetFor("DescendantFonts", pArray); | 862 pBaseDict->SetFor("DescendantFonts", pArray); |
862 pArray->AddReference(this, AddIndirectObject(pFontDict)); | 863 pArray->AddReference(this, pFontDict->GetObjNum()); |
863 return pFontDict; | 864 return pFontDict; |
864 } | 865 } |
865 | 866 |
866 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { | 867 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) { |
867 if (!pFont) | 868 if (!pFont) |
868 return nullptr; | 869 return nullptr; |
869 | 870 |
870 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 871 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
871 charset == FXFONT_GB2312_CHARSET || | 872 charset == FXFONT_GB2312_CHARSET || |
872 charset == FXFONT_HANGUL_CHARSET || | 873 charset == FXFONT_HANGUL_CHARSET || |
873 charset == FXFONT_SHIFTJIS_CHARSET; | 874 charset == FXFONT_SHIFTJIS_CHARSET; |
874 CFX_ByteString basefont = pFont->GetFamilyName(); | 875 CFX_ByteString basefont = pFont->GetFamilyName(); |
875 basefont.Replace(" ", ""); | 876 basefont.Replace(" ", ""); |
876 int flags = | 877 int flags = |
877 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), | 878 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), |
878 false, false, charset == FXFONT_SYMBOL_CHARSET); | 879 false, false, charset == FXFONT_SYMBOL_CHARSET); |
879 | 880 |
880 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); | 881 auto pBaseDict = pdfium::MakeUnique<CPDF_Dictionary>(m_pByteStringPool); |
dsinclair
2016/11/15 18:55:51
Why not NewIndirect here?
Tom Sepez
2016/11/15 19:15:16
Ok, I guess we always add it (no return before lin
| |
881 pBaseDict->SetNameFor("Type", "Font"); | 882 pBaseDict->SetNameFor("Type", "Font"); |
882 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( | 883 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
883 new CFX_UnicodeEncoding(pFont)); | 884 new CFX_UnicodeEncoding(pFont)); |
884 CPDF_Dictionary* pFontDict = pBaseDict; | 885 CPDF_Dictionary* pFontDict = pBaseDict.get(); |
885 if (!bCJK) { | 886 if (!bCJK) { |
886 CPDF_Array* pWidths = new CPDF_Array; | 887 CPDF_Array* pWidths = new CPDF_Array; |
887 for (int charcode = 32; charcode < 128; charcode++) { | 888 for (int charcode = 32; charcode < 128; charcode++) { |
888 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 889 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
889 int char_width = pFont->GetGlyphWidth(glyph_index); | 890 int char_width = pFont->GetGlyphWidth(glyph_index); |
890 pWidths->AddInteger(char_width); | 891 pWidths->AddInteger(char_width); |
891 } | 892 } |
892 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || | 893 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || |
893 charset == FXFONT_SYMBOL_CHARSET) { | 894 charset == FXFONT_SYMBOL_CHARSET) { |
894 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 895 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
895 for (int charcode = 128; charcode <= 255; charcode++) { | 896 for (int charcode = 128; charcode <= 255; charcode++) { |
896 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 897 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
897 int char_width = pFont->GetGlyphWidth(glyph_index); | 898 int char_width = pFont->GetGlyphWidth(glyph_index); |
898 pWidths->AddInteger(char_width); | 899 pWidths->AddInteger(char_width); |
899 } | 900 } |
900 } else { | 901 } else { |
901 size_t i = CalculateEncodingDict(charset, pBaseDict); | 902 size_t i = CalculateEncodingDict(charset, pBaseDict.get()); |
902 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { | 903 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { |
903 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 904 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
904 for (int j = 0; j < 128; j++) { | 905 for (int j = 0; j < 128; j++) { |
905 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]); | 906 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]); |
906 int char_width = pFont->GetGlyphWidth(glyph_index); | 907 int char_width = pFont->GetGlyphWidth(glyph_index); |
907 pWidths->AddInteger(char_width); | 908 pWidths->AddInteger(char_width); |
908 } | 909 } |
909 } | 910 } |
910 } | 911 } |
911 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, | 912 ProcessNonbCJK(pBaseDict.get(), pFont->IsBold(), pFont->IsItalic(), |
912 pWidths); | 913 basefont, pWidths); |
913 } else { | 914 } else { |
914 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, | 915 pFontDict = ProcessbCJK(pBaseDict.get(), charset, bVert, basefont, |
915 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, | 916 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, |
916 CPDF_Array* widthArr) { | 917 CPDF_Array* widthArr) { |
917 InsertWidthArray1(pFont, pEncoding.get(), start, | 918 InsertWidthArray1(pFont, pEncoding.get(), start, |
918 end, widthArr); | 919 end, widthArr); |
919 }); | 920 }); |
920 } | 921 } |
921 AddIndirectObject(pBaseDict); | 922 CPDF_Dictionary* pUnownedBaseDict = |
923 ToDictionary(AddIndirectObject(std::move(pBaseDict))); | |
922 int italicangle = | 924 int italicangle = |
923 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; | 925 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; |
924 FX_RECT bbox; | 926 FX_RECT bbox; |
925 pFont->GetBBox(bbox); | 927 pFont->GetBBox(bbox); |
926 CPDF_Array* pBBox = new CPDF_Array; | 928 CPDF_Array* pBBox = new CPDF_Array; |
927 pBBox->AddInteger(bbox.left); | 929 pBBox->AddInteger(bbox.left); |
928 pBBox->AddInteger(bbox.bottom); | 930 pBBox->AddInteger(bbox.bottom); |
929 pBBox->AddInteger(bbox.right); | 931 pBBox->AddInteger(bbox.right); |
930 pBBox->AddInteger(bbox.top); | 932 pBBox->AddInteger(bbox.top); |
931 int32_t nStemV = 0; | 933 int32_t nStemV = 0; |
932 if (pFont->GetSubstFont()) { | 934 if (pFont->GetSubstFont()) { |
933 nStemV = pFont->GetSubstFont()->m_Weight / 5; | 935 nStemV = pFont->GetSubstFont()->m_Weight / 5; |
934 } else { | 936 } else { |
935 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; | 937 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; |
936 const size_t count = FX_ArraySize(stem_chars); | 938 const size_t count = FX_ArraySize(stem_chars); |
937 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); | 939 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); |
938 nStemV = pFont->GetGlyphWidth(glyph); | 940 nStemV = pFont->GetGlyphWidth(glyph); |
939 for (size_t i = 1; i < count; i++) { | 941 for (size_t i = 1; i < count; i++) { |
940 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 942 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
941 int width = pFont->GetGlyphWidth(glyph); | 943 int width = pFont->GetGlyphWidth(glyph); |
942 if (width > 0 && width < nStemV) | 944 if (width > 0 && width < nStemV) |
943 nStemV = width; | 945 nStemV = width; |
944 } | 946 } |
945 } | 947 } |
946 CPDF_Dictionary* pFontDesc = | 948 CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject( |
947 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), | 949 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), |
948 pFont->GetDescent(), pBBox, nStemV); | 950 pFont->GetDescent(), pBBox, nStemV))); |
949 pFontDict->SetReferenceFor("FontDescriptor", this, | 951 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); |
950 AddIndirectObject(pFontDesc)); | 952 return LoadFont(pUnownedBaseDict); |
951 return LoadFont(pBaseDict); | |
952 } | 953 } |
953 | 954 |
954 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 955 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
955 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, | 956 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, |
956 bool bVert, | 957 bool bVert, |
957 bool bTranslateName) { | 958 bool bTranslateName) { |
958 LOGFONTA lfa; | 959 LOGFONTA lfa; |
959 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); | 960 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); |
960 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); | 961 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); |
961 if (face.GetLength() >= LF_FACESIZE) | 962 if (face.GetLength() >= LF_FACESIZE) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 basefont = pLogFont->lfFaceName; | 1003 basefont = pLogFont->lfFaceName; |
1003 | 1004 |
1004 int italicangle = ptm->otmItalicAngle / 10; | 1005 int italicangle = ptm->otmItalicAngle / 10; |
1005 int ascend = ptm->otmrcFontBox.top; | 1006 int ascend = ptm->otmrcFontBox.top; |
1006 int descend = ptm->otmrcFontBox.bottom; | 1007 int descend = ptm->otmrcFontBox.bottom; |
1007 int capheight = ptm->otmsCapEmHeight; | 1008 int capheight = ptm->otmsCapEmHeight; |
1008 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, | 1009 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, |
1009 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; | 1010 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; |
1010 FX_Free(tm_buf); | 1011 FX_Free(tm_buf); |
1011 basefont.Replace(" ", ""); | 1012 basefont.Replace(" ", ""); |
1012 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); | 1013 auto pBaseDict = pdfium::MakeUnique<CPDF_Dictionary>(m_pByteStringPool); |
dsinclair
2016/11/15 18:55:51
ditto
Tom Sepez
2016/11/15 19:15:16
Done.
| |
1013 pBaseDict->SetNameFor("Type", "Font"); | 1014 pBaseDict->SetNameFor("Type", "Font"); |
1014 CPDF_Dictionary* pFontDict = pBaseDict; | 1015 CPDF_Dictionary* pFontDict = pBaseDict.get(); |
1015 if (!bCJK) { | 1016 if (!bCJK) { |
1016 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || | 1017 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
1017 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || | 1018 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
1018 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { | 1019 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
1019 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 1020 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
1020 } else { | 1021 } else { |
1021 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 1022 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict.get()); |
1022 } | 1023 } |
1023 int char_widths[224]; | 1024 int char_widths[224]; |
1024 GetCharWidth(hDC, 32, 255, char_widths); | 1025 GetCharWidth(hDC, 32, 255, char_widths); |
1025 CPDF_Array* pWidths = new CPDF_Array; | 1026 CPDF_Array* pWidths = new CPDF_Array; |
1026 for (size_t i = 0; i < 224; i++) | 1027 for (size_t i = 0; i < 224; i++) |
1027 pWidths->AddInteger(char_widths[i]); | 1028 pWidths->AddInteger(char_widths[i]); |
1028 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, | 1029 ProcessNonbCJK(pBaseDict.get(), pLogFont->lfWeight > FW_MEDIUM, |
1029 pLogFont->lfItalic != 0, basefont, pWidths); | 1030 pLogFont->lfItalic != 0, basefont, pWidths); |
1030 } else { | 1031 } else { |
1031 pFontDict = | 1032 pFontDict = |
1032 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, | 1033 ProcessbCJK(pBaseDict.get(), pLogFont->lfCharSet, bVert, basefont, |
1033 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { | 1034 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { |
1034 InsertWidthArray(hDC, start, end, widthArr); | 1035 InsertWidthArray(hDC, start, end, widthArr); |
1035 }); | 1036 }); |
1036 } | 1037 } |
1037 AddIndirectObject(pBaseDict); | 1038 CPDF_Dictionary* pUnownedBaseDict = |
1039 AddIndirectObject(std::move(pBaseDict))->AsDictionary(); | |
1038 CPDF_Array* pBBox = new CPDF_Array; | 1040 CPDF_Array* pBBox = new CPDF_Array; |
1039 for (int i = 0; i < 4; i++) | 1041 for (int i = 0; i < 4; i++) |
1040 pBBox->AddInteger(bbox[i]); | 1042 pBBox->AddInteger(bbox[i]); |
1041 CPDF_Dictionary* pFontDesc = | 1043 std::unique_ptr<CPDF_Dictionary> pFontDesc = |
1042 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, | 1044 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, |
1043 pBBox, pLogFont->lfWeight / 5); | 1045 pBBox, pLogFont->lfWeight / 5); |
1044 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1046 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1045 pFontDict->SetReferenceFor("FontDescriptor", this, | 1047 pFontDict->SetReferenceFor("FontDescriptor", this, |
1046 AddIndirectObject(pFontDesc)); | 1048 AddIndirectObject(std::move(pFontDesc))); |
1047 hFont = SelectObject(hDC, hFont); | 1049 hFont = SelectObject(hDC, hFont); |
1048 DeleteObject(hFont); | 1050 DeleteObject(hFont); |
1049 DeleteDC(hDC); | 1051 DeleteDC(hDC); |
1050 return LoadFont(pBaseDict); | 1052 return LoadFont(pUnownedBaseDict); |
1051 } | 1053 } |
1052 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1054 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |