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" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, | 21 std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, |
22 CPDF_Document* pDocument) { | 22 CPDF_Document* pDocument) { |
23 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); | 23 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); |
24 if (!pParentDict) | 24 if (!pParentDict) |
25 return std::unique_ptr<CPDF_Annot>(); | 25 return std::unique_ptr<CPDF_Annot>(); |
26 | 26 |
27 CFX_ByteString sContents = pParentDict->GetStringBy("Contents"); | 27 CFX_ByteString sContents = pParentDict->GetStringBy("Contents"); |
28 if (sContents.IsEmpty()) | 28 if (sContents.IsEmpty()) |
29 return std::unique_ptr<CPDF_Annot>(); | 29 return std::unique_ptr<CPDF_Annot>(); |
30 | 30 |
31 CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; | 31 CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; |
Lei Zhang
2016/09/01 03:53:12
Alternatively, we can have some other container to
Wei Li
2016/09/01 19:08:34
I know the current solution is not ideal. But main
| |
32 pAnnotDict->SetAtName("Type", "Annot"); | 32 pAnnotDict->SetAtName("Type", "Annot"); |
33 pAnnotDict->SetAtName("Subtype", "Popup"); | 33 pAnnotDict->SetAtName("Subtype", "Popup"); |
34 pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); | 34 pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); |
35 pAnnotDict->SetAtString("Contents", sContents); | 35 pAnnotDict->SetAtString("Contents", sContents); |
36 | 36 |
37 CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); | 37 CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); |
38 rect.Normalize(); | 38 rect.Normalize(); |
39 CFX_FloatRect popupRect(0, 0, 200, 200); | 39 CFX_FloatRect popupRect(0, 0, 200, 200); |
40 popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); | 40 popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); |
41 | 41 |
42 pAnnotDict->SetAtRect("Rect", popupRect); | 42 pAnnotDict->SetAtRect("Rect", popupRect); |
43 pAnnotDict->SetAtInteger("F", 0); | 43 pAnnotDict->SetAtInteger("F", 0); |
44 | 44 |
45 std::unique_ptr<CPDF_Annot> pPopupAnnot( | 45 std::unique_ptr<CPDF_Annot> pPopupAnnot( |
46 new CPDF_Annot(pAnnotDict, pDocument)); | 46 new CPDF_Annot(pAnnotDict, pDocument, true)); |
47 pAnnot->SetPopupAnnot(pPopupAnnot.get()); | 47 pAnnot->SetPopupAnnot(pPopupAnnot.get()); |
48 return pPopupAnnot; | 48 return pPopupAnnot; |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | 53 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) |
54 : m_pDocument(pPage->m_pDocument) { | 54 : m_pDocument(pPage->m_pDocument) { |
55 if (!pPage->m_pFormDict) | 55 if (!pPage->m_pFormDict) |
56 return; | 56 return; |
(...skipping 10 matching lines...) Expand all Loading... | |
67 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); | 67 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
68 if (!pDict) | 68 if (!pDict) |
69 continue; | 69 continue; |
70 | 70 |
71 uint32_t dwObjNum = pDict->GetObjNum(); | 71 uint32_t dwObjNum = pDict->GetObjNum(); |
72 if (dwObjNum == 0) { | 72 if (dwObjNum == 0) { |
73 dwObjNum = m_pDocument->AddIndirectObject(pDict); | 73 dwObjNum = m_pDocument->AddIndirectObject(pDict); |
74 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | 74 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); |
75 pAnnots->InsertAt(i, pAction); | 75 pAnnots->InsertAt(i, pAction); |
76 pAnnots->RemoveAt(i + 1); | 76 pAnnots->RemoveAt(i + 1); |
77 pDict = pAnnots->GetDictAt(i); | 77 pDict = pAnnots->GetDictAt(i); |
dsinclair
2016/08/31 20:28:31
Could we clone the dictionary at this point and pa
| |
78 } | 78 } |
79 | 79 |
80 // Skip creating Popup annotation in the PDF document since PDFium provides | 80 // Skip creating Popup annotation in the PDF document since PDFium provides |
81 // its own Popup annotations. | 81 // its own Popup annotations. |
82 if (pDict->GetStringBy("Subtype") == "Popup") | 82 if (pDict->GetStringBy("Subtype") == "Popup") |
83 continue; | 83 continue; |
84 | 84 |
85 m_AnnotList.push_back( | 85 m_AnnotList.push_back( |
86 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); | 86 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument, false))); |
87 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && | 87 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && |
88 CPDF_InterForm::IsUpdateAPEnabled()) { | 88 CPDF_InterForm::IsUpdateAPEnabled()) { |
89 FPDF_GenerateAP(m_pDocument, pDict); | 89 FPDF_GenerateAP(m_pDocument, pDict); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 size_t nAnnotListSize = m_AnnotList.size(); | 93 size_t nAnnotListSize = m_AnnotList.size(); |
94 for (size_t i = 0; i < nAnnotListSize; ++i) { | 94 for (size_t i = 0; i < nAnnotListSize; ++i) { |
95 std::unique_ptr<CPDF_Annot> pPopupAnnot( | 95 std::unique_ptr<CPDF_Annot> pPopupAnnot( |
96 CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); | 96 CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 CPDF_RenderContext* pContext, | 173 CPDF_RenderContext* pContext, |
174 FX_BOOL bPrinting, | 174 FX_BOOL bPrinting, |
175 CFX_Matrix* pMatrix, | 175 CFX_Matrix* pMatrix, |
176 FX_BOOL bShowWidget, | 176 FX_BOOL bShowWidget, |
177 CPDF_RenderOptions* pOptions) { | 177 CPDF_RenderOptions* pOptions) { |
178 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN | 178 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN |
179 : ANNOTFLAG_INVISIBLE; | 179 : ANNOTFLAG_INVISIBLE; |
180 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, | 180 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, |
181 pOptions, nullptr); | 181 pOptions, nullptr); |
182 } | 182 } |
OLD | NEW |