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_annotlist.h" | 7 #include "core/fpdfdoc/include/cpdf_annotlist.h" |
8 | 8 |
9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" |
12 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" | 12 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" |
13 #include "core/fpdfdoc/cpvt_generateap.h" | 13 #include "core/fpdfdoc/cpvt_generateap.h" |
14 #include "core/fpdfdoc/include/cpdf_annot.h" | 14 #include "core/fpdfdoc/include/cpdf_annot.h" |
15 #include "core/fpdfdoc/include/cpdf_interform.h" | 15 #include "core/fpdfdoc/include/cpdf_interform.h" |
16 #include "core/fpdfdoc/include/cpdf_occontext.h" | 16 #include "core/fpdfdoc/include/cpdf_occontext.h" |
17 #include "core/fxge/include/cfx_renderdevice.h" | 17 #include "core/fxge/include/cfx_renderdevice.h" |
18 | 18 |
19 namespace { | |
20 | |
21 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, | |
22 CPDF_Document* pDocument) { | |
23 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); | |
24 if (!pParentDict) | |
25 return std::unique_ptr<CPDF_Annot>(); | |
26 | |
27 CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; | |
28 pAnnotDict->SetAtName("Type", "Annot"); | |
29 pAnnotDict->SetAtName("Subtype", "Popup"); | |
30 pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); | |
31 pAnnotDict->SetAtString("Contents", pParentDict->GetStringBy("Contents")); | |
32 | |
33 CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); | |
34 rect.Normalize(); | |
35 CFX_FloatRect popupRect(0, 0, 200, 200); | |
36 popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); | |
37 | |
38 pAnnotDict->SetAtRect("Rect", popupRect); | |
39 pAnnotDict->SetAtInteger("F", 0); | |
40 | |
41 std::unique_ptr<CPDF_Annot> pPopupAnnot( | |
42 new CPDF_Annot(pAnnotDict, pDocument)); | |
43 pAnnot->SetPopupAnnot(pPopupAnnot.get()); | |
44 return pPopupAnnot; | |
45 } | |
46 | |
47 } // namespace | |
48 | |
19 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | 49 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) |
20 : m_pDocument(pPage->m_pDocument) { | 50 : m_pDocument(pPage->m_pDocument) { |
21 if (!pPage->m_pFormDict) | 51 if (!pPage->m_pFormDict) |
22 return; | 52 return; |
23 | 53 |
24 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); | 54 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); |
25 if (!pAnnots) | 55 if (!pAnnots) |
26 return; | 56 return; |
27 | 57 |
28 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 58 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
29 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 59 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
30 FX_BOOL bRegenerateAP = | 60 FX_BOOL bRegenerateAP = |
31 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); | 61 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); |
32 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { | 62 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { |
33 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); | 63 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
34 if (!pDict) | 64 if (!pDict) |
35 continue; | 65 continue; |
36 | 66 |
37 uint32_t dwObjNum = pDict->GetObjNum(); | 67 uint32_t dwObjNum = pDict->GetObjNum(); |
38 if (dwObjNum == 0) { | 68 if (dwObjNum == 0) { |
39 dwObjNum = m_pDocument->AddIndirectObject(pDict); | 69 dwObjNum = m_pDocument->AddIndirectObject(pDict); |
40 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | 70 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); |
41 pAnnots->InsertAt(i, pAction); | 71 pAnnots->InsertAt(i, pAction); |
42 pAnnots->RemoveAt(i + 1); | 72 pAnnots->RemoveAt(i + 1); |
43 pDict = pAnnots->GetDictAt(i); | 73 pDict = pAnnots->GetDictAt(i); |
44 } | 74 } |
75 | |
45 m_AnnotList.push_back( | 76 m_AnnotList.push_back( |
46 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); | 77 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); |
78 | |
47 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && | 79 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && |
48 CPDF_InterForm::IsUpdateAPEnabled()) { | 80 CPDF_InterForm::IsUpdateAPEnabled()) { |
49 FPDF_GenerateAP(m_pDocument, pDict); | 81 FPDF_GenerateAP(m_pDocument, pDict); |
50 } | 82 } |
51 } | 83 } |
84 | |
85 size_t nAnnotListCount = m_AnnotList.size(); | |
Lei Zhang
2016/08/27 02:16:53
no need for variable.
jaepark
2016/08/29 21:19:24
Actually, the below for loop is pushing back to th
| |
86 for (size_t i = 0; i < nAnnotListCount; ++i) | |
87 m_AnnotList.push_back(CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); | |
52 } | 88 } |
53 | 89 |
54 CPDF_AnnotList::~CPDF_AnnotList() {} | 90 CPDF_AnnotList::~CPDF_AnnotList() {} |
55 | 91 |
56 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, | 92 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, |
57 CFX_RenderDevice* pDevice, | 93 CFX_RenderDevice* pDevice, |
58 CPDF_RenderContext* pContext, | 94 CPDF_RenderContext* pContext, |
59 FX_BOOL bPrinting, | 95 FX_BOOL bPrinting, |
60 CFX_Matrix* pMatrix, | 96 CFX_Matrix* pMatrix, |
61 FX_BOOL bWidgetPass, | 97 FX_BOOL bWidgetPass, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 CPDF_RenderContext* pContext, | 161 CPDF_RenderContext* pContext, |
126 FX_BOOL bPrinting, | 162 FX_BOOL bPrinting, |
127 CFX_Matrix* pMatrix, | 163 CFX_Matrix* pMatrix, |
128 FX_BOOL bShowWidget, | 164 FX_BOOL bShowWidget, |
129 CPDF_RenderOptions* pOptions) { | 165 CPDF_RenderOptions* pOptions) { |
130 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN | 166 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN |
131 : ANNOTFLAG_INVISIBLE; | 167 : ANNOTFLAG_INVISIBLE; |
132 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, | 168 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, |
133 pOptions, nullptr); | 169 pOptions, nullptr); |
134 } | 170 } |
OLD | NEW |