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

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

Issue 1417893003: Add type cast definitions for CPDF_Array. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 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/src/fpdfdoc/doc_formcontrol.cpp ('k') | core/src/fpdfdoc/doc_link.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 "../../include/fpdfdoc/fpdf_doc.h" 7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 #include "doc_utils.h" 8 #include "doc_utils.h"
9 9
10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) { 10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField* pField) {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 if (pValue == NULL) { 301 if (pValue == NULL) {
302 return CFX_WideString(); 302 return CFX_WideString();
303 } 303 }
304 } 304 }
305 switch (pValue->GetType()) { 305 switch (pValue->GetType()) {
306 case PDFOBJ_STRING: 306 case PDFOBJ_STRING:
307 case PDFOBJ_STREAM: 307 case PDFOBJ_STREAM:
308 return pValue->GetUnicodeText(); 308 return pValue->GetUnicodeText();
309 case PDFOBJ_ARRAY: 309 case PDFOBJ_ARRAY:
310 pValue = ((CPDF_Array*)pValue)->GetElementValue(0); 310 pValue = pValue->AsArray()->GetElementValue(0);
311 if (pValue) { 311 if (pValue)
312 return pValue->GetUnicodeText(); 312 return pValue->GetUnicodeText();
313 }
314 break; 313 break;
315 } 314 }
316 return CFX_WideString(); 315 return CFX_WideString();
317 } 316 }
318 CFX_WideString CPDF_FormField::GetValue() { 317 CFX_WideString CPDF_FormField::GetValue() {
319 return GetValue(FALSE); 318 return GetValue(FALSE);
320 } 319 }
321 CFX_WideString CPDF_FormField::GetDefaultValue() { 320 CFX_WideString CPDF_FormField::GetDefaultValue() {
322 return GetValue(TRUE); 321 return GetValue(TRUE);
323 } 322 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 if (pWidgetDict->KeyExist("MaxLen")) { 411 if (pWidgetDict->KeyExist("MaxLen")) {
413 return pWidgetDict->GetInteger("MaxLen"); 412 return pWidgetDict->GetInteger("MaxLen");
414 } 413 }
415 } 414 }
416 return 0; 415 return 0;
417 } 416 }
418 return pObj->GetInteger(); 417 return pObj->GetInteger();
419 } 418 }
420 int CPDF_FormField::CountSelectedItems() { 419 int CPDF_FormField::CountSelectedItems() {
421 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 420 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
422 if (pValue == NULL) { 421 if (!pValue) {
423 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 422 pValue = FPDF_GetFieldAttr(m_pDict, "I");
424 if (pValue == NULL) { 423 if (!pValue)
425 return 0; 424 return 0;
426 }
427 } 425 }
428 426
429 if (pValue->IsString() || pValue->IsNumber()) 427 if (pValue->IsString() || pValue->IsNumber())
430 return pValue->GetString().IsEmpty() ? 0 : 1; 428 return pValue->GetString().IsEmpty() ? 0 : 1;
431 429 if (CPDF_Array* pArray = pValue->AsArray())
432 if (pValue->GetType() != PDFOBJ_ARRAY) { 430 return pArray->GetCount();
433 return 0; 431 return 0;
434 }
435 return ((CPDF_Array*)pValue)->GetCount();
436 } 432 }
437 int CPDF_FormField::GetSelectedIndex(int index) { 433 int CPDF_FormField::GetSelectedIndex(int index) {
438 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 434 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
439 if (pValue == NULL) { 435 if (!pValue) {
440 pValue = FPDF_GetFieldAttr(m_pDict, "I"); 436 pValue = FPDF_GetFieldAttr(m_pDict, "I");
441 if (pValue == NULL) { 437 if (!pValue)
442 return -1; 438 return -1;
443 }
444 } 439 }
445 if (pValue->IsNumber()) 440 if (pValue->IsNumber())
446 return pValue->GetInteger(); 441 return pValue->GetInteger();
447 442
448 CFX_WideString sel_value; 443 CFX_WideString sel_value;
449 if (pValue->IsString()) { 444 if (pValue->IsString()) {
450 if (index != 0) 445 if (index != 0)
451 return -1; 446 return -1;
452
453 sel_value = pValue->GetUnicodeText(); 447 sel_value = pValue->GetUnicodeText();
454 } else { 448 } else {
455 if (pValue->GetType() != PDFOBJ_ARRAY) { 449 CPDF_Array* pArray = pValue->AsArray();
450 if (!pArray || index < 0)
456 return -1; 451 return -1;
457 } 452
458 if (index < 0) { 453 CPDF_Object* elementValue = pArray->GetElementValue(index);
459 return -1;
460 }
461 CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
462 sel_value = 454 sel_value =
463 elementValue ? elementValue->GetUnicodeText() : CFX_WideString(); 455 elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
464 } 456 }
465 if (index < CountSelectedOptions()) { 457 if (index < CountSelectedOptions()) {
466 int iOptIndex = GetSelectedOptionIndex(index); 458 int iOptIndex = GetSelectedOptionIndex(index);
467 CFX_WideString csOpt = GetOptionValue(iOptIndex); 459 CFX_WideString csOpt = GetOptionValue(iOptIndex);
468 if (csOpt == sel_value) { 460 if (csOpt == sel_value) {
469 return iOptIndex; 461 return iOptIndex;
470 } 462 }
471 } 463 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 522
531 if (pValue->IsString()) 523 if (pValue->IsString())
532 return pValue->GetUnicodeText() == opt_value; 524 return pValue->GetUnicodeText() == opt_value;
533 525
534 if (pValue->IsNumber()) { 526 if (pValue->IsNumber()) {
535 if (pValue->GetString().IsEmpty()) 527 if (pValue->GetString().IsEmpty())
536 return FALSE; 528 return FALSE;
537 return (pValue->GetInteger() == index); 529 return (pValue->GetInteger() == index);
538 } 530 }
539 531
540 if (pValue->GetType() != PDFOBJ_ARRAY) { 532 CPDF_Array* pArray = pValue->AsArray();
533 if (!pArray)
541 return FALSE; 534 return FALSE;
542 } 535
543 CPDF_Array* pArray = (CPDF_Array*)pValue;
544 int iPos = -1; 536 int iPos = -1;
545 for (int j = 0; j < CountSelectedOptions(); j++) { 537 for (int j = 0; j < CountSelectedOptions(); j++) {
546 if (GetSelectedOptionIndex(j) == index) { 538 if (GetSelectedOptionIndex(j) == index) {
547 iPos = j; 539 iPos = j;
548 break; 540 break;
549 } 541 }
550 } 542 }
551 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) 543 for (FX_DWORD i = 0; i < pArray->GetCount(); i++)
552 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && 544 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value &&
553 (int)i == iPos) { 545 (int)i == iPos) {
(...skipping 23 matching lines...) Expand all
577 } 569 }
578 if (!bSelected) { 570 if (!bSelected) {
579 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); 571 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
580 if (pValue != NULL) { 572 if (pValue != NULL) {
581 if (m_Type == ListBox) { 573 if (m_Type == ListBox) {
582 SelectOption(index, FALSE); 574 SelectOption(index, FALSE);
583 if (pValue->IsString()) { 575 if (pValue->IsString()) {
584 if (pValue->GetUnicodeText() == opt_value) { 576 if (pValue->GetUnicodeText() == opt_value) {
585 m_pDict->RemoveAt("V"); 577 m_pDict->RemoveAt("V");
586 } 578 }
587 } else if (pValue->GetType() == PDFOBJ_ARRAY) { 579 } else if (pValue->IsArray()) {
588 CPDF_Array* pArray = CPDF_Array::Create(); 580 CPDF_Array* pArray = CPDF_Array::Create();
589 if (pArray == NULL) {
590 return FALSE;
591 }
592 int iCount = CountOptions(); 581 int iCount = CountOptions();
593 for (int i = 0; i < iCount; i++) { 582 for (int i = 0; i < iCount; i++) {
594 if (i != index) { 583 if (i != index) {
595 if (IsItemSelected(i)) { 584 if (IsItemSelected(i)) {
596 opt_value = GetOptionValue(i); 585 opt_value = GetOptionValue(i);
597 pArray->AddString(PDF_EncodeText(opt_value)); 586 pArray->AddString(PDF_EncodeText(opt_value));
598 } 587 }
599 } 588 }
600 } 589 }
601 if (pArray->GetCount() < 1) { 590 if (pArray->GetCount() < 1) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 685 }
697 if (!m_pForm->m_bGenerateAP) { 686 if (!m_pForm->m_bGenerateAP) {
698 return; 687 return;
699 } 688 }
700 for (int i = 0; i < CountControls(); i++) { 689 for (int i = 0; i < CountControls(); i++) {
701 CPDF_FormControl* pControl = GetControl(i); 690 CPDF_FormControl* pControl = GetControl(i);
702 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict); 691 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict);
703 } 692 }
704 } 693 }
705 int CPDF_FormField::CountOptions() { 694 int CPDF_FormField::CountOptions() {
706 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 695 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
707 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { 696 return pArray ? pArray->GetCount() : 0;
708 return 0;
709 }
710 return ((CPDF_Array*)pValue)->GetCount();
711 } 697 }
712 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) { 698 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index) {
713 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt"); 699 CPDF_Array* pArray = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
714 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) { 700 if (!pArray)
715 return CFX_WideString(); 701 return CFX_WideString();
716 } 702
717 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index); 703 CPDF_Object* pOption = pArray->GetElementValue(index);
718 if (pOption == NULL) { 704 if (!pOption)
719 return CFX_WideString(); 705 return CFX_WideString();
720 } 706 if (CPDF_Array* pOptionArray = pOption->AsArray())
721 if (pOption->GetType() == PDFOBJ_ARRAY) { 707 pOption = pOptionArray->GetElementValue(sub_index);
722 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
723 }
724 708
725 CPDF_String* pString = ToString(pOption); 709 CPDF_String* pString = ToString(pOption);
726 return pString ? pString->GetUnicodeText() : CFX_WideString(); 710 return pString ? pString->GetUnicodeText() : CFX_WideString();
727 } 711 }
728 CFX_WideString CPDF_FormField::GetOptionLabel(int index) { 712 CFX_WideString CPDF_FormField::GetOptionLabel(int index) {
729 return GetOptionText(index, 1); 713 return GetOptionText(index, 1);
730 } 714 }
731 CFX_WideString CPDF_FormField::GetOptionValue(int index) { 715 CFX_WideString CPDF_FormField::GetOptionValue(int index) {
732 return GetOptionText(index, 0); 716 return GetOptionText(index, 0);
733 } 717 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 773 }
790 } else { 774 } else {
791 if (i == iControlIndex) { 775 if (i == iControlIndex) {
792 pCtrl->CheckControl(bChecked); 776 pCtrl->CheckControl(bChecked);
793 } else if (bChecked) { 777 } else if (bChecked) {
794 pCtrl->CheckControl(FALSE); 778 pCtrl->CheckControl(FALSE);
795 } 779 }
796 } 780 }
797 } 781 }
798 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); 782 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
799 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { 783 if (!ToArray(pOpt)) {
800 if (bChecked) { 784 if (bChecked) {
801 m_pDict->SetAtName("V", csBExport); 785 m_pDict->SetAtName("V", csBExport);
802 } else { 786 } else {
803 CFX_ByteString csV; 787 CFX_ByteString csV;
804 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); 788 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
805 if (pV != NULL) { 789 if (pV != NULL) {
806 csV = pV->GetString(); 790 csV = pV->GetString();
807 } 791 }
808 if (csV == csBExport) { 792 if (csV == csBExport) {
809 m_pDict->SetAtName("V", "Off"); 793 m_pDict->SetAtName("V", "Off");
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")) 1035 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font"))
1052 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict( 1036 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(
1053 font_name); 1037 font_name);
1054 1038
1055 if (pFontDict == NULL) { 1039 if (pFontDict == NULL) {
1056 return; 1040 return;
1057 } 1041 }
1058 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict); 1042 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1059 m_FontSize = FX_atof(syntax.GetWord()); 1043 m_FontSize = FX_atof(syntax.GetWord());
1060 } 1044 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_formcontrol.cpp ('k') | core/src/fpdfdoc/doc_link.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698