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> |
11 CPDF_Document::CPDF_Document() : CPDF_IndirectObjects(NULL) | 11 CPDF_Document::CPDF_Document() : CPDF_IndirectObjects(NULL) |
12 { | 12 { |
13 m_pRootDict = NULL; | 13 m_pRootDict = NULL; |
14 m_pInfoDict = NULL; | 14 m_pInfoDict = NULL; |
15 m_bLinearized = FALSE; | 15 m_bLinearized = false; |
16 m_dwFirstPageNo = 0; | 16 m_dwFirstPageNo = 0; |
17 m_dwFirstPageObjNum = 0; | 17 m_dwFirstPageObjNum = 0; |
18 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); | 18 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); |
19 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this)
; | 19 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this)
; |
20 } | 20 } |
21 void CPDF_Document::CreateNewDoc() | 21 void CPDF_Document::CreateNewDoc() |
22 { | 22 { |
23 ASSERT(m_pRootDict == NULL && m_pInfoDict == NULL); | 23 ASSERT(m_pRootDict == NULL && m_pInfoDict == NULL); |
24 m_pRootDict = new CPDF_Dictionary; | 24 m_pRootDict = new CPDF_Dictionary; |
25 m_pRootDict->SetAtName("Type", "Catalog"); | 25 m_pRootDict->SetAtName("Type", "Catalog"); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 pWidthArray->AddInteger(*widths); | 208 pWidthArray->AddInteger(*widths); |
209 } else { | 209 } else { |
210 CPDF_Array* pWidthArray1 = new CPDF_Array; | 210 CPDF_Array* pWidthArray1 = new CPDF_Array; |
211 pWidthArray->Add(pWidthArray1); | 211 pWidthArray->Add(pWidthArray1); |
212 for (i = 0; i < size; i ++) { | 212 for (i = 0; i < size; i ++) { |
213 pWidthArray1->AddInteger(widths[i]); | 213 pWidthArray1->AddInteger(widths[i]); |
214 } | 214 } |
215 } | 215 } |
216 FX_Free(widths); | 216 FX_Free(widths); |
217 } | 217 } |
218 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, FX_BOOL bVert, FX_B
OOL bTranslateName) | 218 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTW* pLogFont, bool bVert, bool bT
ranslateName) |
219 { | 219 { |
220 LOGFONTA lfa; | 220 LOGFONTA lfa; |
221 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); | 221 FXSYS_memcpy(&lfa, pLogFont, (char*)lfa.lfFaceName - (char*)&lfa); |
222 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); | 222 CFX_ByteString face = CFX_ByteString::FromUnicode(pLogFont->lfFaceName); |
223 if (face.GetLength() >= LF_FACESIZE) { | 223 if (face.GetLength() >= LF_FACESIZE) { |
224 return NULL; | 224 return NULL; |
225 } | 225 } |
226 FXSYS_strcpy(lfa.lfFaceName, face.c_str()); | 226 FXSYS_strcpy(lfa.lfFaceName, face.c_str()); |
227 return AddWindowsFont(&lfa, bVert, bTranslateName); | 227 return AddWindowsFont(&lfa, bVert, bTranslateName); |
228 } | 228 } |
229 extern CFX_ByteString _FPDF_GetNameFromTT(const uint8_t* name_table, FX_DWORD na
me); | 229 extern CFX_ByteString _FPDF_GetNameFromTT(const uint8_t* name_table, FX_DWORD na
me); |
230 CFX_ByteString _FPDF_GetPSNameFromTT(HDC hDC) | 230 CFX_ByteString _FPDF_GetPSNameFromTT(HDC hDC) |
231 { | 231 { |
232 CFX_ByteString result; | 232 CFX_ByteString result; |
233 DWORD size = ::GetFontData(hDC, 'eman', 0, NULL, 0); | 233 DWORD size = ::GetFontData(hDC, 'eman', 0, NULL, 0); |
234 if (size != GDI_ERROR) { | 234 if (size != GDI_ERROR) { |
235 LPBYTE buffer = FX_Alloc(BYTE, size); | 235 LPBYTE buffer = FX_Alloc(BYTE, size); |
236 ::GetFontData(hDC, 'eman', 0, buffer, size); | 236 ::GetFontData(hDC, 'eman', 0, buffer, size); |
237 result = _FPDF_GetNameFromTT(buffer, 6); | 237 result = _FPDF_GetNameFromTT(buffer, 6); |
238 FX_Free(buffer); | 238 FX_Free(buffer); |
239 } | 239 } |
240 return result; | 240 return result; |
241 } | 241 } |
242 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, FX_BOOL bVert, FX_B
OOL bTranslateName) | 242 CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont, bool bVert, bool bT
ranslateName) |
243 { | 243 { |
244 pLogFont->lfHeight = -1000; | 244 pLogFont->lfHeight = -1000; |
245 pLogFont->lfWidth = 0; | 245 pLogFont->lfWidth = 0; |
246 HGDIOBJ hFont = CreateFontIndirectA(pLogFont); | 246 HGDIOBJ hFont = CreateFontIndirectA(pLogFont); |
247 HDC hDC = CreateCompatibleDC(NULL); | 247 HDC hDC = CreateCompatibleDC(NULL); |
248 hFont = SelectObject(hDC, hFont); | 248 hFont = SelectObject(hDC, hFont); |
249 int tm_size = GetOutlineTextMetrics(hDC, 0, NULL); | 249 int tm_size = GetOutlineTextMetrics(hDC, 0, NULL); |
250 if (tm_size == 0) { | 250 if (tm_size == 0) { |
251 hFont = SelectObject(hDC, hFont); | 251 hFont = SelectObject(hDC, hFont); |
252 DeleteObject(hFont); | 252 DeleteObject(hFont); |
253 DeleteDC(hDC); | 253 DeleteDC(hDC); |
254 return NULL; | 254 return NULL; |
255 } | 255 } |
256 LPBYTE tm_buf = FX_Alloc(BYTE, tm_size); | 256 LPBYTE tm_buf = FX_Alloc(BYTE, tm_size); |
257 OUTLINETEXTMETRIC* ptm = (OUTLINETEXTMETRIC*)tm_buf; | 257 OUTLINETEXTMETRIC* ptm = (OUTLINETEXTMETRIC*)tm_buf; |
258 GetOutlineTextMetrics(hDC, tm_size, ptm); | 258 GetOutlineTextMetrics(hDC, tm_size, ptm); |
259 int flags = 0, italicangle, ascend, descend, capheight, bbox[4]; | 259 int flags = 0, italicangle, ascend, descend, capheight, bbox[4]; |
260 if (pLogFont->lfItalic) { | 260 if (pLogFont->lfItalic) { |
261 flags |= PDFFONT_ITALIC; | 261 flags |= PDFFONT_ITALIC; |
262 } | 262 } |
263 if ((pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH) { | 263 if ((pLogFont->lfPitchAndFamily & 3) == FIXED_PITCH) { |
264 flags |= PDFFONT_FIXEDPITCH; | 264 flags |= PDFFONT_FIXEDPITCH; |
265 } | 265 } |
266 if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN) { | 266 if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_ROMAN) { |
267 flags |= PDFFONT_SERIF; | 267 flags |= PDFFONT_SERIF; |
268 } | 268 } |
269 if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT) { | 269 if ((pLogFont->lfPitchAndFamily & 0xf8) == FF_SCRIPT) { |
270 flags |= PDFFONT_SCRIPT; | 270 flags |= PDFFONT_SCRIPT; |
271 } | 271 } |
272 FX_BOOL bCJK = pLogFont->lfCharSet == CHINESEBIG5_CHARSET || pLogFont->lfCha
rSet == GB2312_CHARSET || | 272 bool bCJK = pLogFont->lfCharSet == CHINESEBIG5_CHARSET || pLogFont->lfCharSe
t == GB2312_CHARSET || |
273 pLogFont->lfCharSet == HANGEUL_CHARSET || pLogFont->lfCharSet
== SHIFTJIS_CHARSET; | 273 pLogFont->lfCharSet == HANGEUL_CHARSET || pLogFont->lfCharSet
== SHIFTJIS_CHARSET; |
274 CFX_ByteString basefont; | 274 CFX_ByteString basefont; |
275 if (bTranslateName && bCJK) { | 275 if (bTranslateName && bCJK) { |
276 basefont = _FPDF_GetPSNameFromTT(hDC); | 276 basefont = _FPDF_GetPSNameFromTT(hDC); |
277 } | 277 } |
278 if (basefont.IsEmpty()) { | 278 if (basefont.IsEmpty()) { |
279 basefont = pLogFont->lfFaceName; | 279 basefont = pLogFont->lfFaceName; |
280 } | 280 } |
281 italicangle = ptm->otmItalicAngle / 10; | 281 italicangle = ptm->otmItalicAngle / 10; |
282 ascend = ptm->otmrcFontBox.top; | 282 ascend = ptm->otmrcFontBox.top; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 static void _CFString2CFXByteString(CFStringRef src, CFX_ByteString &dest) | 542 static void _CFString2CFXByteString(CFStringRef src, CFX_ByteString &dest) |
543 { | 543 { |
544 SInt32 len = CFStringGetLength(src); | 544 SInt32 len = CFStringGetLength(src); |
545 CFRange range = CFRangeMake(0, len); | 545 CFRange range = CFRangeMake(0, len); |
546 CFIndex used = 0; | 546 CFIndex used = 0; |
547 UInt8* pBuffer = (UInt8*)calloc(len+1, sizeof(UInt8)); | 547 UInt8* pBuffer = (UInt8*)calloc(len+1, sizeof(UInt8)); |
548 CFStringGetBytes(src, range, kCFStringEncodingASCII, 0, false, pBuffer, len,
&used); | 548 CFStringGetBytes(src, range, kCFStringEncodingASCII, 0, false, pBuffer, len,
&used); |
549 dest = (FX_CHAR*)pBuffer; | 549 dest = (FX_CHAR*)pBuffer; |
550 free(pBuffer); | 550 free(pBuffer); |
551 } | 551 } |
552 FX_BOOL IsHasCharSet(CFArrayRef languages, const CFX_DWordArray &charSets) | 552 bool IsHasCharSet(CFArrayRef languages, const CFX_DWordArray &charSets) |
553 { | 553 { |
554 int iCount = charSets.GetSize(); | 554 int iCount = charSets.GetSize(); |
555 for (int i = 0; i < CFArrayGetCount(languages); ++i) { | 555 for (int i = 0; i < CFArrayGetCount(languages); ++i) { |
556 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(languages, i)
; | 556 CFStringRef language = (CFStringRef)CFArrayGetValueAtIndex(languages, i)
; |
557 FX_DWORD CharSet = FX_GetCharsetFromLang(CFStringGetCStringPtr(language,
kCFStringEncodingMacRoman), -1); | 557 FX_DWORD CharSet = FX_GetCharsetFromLang(CFStringGetCStringPtr(language,
kCFStringEncodingMacRoman), -1); |
558 for (int j = 0; j < iCount; ++j) { | 558 for (int j = 0; j < iCount; ++j) { |
559 if (CharSet == charSets[j]) { | 559 if (CharSet == charSets[j]) { |
560 return TRUE; | 560 return true; |
561 } | 561 } |
562 } | 562 } |
563 } | 563 } |
564 return FALSE; | 564 return false; |
565 } | 565 } |
566 void FX_GetCharWidth(CTFontRef font, UniChar start, UniChar end, int* width) | 566 void FX_GetCharWidth(CTFontRef font, UniChar start, UniChar end, int* width) |
567 { | 567 { |
568 CGFloat size = CTFontGetSize(font); | 568 CGFloat size = CTFontGetSize(font); |
569 for (; start <= end; ++start) { | 569 for (; start <= end; ++start) { |
570 CGGlyph pGlyph = 0; | 570 CGGlyph pGlyph = 0; |
571 CFIndex count = 1; | 571 CFIndex count = 1; |
572 CTFontGetGlyphsForCharacters(font, &start, &pGlyph, count); | 572 CTFontGetGlyphsForCharacters(font, &start, &pGlyph, count); |
573 CGSize advances; | 573 CGSize advances; |
574 CTFontGetAdvancesForGlyphs(font, kCTFontDefaultOrientation, &pGlyph, &ad
vances, 1); | 574 CTFontGetAdvancesForGlyphs(font, kCTFontDefaultOrientation, &pGlyph, &ad
vances, 1); |
(...skipping 17 matching lines...) Expand all Loading... |
592 pWidthArray->AddInteger(*widths); | 592 pWidthArray->AddInteger(*widths); |
593 } else { | 593 } else { |
594 CPDF_Array* pWidthArray1 = new CPDF_Array; | 594 CPDF_Array* pWidthArray1 = new CPDF_Array; |
595 pWidthArray->Add(pWidthArray1); | 595 pWidthArray->Add(pWidthArray1); |
596 for (i = 0; i < size; i ++) { | 596 for (i = 0; i < size; i ++) { |
597 pWidthArray1->AddInteger(widths[i]); | 597 pWidthArray1->AddInteger(widths[i]); |
598 } | 598 } |
599 } | 599 } |
600 FX_Free(widths); | 600 FX_Free(widths); |
601 } | 601 } |
602 CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont, FX_BOOL bVert, FX_BOOL bTr
anslateName) | 602 CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont, bool bVert, bool bTranslat
eName) |
603 { | 603 { |
604 CTFontRef font = (CTFontRef)pFont; | 604 CTFontRef font = (CTFontRef)pFont; |
605 CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(font); | 605 CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(font); |
606 if (descriptor == NULL) { | 606 if (descriptor == NULL) { |
607 return NULL; | 607 return NULL; |
608 } | 608 } |
609 CFX_ByteString basefont; | 609 CFX_ByteString basefont; |
610 FX_BOOL bCJK = FALSE; | 610 bool bCJK = false; |
611 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, bbox
[4]; | 611 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, bbox
[4]; |
612 FXSYS_memset(bbox, 0, sizeof(int) * 4); | 612 FXSYS_memset(bbox, 0, sizeof(int) * 4); |
613 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute(descriptor,
kCTFontLanguagesAttribute); | 613 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute(descriptor,
kCTFontLanguagesAttribute); |
614 if (languages == NULL) { | 614 if (languages == NULL) { |
615 CFRelease(descriptor); | 615 CFRelease(descriptor); |
616 return NULL; | 616 return NULL; |
617 } | 617 } |
618 CFX_DWordArray charSets; | 618 CFX_DWordArray charSets; |
619 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); | 619 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); |
620 charSets.Add(FXFONT_GB2312_CHARSET); | 620 charSets.Add(FXFONT_GB2312_CHARSET); |
621 charSets.Add(FXFONT_HANGEUL_CHARSET); | 621 charSets.Add(FXFONT_HANGEUL_CHARSET); |
622 charSets.Add(FXFONT_SHIFTJIS_CHARSET); | 622 charSets.Add(FXFONT_SHIFTJIS_CHARSET); |
623 if (IsHasCharSet(languages, charSets)) { | 623 if (IsHasCharSet(languages, charSets)) { |
624 bCJK = TRUE; | 624 bCJK = true; |
625 } | 625 } |
626 CFRelease(descriptor); | 626 CFRelease(descriptor); |
627 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); | 627 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); |
628 if (traits == NULL) { | 628 if (traits == NULL) { |
629 CFRelease(languages); | 629 CFRelease(languages); |
630 return NULL; | 630 return NULL; |
631 } | 631 } |
632 CFNumberRef sybolicTrait = (CFNumberRef)CFDictionaryGetValue(traits, kCTFont
SymbolicTrait); | 632 CFNumberRef sybolicTrait = (CFNumberRef)CFDictionaryGetValue(traits, kCTFont
SymbolicTrait); |
633 CTFontSymbolicTraits trait = 0; | 633 CTFontSymbolicTraits trait = 0; |
634 CFNumberGetValue(sybolicTrait, kCFNumberSInt32Type, &trait); | 634 CFNumberGetValue(sybolicTrait, kCFNumberSInt32Type, &trait); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 pWidths->AddInteger(char_widths[i]); | 730 pWidths->AddInteger(char_widths[i]); |
731 } | 731 } |
732 pBaseDict->SetAt("Widths", pWidths); | 732 pBaseDict->SetAt("Widths", pWidths); |
733 } else { | 733 } else { |
734 flags |= PDFFONT_NONSYMBOLIC; | 734 flags |= PDFFONT_NONSYMBOLIC; |
735 CPDF_Array* pArray = NULL; | 735 CPDF_Array* pArray = NULL; |
736 pFontDict = new CPDF_Dictionary; | 736 pFontDict = new CPDF_Dictionary; |
737 CFX_ByteString cmap; | 737 CFX_ByteString cmap; |
738 CFX_ByteString ordering; | 738 CFX_ByteString ordering; |
739 int supplement; | 739 int supplement; |
740 FX_BOOL bFound = FALSE; | 740 bool bFound = false; |
741 CPDF_Array* pWidthArray = new CPDF_Array; | 741 CPDF_Array* pWidthArray = new CPDF_Array; |
742 charSets.RemoveAll(); | 742 charSets.RemoveAll(); |
743 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); | 743 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); |
744 if (IsHasCharSet(languages, charSets)) { | 744 if (IsHasCharSet(languages, charSets)) { |
745 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; | 745 cmap = bVert ? "ETenms-B5-V" : "ETenms-B5-H"; |
746 ordering = "CNS1"; | 746 ordering = "CNS1"; |
747 supplement = 4; | 747 supplement = 4; |
748 pWidthArray->AddInteger(1); | 748 pWidthArray->AddInteger(1); |
749 _InsertWidthArray(font, 0x20, 0x7e, pWidthArray); | 749 _InsertWidthArray(font, 0x20, 0x7e, pWidthArray); |
750 bFound = TRUE; | 750 bFound = true; |
751 } | 751 } |
752 charSets.RemoveAll(); | 752 charSets.RemoveAll(); |
753 charSets.Add(FXFONT_GB2312_CHARSET); | 753 charSets.Add(FXFONT_GB2312_CHARSET); |
754 if (!bFound && IsHasCharSet(languages, charSets)) { | 754 if (!bFound && IsHasCharSet(languages, charSets)) { |
755 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; | 755 cmap = bVert ? "GBK-EUC-V" : "GBK-EUC-H"; |
756 ordering = "GB1", supplement = 2; | 756 ordering = "GB1", supplement = 2; |
757 pWidthArray->AddInteger(7716); | 757 pWidthArray->AddInteger(7716); |
758 _InsertWidthArray(font, 0x20, 0x20, pWidthArray); | 758 _InsertWidthArray(font, 0x20, 0x20, pWidthArray); |
759 pWidthArray->AddInteger(814); | 759 pWidthArray->AddInteger(814); |
760 _InsertWidthArray(font, 0x21, 0x7e, pWidthArray); | 760 _InsertWidthArray(font, 0x21, 0x7e, pWidthArray); |
761 bFound = TRUE; | 761 bFound = true; |
762 } | 762 } |
763 charSets.RemoveAll(); | 763 charSets.RemoveAll(); |
764 charSets.Add(FXFONT_HANGEUL_CHARSET); | 764 charSets.Add(FXFONT_HANGEUL_CHARSET); |
765 if (!bFound && IsHasCharSet(languages, charSets)) { | 765 if (!bFound && IsHasCharSet(languages, charSets)) { |
766 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; | 766 cmap = bVert ? "KSCms-UHC-V" : "KSCms-UHC-H"; |
767 ordering = "Korea1"; | 767 ordering = "Korea1"; |
768 supplement = 2; | 768 supplement = 2; |
769 pWidthArray->AddInteger(1); | 769 pWidthArray->AddInteger(1); |
770 _InsertWidthArray(font, 0x20, 0x7e, pWidthArray); | 770 _InsertWidthArray(font, 0x20, 0x7e, pWidthArray); |
771 bFound = TRUE; | 771 bFound = true; |
772 } | 772 } |
773 charSets.RemoveAll(); | 773 charSets.RemoveAll(); |
774 charSets.Add(FXFONT_SHIFTJIS_CHARSET); | 774 charSets.Add(FXFONT_SHIFTJIS_CHARSET); |
775 if (!bFound && IsHasCharSet(languages, charSets)) { | 775 if (!bFound && IsHasCharSet(languages, charSets)) { |
776 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; | 776 cmap = bVert ? "90ms-RKSJ-V" : "90ms-RKSJ-H"; |
777 ordering = "Japan1"; | 777 ordering = "Japan1"; |
778 supplement = 5; | 778 supplement = 5; |
779 pWidthArray->AddInteger(231); | 779 pWidthArray->AddInteger(231); |
780 _InsertWidthArray(font, 0x20, 0x7d, pWidthArray); | 780 _InsertWidthArray(font, 0x20, 0x7d, pWidthArray); |
781 pWidthArray->AddInteger(326); | 781 pWidthArray->AddInteger(326); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 pWidthArray->AddInteger(*widths); | 860 pWidthArray->AddInteger(*widths); |
861 } else { | 861 } else { |
862 CPDF_Array* pWidthArray1 = new CPDF_Array; | 862 CPDF_Array* pWidthArray1 = new CPDF_Array; |
863 pWidthArray->Add(pWidthArray1); | 863 pWidthArray->Add(pWidthArray1); |
864 for (i = 0; i < size; i ++) { | 864 for (i = 0; i < size; i ++) { |
865 pWidthArray1->AddInteger(widths[i]); | 865 pWidthArray1->AddInteger(widths[i]); |
866 } | 866 } |
867 } | 867 } |
868 FX_Free(widths); | 868 FX_Free(widths); |
869 } | 869 } |
870 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) | 870 CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, bool bVert) |
871 { | 871 { |
872 if (pFont == NULL) { | 872 if (pFont == NULL) { |
873 return NULL; | 873 return NULL; |
874 } | 874 } |
875 FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || charset == FXFONT_GB
2312_CHARSET || | 875 bool bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || charset == FXFONT_GB231
2_CHARSET || |
876 charset == FXFONT_HANGEUL_CHARSET || charset == FXFONT_SHIFTJ
IS_CHARSET; | 876 charset == FXFONT_HANGEUL_CHARSET || charset == FXFONT_SHIFTJ
IS_CHARSET; |
877 CFX_ByteString basefont = pFont->GetFamilyName(); | 877 CFX_ByteString basefont = pFont->GetFamilyName(); |
878 basefont.Replace(" ", ""); | 878 basefont.Replace(" ", ""); |
879 int flags = 0; | 879 int flags = 0; |
880 if (pFont->IsBold()) { | 880 if (pFont->IsBold()) { |
881 flags |= PDFFONT_FORCEBOLD; | 881 flags |= PDFFONT_FORCEBOLD; |
882 } | 882 } |
883 if (pFont->IsItalic()) { | 883 if (pFont->IsItalic()) { |
884 flags |= PDFFONT_ITALIC; | 884 flags |= PDFFONT_ITALIC; |
885 } | 885 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 } | 1045 } |
1046 } | 1046 } |
1047 } | 1047 } |
1048 delete pEncoding; | 1048 delete pEncoding; |
1049 pFontDesc->SetAtInteger("StemV", nStemV); | 1049 pFontDesc->SetAtInteger("StemV", nStemV); |
1050 AddIndirectObject(pFontDesc); | 1050 AddIndirectObject(pFontDesc); |
1051 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); | 1051 pFontDict->SetAtReference("FontDescriptor", this, pFontDesc); |
1052 return LoadFont(pBaseDict); | 1052 return LoadFont(pBaseDict); |
1053 } | 1053 } |
1054 static int InsertDeletePDFPage(CPDF_Document* pDoc, CPDF_Dictionary* pPages, | 1054 static int InsertDeletePDFPage(CPDF_Document* pDoc, CPDF_Dictionary* pPages, |
1055 int nPagesToGo, CPDF_Dictionary* pPage, FX_BOOL b
Insert, CFX_PtrArray& stackList) | 1055 int nPagesToGo, CPDF_Dictionary* pPage, bool bIns
ert, CFX_PtrArray& stackList) |
1056 { | 1056 { |
1057 CPDF_Array* pKidList = pPages->GetArray("Kids"); | 1057 CPDF_Array* pKidList = pPages->GetArray("Kids"); |
1058 if (!pKidList) { | 1058 if (!pKidList) { |
1059 return -1; | 1059 return -1; |
1060 } | 1060 } |
1061 int nKids = pKidList->GetCount(); | 1061 int nKids = pKidList->GetCount(); |
1062 for (int i = 0; i < nKids; i ++) { | 1062 for (int i = 0; i < nKids; i ++) { |
1063 CPDF_Dictionary* pKid = pKidList->GetDict(i); | 1063 CPDF_Dictionary* pKid = pKidList->GetDict(i); |
1064 if (pKid->GetString("Type") == FX_BSTRC("Page")) { | 1064 if (pKid->GetString("Type") == FX_BSTRC("Page")) { |
1065 if (nPagesToGo == 0) { | 1065 if (nPagesToGo == 0) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 if (!pPagesList) { | 1115 if (!pPagesList) { |
1116 pPagesList = new CPDF_Array; | 1116 pPagesList = new CPDF_Array; |
1117 pPages->SetAt(FX_BSTRC("Kids"), pPagesList); | 1117 pPages->SetAt(FX_BSTRC("Kids"), pPagesList); |
1118 } | 1118 } |
1119 pPagesList->Add(pPageDict, pDoc); | 1119 pPagesList->Add(pPageDict, pDoc); |
1120 pPages->SetAtInteger(FX_BSTRC("Count"), nPages + 1); | 1120 pPages->SetAtInteger(FX_BSTRC("Count"), nPages + 1); |
1121 pPageDict->SetAtReference(FX_BSTRC("Parent"), pDoc, pPages->GetObjNum())
; | 1121 pPageDict->SetAtReference(FX_BSTRC("Parent"), pDoc, pPages->GetObjNum())
; |
1122 } else { | 1122 } else { |
1123 CFX_PtrArray stack; | 1123 CFX_PtrArray stack; |
1124 stack.Add(pPages); | 1124 stack.Add(pPages); |
1125 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0
) { | 1125 if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, true, stack) < 0
) { |
1126 return -1; | 1126 return -1; |
1127 } | 1127 } |
1128 } | 1128 } |
1129 pageList.InsertAt(iPage, pPageDict->GetObjNum()); | 1129 pageList.InsertAt(iPage, pPageDict->GetObjNum()); |
1130 return iPage; | 1130 return iPage; |
1131 } | 1131 } |
1132 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) | 1132 CPDF_Dictionary* CPDF_Document::CreateNewPage(int iPage) |
1133 { | 1133 { |
1134 CPDF_Dictionary* pDict = new CPDF_Dictionary; | 1134 CPDF_Dictionary* pDict = new CPDF_Dictionary; |
1135 pDict->SetAtName("Type", "Page"); | 1135 pDict->SetAtName("Type", "Page"); |
(...skipping 22 matching lines...) Expand all Loading... |
1158 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); | 1158 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); |
1159 if (pPages == NULL) { | 1159 if (pPages == NULL) { |
1160 return; | 1160 return; |
1161 } | 1161 } |
1162 int nPages = pPages->GetInteger("Count"); | 1162 int nPages = pPages->GetInteger("Count"); |
1163 if (iPage < 0 || iPage >= nPages) { | 1163 if (iPage < 0 || iPage >= nPages) { |
1164 return; | 1164 return; |
1165 } | 1165 } |
1166 CFX_PtrArray stack; | 1166 CFX_PtrArray stack; |
1167 stack.Add(pPages); | 1167 stack.Add(pPages); |
1168 if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { | 1168 if (InsertDeletePDFPage(this, pPages, iPage, NULL, false, stack) < 0) { |
1169 return; | 1169 return; |
1170 } | 1170 } |
1171 m_PageList.RemoveAt(iPage); | 1171 m_PageList.RemoveAt(iPage); |
1172 } | 1172 } |
1173 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, const CFX_ByteStrin
gC& name); | 1173 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, const CFX_ByteStrin
gC& name); |
1174 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, const CFX_ByteStringC& nam
e) | 1174 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, const CFX_ByteStringC& nam
e) |
1175 { | 1175 { |
1176 if (pPageDict->KeyExist(name)) { | 1176 if (pPageDict->KeyExist(name)) { |
1177 return; | 1177 return; |
1178 } | 1178 } |
1179 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); | 1179 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); |
1180 if (pObj) { | 1180 if (pObj) { |
1181 pPageDict->SetAt(name, pObj->Clone()); | 1181 pPageDict->SetAt(name, pObj->Clone()); |
1182 } | 1182 } |
1183 } | 1183 } |
OLD | NEW |