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 <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
11 #include "core/src/fpdfapi/fpdf_page/pageint.h" | 11 #include "core/src/fpdfapi/fpdf_page/pageint.h" |
12 | 12 |
13 CPDF_Document::CPDF_Document() : CPDF_IndirectObjects(NULL) { | 13 CPDF_Document::CPDF_Document() : CPDF_IndirectObjects(NULL) { |
14 m_pRootDict = NULL; | 14 m_pRootDict = NULL; |
15 m_pInfoDict = NULL; | 15 m_pInfoDict = NULL; |
16 m_bLinearized = FALSE; | 16 m_bLinearized = FALSE; |
17 m_dwFirstPageNo = 0; | 17 m_dwFirstPageNo = 0; |
18 m_dwFirstPageObjNum = 0; | 18 m_dwFirstPageObjNum = 0; |
19 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); | 19 m_pDocPage = CPDF_ModuleMgr::Get()->GetPageModule()->CreateDocData(this); |
20 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this); | 20 m_pDocRender = CPDF_ModuleMgr::Get()->GetRenderModule()->CreateDocData(this); |
21 } | 21 } |
22 void CPDF_Document::CreateNewDoc() { | 22 void CPDF_Document::CreateNewDoc() { |
23 ASSERT(m_pRootDict == NULL && m_pInfoDict == NULL); | 23 ASSERT(!m_pRootDict && !m_pInfoDict); |
24 m_pRootDict = new CPDF_Dictionary; | 24 m_pRootDict = new CPDF_Dictionary; |
25 m_pRootDict->SetAtName("Type", "Catalog"); | 25 m_pRootDict->SetAtName("Type", "Catalog"); |
26 int objnum = AddIndirectObject(m_pRootDict); | 26 int objnum = AddIndirectObject(m_pRootDict); |
27 CPDF_Dictionary* pPages = new CPDF_Dictionary; | 27 CPDF_Dictionary* pPages = new CPDF_Dictionary; |
28 pPages->SetAtName("Type", "Pages"); | 28 pPages->SetAtName("Type", "Pages"); |
29 pPages->SetAtNumber("Count", 0); | 29 pPages->SetAtNumber("Count", 0); |
30 pPages->SetAt("Kids", new CPDF_Array); | 30 pPages->SetAt("Kids", new CPDF_Array); |
31 objnum = AddIndirectObject(pPages); | 31 objnum = AddIndirectObject(pPages); |
32 m_pRootDict->SetAtReference("Pages", this, objnum); | 32 m_pRootDict->SetAtReference("Pages", this, objnum); |
33 m_pInfoDict = new CPDF_Dictionary; | 33 m_pInfoDict = new CPDF_Dictionary; |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 pWidthArray1->AddInteger(widths[i]); | 543 pWidthArray1->AddInteger(widths[i]); |
544 } | 544 } |
545 } | 545 } |
546 FX_Free(widths); | 546 FX_Free(widths); |
547 } | 547 } |
548 CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont, | 548 CPDF_Font* CPDF_Document::AddMacFont(CTFontRef pFont, |
549 FX_BOOL bVert, | 549 FX_BOOL bVert, |
550 FX_BOOL bTranslateName) { | 550 FX_BOOL bTranslateName) { |
551 CTFontRef font = (CTFontRef)pFont; | 551 CTFontRef font = (CTFontRef)pFont; |
552 CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(font); | 552 CTFontDescriptorRef descriptor = CTFontCopyFontDescriptor(font); |
553 if (descriptor == NULL) { | 553 if (!descriptor) { |
554 return NULL; | 554 return NULL; |
555 } | 555 } |
556 CFX_ByteString basefont; | 556 CFX_ByteString basefont; |
557 FX_BOOL bCJK = FALSE; | 557 FX_BOOL bCJK = FALSE; |
558 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, | 558 int flags = 0, italicangle = 0, ascend = 0, descend = 0, capheight = 0, |
559 bbox[4]; | 559 bbox[4]; |
560 FXSYS_memset(bbox, 0, sizeof(int) * 4); | 560 FXSYS_memset(bbox, 0, sizeof(int) * 4); |
561 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute( | 561 CFArrayRef languages = (CFArrayRef)CTFontDescriptorCopyAttribute( |
562 descriptor, kCTFontLanguagesAttribute); | 562 descriptor, kCTFontLanguagesAttribute); |
563 if (languages == NULL) { | 563 if (!languages) { |
564 CFRelease(descriptor); | 564 CFRelease(descriptor); |
565 return NULL; | 565 return NULL; |
566 } | 566 } |
567 CFX_DWordArray charSets; | 567 CFX_DWordArray charSets; |
568 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); | 568 charSets.Add(FXFONT_CHINESEBIG5_CHARSET); |
569 charSets.Add(FXFONT_GB2312_CHARSET); | 569 charSets.Add(FXFONT_GB2312_CHARSET); |
570 charSets.Add(FXFONT_HANGEUL_CHARSET); | 570 charSets.Add(FXFONT_HANGEUL_CHARSET); |
571 charSets.Add(FXFONT_SHIFTJIS_CHARSET); | 571 charSets.Add(FXFONT_SHIFTJIS_CHARSET); |
572 if (IsHasCharSet(languages, charSets)) { | 572 if (IsHasCharSet(languages, charSets)) { |
573 bCJK = TRUE; | 573 bCJK = TRUE; |
574 } | 574 } |
575 CFRelease(descriptor); | 575 CFRelease(descriptor); |
576 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); | 576 CFDictionaryRef traits = (CFDictionaryRef)CTFontCopyTraits(font); |
577 if (traits == NULL) { | 577 if (!traits) { |
578 CFRelease(languages); | 578 CFRelease(languages); |
579 return NULL; | 579 return NULL; |
580 } | 580 } |
581 CFNumberRef sybolicTrait = | 581 CFNumberRef sybolicTrait = |
582 (CFNumberRef)CFDictionaryGetValue(traits, kCTFontSymbolicTrait); | 582 (CFNumberRef)CFDictionaryGetValue(traits, kCTFontSymbolicTrait); |
583 CTFontSymbolicTraits trait = 0; | 583 CTFontSymbolicTraits trait = 0; |
584 CFNumberGetValue(sybolicTrait, kCFNumberSInt32Type, &trait); | 584 CFNumberGetValue(sybolicTrait, kCFNumberSInt32Type, &trait); |
585 if (trait & kCTFontItalicTrait) { | 585 if (trait & kCTFontItalicTrait) { |
586 flags |= PDFFONT_ITALIC; | 586 flags |= PDFFONT_ITALIC; |
587 } | 587 } |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 CPDF_Array* pWidthArray1 = new CPDF_Array; | 818 CPDF_Array* pWidthArray1 = new CPDF_Array; |
819 pWidthArray->Add(pWidthArray1); | 819 pWidthArray->Add(pWidthArray1); |
820 for (i = 0; i < size; i++) { | 820 for (i = 0; i < size; i++) { |
821 pWidthArray1->AddInteger(widths[i]); | 821 pWidthArray1->AddInteger(widths[i]); |
822 } | 822 } |
823 } | 823 } |
824 FX_Free(widths); | 824 FX_Free(widths); |
825 } | 825 } |
826 | 826 |
827 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) { |
828 if (pFont == NULL) { | 828 if (!pFont) { |
829 return NULL; | 829 return NULL; |
830 } | 830 } |
831 FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || | 831 FX_BOOL bCJK = charset == FXFONT_CHINESEBIG5_CHARSET || |
832 charset == FXFONT_GB2312_CHARSET || | 832 charset == FXFONT_GB2312_CHARSET || |
833 charset == FXFONT_HANGEUL_CHARSET || | 833 charset == FXFONT_HANGEUL_CHARSET || |
834 charset == FXFONT_SHIFTJIS_CHARSET; | 834 charset == FXFONT_SHIFTJIS_CHARSET; |
835 CFX_ByteString basefont = pFont->GetFamilyName(); | 835 CFX_ByteString basefont = pFont->GetFamilyName(); |
836 basefont.Replace(" ", ""); | 836 basefont.Replace(" ", ""); |
837 int flags = 0; | 837 int flags = 0; |
838 if (pFont->IsBold()) { | 838 if (pFont->IsBold()) { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, | 1111 CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font, |
1112 CPDF_FontEncoding* pEncoding) { | 1112 CPDF_FontEncoding* pEncoding) { |
1113 CFX_ByteString name(font); | 1113 CFX_ByteString name(font); |
1114 if (PDF_GetStandardFontName(&name) < 0) | 1114 if (PDF_GetStandardFontName(&name) < 0) |
1115 return nullptr; | 1115 return nullptr; |
1116 return GetPageData()->GetStandardFont(name, pEncoding); | 1116 return GetPageData()->GetStandardFont(name, pEncoding); |
1117 } | 1117 } |
1118 | 1118 |
1119 void CPDF_Document::DeletePage(int iPage) { | 1119 void CPDF_Document::DeletePage(int iPage) { |
1120 CPDF_Dictionary* pRoot = GetRoot(); | 1120 CPDF_Dictionary* pRoot = GetRoot(); |
1121 if (pRoot == NULL) { | 1121 if (!pRoot) { |
1122 return; | 1122 return; |
1123 } | 1123 } |
1124 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); | 1124 CPDF_Dictionary* pPages = pRoot->GetDict("Pages"); |
1125 if (pPages == NULL) { | 1125 if (!pPages) { |
1126 return; | 1126 return; |
1127 } | 1127 } |
1128 int nPages = pPages->GetInteger("Count"); | 1128 int nPages = pPages->GetInteger("Count"); |
1129 if (iPage < 0 || iPage >= nPages) { | 1129 if (iPage < 0 || iPage >= nPages) { |
1130 return; | 1130 return; |
1131 } | 1131 } |
1132 CFX_ArrayTemplate<CPDF_Dictionary*> stack; | 1132 CFX_ArrayTemplate<CPDF_Dictionary*> stack; |
1133 stack.Add(pPages); | 1133 stack.Add(pPages); |
1134 if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { | 1134 if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) { |
1135 return; | 1135 return; |
1136 } | 1136 } |
1137 m_PageList.RemoveAt(iPage); | 1137 m_PageList.RemoveAt(iPage); |
1138 } | 1138 } |
1139 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, | 1139 CPDF_Object* FPDFAPI_GetPageAttr(CPDF_Dictionary* pPageDict, |
1140 const CFX_ByteStringC& name); | 1140 const CFX_ByteStringC& name); |
1141 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, | 1141 void FPDFAPI_FlatPageAttr(CPDF_Dictionary* pPageDict, |
1142 const CFX_ByteStringC& name) { | 1142 const CFX_ByteStringC& name) { |
1143 if (pPageDict->KeyExist(name)) { | 1143 if (pPageDict->KeyExist(name)) { |
1144 return; | 1144 return; |
1145 } | 1145 } |
1146 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); | 1146 CPDF_Object* pObj = FPDFAPI_GetPageAttr(pPageDict, name); |
1147 if (pObj) { | 1147 if (pObj) { |
1148 pPageDict->SetAt(name, pObj->Clone()); | 1148 pPageDict->SetAt(name, pObj->Clone()); |
1149 } | 1149 } |
1150 } | 1150 } |
OLD | NEW |