| 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 "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "../../../include/fpdfapi/fpdf_module.h" | 8 #include "../../../include/fpdfapi/fpdf_module.h" |
| 9 #include "../fpdf_page/pageint.h" | 9 #include "../fpdf_page/pageint.h" |
| 10 #include <limits.h> | 10 #include <limits.h> |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 pFontDesc->SetAtInteger("CapHeight", capheight); | 419 pFontDesc->SetAtInteger("CapHeight", capheight); |
| 420 pFontDesc->SetAtInteger("StemV", pLogFont->lfWeight / 5); | 420 pFontDesc->SetAtInteger("StemV", pLogFont->lfWeight / 5); |
| 421 AddIndirectObject(pFontDesc); | 421 AddIndirectObject(pFontDesc); |
| 422 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); | 422 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); |
| 423 hFont = SelectObject(hDC, hFont); | 423 hFont = SelectObject(hDC, hFont); |
| 424 DeleteObject(hFont); | 424 DeleteObject(hFont); |
| 425 DeleteDC(hDC); | 425 DeleteDC(hDC); |
| 426 return LoadFont(pBaseDict); | 426 return LoadFont(pBaseDict); |
| 427 } | 427 } |
| 428 #endif | 428 #endif |
| 429 |
| 429 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_) | 430 #if (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_) |
| 430 uint32_t FX_GetLangHashCode(const FX_CHAR* pStr) { | 431 uint32_t FX_GetLangHashCode(const FX_CHAR* pStr) { |
| 431 FXSYS_assert(pStr != NULL); | 432 FXSYS_assert(pStr != NULL); |
| 432 int32_t iLength = FXSYS_strlen(pStr); | 433 int32_t iLength = FXSYS_strlen(pStr); |
| 433 const FX_CHAR* pStrEnd = pStr + iLength; | 434 const FX_CHAR* pStrEnd = pStr + iLength; |
| 434 uint32_t uHashCode = 0; | 435 uint32_t uHashCode = 0; |
| 435 while (pStr < pStrEnd) { | 436 while (pStr < pStrEnd) { |
| 436 uHashCode = 31 * uHashCode + tolower(*pStr++); | 437 uHashCode = 31 * uHashCode + tolower(*pStr++); |
| 437 } | 438 } |
| 438 return uHashCode; | 439 return uHashCode; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 785 } |
| 785 } | 786 } |
| 786 } | 787 } |
| 787 pFontDesc->SetAtInteger("StemV", fStemV); | 788 pFontDesc->SetAtInteger("StemV", fStemV); |
| 788 AddIndirectObject(pFontDesc); | 789 AddIndirectObject(pFontDesc); |
| 789 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); | 790 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); |
| 790 CFRelease(traits); | 791 CFRelease(traits); |
| 791 CFRelease(languages); | 792 CFRelease(languages); |
| 792 return LoadFont(pBaseDict); | 793 return LoadFont(pBaseDict); |
| 793 } | 794 } |
| 794 #endif | 795 #endif // (_FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_) |
| 796 |
| 795 static void _InsertWidthArray1(CFX_Font* pFont, | 797 static void _InsertWidthArray1(CFX_Font* pFont, |
| 796 IFX_FontEncoding* pEncoding, | 798 CFX_UnicodeEncoding* pEncoding, |
| 797 FX_WCHAR start, | 799 FX_WCHAR start, |
| 798 FX_WCHAR end, | 800 FX_WCHAR end, |
| 799 CPDF_Array* pWidthArray) { | 801 CPDF_Array* pWidthArray) { |
| 800 int size = end - start + 1; | 802 int size = end - start + 1; |
| 801 int* widths = FX_Alloc(int, size); | 803 int* widths = FX_Alloc(int, size); |
| 802 int i; | 804 int i; |
| 803 for (i = 0; i < size; i++) { | 805 for (i = 0; i < size; i++) { |
| 804 int glyph_index = pEncoding->GlyphFromCharCode(start + i); | 806 int glyph_index = pEncoding->GlyphFromCharCode(start + i); |
| 805 widths[i] = pFont->GetGlyphWidth(glyph_index); | 807 widths[i] = pFont->GetGlyphWidth(glyph_index); |
| 806 } | 808 } |
| 807 for (i = 1; i < size; i++) | 809 for (i = 1; i < size; i++) |
| 808 if (widths[i] != *widths) { | 810 if (widths[i] != *widths) { |
| 809 break; | 811 break; |
| 810 } | 812 } |
| 811 if (i == size) { | 813 if (i == size) { |
| 812 int first = pWidthArray->GetInteger(pWidthArray->GetCount() - 1); | 814 int first = pWidthArray->GetInteger(pWidthArray->GetCount() - 1); |
| 813 pWidthArray->AddInteger(first + size - 1); | 815 pWidthArray->AddInteger(first + size - 1); |
| 814 pWidthArray->AddInteger(*widths); | 816 pWidthArray->AddInteger(*widths); |
| 815 } else { | 817 } else { |
| 816 CPDF_Array* pWidthArray1 = new CPDF_Array; | 818 CPDF_Array* pWidthArray1 = new CPDF_Array; |
| 817 pWidthArray->Add(pWidthArray1); | 819 pWidthArray->Add(pWidthArray1); |
| 818 for (i = 0; i < size; i++) { | 820 for (i = 0; i < size; i++) { |
| 819 pWidthArray1->AddInteger(widths[i]); | 821 pWidthArray1->AddInteger(widths[i]); |
| 820 } | 822 } |
| 821 } | 823 } |
| 822 FX_Free(widths); | 824 FX_Free(widths); |
| 823 } | 825 } |
| 826 |
| 824 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { | 827 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { |
| 825 if (pFont == NULL) { | 828 if (pFont == NULL) { |
| 826 return NULL; | 829 return NULL; |
| 827 } | 830 } |
| 828 FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 831 FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
| 829 charset == FXFONT_GB2312_CHARSET || | 832 charset == FXFONT_GB2312_CHARSET || |
| 830 charset == FXFONT_HANGEUL_CHARSET || | 833 charset == FXFONT_HANGEUL_CHARSET || |
| 831 charset == FXFONT_SHIFTJIS_CHARSET; | 834 charset == FXFONT_SHIFTJIS_CHARSET; |
| 832 CFX_ByteString basefont = pFont->GetFamilyName(); | 835 CFX_ByteString basefont = pFont->GetFamilyName(); |
| 833 basefont.Replace(" ", ""); | 836 basefont.Replace(" ", ""); |
| 834 int flags = 0; | 837 int flags = 0; |
| 835 if (pFont->IsBold()) { | 838 if (pFont->IsBold()) { |
| 836 flags |= PDFFONT_FORCEBOLD; | 839 flags |= PDFFONT_FORCEBOLD; |
| 837 } | 840 } |
| 838 if (pFont->IsItalic()) { | 841 if (pFont->IsItalic()) { |
| 839 flags |= PDFFONT_ITALIC; | 842 flags |= PDFFONT_ITALIC; |
| 840 } | 843 } |
| 841 if (pFont->IsFixedWidth()) { | 844 if (pFont->IsFixedWidth()) { |
| 842 flags |= PDFFONT_FIXEDPITCH; | 845 flags |= PDFFONT_FIXEDPITCH; |
| 843 } | 846 } |
| 844 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary; | 847 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary; |
| 845 pBaseDict->SetAtName("Type", "Font"); | 848 pBaseDict->SetAtName("Type", "Font"); |
| 846 IFX_FontEncoding* pEncoding = FXGE_CreateUnicodeEncoding(pFont); | 849 nonstd::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
| 850 new CFX_UnicodeEncoding(pFont)); |
| 847 CPDF_Dictionary* pFontDict = pBaseDict; | 851 CPDF_Dictionary* pFontDict = pBaseDict; |
| 848 if (!bCJK) { | 852 if (!bCJK) { |
| 849 CPDF_Array* pWidths = new CPDF_Array; | 853 CPDF_Array* pWidths = new CPDF_Array; |
| 850 int charcode; | 854 int charcode; |
| 851 for (charcode = 32; charcode < 128; charcode++) { | 855 for (charcode = 32; charcode < 128; charcode++) { |
| 852 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 856 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
| 853 int char_width = pFont->GetGlyphWidth(glyph_index); | 857 int char_width = pFont->GetGlyphWidth(glyph_index); |
| 854 pWidths->AddInteger(char_width); | 858 pWidths->AddInteger(char_width); |
| 855 } | 859 } |
| 856 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || | 860 if (charset == FXFONT_ANSI_CHARSET || charset == FXFONT_DEFAULT_CHARSET || |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 CFX_ByteString cmap; | 918 CFX_ByteString cmap; |
| 915 CFX_ByteString ordering; | 919 CFX_ByteString ordering; |
| 916 int supplement; | 920 int supplement; |
| 917 CPDF_Array* pWidthArray = new CPDF_Array; | 921 CPDF_Array* pWidthArray = new CPDF_Array; |
| 918 switch (charset) { | 922 switch (charset) { |
| 919 case FXFONT_CHINESEBIG5_CHARSET: | 923 case FXFONT_CHINESEBIG5_CHARSET: |
| 920 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 924 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
| 921 ordering = "CNS1"; | 925 ordering = "CNS1"; |
| 922 supplement = 4; | 926 supplement = 4; |
| 923 pWidthArray->AddInteger(1); | 927 pWidthArray->AddInteger(1); |
| 924 _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7e, pWidthArray); | 928 _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray); |
| 925 break; | 929 break; |
| 926 case FXFONT_GB2312_CHARSET: | 930 case FXFONT_GB2312_CHARSET: |
| 927 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; | 931 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; |
| 928 ordering = "GB1", supplement = 2; | 932 ordering = "GB1", supplement = 2; |
| 929 pWidthArray->AddInteger(7716); | 933 pWidthArray->AddInteger(7716); |
| 930 _InsertWidthArray1(pFont, pEncoding, 0x20, 0x20, pWidthArray); | 934 _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x20, pWidthArray); |
| 931 pWidthArray->AddInteger(814); | 935 pWidthArray->AddInteger(814); |
| 932 _InsertWidthArray1(pFont, pEncoding, 0x21, 0x7e, pWidthArray); | 936 _InsertWidthArray1(pFont, pEncoding.get(), 0x21, 0x7e, pWidthArray); |
| 933 break; | 937 break; |
| 934 case FXFONT_HANGEUL_CHARSET: | 938 case FXFONT_HANGEUL_CHARSET: |
| 935 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; | 939 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; |
| 936 ordering = "Korea1"; | 940 ordering = "Korea1"; |
| 937 supplement = 2; | 941 supplement = 2; |
| 938 pWidthArray->AddInteger(1); | 942 pWidthArray->AddInteger(1); |
| 939 _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7e, pWidthArray); | 943 _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7e, pWidthArray); |
| 940 break; | 944 break; |
| 941 case FXFONT_SHIFTJIS_CHARSET: | 945 case FXFONT_SHIFTJIS_CHARSET: |
| 942 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; | 946 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; |
| 943 ordering = "Japan1"; | 947 ordering = "Japan1"; |
| 944 supplement = 5; | 948 supplement = 5; |
| 945 pWidthArray->AddInteger(231); | 949 pWidthArray->AddInteger(231); |
| 946 _InsertWidthArray1(pFont, pEncoding, 0x20, 0x7d, pWidthArray); | 950 _InsertWidthArray1(pFont, pEncoding.get(), 0x20, 0x7d, pWidthArray); |
| 947 pWidthArray->AddInteger(326); | 951 pWidthArray->AddInteger(326); |
| 948 _InsertWidthArray1(pFont, pEncoding, 0xa0, 0xa0, pWidthArray); | 952 _InsertWidthArray1(pFont, pEncoding.get(), 0xa0, 0xa0, pWidthArray); |
| 949 pWidthArray->AddInteger(327); | 953 pWidthArray->AddInteger(327); |
| 950 _InsertWidthArray1(pFont, pEncoding, 0xa1, 0xdf, pWidthArray); | 954 _InsertWidthArray1(pFont, pEncoding.get(), 0xa1, 0xdf, pWidthArray); |
| 951 pWidthArray->AddInteger(631); | 955 pWidthArray->AddInteger(631); |
| 952 _InsertWidthArray1(pFont, pEncoding, 0x7e, 0x7e, pWidthArray); | 956 _InsertWidthArray1(pFont, pEncoding.get(), 0x7e, 0x7e, pWidthArray); |
| 953 break; | 957 break; |
| 954 } | 958 } |
| 955 pBaseDict->SetAtName("Subtype", "Type0"); | 959 pBaseDict->SetAtName("Subtype", "Type0"); |
| 956 pBaseDict->SetAtName("BaseFont", basefont); | 960 pBaseDict->SetAtName("BaseFont", basefont); |
| 957 pBaseDict->SetAtName("Encoding", cmap); | 961 pBaseDict->SetAtName("Encoding", cmap); |
| 958 pFontDict->SetAt("W", pWidthArray); | 962 pFontDict->SetAt("W", pWidthArray); |
| 959 pFontDict->SetAtName("Type", "Font"); | 963 pFontDict->SetAtName("Type", "Font"); |
| 960 pFontDict->SetAtName("Subtype", "CIDFontType2"); | 964 pFontDict->SetAtName("Subtype", "CIDFontType2"); |
| 961 pFontDict->SetAtName("BaseFont", basefont); | 965 pFontDict->SetAtName("BaseFont", basefont); |
| 962 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary; | 966 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 FX_DWORD glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); | 1000 FX_DWORD glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); |
| 997 nStemV = pFont->GetGlyphWidth(glyph); | 1001 nStemV = pFont->GetGlyphWidth(glyph); |
| 998 for (size_t i = 1; i < count; i++) { | 1002 for (size_t i = 1; i < count; i++) { |
| 999 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 1003 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
| 1000 int width = pFont->GetGlyphWidth(glyph); | 1004 int width = pFont->GetGlyphWidth(glyph); |
| 1001 if (width > 0 && width < nStemV) { | 1005 if (width > 0 && width < nStemV) { |
| 1002 nStemV = width; | 1006 nStemV = width; |
| 1003 } | 1007 } |
| 1004 } | 1008 } |
| 1005 } | 1009 } |
| 1006 delete pEncoding; | |
| 1007 pFontDesc->SetAtInteger("StemV", nStemV); | 1010 pFontDesc->SetAtInteger("StemV", nStemV); |
| 1008 AddIndirectObject(pFontDesc); | 1011 AddIndirectObject(pFontDesc); |
| 1009 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); | 1012 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); |
| 1010 return LoadFont(pBaseDict); | 1013 return LoadFont(pBaseDict); |
| 1011 } | 1014 } |
| 1012 static int InsertDeletePDFPage(CPDF_Document* pDoc, | 1015 static int InsertDeletePDFPage(CPDF_Document* pDoc, |
| 1013 CPDF_Dictionary* pPages, | 1016 CPDF_Dictionary* pPages, |
| 1014 int nPagesToGo, | 1017 int nPagesToGo, |
| 1015 CPDF_Dictionary* pPage, | 1018 CPDF_Dictionary* pPage, |
| 1016 FX_BOOL bInsert, | 1019 FX_BOOL bInsert, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, | 1142 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, |
| 1140 const CFX_ByteStringC& name) { | 1143 const CFX_ByteStringC& name) { |
| 1141 if (pPageDict->KeyExist(name)) { | 1144 if (pPageDict->KeyExist(name)) { |
| 1142 return; | 1145 return; |
| 1143 } | 1146 } |
| 1144 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); | 1147 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); |
| 1145 if (pObj) { | 1148 if (pObj) { |
| 1146 pPageDict->SetAt(name, pObj->Clone()); | 1149 pPageDict->SetAt(name, pObj->Clone()); |
| 1147 } | 1150 } |
| 1148 } | 1151 } |
| OLD | NEW |