Chromium Code Reviews| 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 CPDF_Annot* CreatePopupAnnot(CPDF_Annot* pAnnot, CPDF_Document* pDocument) { | |
|
dsinclair
2016/08/24 14:00:20
Can this return a std::unique_ptr<CPDF_Annot> to s
jaepark
2016/08/24 18:37:48
Done.
| |
| 22 CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); | |
| 23 if (!pParentDict) | |
| 24 return nullptr; | |
| 25 | |
| 26 CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; | |
| 27 pAnnotDict->SetAtName("Type", "Annot"); | |
| 28 pAnnotDict->SetAtName("Subtype", "Popup"); | |
| 29 pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); | |
| 30 pAnnotDict->SetAtString("Contents", pParentDict->GetStringBy("Contents")); | |
| 31 | |
| 32 CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); | |
| 33 CFX_FloatRect popupRect(0, 0, 200, 200); | |
|
dsinclair
2016/08/24 14:00:20
Where does 200 come from? Is it spec, or just a nu
jaepark
2016/08/24 18:37:48
This is just a number. This represents the rectang
| |
| 34 popupRect.Translate((rect.left + rect.right) / 2, | |
|
dsinclair
2016/08/24 14:00:20
Why left + right and not left + popupRect.width? i
jaepark
2016/08/24 18:37:48
I wanted to place the popup note in the middle of
| |
| 35 rect.bottom - popupRect.Height()); | |
| 36 | |
| 37 pAnnotDict->SetAtRect("Rect", popupRect); | |
| 38 pAnnotDict->SetAtInteger("F", 0); | |
| 39 | |
| 40 CPDF_Annot* pPopupAnnot = new CPDF_Annot(pAnnotDict, pDocument); | |
| 41 pAnnot->SetPopupAnnot(pPopupAnnot); | |
| 42 return pPopupAnnot; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 19 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) | 47 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) |
| 20 : m_pDocument(pPage->m_pDocument) { | 48 : m_pDocument(pPage->m_pDocument) { |
| 21 if (!pPage->m_pFormDict) | 49 if (!pPage->m_pFormDict) |
| 22 return; | 50 return; |
| 23 | 51 |
| 24 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); | 52 CPDF_Array* pAnnots = pPage->m_pFormDict->GetArrayBy("Annots"); |
| 25 if (!pAnnots) | 53 if (!pAnnots) |
| 26 return; | 54 return; |
| 27 | 55 |
| 28 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); | 56 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); |
| 29 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 57 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 30 FX_BOOL bRegenerateAP = | 58 FX_BOOL bRegenerateAP = |
| 31 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); | 59 pAcroForm && pAcroForm->GetBooleanBy("NeedAppearances"); |
| 32 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { | 60 for (size_t i = 0; i < pAnnots->GetCount(); ++i) { |
| 33 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); | 61 CPDF_Dictionary* pDict = ToDictionary(pAnnots->GetDirectObjectAt(i)); |
| 34 if (!pDict) | 62 if (!pDict) |
| 35 continue; | 63 continue; |
| 36 | 64 |
| 37 uint32_t dwObjNum = pDict->GetObjNum(); | 65 uint32_t dwObjNum = pDict->GetObjNum(); |
| 38 if (dwObjNum == 0) { | 66 if (dwObjNum == 0) { |
| 39 dwObjNum = m_pDocument->AddIndirectObject(pDict); | 67 dwObjNum = m_pDocument->AddIndirectObject(pDict); |
| 40 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); | 68 CPDF_Reference* pAction = new CPDF_Reference(m_pDocument, dwObjNum); |
| 41 pAnnots->InsertAt(i, pAction); | 69 pAnnots->InsertAt(i, pAction); |
| 42 pAnnots->RemoveAt(i + 1); | 70 pAnnots->RemoveAt(i + 1); |
| 43 pDict = pAnnots->GetDictAt(i); | 71 pDict = pAnnots->GetDictAt(i); |
| 44 } | 72 } |
| 45 m_AnnotList.push_back( | 73 |
| 46 std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); | 74 CPDF_Annot* pAnnot = new CPDF_Annot(pDict, m_pDocument); |
| 75 m_AnnotList.push_back(WrapUnique(pAnnot)); | |
| 76 m_AnnotList.push_back(WrapUnique(CreatePopupAnnot(pAnnot, m_pDocument))); | |
| 77 | |
| 47 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && | 78 if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && |
| 48 CPDF_InterForm::IsUpdateAPEnabled()) { | 79 CPDF_InterForm::IsUpdateAPEnabled()) { |
| 49 FPDF_GenerateAP(m_pDocument, pDict); | 80 FPDF_GenerateAP(m_pDocument, pDict); |
| 50 } | 81 } |
| 51 } | 82 } |
| 52 } | 83 } |
| 53 | 84 |
| 54 CPDF_AnnotList::~CPDF_AnnotList() {} | 85 CPDF_AnnotList::~CPDF_AnnotList() {} |
| 55 | 86 |
| 56 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, | 87 void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 CPDF_RenderContext* pContext, | 157 CPDF_RenderContext* pContext, |
| 127 FX_BOOL bPrinting, | 158 FX_BOOL bPrinting, |
| 128 CFX_Matrix* pMatrix, | 159 CFX_Matrix* pMatrix, |
| 129 FX_BOOL bShowWidget, | 160 FX_BOOL bShowWidget, |
| 130 CPDF_RenderOptions* pOptions) { | 161 CPDF_RenderOptions* pOptions) { |
| 131 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN | 162 uint32_t dwAnnotFlags = bShowWidget ? ANNOTFLAG_INVISIBLE | ANNOTFLAG_HIDDEN |
| 132 : ANNOTFLAG_INVISIBLE; | 163 : ANNOTFLAG_INVISIBLE; |
| 133 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, | 164 DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, dwAnnotFlags, |
| 134 pOptions, nullptr); | 165 pOptions, nullptr); |
| 135 } | 166 } |
| OLD | NEW |