OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/fpdfdoc/cpdf_annot.h" | 7 #include "core/fpdfdoc/cpdf_annot.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
13 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" | 13 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" |
14 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 14 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
| 15 #include "core/fxcrt/include/fx_memory.h" |
15 #include "core/fxge/include/fx_ge.h" | 16 #include "core/fxge/include/fx_ge.h" |
16 | 17 |
17 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) | 18 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) |
18 : m_pAnnotDict(pDict), | 19 : m_pAnnotDict(pDict), |
19 m_pDocument(pDocument), | 20 m_pDocument(pDocument), |
20 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} | 21 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} |
21 | 22 |
22 CPDF_Annot::~CPDF_Annot() { | 23 CPDF_Annot::~CPDF_Annot() { |
23 ClearCachedAP(); | 24 ClearCachedAP(); |
24 } | 25 } |
25 | 26 |
26 void CPDF_Annot::ClearCachedAP() { | 27 void CPDF_Annot::ClearCachedAP() { |
27 for (const auto& pair : m_APMap) { | |
28 delete pair.second; | |
29 } | |
30 m_APMap.clear(); | 28 m_APMap.clear(); |
31 } | 29 } |
32 CFX_ByteString CPDF_Annot::GetSubType() const { | 30 CFX_ByteString CPDF_Annot::GetSubType() const { |
33 return m_sSubtype; | 31 return m_sSubtype; |
34 } | 32 } |
35 | 33 |
36 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { | 34 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { |
37 if (!m_pAnnotDict) { | 35 if (!m_pAnnotDict) { |
38 return; | 36 return; |
39 } | 37 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return nullptr; | 81 return nullptr; |
84 } | 82 } |
85 | 83 |
86 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { | 84 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { |
87 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); | 85 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); |
88 if (!pStream) | 86 if (!pStream) |
89 return nullptr; | 87 return nullptr; |
90 | 88 |
91 auto it = m_APMap.find(pStream); | 89 auto it = m_APMap.find(pStream); |
92 if (it != m_APMap.end()) | 90 if (it != m_APMap.end()) |
93 return it->second; | 91 return it->second.get(); |
94 | 92 |
95 CPDF_Form* pNewForm = | 93 CPDF_Form* pNewForm = |
96 new CPDF_Form(m_pDocument, pPage->m_pResources, pStream); | 94 new CPDF_Form(m_pDocument, pPage->m_pResources, pStream); |
97 pNewForm->ParseContent(nullptr, nullptr, nullptr); | 95 pNewForm->ParseContent(nullptr, nullptr, nullptr); |
98 m_APMap[pStream] = pNewForm; | 96 m_APMap[pStream] = WrapUnique(pNewForm); |
99 return pNewForm; | 97 return pNewForm; |
100 } | 98 } |
101 | 99 |
102 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, | 100 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, |
103 CPDF_Annot* pAnnot, | 101 CPDF_Annot* pAnnot, |
104 CPDF_Annot::AppearanceMode mode, | 102 CPDF_Annot::AppearanceMode mode, |
105 const CFX_Matrix* pUser2Device, | 103 const CFX_Matrix* pUser2Device, |
106 CFX_Matrix& matrix) { | 104 CFX_Matrix& matrix) { |
107 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); | 105 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); |
108 if (!pForm) { | 106 if (!pForm) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 CFX_PathData path; | 237 CFX_PathData path; |
240 width /= 2; | 238 width /= 2; |
241 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 239 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
242 rect.top - width); | 240 rect.top - width); |
243 int fill_type = 0; | 241 int fill_type = 0; |
244 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 242 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
245 fill_type |= FXFILL_NOPATHSMOOTH; | 243 fill_type |= FXFILL_NOPATHSMOOTH; |
246 } | 244 } |
247 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 245 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
248 } | 246 } |
OLD | NEW |