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/include/cpdf_annot.h" | 7 #include "core/fpdfdoc/include/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/fpdfdoc/cpvt_generateap.h" | 15 #include "core/fpdfdoc/cpvt_generateap.h" |
16 #include "core/fxcrt/include/fx_memory.h" | 16 #include "core/fxcrt/include/fx_memory.h" |
17 #include "core/fxge/include/cfx_graphstatedata.h" | 17 #include "core/fxge/include/cfx_graphstatedata.h" |
18 #include "core/fxge/include/cfx_pathdata.h" | 18 #include "core/fxge/include/cfx_pathdata.h" |
19 #include "core/fxge/include/cfx_renderdevice.h" | 19 #include "core/fxge/include/cfx_renderdevice.h" |
20 | 20 |
21 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) | 21 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) |
22 : m_pAnnotDict(pDict), | 22 : m_pAnnotDict(pDict), |
23 m_pDocument(pDocument), | 23 m_pDocument(pDocument), |
24 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) { | 24 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) { |
| 25 GenerateAPIfNeeded(); |
| 26 } |
| 27 |
| 28 CPDF_Annot::~CPDF_Annot() { |
| 29 ClearCachedAP(); |
| 30 } |
| 31 |
| 32 void CPDF_Annot::GenerateAPIfNeeded() { |
25 if (m_sSubtype == "Circle") | 33 if (m_sSubtype == "Circle") |
26 CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict); | 34 CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict); |
27 else if (m_sSubtype == "Highlight") | 35 else if (m_sSubtype == "Highlight") |
28 CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict); | 36 CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict); |
29 else if (m_sSubtype == "Ink") | 37 else if (m_sSubtype == "Ink") |
30 CPVT_GenerateAP::GenerateInkAP(m_pDocument, m_pAnnotDict); | 38 CPVT_GenerateAP::GenerateInkAP(m_pDocument, m_pAnnotDict); |
31 else if (m_sSubtype == "Square") | 39 else if (m_sSubtype == "Square") |
32 CPVT_GenerateAP::GenerateSquareAP(m_pDocument, m_pAnnotDict); | 40 CPVT_GenerateAP::GenerateSquareAP(m_pDocument, m_pAnnotDict); |
33 else if (m_sSubtype == "Squiggly") | 41 else if (m_sSubtype == "Squiggly") |
34 CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, m_pAnnotDict); | 42 CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, m_pAnnotDict); |
35 else if (m_sSubtype == "StrikeOut") | 43 else if (m_sSubtype == "StrikeOut") |
36 CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, m_pAnnotDict); | 44 CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, m_pAnnotDict); |
37 else if (m_sSubtype == "Text") | 45 else if (m_sSubtype == "Text") |
38 CPVT_GenerateAP::GenerateTextAP(m_pDocument, m_pAnnotDict); | 46 CPVT_GenerateAP::GenerateTextAP(m_pDocument, m_pAnnotDict); |
39 else if (m_sSubtype == "Underline") | 47 else if (m_sSubtype == "Underline") |
40 CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict); | 48 CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict); |
41 } | 49 } |
42 | 50 |
43 CPDF_Annot::~CPDF_Annot() { | |
44 ClearCachedAP(); | |
45 } | |
46 | |
47 void CPDF_Annot::ClearCachedAP() { | 51 void CPDF_Annot::ClearCachedAP() { |
48 m_APMap.clear(); | 52 m_APMap.clear(); |
49 } | 53 } |
50 CFX_ByteString CPDF_Annot::GetSubType() const { | 54 CFX_ByteString CPDF_Annot::GetSubType() const { |
51 return m_sSubtype; | 55 return m_sSubtype; |
52 } | 56 } |
53 | 57 |
54 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { | 58 void CPDF_Annot::GetRect(CFX_FloatRect& rect) const { |
55 if (!m_pAnnotDict) { | 59 if (!m_pAnnotDict) { |
56 return; | 60 return; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 146 } |
143 | 147 |
144 FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage, | 148 FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage, |
145 CFX_RenderDevice* pDevice, | 149 CFX_RenderDevice* pDevice, |
146 const CFX_Matrix* pUser2Device, | 150 const CFX_Matrix* pUser2Device, |
147 AppearanceMode mode, | 151 AppearanceMode mode, |
148 const CPDF_RenderOptions* pOptions) { | 152 const CPDF_RenderOptions* pOptions) { |
149 if (IsAnnotationHidden(m_pAnnotDict)) | 153 if (IsAnnotationHidden(m_pAnnotDict)) |
150 return FALSE; | 154 return FALSE; |
151 | 155 |
| 156 // It might happen that by the time this annotation instance was created, |
| 157 // it was flagged as "hidden" (e.g. /F 2), and hence CPVT_GenerateAP decided |
| 158 // to not "generate" its AP. |
| 159 // If for a reason the object is no longer hidden, but still does not have |
| 160 // its "AP" generated, generate it now. |
| 161 GenerateAPIfNeeded(); |
| 162 |
152 CFX_Matrix matrix; | 163 CFX_Matrix matrix; |
153 CPDF_Form* pForm = | 164 CPDF_Form* pForm = |
154 FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix); | 165 FPDFDOC_Annot_GetMatrix(pPage, this, mode, pUser2Device, matrix); |
155 if (!pForm) { | 166 if (!pForm) { |
156 return FALSE; | 167 return FALSE; |
157 } | 168 } |
158 CPDF_RenderContext context(pPage); | 169 CPDF_RenderContext context(pPage); |
159 context.AppendLayer(pForm, &matrix); | 170 context.AppendLayer(pForm, &matrix); |
160 context.Render(pDevice, pOptions, nullptr); | 171 context.Render(pDevice, pOptions, nullptr); |
161 return TRUE; | 172 return TRUE; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 CFX_PathData path; | 277 CFX_PathData path; |
267 width /= 2; | 278 width /= 2; |
268 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 279 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
269 rect.top - width); | 280 rect.top - width); |
270 int fill_type = 0; | 281 int fill_type = 0; |
271 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 282 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
272 fill_type |= FXFILL_NOPATHSMOOTH; | 283 fill_type |= FXFILL_NOPATHSMOOTH; |
273 } | 284 } |
274 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 285 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
275 } | 286 } |
OLD | NEW |