Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: core/fpdfapi/parser/cpdf_document.cpp

Issue 2489283003: Make AddIndirectObject() take a unique_ptr. (Closed)
Patch Set: Address review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_dictionary.cpp ('k') | core/fpdfapi/parser/cpdf_document_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
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;
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);
(...skipping 20 matching lines...) Expand all
911 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, 912 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont,
912 pWidths); 913 pWidths);
913 } else { 914 } else {
914 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, 915 pFontDict = ProcessbCJK(pBaseDict, 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 int italicangle = 922 int italicangle =
923 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; 923 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0;
924 FX_RECT bbox; 924 FX_RECT bbox;
925 pFont->GetBBox(bbox); 925 pFont->GetBBox(bbox);
926 CPDF_Array* pBBox = new CPDF_Array; 926 CPDF_Array* pBBox = new CPDF_Array;
927 pBBox->AddInteger(bbox.left); 927 pBBox->AddInteger(bbox.left);
928 pBBox->AddInteger(bbox.bottom); 928 pBBox->AddInteger(bbox.bottom);
929 pBBox->AddInteger(bbox.right); 929 pBBox->AddInteger(bbox.right);
930 pBBox->AddInteger(bbox.top); 930 pBBox->AddInteger(bbox.top);
931 int32_t nStemV = 0; 931 int32_t nStemV = 0;
932 if (pFont->GetSubstFont()) { 932 if (pFont->GetSubstFont()) {
933 nStemV = pFont->GetSubstFont()->m_Weight / 5; 933 nStemV = pFont->GetSubstFont()->m_Weight / 5;
934 } else { 934 } else {
935 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; 935 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'};
936 const size_t count = FX_ArraySize(stem_chars); 936 const size_t count = FX_ArraySize(stem_chars);
937 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); 937 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]);
938 nStemV = pFont->GetGlyphWidth(glyph); 938 nStemV = pFont->GetGlyphWidth(glyph);
939 for (size_t i = 1; i < count; i++) { 939 for (size_t i = 1; i < count; i++) {
940 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); 940 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]);
941 int width = pFont->GetGlyphWidth(glyph); 941 int width = pFont->GetGlyphWidth(glyph);
942 if (width > 0 && width < nStemV) 942 if (width > 0 && width < nStemV)
943 nStemV = width; 943 nStemV = width;
944 } 944 }
945 } 945 }
946 CPDF_Dictionary* pFontDesc = 946 CPDF_Dictionary* pFontDesc = ToDictionary(AddIndirectObject(
947 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), 947 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(),
948 pFont->GetDescent(), pBBox, nStemV); 948 pFont->GetDescent(), pBBox, nStemV)));
949 pFontDict->SetReferenceFor("FontDescriptor", this, 949 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
950 AddIndirectObject(pFontDesc));
951 return LoadFont(pBaseDict); 950 return LoadFont(pBaseDict);
952 } 951 }
953 952
954 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 953 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
955 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, 954 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont,
956 bool bVert, 955 bool bVert,
957 bool bTranslateName) { 956 bool bTranslateName) {
958 LOGFONTA lfa; 957 LOGFONTA lfa;
959 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); 958 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa);
960 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); 959 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 basefont = pLogFont->lfFaceName; 1001 basefont = pLogFont->lfFaceName;
1003 1002
1004 int italicangle = ptm->otmItalicAngle / 10; 1003 int italicangle = ptm->otmItalicAngle / 10;
1005 int ascend = ptm->otmrcFontBox.top; 1004 int ascend = ptm->otmrcFontBox.top;
1006 int descend = ptm->otmrcFontBox.bottom; 1005 int descend = ptm->otmrcFontBox.bottom;
1007 int capheight = ptm->otmsCapEmHeight; 1006 int capheight = ptm->otmsCapEmHeight;
1008 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, 1007 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom,
1009 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; 1008 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top};
1010 FX_Free(tm_buf); 1009 FX_Free(tm_buf);
1011 basefont.Replace(" ", ""); 1010 basefont.Replace(" ", "");
1012 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); 1011 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
1013 pBaseDict->SetNameFor("Type", "Font"); 1012 pBaseDict->SetNameFor("Type", "Font");
1014 CPDF_Dictionary* pFontDict = pBaseDict; 1013 CPDF_Dictionary* pFontDict = pBaseDict;
1015 if (!bCJK) { 1014 if (!bCJK) {
1016 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || 1015 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET ||
1017 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || 1016 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET ||
1018 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { 1017 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) {
1019 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); 1018 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding");
1020 } else { 1019 } else {
1021 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); 1020 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict);
1022 } 1021 }
1023 int char_widths[224]; 1022 int char_widths[224];
1024 GetCharWidth(hDC, 32, 255, char_widths); 1023 GetCharWidth(hDC, 32, 255, char_widths);
1025 CPDF_Array* pWidths = new CPDF_Array; 1024 CPDF_Array* pWidths = new CPDF_Array;
1026 for (size_t i = 0; i < 224; i++) 1025 for (size_t i = 0; i < 224; i++)
1027 pWidths->AddInteger(char_widths[i]); 1026 pWidths->AddInteger(char_widths[i]);
1028 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, 1027 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM,
1029 pLogFont->lfItalic != 0, basefont, pWidths); 1028 pLogFont->lfItalic != 0, basefont, pWidths);
1030 } else { 1029 } else {
1031 pFontDict = 1030 pFontDict =
1032 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, 1031 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont,
1033 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { 1032 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) {
1034 InsertWidthArray(hDC, start, end, widthArr); 1033 InsertWidthArray(hDC, start, end, widthArr);
1035 }); 1034 });
1036 } 1035 }
1037 AddIndirectObject(pBaseDict);
1038 CPDF_Array* pBBox = new CPDF_Array; 1036 CPDF_Array* pBBox = new CPDF_Array;
1039 for (int i = 0; i < 4; i++) 1037 for (int i = 0; i < 4; i++)
1040 pBBox->AddInteger(bbox[i]); 1038 pBBox->AddInteger(bbox[i]);
1041 CPDF_Dictionary* pFontDesc = 1039 std::unique_ptr<CPDF_Dictionary> pFontDesc =
1042 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, 1040 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend,
1043 pBBox, pLogFont->lfWeight / 5); 1041 pBBox, pLogFont->lfWeight / 5);
1044 pFontDesc->SetIntegerFor("CapHeight", capheight); 1042 pFontDesc->SetIntegerFor("CapHeight", capheight);
1045 pFontDict->SetReferenceFor("FontDescriptor", this, 1043 pFontDict->SetReferenceFor("FontDescriptor", this,
1046 AddIndirectObject(pFontDesc)); 1044 AddIndirectObject(std::move(pFontDesc)));
1047 hFont = SelectObject(hDC, hFont); 1045 hFont = SelectObject(hDC, hFont);
1048 DeleteObject(hFont); 1046 DeleteObject(hFont);
1049 DeleteDC(hDC); 1047 DeleteDC(hDC);
1050 return LoadFont(pBaseDict); 1048 return LoadFont(pBaseDict);
1051 } 1049 }
1052 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1050 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_dictionary.cpp ('k') | core/fpdfapi/parser/cpdf_document_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698