OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "core/fpdfdoc/cpdf_annotlist.h" | |
8 | |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | |
10 #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_renderoptions.h" | |
13 #include "core/fpdfdoc/cpdf_annot.h" | |
14 #include "core/fpdfdoc/cpvt_generateap.h" | |
15 | |
16 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | |
17 : m_pDocument(pPage->m_pDocument) { | |
18 if (!pPage->m_pFormDict) | |
19 return; | |
20 | |
21 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); | |
22 if (!pAnnots) | |
23 return; | |
24 | |
25 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | |
26 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | |
27 FX_BOOL bRegenerateAP = | |
28 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); | |
29 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { | |
30 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); | |
31 if (!pDict) | |
32 continue; | |
33 | |
34 uint32_t dwObjNum = pDict->GetObjNum(); | |
35 if (dwObjNum == 0) { | |
36 dwObjNum = m_pDocument->AddIndirectObject(pDict); | |
37 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | |
38 pAnnots->InsertAt(i, pAction); | |
39 pAnnots->RemoveAt(i + 1); | |
40 pDict = pAnnots->GetDictAt(i); | |
41 } | |
42 m_AnnotList.push_back( | |
43 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); | |
44 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && | |
45 CPDF_InterForm::IsUpdateAPEnabled()) { | |
46 FPDF_GenerateAP(m_pDocument, pDict); | |
47 } | |
48 } | |
49 } | |
50 | |
51 CPDF_AnnotList::~CPDF_AnnotList() {} | |
52 | |
53 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, | |
54 CFX_RenderDevice* pDevice, | |
55 CPDF_RenderContext* pContext, | |
56 FX_BOOL bPrinting, | |
57 CFX_Matrix* pMatrix, | |
58 FX_BOOL bWidgetPass, | |
59 CPDF_RenderOptions* pOptions, | |
60 FX_RECT* clip_rect) { | |
61 for (const auto& pAnnot : m_AnnotList) { | |
62 bool bWidget = pAnnot->GetSubType() == "Widget"; | |
63 if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) | |
64 continue; | |
65 | |
66 uint32_t annot_flags = pAnnot->GetFlags(); | |
67 if (annot_flags & ANNOTFLAG_HIDDEN) | |
68 continue; | |
69 | |
70 if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) | |
71 continue; | |
72 | |
73 if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) | |
74 continue; | |
75 | |
76 if (pOptions) { | |
77 CPDF_OCContext* pOCContext = pOptions->m_pOCContext; | |
78 CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict(); | |
79 if (pOCContext && pAnnotDict && | |
80 !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) { | |
81 continue; | |
82 } | |
83 } | |
84 CFX_FloatRect annot_rect_f; | |
85 pAnnot->GetRect(annot_rect_f); | |
86 CFX_Matrix matrix = *pMatrix; | |
87 if (clip_rect) { | |
88 annot_rect_f.Transform(&matrix); | |
89 FX_RECT annot_rect = annot_rect_f.GetOutterRect(); | |
90 annot_rect.Intersect(*clip_rect); | |
91 if (annot_rect.IsEmpty()) { | |
92 continue; | |
93 } | |
94 } | |
95 if (pContext) { | |
96 pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal); | |
97 } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix, | |
98 CPDF_Annot::Normal, pOptions)) { | |
99 pAnnot->DrawBorder(pDevice, &matrix, pOptions); | |
100 } | |
101 } | |
102 } | |
103 | |
104 void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, | |
105 CFX_RenderDevice* pDevice, | |
106 CPDF_RenderContext* pContext, | |
107 FX_BOOL bPrinting, | |
108 CFX_Matrix* pUser2Device, | |
109 uint32_t dwAnnotFlags, | |
110 CPDF_RenderOptions* pOptions, | |
111 FX_RECT* pClipRect) { | |
112 if (dwAnnotFlags & 0x01) { | |
dsinclair
2016/07/20 19:19:22
Is this ANNOTFLAG_INVISIBLE?
jaepark
2016/07/20 20:45:32
Done.
| |
113 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, FALSE, | |
114 pOptions, pClipRect); | |
115 } | |
116 if (dwAnnotFlags & 0x02) { | |
dsinclair
2016/07/20 19:19:23
And this the HIDDEN flag?
jaepark
2016/07/20 20:45:32
Done.
| |
117 DisplayPass(pPage, pDevice, pContext, bPrinting, pUser2Device, TRUE, | |
118 pOptions, pClipRect); | |
119 } | |
120 } | |
OLD | NEW |