OLD | NEW |
1 // Copyright 2014 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" |
| 8 |
7 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
8 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" | |
12 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" | 13 #include "core/fpdfapi/fpdf_render/include/cpdf_rendercontext.h" |
13 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 14 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
14 #include "core/fpdfdoc/cpvt_generateap.h" | |
15 #include "core/fpdfdoc/include/fpdf_doc.h" | |
16 #include "core/fxge/include/fx_ge.h" | 15 #include "core/fxge/include/fx_ge.h" |
17 | 16 |
18 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | |
19 : m_pDocument(pPage->m_pDocument) { | |
20 if (!pPage->m_pFormDict) | |
21 return; | |
22 | |
23 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); | |
24 if (!pAnnots) | |
25 return; | |
26 | |
27 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | |
28 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
29 FX_BOOL bRegenerateAP = | |
30 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); | |
31 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { | |
32 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); | |
33 if (!pDict) | |
34 continue; | |
35 | |
36 uint32_t dwObjNum = pDict->GetObjNum(); | |
37 if (dwObjNum == 0) { | |
38 dwObjNum = m_pDocument->AddIndirectObject(pDict); | |
39 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | |
40 pAnnots->InsertAt(i, pAction); | |
41 pAnnots->RemoveAt(i + 1); | |
42 pDict = pAnnots->GetDictAt(i); | |
43 } | |
44 m_AnnotList.push_back( | |
45 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); | |
46 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && | |
47 CPDF_InterForm::IsUpdateAPEnabled()) { | |
48 FPDF_GenerateAP(m_pDocument, pDict); | |
49 } | |
50 } | |
51 } | |
52 | |
53 CPDF_AnnotList::~CPDF_AnnotList() {} | |
54 | |
55 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, | |
56 CFX_RenderDevice* pDevice, | |
57 CPDF_RenderContext* pContext, | |
58 FX_BOOL bPrinting, | |
59 CFX_Matrix* pMatrix, | |
60 FX_BOOL bWidgetPass, | |
61 CPDF_RenderOptions* pOptions, | |
62 FX_RECT* clip_rect) { | |
63 for (const auto& pAnnot : m_AnnotList) { | |
64 bool bWidget = pAnnot->GetSubType() == "Widget"; | |
65 if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) | |
66 continue; | |
67 | |
68 uint32_t annot_flags = pAnnot->GetFlags(); | |
69 if (annot_flags & ANNOTFLAG_HIDDEN) | |
70 continue; | |
71 | |
72 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) | |
73 continue; | |
74 | |
75 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) | |
76 continue; | |
77 | |
78 if (pOptions) { | |
79 CPDF_OCContext* pOCContext = pOptions->m_pOCContext; | |
80 CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); | |
81 if (pOCContext && pAnnotDict && | |
82 !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) { | |
83 continue; | |
84 } | |
85 } | |
86 CFX_FloatRect annot_rect_f; | |
87 pAnnot->GetRect(annot_rect_f); | |
88 CFX_Matrix matrix = *pMatrix; | |
89 if (clip_rect) { | |
90 annot_rect_f.Transform(&matrix); | |
91 FX_RECT annot_rect = annot_rect_f.GetOutterRect(); | |
92 annot_rect.Intersect(*clip_rect); | |
93 if (annot_rect.IsEmpty()) { | |
94 continue; | |
95 } | |
96 } | |
97 if (pContext) { | |
98 pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal); | |
99 } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix, | |
100 CPDF_Annot::Normal, pOptions)) { | |
101 pAnnot->DrawBorder(pDevice, &matrix, pOptions); | |
102 } | |
103 } | |
104 } | |
105 | |
106 void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, | |
107 CFX_RenderDevice* pDevice, | |
108 CPDF_RenderContext* pContext, | |
109 FX_BOOL bPrinting, | |
110 CFX_Matrix* pUser2Device, | |
111 uint32_t dwAnnotFlags, | |
112 CPDF_RenderOptions* pOptions, | |
113 FX_RECT* pClipRect) { | |
114 if (dwAnnotFlags & 0x01) { | |
115 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE, | |
116 pOptions, pClipRect); | |
117 } | |
118 if (dwAnnotFlags & 0x02) { | |
119 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, | |
120 pOptions, pClipRect); | |
121 } | |
122 } | |
123 | |
124 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) | 17 CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument) |
125 : m_pAnnotDict(pDict), | 18 : m_pAnnotDict(pDict), |
126 m_pDocument(pDocument), | 19 m_pDocument(pDocument), |
127 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} | 20 m_sSubtype(m_pAnnotDict->GetStringBy("Subtype")) {} |
128 | 21 |
129 CPDF_Annot::~CPDF_Annot() { | 22 CPDF_Annot::~CPDF_Annot() { |
130 ClearCachedAP(); | 23 ClearCachedAP(); |
131 } | 24 } |
132 | 25 |
133 void CPDF_Annot::ClearCachedAP() { | 26 void CPDF_Annot::ClearCachedAP() { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 CFX_PathData path; | 239 CFX_PathData path; |
347 width /= 2; | 240 width /= 2; |
348 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, | 241 path.AppendRect(rect.left + width, rect.bottom + width, rect.right - width, |
349 rect.top - width); | 242 rect.top - width); |
350 int fill_type = 0; | 243 int fill_type = 0; |
351 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { | 244 if (pOptions && (pOptions->m_Flags & RENDER_NOPATHSMOOTH)) { |
352 fill_type |= FXFILL_NOPATHSMOOTH; | 245 fill_type |= FXFILL_NOPATHSMOOTH; |
353 } | 246 } |
354 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); | 247 pDevice->DrawPath(&path, pUser2Device, &graph_state, argb, argb, fill_type); |
355 } | 248 } |
OLD | NEW |