diff options
Diffstat (limited to 'core/fpdfdoc/cpdf_annotlist.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_annotlist.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp index e6c93c1d1e..4c569892c2 100644 --- a/core/fpdfdoc/cpdf_annotlist.cpp +++ b/core/fpdfdoc/cpdf_annotlist.cpp @@ -16,6 +16,40 @@ #include "core/fpdfdoc/include/cpdf_occontext.h" #include "core/fxge/include/cfx_renderdevice.h" +namespace { + +std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot, + CPDF_Document* pDocument) { + CPDF_Dictionary* pParentDict = pAnnot->GetAnnotDict(); + if (!pParentDict) + return std::unique_ptr<CPDF_Annot>(); + + CFX_ByteString sContents = pParentDict->GetStringBy("Contents"); + if (sContents.IsEmpty()) + return std::unique_ptr<CPDF_Annot>(); + + CPDF_Dictionary* pAnnotDict = new CPDF_Dictionary; + pAnnotDict->SetAtName("Type", "Annot"); + pAnnotDict->SetAtName("Subtype", "Popup"); + pAnnotDict->SetAtString("T", pParentDict->GetStringBy("T")); + pAnnotDict->SetAtString("Contents", sContents); + + CFX_FloatRect rect = pParentDict->GetRectBy("Rect"); + rect.Normalize(); + CFX_FloatRect popupRect(0, 0, 200, 200); + popupRect.Translate(rect.left, rect.bottom - popupRect.Height()); + + pAnnotDict->SetAtRect("Rect", popupRect); + pAnnotDict->SetAtInteger("F", 0); + + std::unique_ptr<CPDF_Annot> pPopupAnnot( + new CPDF_Annot(pAnnotDict, pDocument)); + pAnnot->SetPopupAnnot(pPopupAnnot.get()); + return pPopupAnnot; +} + +} // namespace + CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) : m_pDocument(pPage->m_pDocument) { if (!pPage->m_pFormDict) @@ -42,6 +76,12 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) pAnnots->RemoveAt(i + 1); pDict = pAnnots->GetDictAt(i); } + + // Skip creating Popup annotation in the PDF document since PDFium provides + // its own Popup annotations. + if (pDict->GetStringBy("Subtype") == "Popup") + continue; + m_AnnotList.push_back( std::unique_ptr<CPDF_Annot>(new CPDF_Annot(pDict, m_pDocument))); if (bRegenerateAP && pDict->GetStringBy("Subtype") == "Widget" && @@ -49,6 +89,14 @@ CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage) FPDF_GenerateAP(m_pDocument, pDict); } } + + size_t nAnnotListSize = m_AnnotList.size(); + for (size_t i = 0; i < nAnnotListSize; ++i) { + std::unique_ptr<CPDF_Annot> pPopupAnnot( + CreatePopupAnnot(m_AnnotList[i].get(), m_pDocument)); + if (pPopupAnnot) + m_AnnotList.push_back(std::move(pPopupAnnot)); + } } CPDF_AnnotList::~CPDF_AnnotList() {} |