7#include "core/fpdfdoc/cpdf_annotlist.h"
13#include "constants/annotation_common.h"
14#include "constants/annotation_flags.h"
15#include "constants/form_fields.h"
16#include "constants/form_flags.h"
17#include "core/fpdfapi/page/cpdf_occontext.h"
18#include "core/fpdfapi/page/cpdf_page.h"
19#include "core/fpdfapi/parser/cpdf_array.h"
20#include "core/fpdfapi/parser/cpdf_dictionary.h"
21#include "core/fpdfapi/parser/cpdf_document.h"
22#include "core/fpdfapi/parser/cpdf_name.h"
23#include "core/fpdfapi/parser/cpdf_number.h"
24#include "core/fpdfapi/parser/cpdf_reference.h"
25#include "core/fpdfapi/parser/cpdf_string.h"
26#include "core/fpdfapi/parser/fpdf_parser_decode.h"
27#include "core/fpdfapi/render/cpdf_renderoptions.h"
28#include "core/fpdfdoc/cpdf_annot.h"
29#include "core/fpdfdoc/cpdf_formfield.h"
30#include "core/fpdfdoc/cpdf_generateap.h"
31#include "core/fpdfdoc/cpdf_interactiveform.h"
32#include "core/fxge/cfx_renderdevice.h"
72std::unique_ptr<CPDF_Annot> CreatePopupAnnot(
CPDF_Document* pDocument,
86 if (PDF_DecodeText(contents.raw_span()).IsEmpty()) {
90 auto pAnnotDict = pDocument->New<CPDF_Dictionary>();
93 pAnnotDict->SetNewFor<CPDF_String>(
126void GenerateAP(
CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
133 CPDF_FormField::GetFieldAttrForDict(pAnnotDict, pdfium::form_fields::kFT);
137 ByteString field_type = pFieldTypeObj->GetString();
145 CPDF_FormField::GetFieldAttrForDict(pAnnotDict, pdfium::form_fields::kFf);
146 uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
162 RetainPtr<
const CPDF_Dictionary> pParentDict =
163 pAnnotDict->GetDictFor(pdfium::form_fields::kParent);
167 pAnnotDict->SetNewFor<CPDF_String>(
176 RetainPtr<CPDF_Array> pAnnots = pPage->GetMutableAnnotsArray();
180 const CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
181 RetainPtr<
const CPDF_Dictionary> pAcroForm = pRoot->GetDictFor(
"AcroForm");
183 pAcroForm && pAcroForm->GetBooleanFor(
"NeedAppearances",
false);
184 for (size_t i = 0; i < pAnnots->size(); ++i) {
186 ToDictionary(pAnnots->GetMutableDirectObjectAt(i));
189 const ByteString subtype =
191 if (subtype
== "Popup") {
196 pAnnots->ConvertToIndirectObjectAt(i, m_pDocument);
197 m_AnnotList.push_back(std::make_unique<CPDF_Annot>(pDict, m_pDocument));
198 if (bRegenerateAP && subtype
== "Widget" &&
201 GenerateAP(m_pDocument, pDict.Get());
205 m_nAnnotCount = m_AnnotList.size();
206 for (size_t i = 0; i < m_nAnnotCount; ++i) {
207 std::unique_ptr<CPDF_Annot> pPopupAnnot =
208 CreatePopupAnnot(m_pDocument, pPage, m_AnnotList[i].get());
210 m_AnnotList.push_back(std::move(pPopupAnnot));
218 size_t nPopupCount = m_AnnotList.size() - m_nAnnotCount;
219 std::vector<std::unique_ptr<CPDF_Annot>> popups(nPopupCount);
220 for (size_t i = 0; i < nPopupCount; ++i)
221 popups[i] = std::move(m_AnnotList[m_nAnnotCount + i]);
226 auto it = std::find_if(m_AnnotList.begin(), m_AnnotList.end(),
227 [pAnnot](
const std::unique_ptr<CPDF_Annot>& annot) {
228 return annot.get() == pAnnot;
230 return it != m_AnnotList.end();
233void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
239 for (
const auto& pAnnot : m_AnnotList) {
240 bool bWidget = pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET;
241 if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
244 uint32_t annot_flags = pAnnot->GetFlags();
245 if (annot_flags & pdfium::annotation_flags::kHidden)
248 if (bPrinting && (annot_flags & pdfium::annotation_flags::kPrint) == 0)
251 if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView))
255 pAnnot->DrawInContext(pPage, pContext, mtMatrix,
256 CPDF_Annot::AppearanceMode::kNormal);
257 }
else if (!pAnnot->DrawAppearance(pPage, pDevice, mtMatrix,
258 CPDF_Annot::AppearanceMode::kNormal)) {
259 pAnnot->DrawBorder(pDevice, &mtMatrix);
270 DisplayPass(pPage, pDevice, pContext, bPrinting, mtUser2Device,
false);
272 DisplayPass(pPage, pDevice, pContext, bPrinting, mtUser2Device,
true);
constexpr CFX_FloatRect(float l, float b, float r, float t)
void Translate(float e, float f)
bool Contains(const CPDF_Annot *pAnnot) const
void DisplayAnnots(CPDF_Page *pPage, CFX_RenderDevice *pDevice, CPDF_RenderContext *pContext, bool bPrinting, const CFX_Matrix &mtUser2Device, bool bShowWidget)
~CPDF_AnnotList() override
CPDF_AnnotList(CPDF_Page *pPage)
Subtype GetSubtype() const
const CPDF_Dictionary * GetAnnotDict() const
void SetPopupAnnot(CPDF_Annot *pAnnot)
bool KeyExist(const ByteString &key) const
ByteString GetByteStringFor(const ByteString &key) const
CFX_FloatRect GetRectFor(const ByteString &key) const
static void GenerateFormAP(CPDF_Document *pDoc, CPDF_Dictionary *pAnnotDict, FormType type)
float GetPageWidth() const override
bool operator==(const char *ptr) const
bool operator!=(const char *ptr) const