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

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

Issue 2498223005: Make CPDF_Array take unique_ptrs (Closed)
Patch Set: nits 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>
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_number.h" 22 #include "core/fpdfapi/parser/cpdf_number.h"
22 #include "core/fpdfapi/parser/cpdf_parser.h" 23 #include "core/fpdfapi/parser/cpdf_parser.h"
23 #include "core/fpdfapi/parser/cpdf_reference.h" 24 #include "core/fpdfapi/parser/cpdf_reference.h"
24 #include "core/fpdfapi/parser/cpdf_stream.h" 25 #include "core/fpdfapi/parser/cpdf_stream.h"
25 #include "core/fpdfapi/render/render_int.h" 26 #include "core/fpdfapi/render/render_int.h"
26 #include "core/fxcodec/JBig2_DocumentContext.h" 27 #include "core/fxcodec/JBig2_DocumentContext.h"
27 #include "core/fxge/cfx_unicodeencoding.h" 28 #include "core/fxge/cfx_unicodeencoding.h"
28 #include "core/fxge/fx_font.h" 29 #include "core/fxge/fx_font.h"
29 #include "third_party/base/ptr_util.h" 30 #include "third_party/base/ptr_util.h"
30 #include "third_party/base/stl_util.h" 31 #include "third_party/base/stl_util.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 }; 188 };
188 189
189 void InsertWidthArrayImpl(int* widths, int size, CPDF_Array* pWidthArray) { 190 void InsertWidthArrayImpl(int* widths, int size, CPDF_Array* pWidthArray) {
190 int i; 191 int i;
191 for (i = 1; i < size; i++) { 192 for (i = 1; i < size; i++) {
192 if (widths[i] != *widths) 193 if (widths[i] != *widths)
193 break; 194 break;
194 } 195 }
195 if (i == size) { 196 if (i == size) {
196 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1); 197 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1);
197 pWidthArray->AddInteger(first + size - 1); 198 pWidthArray->AddNew<CPDF_Number>(first + size - 1);
198 pWidthArray->AddInteger(*widths); 199 pWidthArray->AddNew<CPDF_Number>(*widths);
199 } else { 200 } else {
200 CPDF_Array* pWidthArray1 = new CPDF_Array; 201 CPDF_Array* pWidthArray1 = pWidthArray->AddNew<CPDF_Array>();
201 pWidthArray->Add(pWidthArray1);
202 for (i = 0; i < size; i++) 202 for (i = 0; i < size; i++)
203 pWidthArray1->AddInteger(widths[i]); 203 pWidthArray1->AddNew<CPDF_Number>(widths[i]);
204 } 204 }
205 FX_Free(widths); 205 FX_Free(widths);
206 } 206 }
207 207
208 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 208 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
209 void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) { 209 void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) {
210 int size = end - start + 1; 210 int size = end - start + 1;
211 int* widths = FX_Alloc(int, size); 211 int* widths = FX_Alloc(int, size);
212 GetCharWidth(hDC, start, end, widths); 212 GetCharWidth(hDC, start, end, widths);
213 InsertWidthArrayImpl(widths, size, pWidthArray); 213 InsertWidthArrayImpl(widths, size, pWidthArray);
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 return false; 681 return false;
682 682
683 for (size_t i = 0; i < pKidList->GetCount(); i++) { 683 for (size_t i = 0; i < pKidList->GetCount(); i++) {
684 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); 684 CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
685 if (pKid->GetStringFor("Type") == "Page") { 685 if (pKid->GetStringFor("Type") == "Page") {
686 if (nPagesToGo != 0) { 686 if (nPagesToGo != 0) {
687 nPagesToGo--; 687 nPagesToGo--;
688 continue; 688 continue;
689 } 689 }
690 if (bInsert) { 690 if (bInsert) {
691 pKidList->InsertAt(i, new CPDF_Reference(this, pPageDict->GetObjNum())); 691 pKidList->InsertNewAt<CPDF_Reference>(i, this, pPageDict->GetObjNum());
692 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum()); 692 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum());
693 } else { 693 } else {
694 pKidList->RemoveAt(i); 694 pKidList->RemoveAt(i);
695 } 695 }
696 pPages->SetIntegerFor( 696 pPages->SetIntegerFor(
697 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); 697 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1));
698 ResetTraversal(); 698 ResetTraversal();
699 break; 699 break;
700 } 700 }
701 int nPages = pKid->GetIntegerFor("Count"); 701 int nPages = pKid->GetIntegerFor("Count");
(...skipping 24 matching lines...) Expand all
726 int nPages = GetPageCount(); 726 int nPages = GetPageCount();
727 if (iPage < 0 || iPage > nPages) 727 if (iPage < 0 || iPage > nPages)
728 return false; 728 return false;
729 729
730 if (iPage == nPages) { 730 if (iPage == nPages) {
731 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); 731 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids");
732 if (!pPagesList) { 732 if (!pPagesList) {
733 pPagesList = new CPDF_Array; 733 pPagesList = new CPDF_Array;
734 pPages->SetFor("Kids", pPagesList); 734 pPages->SetFor("Kids", pPagesList);
735 } 735 }
736 pPagesList->Add(new CPDF_Reference(this, pPageDict->GetObjNum())); 736 pPagesList->AddNew<CPDF_Reference>(this, pPageDict->GetObjNum());
737 pPages->SetIntegerFor("Count", nPages + 1); 737 pPages->SetIntegerFor("Count", nPages + 1);
738 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum()); 738 pPageDict->SetReferenceFor("Parent", this, pPages->GetObjNum());
739 ResetTraversal(); 739 ResetTraversal();
740 } else { 740 } else {
741 std::set<CPDF_Dictionary*> stack = {pPages}; 741 std::set<CPDF_Dictionary*> stack = {pPages};
742 if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack)) 742 if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack))
743 return false; 743 return false;
744 } 744 }
745 m_PageList.InsertAt(iPage, pPageDict->GetObjNum()); 745 m_PageList.InsertAt(iPage, pPageDict->GetObjNum());
746 return true; 746 return true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 break; 778 break;
779 } 779 }
780 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) 780 if (i == FX_ArraySize(g_FX_CharsetUnicodes))
781 return i; 781 return i;
782 782
783 CPDF_Dictionary* pEncodingDict = 783 CPDF_Dictionary* pEncodingDict =
784 NewIndirect<CPDF_Dictionary>(m_pByteStringPool); 784 NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
785 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); 785 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding");
786 786
787 CPDF_Array* pArray = new CPDF_Array; 787 CPDF_Array* pArray = new CPDF_Array;
788 pArray->AddInteger(128); 788 pArray->AddNew<CPDF_Number>(128);
789 789
790 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; 790 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes;
791 for (int j = 0; j < 128; j++) { 791 for (int j = 0; j < 128; j++) {
792 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); 792 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]);
793 pArray->AddName(name.IsEmpty() ? ".notdef" : name); 793 pArray->AddNew<CPDF_Name>(name.IsEmpty() ? ".notdef" : name);
794 } 794 }
795 pEncodingDict->SetFor("Differences", pArray); 795 pEncodingDict->SetFor("Differences", pArray);
796 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); 796 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
797 return i; 797 return i;
798 } 798 }
799 799
800 CPDF_Dictionary* CPDF_Document::ProcessbCJK( 800 CPDF_Dictionary* CPDF_Document::ProcessbCJK(
801 CPDF_Dictionary* pBaseDict, 801 CPDF_Dictionary* pBaseDict,
802 int charset, 802 int charset,
803 bool bVert, 803 bool bVert,
804 CFX_ByteString basefont, 804 CFX_ByteString basefont,
805 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { 805 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) {
806 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); 806 CPDF_Dictionary* pFontDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
807 CFX_ByteString cmap; 807 CFX_ByteString cmap;
808 CFX_ByteString ordering; 808 CFX_ByteString ordering;
809 int supplement = 0; 809 int supplement = 0;
810 CPDF_Array* pWidthArray = new CPDF_Array; 810 CPDF_Array* pWidthArray = new CPDF_Array;
811 switch (charset) { 811 switch (charset) {
812 case FXFONT_CHINESEBIG5_CHARSET: 812 case FXFONT_CHINESEBIG5_CHARSET:
813 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; 813 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
814 ordering = "CNS1"; 814 ordering = "CNS1";
815 supplement = 4; 815 supplement = 4;
816 pWidthArray->AddInteger(1); 816 pWidthArray->AddNew<CPDF_Number>(1);
817 Insert(0x20, 0x7e, pWidthArray); 817 Insert(0x20, 0x7e, pWidthArray);
818 break; 818 break;
819 case FXFONT_GB2312_CHARSET: 819 case FXFONT_GB2312_CHARSET:
820 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; 820 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
821 ordering = "GB1"; 821 ordering = "GB1";
822 supplement = 2; 822 supplement = 2;
823 pWidthArray->AddInteger(7716); 823 pWidthArray->AddNew<CPDF_Number>(7716);
824 Insert(0x20, 0x20, pWidthArray); 824 Insert(0x20, 0x20, pWidthArray);
825 pWidthArray->AddInteger(814); 825 pWidthArray->AddNew<CPDF_Number>(814);
826 Insert(0x21, 0x7e, pWidthArray); 826 Insert(0x21, 0x7e, pWidthArray);
827 break; 827 break;
828 case FXFONT_HANGUL_CHARSET: 828 case FXFONT_HANGUL_CHARSET:
829 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; 829 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
830 ordering = "Korea1"; 830 ordering = "Korea1";
831 supplement = 2; 831 supplement = 2;
832 pWidthArray->AddInteger(1); 832 pWidthArray->AddNew<CPDF_Number>(1);
833 Insert(0x20, 0x7e, pWidthArray); 833 Insert(0x20, 0x7e, pWidthArray);
834 break; 834 break;
835 case FXFONT_SHIFTJIS_CHARSET: 835 case FXFONT_SHIFTJIS_CHARSET:
836 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; 836 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
837 ordering = "Japan1"; 837 ordering = "Japan1";
838 supplement = 5; 838 supplement = 5;
839 pWidthArray->AddInteger(231); 839 pWidthArray->AddNew<CPDF_Number>(231);
840 Insert(0x20, 0x7d, pWidthArray); 840 Insert(0x20, 0x7d, pWidthArray);
841 pWidthArray->AddInteger(326); 841 pWidthArray->AddNew<CPDF_Number>(326);
842 Insert(0xa0, 0xa0, pWidthArray); 842 Insert(0xa0, 0xa0, pWidthArray);
843 pWidthArray->AddInteger(327); 843 pWidthArray->AddNew<CPDF_Number>(327);
844 Insert(0xa1, 0xdf, pWidthArray); 844 Insert(0xa1, 0xdf, pWidthArray);
845 pWidthArray->AddInteger(631); 845 pWidthArray->AddNew<CPDF_Number>(631);
846 Insert(0x7e, 0x7e, pWidthArray); 846 Insert(0x7e, 0x7e, pWidthArray);
847 break; 847 break;
848 } 848 }
849 pBaseDict->SetNameFor("Subtype", "Type0"); 849 pBaseDict->SetNameFor("Subtype", "Type0");
850 pBaseDict->SetNameFor("BaseFont", basefont); 850 pBaseDict->SetNameFor("BaseFont", basefont);
851 pBaseDict->SetNameFor("Encoding", cmap); 851 pBaseDict->SetNameFor("Encoding", cmap);
852 pFontDict->SetFor("W", pWidthArray); 852 pFontDict->SetFor("W", pWidthArray);
853 pFontDict->SetNameFor("Type", "Font"); 853 pFontDict->SetNameFor("Type", "Font");
854 pFontDict->SetNameFor("Subtype", "CIDFontType2"); 854 pFontDict->SetNameFor("Subtype", "CIDFontType2");
855 pFontDict->SetNameFor("BaseFont", basefont); 855 pFontDict->SetNameFor("BaseFont", basefont);
856 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); 856 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool);
857 pCIDSysInfo->SetStringFor("Registry", "Adobe"); 857 pCIDSysInfo->SetStringFor("Registry", "Adobe");
858 pCIDSysInfo->SetStringFor("Ordering", ordering); 858 pCIDSysInfo->SetStringFor("Ordering", ordering);
859 pCIDSysInfo->SetIntegerFor("Supplement", supplement); 859 pCIDSysInfo->SetIntegerFor("Supplement", supplement);
860 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); 860 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
861 CPDF_Array* pArray = new CPDF_Array; 861 CPDF_Array* pArray = new CPDF_Array;
862 pBaseDict->SetFor("DescendantFonts", pArray); 862 pBaseDict->SetFor("DescendantFonts", pArray);
863 pArray->AddReference(this, pFontDict->GetObjNum()); 863 pArray->AddNew<CPDF_Reference>(this, pFontDict->GetObjNum());
864 return pFontDict; 864 return pFontDict;
865 } 865 }
866 866
867 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) {
868 if (!pFont) 868 if (!pFont)
869 return nullptr; 869 return nullptr;
870 870
871 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || 871 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET ||
872 charset == FXFONT_GB2312_CHARSET || 872 charset == FXFONT_GB2312_CHARSET ||
873 charset == FXFONT_HANGUL_CHARSET || 873 charset == FXFONT_HANGUL_CHARSET ||
874 charset == FXFONT_SHIFTJIS_CHARSET; 874 charset == FXFONT_SHIFTJIS_CHARSET;
875 CFX_ByteString basefont = pFont->GetFamilyName(); 875 CFX_ByteString basefont = pFont->GetFamilyName();
876 basefont.Replace(" ", ""); 876 basefont.Replace(" ", "");
877 int flags = 877 int flags =
878 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), 878 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(),
879 false, false, charset == FXFONT_SYMBOL_CHARSET); 879 false, false, charset == FXFONT_SYMBOL_CHARSET);
880 880
881 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool); 881 CPDF_Dictionary* pBaseDict = NewIndirect<CPDF_Dictionary>(m_pByteStringPool);
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->AddInteger(char_width); 891 pWidths->AddNew<CPDF_Number>(char_width);
892 } 892 }
893 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || 893 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET ||
894 charset == FXFONT_SYMBOL_CHARSET) { 894 charset == FXFONT_SYMBOL_CHARSET) {
895 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); 895 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding");
896 for (int charcode = 128; charcode <= 255; charcode++) { 896 for (int charcode = 128; charcode <= 255; charcode++) {
897 int glyph_index = pEncoding->GlyphFromCharCode(charcode); 897 int glyph_index = pEncoding->GlyphFromCharCode(charcode);
898 int char_width = pFont->GetGlyphWidth(glyph_index); 898 int char_width = pFont->GetGlyphWidth(glyph_index);
899 pWidths->AddInteger(char_width); 899 pWidths->AddNew<CPDF_Number>(char_width);
900 } 900 }
901 } else { 901 } else {
902 size_t i = CalculateEncodingDict(charset, pBaseDict); 902 size_t i = CalculateEncodingDict(charset, pBaseDict);
903 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) { 903 if (i < FX_ArraySize(g_FX_CharsetUnicodes)) {
904 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; 904 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes;
905 for (int j = 0; j < 128; j++) { 905 for (int j = 0; j < 128; j++) {
906 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]); 906 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]);
907 int char_width = pFont->GetGlyphWidth(glyph_index); 907 int char_width = pFont->GetGlyphWidth(glyph_index);
908 pWidths->AddInteger(char_width); 908 pWidths->AddNew<CPDF_Number>(char_width);
909 } 909 }
910 } 910 }
911 } 911 }
912 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, 912 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont,
913 pWidths); 913 pWidths);
914 } else { 914 } else {
915 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, 915 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont,
916 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, 916 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end,
917 CPDF_Array* widthArr) { 917 CPDF_Array* widthArr) {
918 InsertWidthArray1(pFont, pEncoding.get(), start, 918 InsertWidthArray1(pFont, pEncoding.get(), start,
919 end, widthArr); 919 end, widthArr);
920 }); 920 });
921 } 921 }
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->AddNew<CPDF_Number>(bbox.left);
928 pBBox->AddInteger(bbox.bottom); 928 pBBox->AddNew<CPDF_Number>(bbox.bottom);
929 pBBox->AddInteger(bbox.right); 929 pBBox->AddNew<CPDF_Number>(bbox.right);
930 pBBox->AddInteger(bbox.top); 930 pBBox->AddNew<CPDF_Number>(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]);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || 1016 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET ||
1017 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { 1017 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) {
1018 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); 1018 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding");
1019 } else { 1019 } else {
1020 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); 1020 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict);
1021 } 1021 }
1022 int char_widths[224]; 1022 int char_widths[224];
1023 GetCharWidth(hDC, 32, 255, char_widths); 1023 GetCharWidth(hDC, 32, 255, char_widths);
1024 CPDF_Array* pWidths = new CPDF_Array; 1024 CPDF_Array* pWidths = new CPDF_Array;
1025 for (size_t i = 0; i < 224; i++) 1025 for (size_t i = 0; i < 224; i++)
1026 pWidths->AddInteger(char_widths[i]); 1026 pWidths->AddNew<CPDF_Number>(char_widths[i]);
1027 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, 1027 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM,
1028 pLogFont->lfItalic != 0, basefont, pWidths); 1028 pLogFont->lfItalic != 0, basefont, pWidths);
1029 } else { 1029 } else {
1030 pFontDict = 1030 pFontDict =
1031 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, 1031 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont,
1032 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { 1032 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) {
1033 InsertWidthArray(hDC, start, end, widthArr); 1033 InsertWidthArray(hDC, start, end, widthArr);
1034 }); 1034 });
1035 } 1035 }
1036 CPDF_Array* pBBox = new CPDF_Array; 1036 CPDF_Array* pBBox = new CPDF_Array;
1037 for (int i = 0; i < 4; i++) 1037 for (int i = 0; i < 4; i++)
1038 pBBox->AddInteger(bbox[i]); 1038 pBBox->AddNew<CPDF_Number>(bbox[i]);
1039 std::unique_ptr<CPDF_Dictionary> pFontDesc = 1039 std::unique_ptr<CPDF_Dictionary> pFontDesc =
1040 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, 1040 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend,
1041 pBBox, pLogFont->lfWeight / 5); 1041 pBBox, pLogFont->lfWeight / 5);
1042 pFontDesc->SetIntegerFor("CapHeight", capheight); 1042 pFontDesc->SetIntegerFor("CapHeight", capheight);
1043 pFontDict->SetReferenceFor("FontDescriptor", this, 1043 pFontDict->SetReferenceFor("FontDescriptor", this,
1044 AddIndirectObject(std::move(pFontDesc))); 1044 AddIndirectObject(std::move(pFontDesc)));
1045 hFont = SelectObject(hDC, hFont); 1045 hFont = SelectObject(hDC, hFont);
1046 DeleteObject(hFont); 1046 DeleteObject(hFont);
1047 DeleteDC(hDC); 1047 DeleteDC(hDC);
1048 return LoadFont(pBaseDict); 1048 return LoadFont(pBaseDict);
1049 } 1049 }
1050 #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