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

Side by Side Diff: core/src/fpdfdoc/doc_formcontrol.cpp

Issue 1436843003: Merge to XFA: Cleanup CPDF_ApSettings and CJS_Parameters. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 1 month 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/src/fpdfdoc/doc_form.cpp ('k') | fpdfsdk/src/javascript/Document.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/include/fpdfdoc/fpdf_doc.h" 7 #include "core/include/fpdfdoc/fpdf_doc.h"
8 8
9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, 9 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField,
10 CPDF_Dictionary* pWidgetDict) { 10 CPDF_Dictionary* pWidgetDict) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); 182 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I");
183 int i = 0; 183 int i = 0;
184 while (g_sHighlightingMode[i][0] != '\0') { 184 while (g_sHighlightingMode[i][0] != '\0') {
185 if (csH.Equal(g_sHighlightingMode[i])) { 185 if (csH.Equal(g_sHighlightingMode[i])) {
186 return (HighlightingMode)i; 186 return (HighlightingMode)i;
187 } 187 }
188 i++; 188 i++;
189 } 189 }
190 return Invert; 190 return Invert;
191 } 191 }
192 CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate) { 192
193 if (!m_pWidgetDict) { 193 CPDF_ApSettings CPDF_FormControl::GetMK() const {
194 return NULL; 194 return CPDF_ApSettings(m_pWidgetDict ? m_pWidgetDict->GetDict(FX_BSTRC("MK"))
195 } 195 : nullptr);
196 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK"));
197 if (!mk && bCreate) {
198 mk = CPDF_Dictionary::Create();
199 if (mk == NULL) {
200 return NULL;
201 }
202 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk);
203 }
204 return mk;
205 } 196 }
206 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) { 197
207 CPDF_ApSettings mk = GetMK(FALSE); 198 bool CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) const {
208 return mk.HasMKEntry(csEntry); 199 return GetMK().HasMKEntry(csEntry);
209 } 200 }
201
210 int CPDF_FormControl::GetRotation() { 202 int CPDF_FormControl::GetRotation() {
211 CPDF_ApSettings mk = GetMK(FALSE); 203 return GetMK().GetRotation();
212 return mk.GetRotation();
213 } 204 }
205
214 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) { 206 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) {
215 CPDF_ApSettings mk = GetMK(FALSE); 207 return GetMK().GetColor(iColorType, csEntry);
216 return mk.GetColor(iColorType, csEntry);
217 } 208 }
209
218 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) { 210 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) {
219 CPDF_ApSettings mk = GetMK(FALSE); 211 return GetMK().GetOriginalColor(index, csEntry);
220 return mk.GetOriginalColor(index, csEntry);
221 } 212 }
213
222 void CPDF_FormControl::GetOriginalColor(int& iColorType, 214 void CPDF_FormControl::GetOriginalColor(int& iColorType,
223 FX_FLOAT fc[4], 215 FX_FLOAT fc[4],
224 CFX_ByteString csEntry) { 216 CFX_ByteString csEntry) {
225 CPDF_ApSettings mk = GetMK(FALSE); 217 GetMK().GetOriginalColor(iColorType, fc, csEntry);
226 mk.GetOriginalColor(iColorType, fc, csEntry);
227 } 218 }
228 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) { 219 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) {
229 CPDF_ApSettings mk = GetMK(FALSE); 220 return GetMK().GetCaption(csEntry);
230 return mk.GetCaption(csEntry);
231 } 221 }
222
232 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) { 223 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) {
233 CPDF_ApSettings mk = GetMK(FALSE); 224 return GetMK().GetIcon(csEntry);
234 return mk.GetIcon(csEntry);
235 } 225 }
226
236 CPDF_IconFit CPDF_FormControl::GetIconFit() { 227 CPDF_IconFit CPDF_FormControl::GetIconFit() {
237 CPDF_ApSettings mk = GetMK(FALSE); 228 return GetMK().GetIconFit();
238 return mk.GetIconFit();
239 } 229 }
230
240 int CPDF_FormControl::GetTextPosition() { 231 int CPDF_FormControl::GetTextPosition() {
241 CPDF_ApSettings mk = GetMK(FALSE); 232 return GetMK().GetTextPosition();
242 return mk.GetTextPosition();
243 } 233 }
234
244 CPDF_Action CPDF_FormControl::GetAction() { 235 CPDF_Action CPDF_FormControl::GetAction() {
245 if (!m_pWidgetDict) { 236 if (!m_pWidgetDict) {
246 return CPDF_Action(); 237 return CPDF_Action();
247 } 238 }
248 if (m_pWidgetDict->KeyExist("A")) { 239 if (m_pWidgetDict->KeyExist("A")) {
249 return CPDF_Action(m_pWidgetDict->GetDict("A")); 240 return CPDF_Action(m_pWidgetDict->GetDict("A"));
250 } 241 }
251 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); 242 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A");
252 if (!pObj) { 243 if (!pObj) {
253 return CPDF_Action(); 244 return CPDF_Action();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 315 }
325 if (m_pWidgetDict->KeyExist("Q")) { 316 if (m_pWidgetDict->KeyExist("Q")) {
326 return m_pWidgetDict->GetInteger("Q", 0); 317 return m_pWidgetDict->GetInteger("Q", 0);
327 } 318 }
328 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); 319 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
329 if (pObj == NULL) { 320 if (pObj == NULL) {
330 return m_pField->m_pForm->GetFormAlignment(); 321 return m_pField->m_pForm->GetFormAlignment();
331 } 322 }
332 return pObj->GetInteger(); 323 return pObj->GetInteger();
333 } 324 }
334 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) { 325
335 if (m_pDict == NULL) { 326 CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
336 return FALSE; 327
337 } 328 bool CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) const {
338 return m_pDict->KeyExist(csEntry); 329 return m_pDict && m_pDict->KeyExist(csEntry);
339 } 330 }
340 int CPDF_ApSettings::GetRotation() { 331
341 if (m_pDict == NULL) { 332 int CPDF_ApSettings::GetRotation() const {
333 return m_pDict ? m_pDict->GetInteger(FX_BSTRC("R")) : 0;
334 }
335
336 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
337 const CFX_ByteStringC& csEntry) const {
338 iColorType = COLORTYPE_TRANSPARENT;
339 if (!m_pDict)
342 return 0; 340 return 0;
343 } 341
344 return m_pDict->GetInteger(FX_BSTRC("R")); 342 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
345 } 343 if (!pEntry)
346 FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
347 const CFX_ByteStringC& csEntry) {
348 iColorType = COLORTYPE_TRANSPARENT;
349 if (m_pDict == NULL) {
350 return 0; 344 return 0;
351 } 345
352 FX_ARGB color = 0; 346 FX_ARGB color = 0;
353 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
354 if (pEntry == NULL) {
355 return color;
356 }
357 FX_DWORD dwCount = pEntry->GetCount(); 347 FX_DWORD dwCount = pEntry->GetCount();
358 if (dwCount == 1) { 348 if (dwCount == 1) {
359 iColorType = COLORTYPE_GRAY; 349 iColorType = COLORTYPE_GRAY;
360 FX_FLOAT g = pEntry->GetNumber(0) * 255; 350 FX_FLOAT g = pEntry->GetNumber(0) * 255;
361 color = ArgbEncode(255, (int)g, (int)g, (int)g); 351 color = ArgbEncode(255, (int)g, (int)g, (int)g);
362 } else if (dwCount == 3) { 352 } else if (dwCount == 3) {
363 iColorType = COLORTYPE_RGB; 353 iColorType = COLORTYPE_RGB;
364 FX_FLOAT r = pEntry->GetNumber(0) * 255; 354 FX_FLOAT r = pEntry->GetNumber(0) * 255;
365 FX_FLOAT g = pEntry->GetNumber(1) * 255; 355 FX_FLOAT g = pEntry->GetNumber(1) * 255;
366 FX_FLOAT b = pEntry->GetNumber(2) * 255; 356 FX_FLOAT b = pEntry->GetNumber(2) * 255;
367 color = ArgbEncode(255, (int)r, (int)g, (int)b); 357 color = ArgbEncode(255, (int)r, (int)g, (int)b);
368 } else if (dwCount == 4) { 358 } else if (dwCount == 4) {
369 iColorType = COLORTYPE_CMYK; 359 iColorType = COLORTYPE_CMYK;
370 FX_FLOAT c = pEntry->GetNumber(0); 360 FX_FLOAT c = pEntry->GetNumber(0);
371 FX_FLOAT m = pEntry->GetNumber(1); 361 FX_FLOAT m = pEntry->GetNumber(1);
372 FX_FLOAT y = pEntry->GetNumber(2); 362 FX_FLOAT y = pEntry->GetNumber(2);
373 FX_FLOAT k = pEntry->GetNumber(3); 363 FX_FLOAT k = pEntry->GetNumber(3);
374 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k); 364 FX_FLOAT r = 1.0f - FX_MIN(1.0f, c + k);
375 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k); 365 FX_FLOAT g = 1.0f - FX_MIN(1.0f, m + k);
376 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k); 366 FX_FLOAT b = 1.0f - FX_MIN(1.0f, y + k);
377 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255)); 367 color = ArgbEncode(255, (int)(r * 255), (int)(g * 255), (int)(b * 255));
378 } 368 }
379 return color; 369 return color;
380 } 370 }
381 FX_FLOAT CPDF_ApSettings::GetOriginalColor(int index, 371
382 const CFX_ByteStringC& csEntry) { 372 FX_FLOAT CPDF_ApSettings::GetOriginalColor(
383 if (m_pDict == NULL) { 373 int index,
374 const CFX_ByteStringC& csEntry) const {
375 if (!m_pDict)
384 return 0; 376 return 0;
385 } 377
386 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); 378 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
387 if (pEntry != NULL) { 379 return pEntry ? pEntry->GetNumber(index) : 0;
388 return pEntry->GetNumber(index);
389 }
390 return 0;
391 } 380 }
381
392 void CPDF_ApSettings::GetOriginalColor(int& iColorType, 382 void CPDF_ApSettings::GetOriginalColor(int& iColorType,
393 FX_FLOAT fc[4], 383 FX_FLOAT fc[4],
394 const CFX_ByteStringC& csEntry) { 384 const CFX_ByteStringC& csEntry) const {
395 iColorType = COLORTYPE_TRANSPARENT; 385 iColorType = COLORTYPE_TRANSPARENT;
396 for (int i = 0; i < 4; i++) { 386 for (int i = 0; i < 4; i++) {
397 fc[i] = 0; 387 fc[i] = 0;
398 } 388 }
399 if (m_pDict == NULL) { 389 if (m_pDict == NULL) {
400 return; 390 return;
401 } 391 }
402 CPDF_Array* pEntry = m_pDict->GetArray(csEntry); 392 CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
403 if (pEntry == NULL) { 393 if (pEntry == NULL) {
404 return; 394 return;
405 } 395 }
406 FX_DWORD dwCount = pEntry->GetCount(); 396 FX_DWORD dwCount = pEntry->GetCount();
407 if (dwCount == 1) { 397 if (dwCount == 1) {
408 iColorType = COLORTYPE_GRAY; 398 iColorType = COLORTYPE_GRAY;
409 fc[0] = pEntry->GetNumber(0); 399 fc[0] = pEntry->GetNumber(0);
410 } else if (dwCount == 3) { 400 } else if (dwCount == 3) {
411 iColorType = COLORTYPE_RGB; 401 iColorType = COLORTYPE_RGB;
412 fc[0] = pEntry->GetNumber(0); 402 fc[0] = pEntry->GetNumber(0);
413 fc[1] = pEntry->GetNumber(1); 403 fc[1] = pEntry->GetNumber(1);
414 fc[2] = pEntry->GetNumber(2); 404 fc[2] = pEntry->GetNumber(2);
415 } else if (dwCount == 4) { 405 } else if (dwCount == 4) {
416 iColorType = COLORTYPE_CMYK; 406 iColorType = COLORTYPE_CMYK;
417 fc[0] = pEntry->GetNumber(0); 407 fc[0] = pEntry->GetNumber(0);
418 fc[1] = pEntry->GetNumber(1); 408 fc[1] = pEntry->GetNumber(1);
419 fc[2] = pEntry->GetNumber(2); 409 fc[2] = pEntry->GetNumber(2);
420 fc[3] = pEntry->GetNumber(3); 410 fc[3] = pEntry->GetNumber(3);
421 } 411 }
422 } 412 }
423 CFX_WideString CPDF_ApSettings::GetCaption(const CFX_ByteStringC& csEntry) { 413
424 CFX_WideString csCaption; 414 CFX_WideString CPDF_ApSettings::GetCaption(
425 if (m_pDict == NULL) { 415 const CFX_ByteStringC& csEntry) const {
426 return csCaption; 416 return m_pDict ? m_pDict->GetUnicodeText(csEntry) : CFX_WideString();
427 }
428 return m_pDict->GetUnicodeText(csEntry);
429 } 417 }
430 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) { 418
431 if (m_pDict == NULL) { 419 CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) const {
432 return NULL; 420 return m_pDict ? m_pDict->GetStream(csEntry) : nullptr;
433 }
434 return m_pDict->GetStream(csEntry);
435 } 421 }
436 CPDF_IconFit CPDF_ApSettings::GetIconFit() { 422
437 if (m_pDict == NULL) { 423 CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
438 return NULL; 424 return m_pDict ? m_pDict->GetDict(FX_BSTRC("IF")) : nullptr;
439 }
440 return m_pDict->GetDict(FX_BSTRC("IF"));
441 } 425 }
442 int CPDF_ApSettings::GetTextPosition() { 426
443 if (m_pDict == NULL) { 427 int CPDF_ApSettings::GetTextPosition() const {
444 return TEXTPOS_CAPTION; 428 return m_pDict ? m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION)
445 } 429 : TEXTPOS_CAPTION;
446 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION);
447 } 430 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_form.cpp ('k') | fpdfsdk/src/javascript/Document.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698