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/include/fpdfapi/fpdf_pageobj.h" | 7 #include "core/include/fpdfapi/fpdf_pageobj.h" |
8 #include "core/include/fpdfdoc/fpdf_doc.h" | 8 #include "core/include/fpdfdoc/fpdf_doc.h" |
9 #include "third_party/base/nonstd_unique_ptr.h" | 9 #include "third_party/base/nonstd_unique_ptr.h" |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 | 118 |
119 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList) | 119 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_AnnotList* pList) |
120 : m_pAnnotDict(pDict), | 120 : m_pAnnotDict(pDict), |
121 m_pList(pList), | 121 m_pList(pList), |
122 m_sSubtype(m_pAnnotDict->GetConstString(FX_BSTRC("Subtype"))) {} | 122 m_sSubtype(m_pAnnotDict->GetConstString(FX_BSTRC("Subtype"))) {} |
123 CPDF_Annot::~CPDF_Annot() { | 123 CPDF_Annot::~CPDF_Annot() { |
124 ClearCachedAP(); | 124 ClearCachedAP(); |
125 } | 125 } |
126 void CPDF_Annot::ClearCachedAP() { | 126 void CPDF_Annot::ClearCachedAP() { |
127 FX_POSITION pos = m_APMap.GetStartPosition(); | 127 for (const auto& pair : m_APMap) { |
128 while (pos) { | 128 delete pair.second; |
129 void* pForm; | |
130 void* pObjects; | |
131 m_APMap.GetNextAssoc(pos, pForm, pObjects); | |
132 delete (CPDF_PageObjects*)pObjects; | |
133 } | 129 } |
134 m_APMap.RemoveAll(); | 130 m_APMap.clear(); |
135 } | 131 } |
136 CFX_ByteString CPDF_Annot::GetSubType() const { | 132 CFX_ByteString CPDF_Annot::GetSubType() const { |
137 return m_sSubtype; | 133 return m_sSubtype; |
138 } | 134 } |
139 | 135 |
140 void CPDF_Annot::GetRect(CPDF_Rect& rect) const { | 136 void CPDF_Annot::GetRect(CPDF_Rect& rect) const { |
141 if (m_pAnnotDict == NULL) { | 137 if (m_pAnnotDict == NULL) { |
142 return; | 138 return; |
143 } | 139 } |
144 rect = m_pAnnotDict->GetRect("Rect"); | 140 rect = m_pAnnotDict->GetRect("Rect"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return pDict->GetStream(as); | 181 return pDict->GetStream(as); |
186 } | 182 } |
187 return nullptr; | 183 return nullptr; |
188 } | 184 } |
189 | 185 |
190 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { | 186 CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) { |
191 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); | 187 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode); |
192 if (!pStream) | 188 if (!pStream) |
193 return nullptr; | 189 return nullptr; |
194 | 190 |
195 void* pForm; | 191 auto it = m_APMap.find(pStream); |
196 if (m_APMap.Lookup(pStream, pForm)) | 192 if (it != m_APMap.end()) |
197 return static_cast<CPDF_Form*>(pForm); | 193 return it->second; |
198 | 194 |
199 CPDF_Form* pNewForm = | 195 CPDF_Form* pNewForm = |
200 new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream); | 196 new CPDF_Form(m_pList->GetDocument(), pPage->m_pResources, pStream); |
201 pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr); | 197 pNewForm->ParseContent(nullptr, nullptr, nullptr, nullptr); |
202 m_APMap.SetAt(pStream, pNewForm); | 198 m_APMap[pStream] = pNewForm; |
203 return pNewForm; | 199 return pNewForm; |
204 } | 200 } |
205 | 201 |
206 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, | 202 static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, |
207 CPDF_Annot* pAnnot, | 203 CPDF_Annot* pAnnot, |
208 CPDF_Annot::AppearanceMode mode, | 204 CPDF_Annot::AppearanceMode mode, |
209 const CFX_Matrix* pUser2Device, | 205 const CFX_Matrix* pUser2Device, |
210 CFX_Matrix& matrix) { | 206 CFX_Matrix& matrix) { |
211 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); | 207 CPDF_Form* pForm = pAnnot->GetAPForm(pPage, mode); |
212 if (!pForm) { | 208 if (!pForm) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 CPDF_PathData path; | 339 CPDF_PathData path; |
344 width /= 2; | 340 width /= 2; |
345 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 341 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
346 rect.top - width); | 342 rect.top - width); |
347 int fill_type = 0; | 343 int fill_type = 0; |
348 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 344 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
349 fill_type |= FXFILL_NOPATHSMOOTH; | 345 fill_type |= FXFILL_NOPATHSMOOTH; |
350 } | 346 } |
351 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 347 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
352 } | 348 } |
OLD | NEW |