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 namespace { |
| 22 |
| 23 bool ShouldGenerateAPForAnnotation(CPDF_Dictionary* pAnnotDict) { |
| 24 // If AP dictionary exists, we use the appearance defined in the |
| 25 // existing AP dictionary. |
| 26 if (pAnnotDict->KeyExist("AP")) |
| 27 return false; |
| 28 |
| 29 return !CPDF_Annot::IsAnnotationHidden(pAnnotDict); |
| 30 } |
| 31 |
| 32 } // namespace |
| 33 |
21 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, | 34 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, |
22 CPDF_Document* pDocument, | 35 CPDF_Document* pDocument, |
23 bool bToOwnDict) | 36 bool bToOwnDict) |
24 : m_bOwnedAnnotDict(bToOwnDict), | 37 : m_bOwnedAnnotDict(bToOwnDict), |
25 m_pAnnotDict(pDict), | 38 m_pAnnotDict(pDict), |
26 m_pDocument(pDocument), | 39 m_pDocument(pDocument), |
27 m_bOpenState(false), | 40 m_bOpenState(false), |
28 m_pPopupAnnot(nullptr) { | 41 m_pPopupAnnot(nullptr) { |
29 m_nSubtype = StringToAnnotSubtype(m_pAnnotDict->GetStringBy("Subtype")); | 42 m_nSubtype = StringToAnnotSubtype(m_pAnnotDict->GetStringBy("Subtype")); |
30 GenerateAPIfNeeded(); | 43 GenerateAPIfNeeded(); |
31 } | 44 } |
32 | 45 |
33 CPDF_Annot::~CPDF_Annot() { | 46 CPDF_Annot::~CPDF_Annot() { |
34 if (m_bOwnedAnnotDict) | 47 if (m_bOwnedAnnotDict) |
35 m_pAnnotDict->Release(); | 48 m_pAnnotDict->Release(); |
36 ClearCachedAP(); | 49 ClearCachedAP(); |
37 } | 50 } |
38 | 51 |
39 void CPDF_Annot::GenerateAPIfNeeded() { | 52 void CPDF_Annot::GenerateAPIfNeeded() { |
| 53 if (!ShouldGenerateAPForAnnotation(m_pAnnotDict)) |
| 54 return; |
| 55 |
40 if (m_nSubtype == CPDF_Annot::Subtype::CIRCLE) | 56 if (m_nSubtype == CPDF_Annot::Subtype::CIRCLE) |
41 CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict); | 57 CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict); |
42 else if (m_nSubtype == CPDF_Annot::Subtype::HIGHLIGHT) | 58 else if (m_nSubtype == CPDF_Annot::Subtype::HIGHLIGHT) |
43 CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict); | 59 CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict); |
44 else if (m_nSubtype == CPDF_Annot::Subtype::INK) | 60 else if (m_nSubtype == CPDF_Annot::Subtype::INK) |
45 CPVT_GenerateAP::GenerateInkAP(m_pDocument, m_pAnnotDict); | 61 CPVT_GenerateAP::GenerateInkAP(m_pDocument, m_pAnnotDict); |
46 else if (m_nSubtype == CPDF_Annot::Subtype::POPUP) | 62 else if (m_nSubtype == CPDF_Annot::Subtype::POPUP) |
47 CPVT_GenerateAP::GeneratePopupAP(m_pDocument, m_pAnnotDict); | 63 CPVT_GenerateAP::GeneratePopupAP(m_pDocument, m_pAnnotDict); |
48 else if (m_nSubtype == CPDF_Annot::Subtype::SQUARE) | 64 else if (m_nSubtype == CPDF_Annot::Subtype::SQUARE) |
49 CPVT_GenerateAP::GenerateSquareAP(m_pDocument, m_pAnnotDict); | 65 CPVT_GenerateAP::GenerateSquareAP(m_pDocument, m_pAnnotDict); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return nullptr; | 158 return nullptr; |
143 } | 159 } |
144 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectBy("BBox"); | 160 CFX_FloatRect form_bbox = pForm->m_pFormDict->GetRectBy("BBox"); |
145 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); | 161 CFX_Matrix form_matrix = pForm->m_pFormDict->GetMatrixBy("Matrix"); |
146 form_matrix.TransformRect(form_bbox); | 162 form_matrix.TransformRect(form_bbox); |
147 matrix.MatchRect(pAnnot->GetRect(), form_bbox); | 163 matrix.MatchRect(pAnnot->GetRect(), form_bbox); |
148 matrix.Concat(*pUser2Device); | 164 matrix.Concat(*pUser2Device); |
149 return pForm; | 165 return pForm; |
150 } | 166 } |
151 | 167 |
152 // static | 168 // Static. |
153 bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) { | 169 bool CPDF_Annot::IsAnnotationHidden(CPDF_Dictionary* pAnnotDict) { |
154 return !!(pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN); | 170 return !!(pAnnotDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN); |
155 } | 171 } |
156 | 172 |
157 // Static. | 173 // Static. |
158 CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype( | 174 CPDF_Annot::Subtype CPDF_Annot::StringToAnnotSubtype( |
159 const CFX_ByteString& sSubtype) { | 175 const CFX_ByteString& sSubtype) { |
160 if (sSubtype == "Text") | 176 if (sSubtype == "Text") |
161 return CPDF_Annot::Subtype::TEXT; | 177 return CPDF_Annot::Subtype::TEXT; |
162 if (sSubtype == "Link") | 178 if (sSubtype == "Link") |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 CFX_PathData path; | 423 CFX_PathData path; |
408 width /= 2; | 424 width /= 2; |
409 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 425 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
410 rect.top - width); | 426 rect.top - width); |
411 int fill_type = 0; | 427 int fill_type = 0; |
412 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 428 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
413 fill_type |= FXFILL_NOPATHSMOOTH; | 429 fill_type |= FXFILL_NOPATHSMOOTH; |
414 } | 430 } |
415 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 431 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
416 } | 432 } |
OLD | NEW |