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

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

Issue 2341373003: Reduce duplicated code in CPDF_Document by adding auxiliary methods (Closed)
Patch Set: Fix winbots Created 4 years, 3 months 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
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/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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 {FXFONT_THAI_CHARSET, g_FX_CP874Unicodes}, 176 {FXFONT_THAI_CHARSET, g_FX_CP874Unicodes},
177 {FXFONT_EASTEUROPE_CHARSET, g_FX_CP1250Unicodes}, 177 {FXFONT_EASTEUROPE_CHARSET, g_FX_CP1250Unicodes},
178 {FXFONT_RUSSIAN_CHARSET, g_FX_CP1251Unicodes}, 178 {FXFONT_RUSSIAN_CHARSET, g_FX_CP1251Unicodes},
179 {FXFONT_GREEK_CHARSET, g_FX_CP1253Unicodes}, 179 {FXFONT_GREEK_CHARSET, g_FX_CP1253Unicodes},
180 {FXFONT_TURKISH_CHARSET, g_FX_CP1254Unicodes}, 180 {FXFONT_TURKISH_CHARSET, g_FX_CP1254Unicodes},
181 {FXFONT_HEBREW_CHARSET, g_FX_CP1255Unicodes}, 181 {FXFONT_HEBREW_CHARSET, g_FX_CP1255Unicodes},
182 {FXFONT_ARABIC_CHARSET, g_FX_CP1256Unicodes}, 182 {FXFONT_ARABIC_CHARSET, g_FX_CP1256Unicodes},
183 {FXFONT_BALTIC_CHARSET, g_FX_CP1257Unicodes}, 183 {FXFONT_BALTIC_CHARSET, g_FX_CP1257Unicodes},
184 }; 184 };
185 185
186 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 186 void InsertWidthArrayImpl(int* widths, int size, CPDF_Array* pWidthArray) {
187 void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) {
188 int size = end - start + 1;
189 int* widths = FX_Alloc(int, size);
190 GetCharWidth(hDC, start, end, widths);
191 int i; 187 int i;
192 for (i = 1; i < size; i++) { 188 for (i = 1; i < size; i++) {
193 if (widths[i] != *widths) 189 if (widths[i] != *widths)
194 break; 190 break;
195 } 191 }
196 if (i == size) { 192 if (i == size) {
197 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1); 193 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1);
198 pWidthArray->AddInteger(first + size - 1); 194 pWidthArray->AddInteger(first + size - 1);
199 pWidthArray->AddInteger(*widths); 195 pWidthArray->AddInteger(*widths);
200 } else { 196 } else {
201 CPDF_Array* pWidthArray1 = new CPDF_Array; 197 CPDF_Array* pWidthArray1 = new CPDF_Array;
202 pWidthArray->Add(pWidthArray1); 198 pWidthArray->Add(pWidthArray1);
203 for (i = 0; i < size; i++) 199 for (i = 0; i < size; i++)
204 pWidthArray1->AddInteger(widths[i]); 200 pWidthArray1->AddInteger(widths[i]);
205 } 201 }
206 FX_Free(widths); 202 FX_Free(widths);
207 } 203 }
208 204
205 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
206 void InsertWidthArray(HDC hDC, int start, int end, CPDF_Array* pWidthArray) {
207 int size = end - start + 1;
208 int* widths = FX_Alloc(int, size);
209 GetCharWidth(hDC, start, end, widths);
210 InsertWidthArrayImpl(widths, size, pWidthArray);
211 }
212
209 CFX_ByteString FPDF_GetPSNameFromTT(HDC hDC) { 213 CFX_ByteString FPDF_GetPSNameFromTT(HDC hDC) {
210 CFX_ByteString result; 214 CFX_ByteString result;
211 DWORD size = ::GetFontData(hDC, 'eman', 0, nullptr, 0); 215 DWORD size = ::GetFontData(hDC, 'eman', 0, nullptr, 0);
212 if (size != GDI_ERROR) { 216 if (size != GDI_ERROR) {
213 LPBYTE buffer = FX_Alloc(BYTE, size); 217 LPBYTE buffer = FX_Alloc(BYTE, size);
214 ::GetFontData(hDC, 'eman', 0, buffer, size); 218 ::GetFontData(hDC, 'eman', 0, buffer, size);
215 result = GetNameFromTT(buffer, size, 6); 219 result = GetNameFromTT(buffer, size, 6);
216 FX_Free(buffer); 220 FX_Free(buffer);
217 } 221 }
218 return result; 222 return result;
219 } 223 }
220 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 224 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
221 225
222 void InsertWidthArray1(CFX_Font* pFont, 226 void InsertWidthArray1(CFX_Font* pFont,
223 CFX_UnicodeEncoding* pEncoding, 227 CFX_UnicodeEncoding* pEncoding,
224 FX_WCHAR start, 228 FX_WCHAR start,
225 FX_WCHAR end, 229 FX_WCHAR end,
226 CPDF_Array* pWidthArray) { 230 CPDF_Array* pWidthArray) {
227 int size = end - start + 1; 231 int size = end - start + 1;
228 int* widths = FX_Alloc(int, size); 232 int* widths = FX_Alloc(int, size);
229 int i; 233 int i;
230 for (i = 0; i < size; i++) { 234 for (i = 0; i < size; i++) {
231 int glyph_index = pEncoding->GlyphFromCharCode(start + i); 235 int glyph_index = pEncoding->GlyphFromCharCode(start + i);
232 widths[i] = pFont->GetGlyphWidth(glyph_index); 236 widths[i] = pFont->GetGlyphWidth(glyph_index);
233 } 237 }
234 for (i = 1; i < size; i++) { 238 InsertWidthArrayImpl(widths, size, pWidthArray);
235 if (widths[i] != *widths)
236 break;
237 }
238 if (i == size) {
239 int first = pWidthArray->GetIntegerAt(pWidthArray->GetCount() - 1);
240 pWidthArray->AddInteger(first + size - 1);
241 pWidthArray->AddInteger(*widths);
242 } else {
243 CPDF_Array* pWidthArray1 = new CPDF_Array;
244 pWidthArray->Add(pWidthArray1);
245 for (i = 0; i < size; i++) {
246 pWidthArray1->AddInteger(widths[i]);
247 }
248 }
249 FX_Free(widths);
250 } 239 }
251 240
252 int InsertDeletePDFPage(CPDF_Document* pDoc, 241 int InsertDeletePDFPage(CPDF_Document* pDoc,
253 CPDF_Dictionary* pPages, 242 CPDF_Dictionary* pPages,
254 int nPagesToGo, 243 int nPagesToGo,
255 CPDF_Dictionary* pPage, 244 CPDF_Dictionary* pPage,
256 FX_BOOL bInsert, 245 FX_BOOL bInsert,
257 std::set<CPDF_Dictionary*>* pVisited) { 246 std::set<CPDF_Dictionary*>* pVisited) {
258 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); 247 CPDF_Array* pKidList = pPages->GetArrayFor("Kids");
259 if (!pKidList) 248 if (!pKidList)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 basefont += ",Bold"; 377 basefont += ",Bold";
389 else if (italic) 378 else if (italic)
390 basefont += ",Italic"; 379 basefont += ",Italic";
391 pBaseDict->SetNameFor("Subtype", "TrueType"); 380 pBaseDict->SetNameFor("Subtype", "TrueType");
392 pBaseDict->SetNameFor("BaseFont", basefont); 381 pBaseDict->SetNameFor("BaseFont", basefont);
393 pBaseDict->SetNumberFor("FirstChar", 32); 382 pBaseDict->SetNumberFor("FirstChar", 32);
394 pBaseDict->SetNumberFor("LastChar", 255); 383 pBaseDict->SetNumberFor("LastChar", 255);
395 pBaseDict->SetFor("Widths", pWidths); 384 pBaseDict->SetFor("Widths", pWidths);
396 } 385 }
397 386
387 CPDF_Dictionary* CalculateFontDesc(CFX_ByteString basefont,
388 int flags,
389 int italicangle,
390 int ascend,
391 int descend,
392 CPDF_Array* bbox,
393 int32_t stemV) {
394 CPDF_Dictionary* pFontDesc = new CPDF_Dictionary;
395 pFontDesc->SetNameFor("Type", "FontDescriptor");
396 pFontDesc->SetNameFor("FontName", basefont);
397 pFontDesc->SetIntegerFor("Flags", flags);
398 pFontDesc->SetFor("FontBBox", bbox);
399 pFontDesc->SetIntegerFor("ItalicAngle", italicangle);
400 pFontDesc->SetIntegerFor("Ascent", ascend);
401 pFontDesc->SetIntegerFor("Descent", descend);
402 pFontDesc->SetIntegerFor("StemV", stemV);
403 return pFontDesc;
404 }
405
398 } // namespace 406 } // namespace
399 407
400 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser) 408 CPDF_Document::CPDF_Document(std::unique_ptr<CPDF_Parser> pParser)
401 : CPDF_IndirectObjectHolder(), 409 : CPDF_IndirectObjectHolder(),
402 m_pParser(std::move(pParser)), 410 m_pParser(std::move(pParser)),
403 m_pRootDict(nullptr), 411 m_pRootDict(nullptr),
404 m_pInfoDict(nullptr), 412 m_pInfoDict(nullptr),
405 m_bLinearized(false), 413 m_bLinearized(false),
406 m_iFirstPageNo(0), 414 m_iFirstPageNo(0),
407 m_dwFirstPageObjNum(0), 415 m_dwFirstPageObjNum(0),
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 for (int j = 0; j < 128; j++) { 745 for (int j = 0; j < 128; j++) {
738 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); 746 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]);
739 pArray->AddName(name.IsEmpty() ? ".notdef" : name); 747 pArray->AddName(name.IsEmpty() ? ".notdef" : name);
740 } 748 }
741 pEncodingDict->SetFor("Differences", pArray); 749 pEncodingDict->SetFor("Differences", pArray);
742 AddIndirectObject(pEncodingDict); 750 AddIndirectObject(pEncodingDict);
743 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); 751 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
744 return i; 752 return i;
745 } 753 }
746 754
755 CPDF_Dictionary* CPDF_Document::ProcessbCJK(
756 CPDF_Dictionary* pBaseDict,
757 int charset,
758 FX_BOOL bVert,
759 CFX_ByteString basefont,
760 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) {
761 CPDF_Dictionary* pFontDict = new CPDF_Dictionary;
762 CFX_ByteString cmap;
763 CFX_ByteString ordering;
764 int supplement = 0;
765 CPDF_Array* pWidthArray = new CPDF_Array;
766 switch (charset) {
767 case FXFONT_CHINESEBIG5_CHARSET:
768 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
769 ordering = "CNS1";
770 supplement = 4;
771 pWidthArray->AddInteger(1);
772 Insert(0x20, 0x7e, pWidthArray);
773 break;
774 case FXFONT_GB2312_CHARSET:
775 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
776 ordering = "GB1";
777 supplement = 2;
778 pWidthArray->AddInteger(7716);
779 Insert(0x20, 0x20, pWidthArray);
780 pWidthArray->AddInteger(814);
781 Insert(0x21, 0x7e, pWidthArray);
782 break;
783 case FXFONT_HANGEUL_CHARSET:
784 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
785 ordering = "Korea1";
786 supplement = 2;
787 pWidthArray->AddInteger(1);
788 Insert(0x20, 0x7e, pWidthArray);
789 break;
790 case FXFONT_SHIFTJIS_CHARSET:
791 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
792 ordering = "Japan1";
793 supplement = 5;
794 pWidthArray->AddInteger(231);
795 Insert(0x20, 0x7d, pWidthArray);
796 pWidthArray->AddInteger(326);
797 Insert(0xa0, 0xa0, pWidthArray);
798 pWidthArray->AddInteger(327);
799 Insert(0xa1, 0xdf, pWidthArray);
800 pWidthArray->AddInteger(631);
801 Insert(0x7e, 0x7e, pWidthArray);
802 break;
803 }
804 pBaseDict->SetNameFor("Subtype", "Type0");
805 pBaseDict->SetNameFor("BaseFont", basefont);
806 pBaseDict->SetNameFor("Encoding", cmap);
807 pFontDict->SetFor("W", pWidthArray);
808 pFontDict->SetNameFor("Type", "Font");
809 pFontDict->SetNameFor("Subtype", "CIDFontType2");
810 pFontDict->SetNameFor("BaseFont", basefont);
811 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary;
812 pCIDSysInfo->SetStringFor("Registry", "Adobe");
813 pCIDSysInfo->SetStringFor("Ordering", ordering);
814 pCIDSysInfo->SetIntegerFor("Supplement", supplement);
815 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
816 CPDF_Array* pArray = new CPDF_Array;
817 pBaseDict->SetFor("DescendantFonts", pArray);
818 AddIndirectObject(pFontDict);
819 pArray->AddReference(this, pFontDict);
820 return pFontDict;
821 }
822
747 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { 823 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
748 if (!pFont) 824 if (!pFont)
749 return nullptr; 825 return nullptr;
750 826
751 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || 827 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET ||
752 charset == FXFONT_GB2312_CHARSET || 828 charset == FXFONT_GB2312_CHARSET ||
753 charset == FXFONT_HANGEUL_CHARSET || 829 charset == FXFONT_HANGEUL_CHARSET ||
754 charset == FXFONT_SHIFTJIS_CHARSET; 830 charset == FXFONT_SHIFTJIS_CHARSET;
755 CFX_ByteString basefont = pFont->GetFamilyName(); 831 CFX_ByteString basefont = pFont->GetFamilyName();
756 basefont.Replace(" ", ""); 832 basefont.Replace(" ", "");
(...skipping 28 matching lines...) Expand all
785 for (int j = 0; j < 128; j++) { 861 for (int j = 0; j < 128; j++) {
786 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]); 862 int glyph_index = pEncoding->GlyphFromCharCode(pUnicodes[j]);
787 int char_width = pFont->GetGlyphWidth(glyph_index); 863 int char_width = pFont->GetGlyphWidth(glyph_index);
788 pWidths->AddInteger(char_width); 864 pWidths->AddInteger(char_width);
789 } 865 }
790 } 866 }
791 } 867 }
792 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, 868 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont,
793 pWidths); 869 pWidths);
794 } else { 870 } else {
795 flags |= PDFFONT_NONSYMBOLIC; 871 auto Insert = [&](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) {
Tom Sepez 2016/09/16 19:42:14 nit: local not needed, it's much more fun to have
796 pFontDict = new CPDF_Dictionary; 872 InsertWidthArray1(pFont, pEncoding.get(), start, end, widthArr);
797 CFX_ByteString cmap; 873 };
798 CFX_ByteString ordering; 874 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, Insert);
799 int supplement = 0;
800 CPDF_Array* pWidthArray = new CPDF_Array;
801 switch (charset) {
802 case FXFONT_CHINESEBIG5_CHARSET:
803 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
804 ordering = "CNS1";
805 supplement = 4;
806 pWidthArray->AddInteger(1);
807 InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray);
808 break;
809 case FXFONT_GB2312_CHARSET:
810 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
811 ordering = "GB1";
812 supplement = 2;
813 pWidthArray->AddInteger(7716);
814 InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x20, pWidthArray);
815 pWidthArray->AddInteger(814);
816 InsertWidthArray1(pFont, pEncoding.get(), 0x21, 0x7e, pWidthArray);
817 break;
818 case FXFONT_HANGEUL_CHARSET:
819 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
820 ordering = "Korea1";
821 supplement = 2;
822 pWidthArray->AddInteger(1);
823 InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray);
824 break;
825 case FXFONT_SHIFTJIS_CHARSET:
826 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
827 ordering = "Japan1";
828 supplement = 5;
829 pWidthArray->AddInteger(231);
830 InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7d, pWidthArray);
831 pWidthArray->AddInteger(326);
832 InsertWidthArray1(pFont, pEncoding.get(), 0xa0, 0xa0, pWidthArray);
833 pWidthArray->AddInteger(327);
834 InsertWidthArray1(pFont, pEncoding.get(), 0xa1, 0xdf, pWidthArray);
835 pWidthArray->AddInteger(631);
836 InsertWidthArray1(pFont, pEncoding.get(), 0x7e, 0x7e, pWidthArray);
837 break;
838 }
839 pBaseDict->SetNameFor("Subtype", "Type0");
840 pBaseDict->SetNameFor("BaseFont", basefont);
841 pBaseDict->SetNameFor("Encoding", cmap);
842 pFontDict->SetFor("W", pWidthArray);
843 pFontDict->SetNameFor("Type", "Font");
844 pFontDict->SetNameFor("Subtype", "CIDFontType2");
845 pFontDict->SetNameFor("BaseFont", basefont);
846 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary;
847 pCIDSysInfo->SetStringFor("Registry", "Adobe");
848 pCIDSysInfo->SetStringFor("Ordering", ordering);
849 pCIDSysInfo->SetIntegerFor("Supplement", supplement);
850 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
851 CPDF_Array* pArray = new CPDF_Array;
852 pBaseDict->SetFor("DescendantFonts", pArray);
853 AddIndirectObject(pFontDict);
854 pArray->AddReference(this, pFontDict);
855 } 875 }
856 AddIndirectObject(pBaseDict); 876 AddIndirectObject(pBaseDict);
857 CPDF_Dictionary* pFontDesc = new CPDF_Dictionary; 877 int italicangle =
858 pFontDesc->SetNameFor("Type", "FontDescriptor"); 878 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0;
859 pFontDesc->SetNameFor("FontName", basefont);
860 pFontDesc->SetIntegerFor("Flags", flags);
861 pFontDesc->SetIntegerFor(
862 "ItalicAngle",
863 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0);
864 pFontDesc->SetIntegerFor("Ascent", pFont->GetAscent());
865 pFontDesc->SetIntegerFor("Descent", pFont->GetDescent());
866 FX_RECT bbox; 879 FX_RECT bbox;
867 pFont->GetBBox(bbox); 880 pFont->GetBBox(bbox);
868 CPDF_Array* pBBox = new CPDF_Array; 881 CPDF_Array* pBBox = new CPDF_Array;
869 pBBox->AddInteger(bbox.left); 882 pBBox->AddInteger(bbox.left);
870 pBBox->AddInteger(bbox.bottom); 883 pBBox->AddInteger(bbox.bottom);
871 pBBox->AddInteger(bbox.right); 884 pBBox->AddInteger(bbox.right);
872 pBBox->AddInteger(bbox.top); 885 pBBox->AddInteger(bbox.top);
873 pFontDesc->SetFor("FontBBox", pBBox);
874 int32_t nStemV = 0; 886 int32_t nStemV = 0;
875 if (pFont->GetSubstFont()) { 887 if (pFont->GetSubstFont()) {
876 nStemV = pFont->GetSubstFont()->m_Weight / 5; 888 nStemV = pFont->GetSubstFont()->m_Weight / 5;
877 } else { 889 } else {
878 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; 890 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'};
879 const size_t count = FX_ArraySize(stem_chars); 891 const size_t count = FX_ArraySize(stem_chars);
880 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); 892 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]);
881 nStemV = pFont->GetGlyphWidth(glyph); 893 nStemV = pFont->GetGlyphWidth(glyph);
882 for (size_t i = 1; i < count; i++) { 894 for (size_t i = 1; i < count; i++) {
883 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); 895 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]);
884 int width = pFont->GetGlyphWidth(glyph); 896 int width = pFont->GetGlyphWidth(glyph);
885 if (width > 0 && width < nStemV) 897 if (width > 0 && width < nStemV)
886 nStemV = width; 898 nStemV = width;
887 } 899 }
888 } 900 }
889 pFontDesc->SetIntegerFor("StemV", nStemV); 901 CPDF_Dictionary* pFontDesc =
902 CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(),
903 pFont->GetDescent(), pBBox, nStemV);
890 AddIndirectObject(pFontDesc); 904 AddIndirectObject(pFontDesc);
891 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); 905 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
892 return LoadFont(pBaseDict); 906 return LoadFont(pBaseDict);
893 } 907 }
894 908
895 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 909 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
896 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, 910 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont,
897 FX_BOOL bVert, 911 FX_BOOL bVert,
898 FX_BOOL bTranslateName) { 912 FX_BOOL bTranslateName) {
899 LOGFONTA lfa; 913 LOGFONTA lfa;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); 976 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict);
963 } 977 }
964 int char_widths[224]; 978 int char_widths[224];
965 GetCharWidth(hDC, 32, 255, char_widths); 979 GetCharWidth(hDC, 32, 255, char_widths);
966 CPDF_Array* pWidths = new CPDF_Array; 980 CPDF_Array* pWidths = new CPDF_Array;
967 for (size_t i = 0; i < 224; i++) 981 for (size_t i = 0; i < 224; i++)
968 pWidths->AddInteger(char_widths[i]); 982 pWidths->AddInteger(char_widths[i]);
969 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, 983 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM,
970 pLogFont->lfItalic != 0, basefont, pWidths); 984 pLogFont->lfItalic != 0, basefont, pWidths);
971 } else { 985 } else {
972 pFontDict = new CPDF_Dictionary; 986 auto Insert = [&](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) {
973 CFX_ByteString cmap; 987 InsertWidthArray(hDC, start, end, widthArr);
974 CFX_ByteString ordering; 988 };
975 int supplement = 0; 989 pFontDict =
976 CPDF_Array* pWidthArray = new CPDF_Array; 990 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, Insert);
977 switch (pLogFont->lfCharSet) {
978 case CHINESEBIG5_CHARSET:
979 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H";
980 ordering = "CNS1";
981 supplement = 4;
982 pWidthArray->AddInteger(1);
983 InsertWidthArray(hDC, 0x20, 0x7e, pWidthArray);
984 break;
985 case GB2312_CHARSET:
986 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H";
987 ordering = "GB1", supplement = 2;
988 pWidthArray->AddInteger(7716);
989 InsertWidthArray(hDC, 0x20, 0x20, pWidthArray);
990 pWidthArray->AddInteger(814);
991 InsertWidthArray(hDC, 0x21, 0x7e, pWidthArray);
992 break;
993 case HANGEUL_CHARSET:
994 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H";
995 ordering = "Korea1";
996 supplement = 2;
997 pWidthArray->AddInteger(1);
998 InsertWidthArray(hDC, 0x20, 0x7e, pWidthArray);
999 break;
1000 case SHIFTJIS_CHARSET:
1001 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H";
1002 ordering = "Japan1";
1003 supplement = 5;
1004 pWidthArray->AddInteger(231);
1005 InsertWidthArray(hDC, 0x20, 0x7d, pWidthArray);
1006 pWidthArray->AddInteger(326);
1007 InsertWidthArray(hDC, 0xa0, 0xa0, pWidthArray);
1008 pWidthArray->AddInteger(327);
1009 InsertWidthArray(hDC, 0xa1, 0xdf, pWidthArray);
1010 pWidthArray->AddInteger(631);
1011 InsertWidthArray(hDC, 0x7e, 0x7e, pWidthArray);
1012 break;
1013 }
1014 pBaseDict->SetNameFor("Subtype", "Type0");
1015 pBaseDict->SetNameFor("BaseFont", basefont);
1016 pBaseDict->SetNameFor("Encoding", cmap);
1017 pFontDict->SetFor("W", pWidthArray);
1018 pFontDict->SetNameFor("Type", "Font");
1019 pFontDict->SetNameFor("Subtype", "CIDFontType2");
1020 pFontDict->SetNameFor("BaseFont", basefont);
1021 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary;
1022 pCIDSysInfo->SetStringFor("Registry", "Adobe");
1023 pCIDSysInfo->SetStringFor("Ordering", ordering);
1024 pCIDSysInfo->SetIntegerFor("Supplement", supplement);
1025 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
1026 CPDF_Array* pArray = new CPDF_Array;
1027 pBaseDict->SetFor("DescendantFonts", pArray);
1028 AddIndirectObject(pFontDict);
1029 pArray->AddReference(this, pFontDict);
1030 } 991 }
1031 AddIndirectObject(pBaseDict); 992 AddIndirectObject(pBaseDict);
1032 CPDF_Dictionary* pFontDesc = new CPDF_Dictionary;
1033 pFontDesc->SetNameFor("Type", "FontDescriptor");
1034 pFontDesc->SetNameFor("FontName", basefont);
1035 pFontDesc->SetIntegerFor("Flags", flags);
1036 CPDF_Array* pBBox = new CPDF_Array; 993 CPDF_Array* pBBox = new CPDF_Array;
1037 for (int i = 0; i < 4; i++) 994 for (int i = 0; i < 4; i++)
1038 pBBox->AddInteger(bbox[i]); 995 pBBox->AddInteger(bbox[i]);
1039 pFontDesc->SetFor("FontBBox", pBBox); 996 CPDF_Dictionary* pFontDesc =
1040 pFontDesc->SetIntegerFor("ItalicAngle", italicangle); 997 CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox,
1041 pFontDesc->SetIntegerFor("Ascent", ascend); 998 pLogFont->lfWeight / 5);
1042 pFontDesc->SetIntegerFor("Descent", descend);
1043 pFontDesc->SetIntegerFor("CapHeight", capheight); 999 pFontDesc->SetIntegerFor("CapHeight", capheight);
1044 pFontDesc->SetIntegerFor("StemV", pLogFont->lfWeight / 5);
1045 AddIndirectObject(pFontDesc); 1000 AddIndirectObject(pFontDesc);
1046 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); 1001 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
1047 hFont = SelectObject(hDC, hFont); 1002 hFont = SelectObject(hDC, hFont);
1048 DeleteObject(hFont); 1003 DeleteObject(hFont);
1049 DeleteDC(hDC); 1004 DeleteDC(hDC);
1050 return LoadFont(pBaseDict); 1005 return LoadFont(pBaseDict);
1051 } 1006 }
1052 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 1007 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_parser/include/cpdf_document.h » ('j') | core/fpdfapi/fpdf_parser/include/cpdf_document.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698