| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, |
| 796 pFontDict = new CPDF_Dictionary; | 872 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, |
| 797 CFX_ByteString cmap; | 873 CPDF_Array* widthArr) { |
| 798 CFX_ByteString ordering; | 874 InsertWidthArray1(pFont, pEncoding.get(), start, |
| 799 int supplement = 0; | 875 end, widthArr); |
| 800 CPDF_Array* pWidthArray = new CPDF_Array; | 876 }); |
| 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 } | 877 } |
| 856 AddIndirectObject(pBaseDict); | 878 AddIndirectObject(pBaseDict); |
| 857 CPDF_Dictionary* pFontDesc = new CPDF_Dictionary; | 879 int italicangle = |
| 858 pFontDesc->SetNameFor("Type", "FontDescriptor"); | 880 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; | 881 FX_RECT bbox; |
| 867 pFont->GetBBox(bbox); | 882 pFont->GetBBox(bbox); |
| 868 CPDF_Array* pBBox = new CPDF_Array; | 883 CPDF_Array* pBBox = new CPDF_Array; |
| 869 pBBox->AddInteger(bbox.left); | 884 pBBox->AddInteger(bbox.left); |
| 870 pBBox->AddInteger(bbox.bottom); | 885 pBBox->AddInteger(bbox.bottom); |
| 871 pBBox->AddInteger(bbox.right); | 886 pBBox->AddInteger(bbox.right); |
| 872 pBBox->AddInteger(bbox.top); | 887 pBBox->AddInteger(bbox.top); |
| 873 pFontDesc->SetFor("FontBBox", pBBox); | |
| 874 int32_t nStemV = 0; | 888 int32_t nStemV = 0; |
| 875 if (pFont->GetSubstFont()) { | 889 if (pFont->GetSubstFont()) { |
| 876 nStemV = pFont->GetSubstFont()->m_Weight / 5; | 890 nStemV = pFont->GetSubstFont()->m_Weight / 5; |
| 877 } else { | 891 } else { |
| 878 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; | 892 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; |
| 879 const size_t count = FX_ArraySize(stem_chars); | 893 const size_t count = FX_ArraySize(stem_chars); |
| 880 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); | 894 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); |
| 881 nStemV = pFont->GetGlyphWidth(glyph); | 895 nStemV = pFont->GetGlyphWidth(glyph); |
| 882 for (size_t i = 1; i < count; i++) { | 896 for (size_t i = 1; i < count; i++) { |
| 883 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 897 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
| 884 int width = pFont->GetGlyphWidth(glyph); | 898 int width = pFont->GetGlyphWidth(glyph); |
| 885 if (width > 0 && width < nStemV) | 899 if (width > 0 && width < nStemV) |
| 886 nStemV = width; | 900 nStemV = width; |
| 887 } | 901 } |
| 888 } | 902 } |
| 889 pFontDesc->SetIntegerFor("StemV", nStemV); | 903 CPDF_Dictionary* pFontDesc = |
| 904 CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(), |
| 905 pFont->GetDescent(), pBBox, nStemV); |
| 890 AddIndirectObject(pFontDesc); | 906 AddIndirectObject(pFontDesc); |
| 891 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); | 907 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); |
| 892 return LoadFont(pBaseDict); | 908 return LoadFont(pBaseDict); |
| 893 } | 909 } |
| 894 | 910 |
| 895 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 911 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 896 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, | 912 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, |
| 897 FX_BOOL bVert, | 913 FX_BOOL bVert, |
| 898 FX_BOOL bTranslateName) { | 914 FX_BOOL bTranslateName) { |
| 899 LOGFONTA lfa; | 915 LOGFONTA lfa; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 978 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
| 963 } | 979 } |
| 964 int char_widths[224]; | 980 int char_widths[224]; |
| 965 GetCharWidth(hDC, 32, 255, char_widths); | 981 GetCharWidth(hDC, 32, 255, char_widths); |
| 966 CPDF_Array* pWidths = new CPDF_Array; | 982 CPDF_Array* pWidths = new CPDF_Array; |
| 967 for (size_t i = 0; i < 224; i++) | 983 for (size_t i = 0; i < 224; i++) |
| 968 pWidths->AddInteger(char_widths[i]); | 984 pWidths->AddInteger(char_widths[i]); |
| 969 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, | 985 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, |
| 970 pLogFont->lfItalic != 0, basefont, pWidths); | 986 pLogFont->lfItalic != 0, basefont, pWidths); |
| 971 } else { | 987 } else { |
| 972 pFontDict = new CPDF_Dictionary; | 988 pFontDict = |
| 973 CFX_ByteString cmap; | 989 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, |
| 974 CFX_ByteString ordering; | 990 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { |
| 975 int supplement = 0; | 991 InsertWidthArray(hDC, start, end, widthArr); |
| 976 CPDF_Array* pWidthArray = new CPDF_Array; | 992 }); |
| 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 } | 993 } |
| 1031 AddIndirectObject(pBaseDict); | 994 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; | 995 CPDF_Array* pBBox = new CPDF_Array; |
| 1037 for (int i = 0; i < 4; i++) | 996 for (int i = 0; i < 4; i++) |
| 1038 pBBox->AddInteger(bbox[i]); | 997 pBBox->AddInteger(bbox[i]); |
| 1039 pFontDesc->SetFor("FontBBox", pBBox); | 998 CPDF_Dictionary* pFontDesc = |
| 1040 pFontDesc->SetIntegerFor("ItalicAngle", italicangle); | 999 CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox, |
| 1041 pFontDesc->SetIntegerFor("Ascent", ascend); | 1000 pLogFont->lfWeight / 5); |
| 1042 pFontDesc->SetIntegerFor("Descent", descend); | |
| 1043 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1001 pFontDesc->SetIntegerFor("CapHeight", capheight); |
| 1044 pFontDesc->SetIntegerFor("StemV", pLogFont->lfWeight / 5); | |
| 1045 AddIndirectObject(pFontDesc); | 1002 AddIndirectObject(pFontDesc); |
| 1046 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); | 1003 pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc); |
| 1047 hFont = SelectObject(hDC, hFont); | 1004 hFont = SelectObject(hDC, hFont); |
| 1048 DeleteObject(hFont); | 1005 DeleteObject(hFont); |
| 1049 DeleteDC(hDC); | 1006 DeleteDC(hDC); |
| 1050 return LoadFont(pBaseDict); | 1007 return LoadFont(pBaseDict); |
| 1051 } | 1008 } |
| 1052 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1009 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| OLD | NEW |