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 "../../../include/fdrm/fx_crypt.h" | 9 #include "../../../include/fdrm/fx_crypt.h" |
10 #include "../fpdf_font/font_int.h" | 10 #include "../fpdf_font/font_int.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 { | 71 { |
72 m_pPageModule.reset(new CPDF_PageModule); | 72 m_pPageModule.reset(new CPDF_PageModule); |
73 } | 73 } |
74 | 74 |
75 void CPDF_PageModule::ReleaseDoc(CPDF_Document* pDoc) | 75 void CPDF_PageModule::ReleaseDoc(CPDF_Document* pDoc) |
76 { | 76 { |
77 delete pDoc->GetPageData(); | 77 delete pDoc->GetPageData(); |
78 } | 78 } |
79 void CPDF_PageModule::ClearDoc(CPDF_Document* pDoc) | 79 void CPDF_PageModule::ClearDoc(CPDF_Document* pDoc) |
80 { | 80 { |
81 pDoc->GetPageData()->Clear(false); | 81 pDoc->GetPageData()->Clear(FALSE); |
82 } | 82 } |
83 void CPDF_PageModule::NotifyCJKAvailable() | 83 void CPDF_PageModule::NotifyCJKAvailable() |
84 { | 84 { |
85 m_FontGlobals.m_CMapManager.ReloadAll(); | 85 m_FontGlobals.m_CMapManager.ReloadAll(); |
86 } | 86 } |
87 | 87 |
88 CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) | 88 CPDF_Font* CPDF_Document::LoadFont(CPDF_Dictionary* pFontDict) |
89 { | 89 { |
90 ASSERT(pFontDict); | 90 ASSERT(pFontDict); |
91 return GetValidatePageData()->GetFont(pFontDict, false); | 91 return GetValidatePageData()->GetFont(pFontDict, FALSE); |
92 } | 92 } |
93 | 93 |
94 CPDF_StreamAcc* CPDF_Document::LoadFontFile(CPDF_Stream* pStream) | 94 CPDF_StreamAcc* CPDF_Document::LoadFontFile(CPDF_Stream* pStream) |
95 { | 95 { |
96 return GetValidatePageData()->GetFontFileStreamAcc(pStream); | 96 return GetValidatePageData()->GetFontFileStreamAcc(pStream); |
97 } | 97 } |
98 | 98 |
99 CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name); | 99 CPDF_ColorSpace* _CSFromName(const CFX_ByteString& name); |
100 CPDF_ColorSpace* CPDF_Document::LoadColorSpace(CPDF_Object* pCSObj, CPDF_Diction
ary* pResources) | 100 CPDF_ColorSpace* CPDF_Document::LoadColorSpace(CPDF_Object* pCSObj, CPDF_Diction
ary* pResources) |
101 { | 101 { |
102 return GetValidatePageData()->GetColorSpace(pCSObj, pResources); | 102 return GetValidatePageData()->GetColorSpace(pCSObj, pResources); |
103 } | 103 } |
104 CPDF_Pattern* CPDF_Document::LoadPattern(CPDF_Object* pPatternObj, bool bShading
, const CFX_AffineMatrix* matrix) | 104 CPDF_Pattern* CPDF_Document::LoadPattern(CPDF_Object* pPatternObj, FX_BOOL bShad
ing, const CFX_AffineMatrix* matrix) |
105 { | 105 { |
106 return GetValidatePageData()->GetPattern(pPatternObj, bShading, matrix); | 106 return GetValidatePageData()->GetPattern(pPatternObj, bShading, matrix); |
107 } | 107 } |
108 CPDF_IccProfile* CPDF_Document::LoadIccProfile(CPDF_Stream* pStream) | 108 CPDF_IccProfile* CPDF_Document::LoadIccProfile(CPDF_Stream* pStream) |
109 { | 109 { |
110 return GetValidatePageData()->GetIccProfile(pStream); | 110 return GetValidatePageData()->GetIccProfile(pStream); |
111 } | 111 } |
112 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) | 112 CPDF_Image* CPDF_Document::LoadImageF(CPDF_Object* pObj) |
113 { | 113 { |
114 if (!pObj) { | 114 if (!pObj) { |
115 return NULL; | 115 return NULL; |
116 } | 116 } |
117 FXSYS_assert(pObj->GetObjNum()); | 117 FXSYS_assert(pObj->GetObjNum()); |
118 return GetValidatePageData()->GetImage(pObj); | 118 return GetValidatePageData()->GetImage(pObj); |
119 } | 119 } |
120 void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj) | 120 void CPDF_Document::RemoveColorSpaceFromPageData(CPDF_Object* pCSObj) |
121 { | 121 { |
122 if (!pCSObj) { | 122 if (!pCSObj) { |
123 return; | 123 return; |
124 } | 124 } |
125 GetPageData()->ReleaseColorSpace(pCSObj); | 125 GetPageData()->ReleaseColorSpace(pCSObj); |
126 } | 126 } |
127 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) | 127 CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) |
128 : m_pPDFDoc(pPDFDoc), | 128 : m_pPDFDoc(pPDFDoc), |
129 m_bForceClear(false) | 129 m_bForceClear(FALSE) |
130 { | 130 { |
131 } | 131 } |
132 | 132 |
133 CPDF_DocPageData::~CPDF_DocPageData() | 133 CPDF_DocPageData::~CPDF_DocPageData() |
134 { | 134 { |
135 Clear(false); | 135 Clear(FALSE); |
136 Clear(true); | 136 Clear(TRUE); |
137 | 137 |
138 for (auto& it : m_PatternMap) | 138 for (auto& it : m_PatternMap) |
139 delete it.second; | 139 delete it.second; |
140 m_PatternMap.clear(); | 140 m_PatternMap.clear(); |
141 | 141 |
142 for (auto& it : m_FontMap) | 142 for (auto& it : m_FontMap) |
143 delete it.second; | 143 delete it.second; |
144 m_FontMap.clear(); | 144 m_FontMap.clear(); |
145 | 145 |
146 for (auto& it : m_ColorSpaceMap) | 146 for (auto& it : m_ColorSpaceMap) |
147 delete it.second; | 147 delete it.second; |
148 m_ColorSpaceMap.clear(); | 148 m_ColorSpaceMap.clear(); |
149 } | 149 } |
150 | 150 |
151 void CPDF_DocPageData::Clear(bool bForceRelease) | 151 void CPDF_DocPageData::Clear(FX_BOOL bForceRelease) |
152 { | 152 { |
153 m_bForceClear = bForceRelease; | 153 m_bForceClear = bForceRelease; |
154 | 154 |
155 for (auto& it : m_PatternMap) { | 155 for (auto& it : m_PatternMap) { |
156 CPDF_CountedPattern* ptData = it.second; | 156 CPDF_CountedPattern* ptData = it.second; |
157 if (!ptData->get()) | 157 if (!ptData->get()) |
158 continue; | 158 continue; |
159 | 159 |
160 if (bForceRelease || ptData->use_count() < 2) { | 160 if (bForceRelease || ptData->use_count() < 2) { |
161 ptData->get()->SetForceClear(bForceRelease); | 161 ptData->get()->SetForceClear(bForceRelease); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 continue; | 228 continue; |
229 | 229 |
230 if (bForceRelease || imageData->use_count() < 2) { | 230 if (bForceRelease || imageData->use_count() < 2) { |
231 delete imageData->get(); | 231 delete imageData->get(); |
232 delete imageData; | 232 delete imageData; |
233 m_ImageMap.erase(curr_it); | 233 m_ImageMap.erase(curr_it); |
234 } | 234 } |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, bool findOnly) | 238 CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict, FX_BOOL findOnl
y) |
239 { | 239 { |
240 if (!pFontDict) { | 240 if (!pFontDict) { |
241 return NULL; | 241 return NULL; |
242 } | 242 } |
243 if (findOnly) { | 243 if (findOnly) { |
244 auto it = m_FontMap.find(pFontDict); | 244 auto it = m_FontMap.find(pFontDict); |
245 if (it != m_FontMap.end() && it->second->get()) { | 245 if (it != m_FontMap.end() && it->second->get()) { |
246 return it->second->AddRef(); | 246 return it->second->AddRef(); |
247 } | 247 } |
248 return nullptr; | 248 return nullptr; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 CPDF_CountedColorSpace* csData = it->second; | 425 CPDF_CountedColorSpace* csData = it->second; |
426 if (csData->get()) { | 426 if (csData->get()) { |
427 csData->RemoveRef(); | 427 csData->RemoveRef(); |
428 if (csData->use_count() == 0) { | 428 if (csData->use_count() == 0) { |
429 csData->get()->ReleaseCS(); | 429 csData->get()->ReleaseCS(); |
430 csData->reset(nullptr); | 430 csData->reset(nullptr); |
431 } | 431 } |
432 } | 432 } |
433 } | 433 } |
434 | 434 |
435 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, bool bShadi
ng, const CFX_AffineMatrix* matrix) | 435 CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bSh
ading, const CFX_AffineMatrix* matrix) |
436 { | 436 { |
437 if (!pPatternObj) | 437 if (!pPatternObj) |
438 return nullptr; | 438 return nullptr; |
439 | 439 |
440 CPDF_CountedPattern* ptData = nullptr; | 440 CPDF_CountedPattern* ptData = nullptr; |
441 auto it = m_PatternMap.find(pPatternObj); | 441 auto it = m_PatternMap.find(pPatternObj); |
442 if (it != m_PatternMap.end()) { | 442 if (it != m_PatternMap.end()) { |
443 ptData = it->second; | 443 ptData = it->second; |
444 if (ptData->get()) { | 444 if (ptData->get()) { |
445 return ptData->AddRef(); | 445 return ptData->AddRef(); |
446 } | 446 } |
447 } | 447 } |
448 CPDF_Pattern* pPattern = nullptr; | 448 CPDF_Pattern* pPattern = nullptr; |
449 if (bShading) { | 449 if (bShading) { |
450 pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, mat
rix); | 450 pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, mat
rix); |
451 } else { | 451 } else { |
452 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr; | 452 CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : nullptr; |
453 if (pDict) { | 453 if (pDict) { |
454 int type = pDict->GetInteger(FX_BSTRC("PatternType")); | 454 int type = pDict->GetInteger(FX_BSTRC("PatternType")); |
455 if (type == 1) { | 455 if (type == 1) { |
456 pPattern = new CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix
); | 456 pPattern = new CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix
); |
457 } else if (type == 2) { | 457 } else if (type == 2) { |
458 pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, false
, matrix); | 458 pPattern = new CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, FALSE
, matrix); |
459 } | 459 } |
460 } | 460 } |
461 } | 461 } |
462 if (!pPattern) | 462 if (!pPattern) |
463 return nullptr; | 463 return nullptr; |
464 | 464 |
465 if (!ptData) { | 465 if (!ptData) { |
466 ptData = new CPDF_CountedPattern(pPattern); | 466 ptData = new CPDF_CountedPattern(pPattern); |
467 m_PatternMap[pPatternObj] = ptData; | 467 m_PatternMap[pPatternObj] = ptData; |
468 } else { | 468 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
494 if (!pImageStream) | 494 if (!pImageStream) |
495 return nullptr; | 495 return nullptr; |
496 | 496 |
497 const FX_DWORD dwImageObjNum = pImageStream->GetObjNum(); | 497 const FX_DWORD dwImageObjNum = pImageStream->GetObjNum(); |
498 auto it = m_ImageMap.find(dwImageObjNum); | 498 auto it = m_ImageMap.find(dwImageObjNum); |
499 if (it != m_ImageMap.end()) { | 499 if (it != m_ImageMap.end()) { |
500 return it->second->AddRef(); | 500 return it->second->AddRef(); |
501 } | 501 } |
502 | 502 |
503 CPDF_Image* pImage = new CPDF_Image(m_pPDFDoc); | 503 CPDF_Image* pImage = new CPDF_Image(m_pPDFDoc); |
504 pImage->LoadImageF((CPDF_Stream*)pImageStream, false); | 504 pImage->LoadImageF((CPDF_Stream*)pImageStream, FALSE); |
505 | 505 |
506 CPDF_CountedImage* imageData = new CPDF_CountedImage(pImage); | 506 CPDF_CountedImage* imageData = new CPDF_CountedImage(pImage); |
507 m_ImageMap[dwImageObjNum] = imageData; | 507 m_ImageMap[dwImageObjNum] = imageData; |
508 return imageData->AddRef(); | 508 return imageData->AddRef(); |
509 } | 509 } |
510 | 510 |
511 void CPDF_DocPageData::ReleaseImage(CPDF_Object* pImageStream) | 511 void CPDF_DocPageData::ReleaseImage(CPDF_Object* pImageStream) |
512 { | 512 { |
513 if (!pImageStream || !pImageStream->GetObjNum()) | 513 if (!pImageStream || !pImageStream->GetObjNum()) |
514 return; | 514 return; |
(...skipping 18 matching lines...) Expand all Loading... |
533 { | 533 { |
534 if (!pIccProfileStream) | 534 if (!pIccProfileStream) |
535 return NULL; | 535 return NULL; |
536 | 536 |
537 auto it = m_IccProfileMap.find(pIccProfileStream); | 537 auto it = m_IccProfileMap.find(pIccProfileStream); |
538 if (it != m_IccProfileMap.end()) { | 538 if (it != m_IccProfileMap.end()) { |
539 return it->second->AddRef(); | 539 return it->second->AddRef(); |
540 } | 540 } |
541 | 541 |
542 CPDF_StreamAcc stream; | 542 CPDF_StreamAcc stream; |
543 stream.LoadAllData(pIccProfileStream, false); | 543 stream.LoadAllData(pIccProfileStream, FALSE); |
544 uint8_t digest[20]; | 544 uint8_t digest[20]; |
545 CPDF_Stream* pCopiedStream = nullptr; | 545 CPDF_Stream* pCopiedStream = nullptr; |
546 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); | 546 CRYPT_SHA1Generate(stream.GetData(), stream.GetSize(), digest); |
547 if (m_HashProfileMap.Lookup(CFX_ByteStringC(digest, 20), (void*&)pCopiedStre
am)) { | 547 if (m_HashProfileMap.Lookup(CFX_ByteStringC(digest, 20), (void*&)pCopiedStre
am)) { |
548 auto it_copied_stream = m_IccProfileMap.find(pCopiedStream); | 548 auto it_copied_stream = m_IccProfileMap.find(pCopiedStream); |
549 return it_copied_stream->second->AddRef(); | 549 return it_copied_stream->second->AddRef(); |
550 } | 550 } |
551 CPDF_IccProfile* pProfile = new CPDF_IccProfile(stream.GetData(), stream.Get
Size()); | 551 CPDF_IccProfile* pProfile = new CPDF_IccProfile(stream.GetData(), stream.Get
Size()); |
552 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); | 552 CPDF_CountedIccProfile* ipData = new CPDF_CountedIccProfile(pProfile); |
553 m_IccProfileMap[pIccProfileStream] = ipData; | 553 m_IccProfileMap[pIccProfileStream] = ipData; |
(...skipping 29 matching lines...) Expand all Loading... |
583 return it->second->AddRef(); | 583 return it->second->AddRef(); |
584 | 584 |
585 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); | 585 CPDF_Dictionary* pFontDict = pFontStream->GetDict(); |
586 int32_t org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + | 586 int32_t org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + |
587 pFontDict->GetInteger(FX_BSTRC("Length2")) + | 587 pFontDict->GetInteger(FX_BSTRC("Length2")) + |
588 pFontDict->GetInteger(FX_BSTRC("Length3")); | 588 pFontDict->GetInteger(FX_BSTRC("Length3")); |
589 if (org_size < 0) | 589 if (org_size < 0) |
590 org_size = 0; | 590 org_size = 0; |
591 | 591 |
592 CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; | 592 CPDF_StreamAcc* pFontFile = new CPDF_StreamAcc; |
593 pFontFile->LoadAllData(pFontStream, false, org_size); | 593 pFontFile->LoadAllData(pFontStream, FALSE, org_size); |
594 | 594 |
595 CPDF_CountedStreamAcc* ftData = new CPDF_CountedStreamAcc(pFontFile); | 595 CPDF_CountedStreamAcc* ftData = new CPDF_CountedStreamAcc(pFontFile); |
596 m_FontFileMap[pFontStream] = ftData; | 596 m_FontFileMap[pFontStream] = ftData; |
597 return ftData->AddRef(); | 597 return ftData->AddRef(); |
598 } | 598 } |
599 | 599 |
600 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, bool b
Force) | 600 void CPDF_DocPageData::ReleaseFontFileStreamAcc(CPDF_Stream* pFontStream, FX_BOO
L bForce) |
601 { | 601 { |
602 if (!pFontStream) | 602 if (!pFontStream) |
603 return; | 603 return; |
604 | 604 |
605 auto it = m_FontFileMap.find(pFontStream); | 605 auto it = m_FontFileMap.find(pFontStream); |
606 if (it == m_FontFileMap.end()) | 606 if (it == m_FontFileMap.end()) |
607 return; | 607 return; |
608 | 608 |
609 CPDF_CountedStreamAcc* findData = it->second; | 609 CPDF_CountedStreamAcc* findData = it->second; |
610 if (!findData) | 610 if (!findData) |
(...skipping 17 matching lines...) Expand all Loading... |
628 } | 628 } |
629 | 629 |
630 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj)
const | 630 CPDF_CountedPattern* CPDF_DocPageData::FindPatternPtr(CPDF_Object* pPatternObj)
const |
631 { | 631 { |
632 if (!pPatternObj) | 632 if (!pPatternObj) |
633 return nullptr; | 633 return nullptr; |
634 | 634 |
635 auto it = m_PatternMap.find(pPatternObj); | 635 auto it = m_PatternMap.find(pPatternObj); |
636 return it != m_PatternMap.end() ? it->second : nullptr; | 636 return it != m_PatternMap.end() ? it->second : nullptr; |
637 } | 637 } |
OLD | NEW |