7#include "core/fpdfdoc/cpdf_formcontrol.h"
12#include "constants/form_fields.h"
13#include "core/fpdfapi/font/cpdf_font.h"
14#include "core/fpdfapi/page/cpdf_docpagedata.h"
15#include "core/fpdfapi/parser/cpdf_array.h"
16#include "core/fpdfapi/parser/cpdf_dictionary.h"
17#include "core/fpdfapi/parser/cpdf_name.h"
18#include "core/fpdfapi/parser/cpdf_stream.h"
19#include "core/fpdfapi/parser/fpdf_parser_decode.h"
20#include "core/fpdfapi/parser/fpdf_parser_utility.h"
21#include "core/fpdfdoc/cpdf_interactiveform.h"
22#include "third_party/base/check.h"
26constexpr char kHighlightModes[] = {
'N',
'I',
'O',
'P',
'T'};
30 "HighlightingMode mismatch");
32 "HighlightingMode mismatch");
34 "HighlightingMode mismatch");
36 "HighlightingMode mismatch");
38 "HighlightingMode mismatch");
46 DCHECK(m_pWidgetDict);
52 return m_pWidgetDict->GetRectFor(
"Rect");
56 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
57 GetType() == CPDF_FormField::kRadioButton);
58 RetainPtr<
const CPDF_Dictionary> pAP = m_pWidgetDict->GetDictFor(
"AP");
62 RetainPtr<
const CPDF_Dictionary> pN = pAP->GetDictFor(
"N");
67 for (
const auto& it : locker) {
68 if (it.first !=
"Off")
75 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
76 GetType() == CPDF_FormField::kRadioButton);
78 if (ToArray(m_pField->GetFieldAttr(
"Opt")))
79 csOn = ByteString::FormatInteger(m_pField->GetControlIndex(
this));
86 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
87 GetType() == CPDF_FormField::kRadioButton);
89 RetainPtr<
const CPDF_Array> pArray = ToArray(m_pField->GetFieldAttr(
"Opt"));
91 csOn = pArray->GetByteStringAt(m_pField->GetControlIndex(
this));
94 return PDF_DecodeText(csOn.raw_span());
98 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
99 GetType() == CPDF_FormField::kRadioButton);
101 ByteString csAS = m_pWidgetDict->GetByteStringFor(
"AS");
106 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
107 GetType() == CPDF_FormField::kRadioButton);
112 ByteString csDV = pDV->GetString();
114 return (csDV
== csOn);
118 DCHECK(GetType() == CPDF_FormField::kCheckBox ||
119 GetType() == CPDF_FormField::kRadioButton);
120 ByteString csOldAS = m_pWidgetDict->GetByteStringFor(
"AS",
"Off");
121 ByteString csAS =
"Off";
126 m_pWidgetDict->SetNewFor<CPDF_Name>(
"AS", csAS);
131 ByteString csH = m_pWidgetDict->GetByteStringFor(
"H",
"I");
132 for (size_t i = 0; i <
std::size(kHighlightModes); ++i) {
134 if (csH == ByteStringView(kHighlightModes[i]))
141 return CPDF_ApSettings(m_pWidgetDict->GetMutableDictFor(
"MK"));
153 const ByteString& csEntry) {
158 const ByteString& csEntry) {
183 if (m_pWidgetDict->KeyExist(pdfium::form_fields::kDA)) {
184 return CPDF_DefaultAppearance(
185 m_pWidgetDict->GetByteStringFor(pdfium::form_fields::kDA));
188 m_pField->GetFieldAttr(pdfium::form_fields::kDA);
192 return m_pForm->GetDefaultAppearance();
198 return absl::nullopt;
200 return WideString
::FromDefANSI(pFont->GetBaseFontName().AsStringView()
);
206 absl::optional<ByteString> csFontNameTag = cDA.GetFont(&fFontSize);
207 if (!csFontNameTag.has_value() || csFontNameTag->IsEmpty())
210 RetainPtr<CPDF_Dictionary> pDRDict = ToDictionary(
211 CPDF_FormField::GetMutableFieldAttrForDict(m_pWidgetDict.Get(),
"DR"));
213 RetainPtr<CPDF_Dictionary> pFonts = pDRDict->GetMutableDictFor(
"Font");
214 if (ValidateFontResourceDict(pFonts.Get())) {
216 pFonts->GetMutableDictFor(csFontNameTag.value());
219 m_pForm->GetFontForElement(std::move(pElement));
229 RetainPtr<CPDF_Dictionary> pPageDict = m_pWidgetDict->GetMutableDictFor(
"P");
230 RetainPtr<CPDF_Dictionary> pDict = ToDictionary(
231 CPDF_FormField::GetMutableFieldAttrForDict(pPageDict.Get(),
"Resources"));
235 RetainPtr<CPDF_Dictionary> pFonts = pDict->GetMutableDictFor(
"Font");
236 if (!ValidateFontResourceDict(pFonts.Get()))
240 pFonts->GetMutableDictFor(csFontNameTag.value());
244 return m_pForm->GetFontForElement(std::move(pElement));
248 if (m_pWidgetDict->KeyExist(pdfium::form_fields::kQ))
249 return m_pWidgetDict->GetIntegerFor(pdfium::form_fields::kQ, 0);
252 m_pField->GetFieldAttr(pdfium::form_fields::kQ);
254 return pObj->GetInteger();
256 return m_pForm->GetFormAlignment();
CFX_Color GetOriginalColor(const ByteString &csEntry) const
bool HasMKEntry(const ByteString &csEntry) const
RetainPtr< CPDF_Stream > GetIcon(const ByteString &csEntry) const
CPDF_IconFit GetIconFit() const
WideString GetCaption(const ByteString &csEntry) const
float GetOriginalColorComponent(int index, const ByteString &csEntry) const
CFX_Color::TypeAndARGB GetColorARGB(const ByteString &csEntry) const
int GetTextPosition() const
bool operator==(const ByteString &other) const
ByteString & operator=(const char *str)
ByteString & operator=(ByteString &&that) noexcept
static WideString FromDefANSI(ByteStringView str)