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/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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); | 249 CPDF_Array* pKidList = pPages->GetArrayFor("Kids"); |
250 if (!pKidList) | 250 if (!pKidList) |
251 return -1; | 251 return -1; |
252 | 252 |
253 for (size_t i = 0; i < pKidList->GetCount(); i++) { | 253 for (size_t i = 0; i < pKidList->GetCount(); i++) { |
254 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); | 254 CPDF_Dictionary* pKid = pKidList->GetDictAt(i); |
255 if (pKid->GetStringFor("Type") == "Page") { | 255 if (pKid->GetStringFor("Type") == "Page") { |
256 if (nPagesToGo == 0) { | 256 if (nPagesToGo == 0) { |
257 if (bInsert) { | 257 if (bInsert) { |
258 pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); | 258 pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum())); |
259 pPage->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); | 259 pPage->SetReferenceFor("Parent", pDoc, pPages); |
260 } else { | 260 } else { |
261 pKidList->RemoveAt(i); | 261 pKidList->RemoveAt(i); |
262 } | 262 } |
263 pPages->SetIntegerFor( | 263 pPages->SetIntegerFor( |
264 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); | 264 "Count", pPages->GetIntegerFor("Count") + (bInsert ? 1 : -1)); |
265 return 1; | 265 return 1; |
266 } | 266 } |
267 nPagesToGo--; | 267 nPagesToGo--; |
268 } else { | 268 } else { |
269 int nPages = pKid->GetIntegerFor("Count"); | 269 int nPages = pKid->GetIntegerFor("Count"); |
(...skipping 30 matching lines...) Expand all Loading... | |
300 return -1; | 300 return -1; |
301 | 301 |
302 if (iPage == nPages) { | 302 if (iPage == nPages) { |
303 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); | 303 CPDF_Array* pPagesList = pPages->GetArrayFor("Kids"); |
304 if (!pPagesList) { | 304 if (!pPagesList) { |
305 pPagesList = new CPDF_Array; | 305 pPagesList = new CPDF_Array; |
306 pPages->SetFor("Kids", pPagesList); | 306 pPages->SetFor("Kids", pPagesList); |
307 } | 307 } |
308 pPagesList->Add(new CPDF_Reference(pDoc, pPageDict->GetObjNum())); | 308 pPagesList->Add(new CPDF_Reference(pDoc, pPageDict->GetObjNum())); |
309 pPages->SetIntegerFor("Count", nPages + 1); | 309 pPages->SetIntegerFor("Count", nPages + 1); |
310 pPageDict->SetReferenceFor("Parent", pDoc, pPages->GetObjNum()); | 310 pPageDict->SetReferenceFor("Parent", pDoc, pPages); |
311 } else { | 311 } else { |
312 std::set<CPDF_Dictionary*> stack = {pPages}; | 312 std::set<CPDF_Dictionary*> stack = {pPages}; |
313 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0) | 313 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, &stack) < 0) |
314 return -1; | 314 return -1; |
315 } | 315 } |
316 pageList.InsertAt(iPage, pPageDict->GetObjNum()); | 316 pageList.InsertAt(iPage, pPageDict->GetObjNum()); |
317 return iPage; | 317 return iPage; |
318 } | 318 } |
319 | 319 |
320 int CountPages(CPDF_Dictionary* pPages, | 320 int CountPages(CPDF_Dictionary* pPages, |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) { | 686 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) { |
687 if (!pObj) | 687 if (!pObj) |
688 return nullptr; | 688 return nullptr; |
689 | 689 |
690 ASSERT(pObj->GetObjNum()); | 690 ASSERT(pObj->GetObjNum()); |
691 return m_pDocPage->GetImage(pObj); | 691 return m_pDocPage->GetImage(pObj); |
692 } | 692 } |
693 | 693 |
694 void CPDF_Document::CreateNewDoc() { | 694 void CPDF_Document::CreateNewDoc() { |
695 ASSERT(!m_pRootDict && !m_pInfoDict); | 695 ASSERT(!m_pRootDict && !m_pInfoDict); |
696 m_pRootDict = new CPDF_Dictionary(m_pByteStringPool); | 696 m_pRootDict = AddIndirectDictionary(m_pByteStringPool); |
697 m_pRootDict->SetNameFor("Type", "Catalog"); | 697 m_pRootDict->SetNameFor("Type", "Catalog"); |
698 AddIndirectObject(m_pRootDict); | |
699 | 698 |
700 CPDF_Dictionary* pPages = new CPDF_Dictionary(m_pByteStringPool); | 699 CPDF_Dictionary* pPages = AddIndirectDictionary(m_pByteStringPool); |
701 pPages->SetNameFor("Type", "Pages"); | 700 pPages->SetNameFor("Type", "Pages"); |
702 pPages->SetNumberFor("Count", 0); | 701 pPages->SetNumberFor("Count", 0); |
703 pPages->SetFor("Kids", new CPDF_Array); | 702 pPages->SetFor("Kids", new CPDF_Array); |
704 m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages)); | 703 |
705 m_pInfoDict = new CPDF_Dictionary(m_pByteStringPool); | 704 m_pRootDict->SetReferenceFor("Pages", this, pPages); |
706 AddIndirectObject(m_pInfoDict); | 705 m_pInfoDict = AddIndirectDictionary(m_pByteStringPool); |
707 } | 706 } |
708 | 707 |
709 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { | 708 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) { |
710 CPDF_Dictionary* pDict = new CPDF_Dictionary(m_pByteStringPool); | 709 CPDF_Dictionary* pDict = AddIndirectDictionary(m_pByteStringPool); |
711 pDict->SetNameFor("Type", "Page"); | 710 pDict->SetNameFor("Type", "Page"); |
712 uint32_t dwObjNum = AddIndirectObject(pDict); | |
713 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { | 711 if (InsertNewPage(this, iPage, pDict, m_PageList) < 0) { |
714 ReleaseIndirectObject(dwObjNum); | 712 DeleteIndirectObject(pDict->GetObjNum()); |
715 return nullptr; | 713 return nullptr; |
716 } | 714 } |
717 return pDict; | 715 return pDict; |
718 } | 716 } |
719 | 717 |
720 void CPDF_Document::DeletePage(int iPage) { | 718 void CPDF_Document::DeletePage(int iPage) { |
721 CPDF_Dictionary* pPages = GetPagesDict(); | 719 CPDF_Dictionary* pPages = GetPagesDict(); |
722 if (!pPages) | 720 if (!pPages) |
723 return; | 721 return; |
724 | 722 |
(...skipping 18 matching lines...) Expand all Loading... | |
743 | 741 |
744 size_t CPDF_Document::CalculateEncodingDict(int charset, | 742 size_t CPDF_Document::CalculateEncodingDict(int charset, |
745 CPDF_Dictionary* pBaseDict) { | 743 CPDF_Dictionary* pBaseDict) { |
746 size_t i; | 744 size_t i; |
747 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { | 745 for (i = 0; i < FX_ArraySize(g_FX_CharsetUnicodes); ++i) { |
748 if (g_FX_CharsetUnicodes[i].m_Charset == charset) | 746 if (g_FX_CharsetUnicodes[i].m_Charset == charset) |
749 break; | 747 break; |
750 } | 748 } |
751 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) | 749 if (i == FX_ArraySize(g_FX_CharsetUnicodes)) |
752 return i; | 750 return i; |
753 CPDF_Dictionary* pEncodingDict = new CPDF_Dictionary(m_pByteStringPool); | 751 |
752 CPDF_Dictionary* pEncodingDict = AddIndirectDictionary(m_pByteStringPool); | |
754 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); | 753 pEncodingDict->SetNameFor("BaseEncoding", "WinAnsiEncoding"); |
755 CPDF_Array* pArray = new CPDF_Array; | 754 CPDF_Array* pArray = new CPDF_Array; |
756 pArray->AddInteger(128); | 755 pArray->AddInteger(128); |
757 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; | 756 const uint16_t* pUnicodes = g_FX_CharsetUnicodes[i].m_pUnicodes; |
758 for (int j = 0; j < 128; j++) { | 757 for (int j = 0; j < 128; j++) { |
759 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); | 758 CFX_ByteString name = PDF_AdobeNameFromUnicode(pUnicodes[j]); |
760 pArray->AddName(name.IsEmpty() ? ".notdef" : name); | 759 pArray->AddName(name.IsEmpty() ? ".notdef" : name); |
761 } | 760 } |
762 pEncodingDict->SetFor("Differences", pArray); | 761 pEncodingDict->SetFor("Differences", pArray); |
763 pBaseDict->SetReferenceFor("Encoding", this, | 762 pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict); |
764 AddIndirectObject(pEncodingDict)); | |
765 | |
766 return i; | 763 return i; |
767 } | 764 } |
768 | 765 |
769 CPDF_Dictionary* CPDF_Document::ProcessbCJK( | 766 CPDF_Dictionary* CPDF_Document::ProcessbCJK( |
770 CPDF_Dictionary* pBaseDict, | 767 CPDF_Dictionary* pBaseDict, |
771 int charset, | 768 int charset, |
772 FX_BOOL bVert, | 769 FX_BOOL bVert, |
773 CFX_ByteString basefont, | 770 CFX_ByteString basefont, |
774 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { | 771 std::function<void(FX_WCHAR, FX_WCHAR, CPDF_Array*)> Insert) { |
775 CPDF_Dictionary* pFontDict = new CPDF_Dictionary(m_pByteStringPool); | 772 UniqueDictionary pFontDict(new CPDF_Dictionary(m_pByteStringPool)); |
776 CFX_ByteString cmap; | 773 CFX_ByteString cmap; |
777 CFX_ByteString ordering; | 774 CFX_ByteString ordering; |
778 int supplement = 0; | 775 int supplement = 0; |
779 CPDF_Array* pWidthArray = new CPDF_Array; | 776 CPDF_Array* pWidthArray = new CPDF_Array; |
780 switch (charset) { | 777 switch (charset) { |
781 case FXFONT_CHINESEBIG5_CHARSET: | 778 case FXFONT_CHINESEBIG5_CHARSET: |
782 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 779 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
783 ordering = "CNS1"; | 780 ordering = "CNS1"; |
784 supplement = 4; | 781 supplement = 4; |
785 pWidthArray->AddInteger(1); | 782 pWidthArray->AddInteger(1); |
(...skipping 29 matching lines...) Expand all Loading... | |
815 Insert(0x7e, 0x7e, pWidthArray); | 812 Insert(0x7e, 0x7e, pWidthArray); |
816 break; | 813 break; |
817 } | 814 } |
818 pBaseDict->SetNameFor("Subtype", "Type0"); | 815 pBaseDict->SetNameFor("Subtype", "Type0"); |
819 pBaseDict->SetNameFor("BaseFont", basefont); | 816 pBaseDict->SetNameFor("BaseFont", basefont); |
820 pBaseDict->SetNameFor("Encoding", cmap); | 817 pBaseDict->SetNameFor("Encoding", cmap); |
821 pFontDict->SetFor("W", pWidthArray); | 818 pFontDict->SetFor("W", pWidthArray); |
822 pFontDict->SetNameFor("Type", "Font"); | 819 pFontDict->SetNameFor("Type", "Font"); |
823 pFontDict->SetNameFor("Subtype", "CIDFontType2"); | 820 pFontDict->SetNameFor("Subtype", "CIDFontType2"); |
824 pFontDict->SetNameFor("BaseFont", basefont); | 821 pFontDict->SetNameFor("BaseFont", basefont); |
822 | |
825 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); | 823 CPDF_Dictionary* pCIDSysInfo = new CPDF_Dictionary(m_pByteStringPool); |
826 pCIDSysInfo->SetStringFor("Registry", "Adobe"); | 824 pCIDSysInfo->SetStringFor("Registry", "Adobe"); |
827 pCIDSysInfo->SetStringFor("Ordering", ordering); | 825 pCIDSysInfo->SetStringFor("Ordering", ordering); |
828 pCIDSysInfo->SetIntegerFor("Supplement", supplement); | 826 pCIDSysInfo->SetIntegerFor("Supplement", supplement); |
829 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); | 827 pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo); |
828 | |
830 CPDF_Array* pArray = new CPDF_Array; | 829 CPDF_Array* pArray = new CPDF_Array; |
831 pBaseDict->SetFor("DescendantFonts", pArray); | 830 pBaseDict->SetFor("DescendantFonts", pArray); |
832 pArray->AddReference(this, AddIndirectObject(pFontDict)); | 831 |
833 return pFontDict; | 832 CPDF_Object* pUnowned = AddIndirectObject(std::move(pFontDict)); |
Lei Zhang
2016/10/14 23:24:38
Can we do CPDF_Dictionary* pFontDict = AddIndirect
Tom Sepez
2016/10/14 23:42:29
Done.
| |
833 pArray->AddReference(this, pUnowned); | |
834 return ToDictionary(pUnowned); | |
834 } | 835 } |
835 | 836 |
836 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { | 837 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) { |
837 if (!pFont) | 838 if (!pFont) |
838 return nullptr; | 839 return nullptr; |
839 | 840 |
840 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 841 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
841 charset == FXFONT_GB2312_CHARSET || | 842 charset == FXFONT_GB2312_CHARSET || |
842 charset == FXFONT_HANGUL_CHARSET || | 843 charset == FXFONT_HANGUL_CHARSET || |
843 charset == FXFONT_SHIFTJIS_CHARSET; | 844 charset == FXFONT_SHIFTJIS_CHARSET; |
844 CFX_ByteString basefont = pFont->GetFamilyName(); | 845 CFX_ByteString basefont = pFont->GetFamilyName(); |
845 basefont.Replace(" ", ""); | 846 basefont.Replace(" ", ""); |
846 int flags = | 847 int flags = |
847 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), | 848 CalculateFlags(pFont->IsBold(), pFont->IsItalic(), pFont->IsFixedWidth(), |
848 false, false, charset == FXFONT_SYMBOL_CHARSET); | 849 false, false, charset == FXFONT_SYMBOL_CHARSET); |
849 | 850 |
850 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); | 851 CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool); |
851 pBaseDict->SetNameFor("Type", "Font"); | 852 pBaseDict->SetNameFor("Type", "Font"); |
852 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( | 853 std::unique_ptr<CFX_UnicodeEncoding> pEncoding( |
853 new CFX_UnicodeEncoding(pFont)); | 854 new CFX_UnicodeEncoding(pFont)); |
854 CPDF_Dictionary* pFontDict = pBaseDict; | 855 CPDF_Dictionary* pFontDict = pBaseDict; |
855 if (!bCJK) { | 856 if (!bCJK) { |
856 CPDF_Array* pWidths = new CPDF_Array; | 857 CPDF_Array* pWidths = new CPDF_Array; |
857 for (int charcode = 32; charcode < 128; charcode++) { | 858 for (int charcode = 32; charcode < 128; charcode++) { |
858 int glyph_index = pEncoding->GlyphFromCharCode(charcode); | 859 int glyph_index = pEncoding->GlyphFromCharCode(charcode); |
859 int char_width = pFont->GetGlyphWidth(glyph_index); | 860 int char_width = pFont->GetGlyphWidth(glyph_index); |
860 pWidths->AddInteger(char_width); | 861 pWidths->AddInteger(char_width); |
(...skipping 20 matching lines...) Expand all Loading... | |
881 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, | 882 ProcessNonbCJK(pBaseDict, pFont->IsBold(), pFont->IsItalic(), basefont, |
882 pWidths); | 883 pWidths); |
883 } else { | 884 } else { |
884 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, | 885 pFontDict = ProcessbCJK(pBaseDict, charset, bVert, basefont, |
885 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, | 886 [pFont, &pEncoding](FX_WCHAR start, FX_WCHAR end, |
886 CPDF_Array* widthArr) { | 887 CPDF_Array* widthArr) { |
887 InsertWidthArray1(pFont, pEncoding.get(), start, | 888 InsertWidthArray1(pFont, pEncoding.get(), start, |
888 end, widthArr); | 889 end, widthArr); |
889 }); | 890 }); |
890 } | 891 } |
891 AddIndirectObject(pBaseDict); | |
892 int italicangle = | 892 int italicangle = |
893 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; | 893 pFont->GetSubstFont() ? pFont->GetSubstFont()->m_ItalicAngle : 0; |
894 FX_RECT bbox; | 894 FX_RECT bbox; |
895 pFont->GetBBox(bbox); | 895 pFont->GetBBox(bbox); |
896 CPDF_Array* pBBox = new CPDF_Array; | 896 CPDF_Array* pBBox = new CPDF_Array; |
897 pBBox->AddInteger(bbox.left); | 897 pBBox->AddInteger(bbox.left); |
898 pBBox->AddInteger(bbox.bottom); | 898 pBBox->AddInteger(bbox.bottom); |
899 pBBox->AddInteger(bbox.right); | 899 pBBox->AddInteger(bbox.right); |
900 pBBox->AddInteger(bbox.top); | 900 pBBox->AddInteger(bbox.top); |
901 int32_t nStemV = 0; | 901 int32_t nStemV = 0; |
902 if (pFont->GetSubstFont()) { | 902 if (pFont->GetSubstFont()) { |
903 nStemV = pFont->GetSubstFont()->m_Weight / 5; | 903 nStemV = pFont->GetSubstFont()->m_Weight / 5; |
904 } else { | 904 } else { |
905 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; | 905 static const FX_CHAR stem_chars[] = {'i', 'I', '!', '1'}; |
906 const size_t count = FX_ArraySize(stem_chars); | 906 const size_t count = FX_ArraySize(stem_chars); |
907 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); | 907 uint32_t glyph = pEncoding->GlyphFromCharCode(stem_chars[0]); |
908 nStemV = pFont->GetGlyphWidth(glyph); | 908 nStemV = pFont->GetGlyphWidth(glyph); |
909 for (size_t i = 1; i < count; i++) { | 909 for (size_t i = 1; i < count; i++) { |
910 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); | 910 glyph = pEncoding->GlyphFromCharCode(stem_chars[i]); |
911 int width = pFont->GetGlyphWidth(glyph); | 911 int width = pFont->GetGlyphWidth(glyph); |
912 if (width > 0 && width < nStemV) | 912 if (width > 0 && width < nStemV) |
913 nStemV = width; | 913 nStemV = width; |
914 } | 914 } |
915 } | 915 } |
916 CPDF_Dictionary* pFontDesc = | 916 CPDF_Dictionary* pFontDesc = |
917 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), | 917 CalculateFontDesc(this, basefont, flags, italicangle, pFont->GetAscent(), |
918 pFont->GetDescent(), pBBox, nStemV); | 918 pFont->GetDescent(), pBBox, nStemV); |
919 pFontDict->SetReferenceFor("FontDescriptor", this, | 919 pFontDict->SetReferenceFor( |
920 AddIndirectObject(pFontDesc)); | 920 "FontDescriptor", this, |
921 AddIndirectObject(UniqueDictionary(pFontDesc))); // Owner? | |
921 return LoadFont(pBaseDict); | 922 return LoadFont(pBaseDict); |
922 } | 923 } |
923 | 924 |
924 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 925 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
925 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, | 926 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, |
926 FX_BOOL bVert, | 927 FX_BOOL bVert, |
927 FX_BOOL bTranslateName) { | 928 FX_BOOL bTranslateName) { |
928 LOGFONTA lfa; | 929 LOGFONTA lfa; |
929 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); | 930 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); |
930 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); | 931 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 basefont = pLogFont->lfFaceName; | 973 basefont = pLogFont->lfFaceName; |
973 | 974 |
974 int italicangle = ptm->otmItalicAngle / 10; | 975 int italicangle = ptm->otmItalicAngle / 10; |
975 int ascend = ptm->otmrcFontBox.top; | 976 int ascend = ptm->otmrcFontBox.top; |
976 int descend = ptm->otmrcFontBox.bottom; | 977 int descend = ptm->otmrcFontBox.bottom; |
977 int capheight = ptm->otmsCapEmHeight; | 978 int capheight = ptm->otmsCapEmHeight; |
978 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, | 979 int bbox[4] = {ptm->otmrcFontBox.left, ptm->otmrcFontBox.bottom, |
979 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; | 980 ptm->otmrcFontBox.right, ptm->otmrcFontBox.top}; |
980 FX_Free(tm_buf); | 981 FX_Free(tm_buf); |
981 basefont.Replace(" ", ""); | 982 basefont.Replace(" ", ""); |
982 CPDF_Dictionary* pBaseDict = new CPDF_Dictionary(m_pByteStringPool); | 983 CPDF_Dictionary* pBaseDict = AddIndirectDictionary(m_pByteStringPool); |
983 pBaseDict->SetNameFor("Type", "Font"); | 984 pBaseDict->SetNameFor("Type", "Font"); |
984 CPDF_Dictionary* pFontDict = pBaseDict; | 985 CPDF_Dictionary* pFontDict = pBaseDict; |
985 if (!bCJK) { | 986 if (!bCJK) { |
986 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || | 987 if (pLogFont->lfCharSet == FXFONT_ANSI_CHARSET || |
987 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || | 988 pLogFont->lfCharSet == FXFONT_DEFAULT_CHARSET || |
988 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { | 989 pLogFont->lfCharSet == FXFONT_SYMBOL_CHARSET) { |
989 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); | 990 pBaseDict->SetNameFor("Encoding", "WinAnsiEncoding"); |
990 } else { | 991 } else { |
991 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); | 992 CalculateEncodingDict(pLogFont->lfCharSet, pBaseDict); |
992 } | 993 } |
993 int char_widths[224]; | 994 int char_widths[224]; |
994 GetCharWidth(hDC, 32, 255, char_widths); | 995 GetCharWidth(hDC, 32, 255, char_widths); |
995 CPDF_Array* pWidths = new CPDF_Array; | 996 CPDF_Array* pWidths = new CPDF_Array; |
996 for (size_t i = 0; i < 224; i++) | 997 for (size_t i = 0; i < 224; i++) |
997 pWidths->AddInteger(char_widths[i]); | 998 pWidths->AddInteger(char_widths[i]); |
998 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, | 999 ProcessNonbCJK(pBaseDict, pLogFont->lfWeight > FW_MEDIUM, |
999 pLogFont->lfItalic != 0, basefont, pWidths); | 1000 pLogFont->lfItalic != 0, basefont, pWidths); |
1000 } else { | 1001 } else { |
1001 pFontDict = | 1002 pFontDict = |
1002 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, | 1003 ProcessbCJK(pBaseDict, pLogFont->lfCharSet, bVert, basefont, |
1003 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { | 1004 [&hDC](FX_WCHAR start, FX_WCHAR end, CPDF_Array* widthArr) { |
1004 InsertWidthArray(hDC, start, end, widthArr); | 1005 InsertWidthArray(hDC, start, end, widthArr); |
1005 }); | 1006 }); |
1006 } | 1007 } |
1007 AddIndirectObject(pBaseDict); | |
1008 CPDF_Array* pBBox = new CPDF_Array; | 1008 CPDF_Array* pBBox = new CPDF_Array; |
1009 for (int i = 0; i < 4; i++) | 1009 for (int i = 0; i < 4; i++) |
1010 pBBox->AddInteger(bbox[i]); | 1010 pBBox->AddInteger(bbox[i]); |
1011 CPDF_Dictionary* pFontDesc = | 1011 CPDF_Dictionary* pFontDesc = |
1012 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, | 1012 CalculateFontDesc(this, basefont, flags, italicangle, ascend, descend, |
1013 pBBox, pLogFont->lfWeight / 5); | 1013 pBBox, pLogFont->lfWeight / 5); |
1014 pFontDesc->SetIntegerFor("CapHeight", capheight); | 1014 pFontDesc->SetIntegerFor("CapHeight", capheight); |
1015 pFontDict->SetReferenceFor("FontDescriptor", this, | 1015 pFontDict->SetReferenceFor( |
1016 AddIndirectObject(pFontDesc)); | 1016 "FontDescriptor", this, |
1017 AddIndirectObject(UniqueObject(pFontDesc))); // Owner? | |
1017 hFont = SelectObject(hDC, hFont); | 1018 hFont = SelectObject(hDC, hFont); |
1018 DeleteObject(hFont); | 1019 DeleteObject(hFont); |
1019 DeleteDC(hDC); | 1020 DeleteDC(hDC); |
1020 return LoadFont(pBaseDict); | 1021 return LoadFont(pBaseDict); |
1021 } | 1022 } |
1022 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 1023 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
OLD | NEW |