Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: core/fpdfdoc/cpdf_formcontrol.cpp

Issue 2334323005: Rename dictionary set and get methods (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/cpdf_filespec_unittest.cpp ('k') | core/fpdfdoc/cpdf_formfield.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_formcontrol.h" 7 #include "core/fpdfdoc/include/cpdf_formcontrol.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 17 matching lines...) Expand all
28 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, 28 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
29 CPDF_Dictionary* pWidgetDict) 29 CPDF_Dictionary* pWidgetDict)
30 : m_pField(pField), 30 : m_pField(pField),
31 m_pWidgetDict(pWidgetDict), 31 m_pWidgetDict(pWidgetDict),
32 m_pForm(m_pField->m_pForm) {} 32 m_pForm(m_pField->m_pForm) {}
33 33
34 CFX_ByteString CPDF_FormControl::GetOnStateName() const { 34 CFX_ByteString CPDF_FormControl::GetOnStateName() const {
35 ASSERT(GetType() == CPDF_FormField::CheckBox || 35 ASSERT(GetType() == CPDF_FormField::CheckBox ||
36 GetType() == CPDF_FormField::RadioButton); 36 GetType() == CPDF_FormField::RadioButton);
37 CFX_ByteString csOn; 37 CFX_ByteString csOn;
38 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); 38 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP");
39 if (!pAP) 39 if (!pAP)
40 return csOn; 40 return csOn;
41 41
42 CPDF_Dictionary* pN = pAP->GetDictBy("N"); 42 CPDF_Dictionary* pN = pAP->GetDictFor("N");
43 if (!pN) 43 if (!pN)
44 return csOn; 44 return csOn;
45 45
46 for (const auto& it : *pN) { 46 for (const auto& it : *pN) {
47 if (it.first != "Off") 47 if (it.first != "Off")
48 return it.first; 48 return it.first;
49 } 49 }
50 return CFX_ByteString(); 50 return CFX_ByteString();
51 } 51 }
52 52
53 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) { 53 void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
54 ASSERT(GetType() == CPDF_FormField::CheckBox || 54 ASSERT(GetType() == CPDF_FormField::CheckBox ||
55 GetType() == CPDF_FormField::RadioButton); 55 GetType() == CPDF_FormField::RadioButton);
56 CFX_ByteString csValue = csOn; 56 CFX_ByteString csValue = csOn;
57 if (csValue.IsEmpty()) 57 if (csValue.IsEmpty())
58 csValue = "Yes"; 58 csValue = "Yes";
59 else if (csValue == "Off") 59 else if (csValue == "Off")
60 csValue = "Yes"; 60 csValue = "Yes";
61 61
62 CFX_ByteString csAS = m_pWidgetDict->GetStringBy("AS", "Off"); 62 CFX_ByteString csAS = m_pWidgetDict->GetStringFor("AS", "Off");
63 if (csAS != "Off") 63 if (csAS != "Off")
64 m_pWidgetDict->SetAtName("AS", csValue); 64 m_pWidgetDict->SetNameFor("AS", csValue);
65 65
66 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictBy("AP"); 66 CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP");
67 if (!pAP) 67 if (!pAP)
68 return; 68 return;
69 69
70 for (const auto& it : *pAP) { 70 for (const auto& it : *pAP) {
71 CPDF_Object* pObj1 = it.second; 71 CPDF_Object* pObj1 = it.second;
72 if (!pObj1) 72 if (!pObj1)
73 continue; 73 continue;
74 74
75 CPDF_Object* pObjDirect1 = pObj1->GetDirect(); 75 CPDF_Object* pObjDirect1 = pObj1->GetDirect();
76 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary(); 76 CPDF_Dictionary* pSubDict = pObjDirect1->AsDictionary();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 if (csOn.IsEmpty()) 123 if (csOn.IsEmpty())
124 csOn = "Yes"; 124 csOn = "Yes";
125 return PDF_DecodeText(csOn); 125 return PDF_DecodeText(csOn);
126 } 126 }
127 127
128 bool CPDF_FormControl::IsChecked() const { 128 bool CPDF_FormControl::IsChecked() const {
129 ASSERT(GetType() == CPDF_FormField::CheckBox || 129 ASSERT(GetType() == CPDF_FormField::CheckBox ||
130 GetType() == CPDF_FormField::RadioButton); 130 GetType() == CPDF_FormField::RadioButton);
131 CFX_ByteString csOn = GetOnStateName(); 131 CFX_ByteString csOn = GetOnStateName();
132 CFX_ByteString csAS = m_pWidgetDict->GetStringBy("AS"); 132 CFX_ByteString csAS = m_pWidgetDict->GetStringFor("AS");
133 return csAS == csOn; 133 return csAS == csOn;
134 } 134 }
135 135
136 bool CPDF_FormControl::IsDefaultChecked() const { 136 bool CPDF_FormControl::IsDefaultChecked() const {
137 ASSERT(GetType() == CPDF_FormField::CheckBox || 137 ASSERT(GetType() == CPDF_FormField::CheckBox ||
138 GetType() == CPDF_FormField::RadioButton); 138 GetType() == CPDF_FormField::RadioButton);
139 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); 139 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV");
140 if (!pDV) 140 if (!pDV)
141 return FALSE; 141 return FALSE;
142 142
143 CFX_ByteString csDV = pDV->GetString(); 143 CFX_ByteString csDV = pDV->GetString();
144 CFX_ByteString csOn = GetOnStateName(); 144 CFX_ByteString csOn = GetOnStateName();
145 return (csDV == csOn); 145 return (csDV == csOn);
146 } 146 }
147 147
148 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) { 148 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) {
149 ASSERT(GetType() == CPDF_FormField::CheckBox || 149 ASSERT(GetType() == CPDF_FormField::CheckBox ||
150 GetType() == CPDF_FormField::RadioButton); 150 GetType() == CPDF_FormField::RadioButton);
151 CFX_ByteString csOn = GetOnStateName(); 151 CFX_ByteString csOn = GetOnStateName();
152 CFX_ByteString csOldAS = m_pWidgetDict->GetStringBy("AS", "Off"); 152 CFX_ByteString csOldAS = m_pWidgetDict->GetStringFor("AS", "Off");
153 CFX_ByteString csAS = "Off"; 153 CFX_ByteString csAS = "Off";
154 if (bChecked) 154 if (bChecked)
155 csAS = csOn; 155 csAS = csOn;
156 if (csOldAS == csAS) 156 if (csOldAS == csAS)
157 return; 157 return;
158 m_pWidgetDict->SetAtName("AS", csAS); 158 m_pWidgetDict->SetNameFor("AS", csAS);
159 } 159 }
160 160
161 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, 161 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice,
162 CFX_Matrix* pMatrix, 162 CFX_Matrix* pMatrix,
163 CPDF_Page* pPage, 163 CPDF_Page* pPage,
164 CPDF_Annot::AppearanceMode mode, 164 CPDF_Annot::AppearanceMode mode,
165 const CPDF_RenderOptions* pOptions) { 165 const CPDF_RenderOptions* pOptions) {
166 if (m_pWidgetDict->GetIntegerBy("F") & ANNOTFLAG_HIDDEN) 166 if (m_pWidgetDict->GetIntegerFor("F") & ANNOTFLAG_HIDDEN)
167 return; 167 return;
168 168
169 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); 169 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode);
170 if (!pStream) 170 if (!pStream)
171 return; 171 return;
172 172
173 CFX_FloatRect form_bbox = pStream->GetDict()->GetRectBy("BBox"); 173 CFX_FloatRect form_bbox = pStream->GetDict()->GetRectFor("BBox");
174 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixBy("Matrix"); 174 CFX_Matrix form_matrix = pStream->GetDict()->GetMatrixFor("Matrix");
175 form_matrix.TransformRect(form_bbox); 175 form_matrix.TransformRect(form_bbox);
176 CFX_FloatRect arect = m_pWidgetDict->GetRectBy("Rect"); 176 CFX_FloatRect arect = m_pWidgetDict->GetRectFor("Rect");
177 CFX_Matrix matrix; 177 CFX_Matrix matrix;
178 matrix.MatchRect(arect, form_bbox); 178 matrix.MatchRect(arect, form_bbox);
179 matrix.Concat(*pMatrix); 179 matrix.Concat(*pMatrix);
180 CPDF_Form form(m_pField->m_pForm->m_pDocument, 180 CPDF_Form form(m_pField->m_pForm->m_pDocument,
181 m_pField->m_pForm->m_pFormDict->GetDictBy("DR"), pStream); 181 m_pField->m_pForm->m_pFormDict->GetDictFor("DR"), pStream);
182 form.ParseContent(nullptr, nullptr, nullptr); 182 form.ParseContent(nullptr, nullptr, nullptr);
183 CPDF_RenderContext context(pPage); 183 CPDF_RenderContext context(pPage);
184 context.AppendLayer(&form, &matrix); 184 context.AppendLayer(&form, &matrix);
185 context.Render(pDevice, pOptions, nullptr); 185 context.Render(pDevice, pOptions, nullptr);
186 } 186 }
187 187
188 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() { 188 CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() {
189 if (!m_pWidgetDict) 189 if (!m_pWidgetDict)
190 return Invert; 190 return Invert;
191 191
192 CFX_ByteString csH = m_pWidgetDict->GetStringBy("H", "I"); 192 CFX_ByteString csH = m_pWidgetDict->GetStringFor("H", "I");
193 for (size_t i = 0; i < FX_ArraySize(g_sHighlightingMode); ++i) { 193 for (size_t i = 0; i < FX_ArraySize(g_sHighlightingMode); ++i) {
194 if (csH == g_sHighlightingMode[i]) 194 if (csH == g_sHighlightingMode[i])
195 return static_cast<HighlightingMode>(i); 195 return static_cast<HighlightingMode>(i);
196 } 196 }
197 return Invert; 197 return Invert;
198 } 198 }
199 199
200 CPDF_ApSettings CPDF_FormControl::GetMK() const { 200 CPDF_ApSettings CPDF_FormControl::GetMK() const {
201 return CPDF_ApSettings(m_pWidgetDict ? m_pWidgetDict->GetDictBy("MK") 201 return CPDF_ApSettings(m_pWidgetDict ? m_pWidgetDict->GetDictFor("MK")
202 : nullptr); 202 : nullptr);
203 } 203 }
204 204
205 bool CPDF_FormControl::HasMKEntry(const CFX_ByteString& csEntry) const { 205 bool CPDF_FormControl::HasMKEntry(const CFX_ByteString& csEntry) const {
206 return GetMK().HasMKEntry(csEntry); 206 return GetMK().HasMKEntry(csEntry);
207 } 207 }
208 208
209 int CPDF_FormControl::GetRotation() { 209 int CPDF_FormControl::GetRotation() {
210 return GetMK().GetRotation(); 210 return GetMK().GetRotation();
211 } 211 }
(...skipping 28 matching lines...) Expand all
240 240
241 int CPDF_FormControl::GetTextPosition() { 241 int CPDF_FormControl::GetTextPosition() {
242 return GetMK().GetTextPosition(); 242 return GetMK().GetTextPosition();
243 } 243 }
244 244
245 CPDF_Action CPDF_FormControl::GetAction() { 245 CPDF_Action CPDF_FormControl::GetAction() {
246 if (!m_pWidgetDict) 246 if (!m_pWidgetDict)
247 return CPDF_Action(); 247 return CPDF_Action();
248 248
249 if (m_pWidgetDict->KeyExist("A")) 249 if (m_pWidgetDict->KeyExist("A"))
250 return CPDF_Action(m_pWidgetDict->GetDictBy("A")); 250 return CPDF_Action(m_pWidgetDict->GetDictFor("A"));
251 251
252 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); 252 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A");
253 if (!pObj) 253 if (!pObj)
254 return CPDF_Action(); 254 return CPDF_Action();
255 255
256 return CPDF_Action(pObj->GetDict()); 256 return CPDF_Action(pObj->GetDict());
257 } 257 }
258 258
259 CPDF_AAction CPDF_FormControl::GetAdditionalAction() { 259 CPDF_AAction CPDF_FormControl::GetAdditionalAction() {
260 if (!m_pWidgetDict) 260 if (!m_pWidgetDict)
261 return CPDF_AAction(); 261 return CPDF_AAction();
262 262
263 if (m_pWidgetDict->KeyExist("AA")) 263 if (m_pWidgetDict->KeyExist("AA"))
264 return CPDF_AAction(m_pWidgetDict->GetDictBy("AA")); 264 return CPDF_AAction(m_pWidgetDict->GetDictFor("AA"));
265 return m_pField->GetAdditionalAction(); 265 return m_pField->GetAdditionalAction();
266 } 266 }
267 267
268 CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() { 268 CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() {
269 if (!m_pWidgetDict) 269 if (!m_pWidgetDict)
270 return CPDF_DefaultAppearance(); 270 return CPDF_DefaultAppearance();
271 271
272 if (m_pWidgetDict->KeyExist("DA")) 272 if (m_pWidgetDict->KeyExist("DA"))
273 return CPDF_DefaultAppearance(m_pWidgetDict->GetStringBy("DA")); 273 return CPDF_DefaultAppearance(m_pWidgetDict->GetStringFor("DA"));
274 274
275 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA"); 275 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA");
276 if (pObj) 276 if (pObj)
277 return CPDF_DefaultAppearance(pObj->GetString()); 277 return CPDF_DefaultAppearance(pObj->GetString());
278 return m_pField->m_pForm->GetDefaultAppearance(); 278 return m_pField->m_pForm->GetDefaultAppearance();
279 } 279 }
280 280
281 CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { 281 CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
282 CPDF_DefaultAppearance cDA = GetDefaultAppearance(); 282 CPDF_DefaultAppearance cDA = GetDefaultAppearance();
283 CFX_ByteString csFontNameTag; 283 CFX_ByteString csFontNameTag;
284 FX_FLOAT fFontSize; 284 FX_FLOAT fFontSize;
285 cDA.GetFont(csFontNameTag, fFontSize); 285 cDA.GetFont(csFontNameTag, fFontSize);
286 if (csFontNameTag.IsEmpty()) 286 if (csFontNameTag.IsEmpty())
287 return nullptr; 287 return nullptr;
288 288
289 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR"); 289 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pWidgetDict, "DR");
290 if (CPDF_Dictionary* pDict = ToDictionary(pObj)) { 290 if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
291 CPDF_Dictionary* pFonts = pDict->GetDictBy("Font"); 291 CPDF_Dictionary* pFonts = pDict->GetDictFor("Font");
292 if (pFonts) { 292 if (pFonts) {
293 CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag); 293 CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag);
294 if (pElement) { 294 if (pElement) {
295 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); 295 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
296 if (pFont) 296 if (pFont)
297 return pFont; 297 return pFont;
298 } 298 }
299 } 299 }
300 } 300 }
301 if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag)) 301 if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag))
302 return pFormFont; 302 return pFormFont;
303 303
304 CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDictBy("P"); 304 CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDictFor("P");
305 pObj = FPDF_GetFieldAttr(pPageDict, "Resources"); 305 pObj = FPDF_GetFieldAttr(pPageDict, "Resources");
306 if (CPDF_Dictionary* pDict = ToDictionary(pObj)) { 306 if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
307 CPDF_Dictionary* pFonts = pDict->GetDictBy("Font"); 307 CPDF_Dictionary* pFonts = pDict->GetDictFor("Font");
308 if (pFonts) { 308 if (pFonts) {
309 CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag); 309 CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag);
310 if (pElement) { 310 if (pElement) {
311 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); 311 CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
312 if (pFont) 312 if (pFont)
313 return pFont; 313 return pFont;
314 } 314 }
315 } 315 }
316 } 316 }
317 return nullptr; 317 return nullptr;
318 } 318 }
319 319
320 int CPDF_FormControl::GetControlAlignment() { 320 int CPDF_FormControl::GetControlAlignment() {
321 if (!m_pWidgetDict) 321 if (!m_pWidgetDict)
322 return 0; 322 return 0;
323 if (m_pWidgetDict->KeyExist("Q")) 323 if (m_pWidgetDict->KeyExist("Q"))
324 return m_pWidgetDict->GetIntegerBy("Q", 0); 324 return m_pWidgetDict->GetIntegerFor("Q", 0);
325 325
326 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); 326 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
327 if (pObj) 327 if (pObj)
328 return pObj->GetInteger(); 328 return pObj->GetInteger();
329 return m_pField->m_pForm->GetFormAlignment(); 329 return m_pField->m_pForm->GetFormAlignment();
330 } 330 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_filespec_unittest.cpp ('k') | core/fpdfdoc/cpdf_formfield.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698