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

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

Issue 1243883003: Fix else-after-returns throughout pdfium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase, Address comments. Created 5 years, 5 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_basic.cpp ('k') | core/src/fpdfdoc/doc_formcontrol.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 const int nMaxRecursion = 32; 10 const int nMaxRecursion = 32;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 LOGFONTA lf; 347 LOGFONTA lf;
348 } PDF_FONTDATA, FAR* LPDF_FONTDATA; 348 } PDF_FONTDATA, FAR* LPDF_FONTDATA;
349 static int CALLBACK EnumFontFamExProc( ENUMLOGFONTEXA *lpelfe, 349 static int CALLBACK EnumFontFamExProc( ENUMLOGFONTEXA *lpelfe,
350 NEWTEXTMETRICEX *lpntme, 350 NEWTEXTMETRICEX *lpntme,
351 DWORD FontType, 351 DWORD FontType,
352 LPARAM lParam 352 LPARAM lParam
353 ) 353 )
354 { 354 {
355 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@') != NULL) { 355 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@') != NULL) {
356 return 1; 356 return 1;
357 } else {
358 LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
359 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
360 pData->bFind = TRUE;
361 return 0;
362 } 357 }
358 LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
359 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
360 pData->bFind = TRUE;
361 return 0;
363 } 362 }
364 static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) 363 static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf)
365 { 364 {
366 PDF_FONTDATA fd; 365 PDF_FONTDATA fd;
367 memset(&fd, 0, sizeof(PDF_FONTDATA)); 366 memset(&fd, 0, sizeof(PDF_FONTDATA));
368 HDC hDC = ::GetDC(NULL); 367 HDC hDC = ::GetDC(NULL);
369 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd, 0); 368 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd, 0);
370 ::ReleaseDC(NULL, hDC); 369 ::ReleaseDC(NULL, hDC);
371 if (fd.bFind) { 370 if (fd.bFind) {
372 memcpy(&lf, &fd.lf, sizeof(LOGFONTA)); 371 memcpy(&lf, &fd.lf, sizeof(LOGFONTA));
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (pControl == NULL || csNewFieldName.IsEmpty()) { 689 if (pControl == NULL || csNewFieldName.IsEmpty()) {
691 return FALSE; 690 return FALSE;
692 } 691 }
693 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField(); 692 CPDF_FormField* pField = ((CPDF_FormControl*)pControl)->GetField();
694 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, pCo ntrol); 693 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, pCo ntrol);
695 } 694 }
696 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, const CFX_Byte String& name2) 695 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, const CFX_Byte String& name2)
697 { 696 {
698 const FX_CHAR* ptr1 = name1; 697 const FX_CHAR* ptr1 = name1;
699 const FX_CHAR* ptr2 = name2; 698 const FX_CHAR* ptr2 = name2;
700 if (name1.GetLength() != name2.GetLength()) { 699 if (name1.GetLength() == name2.GetLength()) {
701 int i = 0;
702 while (ptr1[i] == ptr2[i]) {
703 i ++;
704 }
705 if (i == name1.GetLength()) {
706 return 2;
707 }
708 if (i == name2.GetLength()) {
709 return 3;
710 }
711 return 0;
712 } else {
713 return name1 == name2 ? 1 : 0; 700 return name1 == name2 ? 1 : 0;
714 } 701 }
702 int i = 0;
703 while (ptr1[i] == ptr2[i]) {
704 i ++;
705 }
706 if (i == name1.GetLength()) {
707 return 2;
708 }
709 if (i == name2.GetLength()) {
710 return 3;
711 }
712 return 0;
715 } 713 }
716 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, const CFX_Wide String& name2) 714 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, const CFX_Wide String& name2)
717 { 715 {
718 const FX_WCHAR* ptr1 = name1.c_str(); 716 const FX_WCHAR* ptr1 = name1.c_str();
719 const FX_WCHAR* ptr2 = name2.c_str(); 717 const FX_WCHAR* ptr2 = name2.c_str();
720 if (name1.GetLength() != name2.GetLength()) { 718 if (name1.GetLength() == name2.GetLength()) {
721 int i = 0;
722 while (ptr1[i] == ptr2[i]) {
723 i ++;
724 }
725 if (i == name1.GetLength()) {
726 return 2;
727 }
728 if (i == name2.GetLength()) {
729 return 3;
730 }
731 return 0;
732 } else {
733 return name1 == name2 ? 1 : 0; 719 return name1 == name2 ? 1 : 0;
734 } 720 }
721 int i = 0;
722 while (ptr1[i] == ptr2[i]) {
723 i ++;
724 }
725 if (i == name1.GetLength()) {
726 return 2;
727 }
728 if (i == name2.GetLength()) {
729 return 3;
730 }
731 return 0;
735 } 732 }
736 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString &csFieldName) 733 FX_DWORD CPDF_InterForm::CountFields(const CFX_WideString &csFieldName)
737 { 734 {
738 if (csFieldName.IsEmpty()) { 735 if (csFieldName.IsEmpty()) {
739 return (FX_DWORD)m_pFieldTree->m_Root.CountFields(); 736 return (FX_DWORD)m_pFieldTree->m_Root.CountFields();
740 } 737 }
741 CFieldTree::_Node *pNode = m_pFieldTree->FindNode(csFieldName); 738 CFieldTree::_Node *pNode = m_pFieldTree->FindNode(csFieldName);
742 if (pNode == NULL) { 739 if (pNode == NULL) {
743 return 0; 740 return 0;
744 } 741 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 return NULL; 890 return NULL;
894 } 891 }
895 CPDF_FormControl* CPDF_InterForm::GetControlByDict(CPDF_Dictionary* pWidgetDict) const 892 CPDF_FormControl* CPDF_InterForm::GetControlByDict(CPDF_Dictionary* pWidgetDict) const
896 { 893 {
897 CPDF_FormControl* pControl = NULL; 894 CPDF_FormControl* pControl = NULL;
898 m_ControlMap.Lookup(pWidgetDict, (void*&)pControl); 895 m_ControlMap.Lookup(pWidgetDict, (void*&)pControl);
899 return pControl; 896 return pControl;
900 } 897 }
901 FX_DWORD CPDF_InterForm::CountInternalFields(const CFX_WideString& csFieldName) const 898 FX_DWORD CPDF_InterForm::CountInternalFields(const CFX_WideString& csFieldName) const
902 { 899 {
903 if (m_pFormDict == NULL) { 900 if (!m_pFormDict) {
904 return 0; 901 return 0;
905 } 902 }
906 CPDF_Array* pArray = m_pFormDict->GetArray("Fields"); 903 CPDF_Array* pArray = m_pFormDict->GetArray("Fields");
907 if (pArray == NULL) { 904 if (!pArray) {
908 return 0; 905 return 0;
909 } 906 }
910 if (csFieldName.IsEmpty()) { 907 if (csFieldName.IsEmpty()) {
911 return pArray->GetCount(); 908 return pArray->GetCount();
912 } else { 909 }
913 int iLength = csFieldName.GetLength(); 910 int iLength = csFieldName.GetLength();
914 int iPos = 0; 911 int iPos = 0;
915 CPDF_Dictionary* pDict = NULL; 912 CPDF_Dictionary* pDict = NULL;
916 while (pArray != NULL) { 913 while (pArray != NULL) {
917 CFX_WideString csSub; 914 CFX_WideString csSub;
918 if (iPos < iLength && csFieldName[iPos] == L'.') { 915 if (iPos < iLength && csFieldName[iPos] == L'.') {
919 iPos ++; 916 iPos ++;
917 }
918 while (iPos < iLength && csFieldName[iPos] != L'.') {
919 csSub += csFieldName[iPos ++];
920 }
921 int iCount = pArray->GetCount();
922 FX_BOOL bFind = FALSE;
923 for (int i = 0; i < iCount; i ++) {
924 pDict = pArray->GetDict(i);
925 if (pDict == NULL) {
926 continue;
920 } 927 }
921 while (iPos < iLength && csFieldName[iPos] != L'.') { 928 CFX_WideString csT = pDict->GetUnicodeText("T");
922 csSub += csFieldName[iPos ++]; 929 if (csT == csSub) {
923 } 930 bFind = TRUE;
924 int iCount = pArray->GetCount();
925 FX_BOOL bFind = FALSE;
926 for (int i = 0; i < iCount; i ++) {
927 pDict = pArray->GetDict(i);
928 if (pDict == NULL) {
929 continue;
930 }
931 CFX_WideString csT = pDict->GetUnicodeText("T");
932 if (csT == csSub) {
933 bFind = TRUE;
934 break;
935 }
936 }
937 if (!bFind) {
938 return 0;
939 }
940 if (iPos >= iLength) {
941 break; 931 break;
942 } 932 }
943 pArray = pDict->GetArray("Kids");
944 } 933 }
945 if (pDict == NULL) { 934 if (!bFind) {
946 return 0; 935 return 0;
947 } else {
948 pArray = pDict->GetArray("Kids");
949 if (pArray == NULL) {
950 return 1;
951 } else {
952 return pArray->GetCount();
953 }
954 } 936 }
937 if (iPos >= iLength) {
938 break;
939 }
940 pArray = pDict->GetArray("Kids");
955 } 941 }
942 if (!pDict) {
943 return 0;
944 }
945 pArray = pDict->GetArray("Kids");
946 return pArray ? pArray->GetCount() : 1;
956 } 947 }
948
957 CPDF_Dictionary* CPDF_InterForm::GetInternalField(FX_DWORD index, const CFX_Wide String& csFieldName) const 949 CPDF_Dictionary* CPDF_InterForm::GetInternalField(FX_DWORD index, const CFX_Wide String& csFieldName) const
958 { 950 {
959 if (m_pFormDict == NULL) { 951 if (!m_pFormDict) {
960 return NULL; 952 return nullptr;
961 } 953 }
962 CPDF_Array* pArray = m_pFormDict->GetArray("Fields"); 954 CPDF_Array* pArray = m_pFormDict->GetArray("Fields");
963 if (pArray == NULL) { 955 if (!pArray) {
964 return 0; 956 return nullptr;
965 } 957 }
966 if (csFieldName.IsEmpty()) { 958 if (csFieldName.IsEmpty()) {
967 return pArray->GetDict(index); 959 return pArray->GetDict(index);
968 } else { 960 }
969 int iLength = csFieldName.GetLength(); 961 int iLength = csFieldName.GetLength();
970 int iPos = 0; 962 int iPos = 0;
971 CPDF_Dictionary* pDict = NULL; 963 CPDF_Dictionary* pDict = NULL;
972 while (pArray != NULL) { 964 while (pArray != NULL) {
973 CFX_WideString csSub; 965 CFX_WideString csSub;
974 if (iPos < iLength && csFieldName[iPos] == L'.') { 966 if (iPos < iLength && csFieldName[iPos] == L'.') {
975 iPos ++; 967 iPos ++;
968 }
969 while (iPos < iLength && csFieldName[iPos] != L'.') {
970 csSub += csFieldName[iPos ++];
971 }
972 int iCount = pArray->GetCount();
973 FX_BOOL bFind = FALSE;
974 for (int i = 0; i < iCount; i ++) {
975 pDict = pArray->GetDict(i);
976 if (pDict == NULL) {
977 continue;
976 } 978 }
977 while (iPos < iLength && csFieldName[iPos] != L'.') { 979 CFX_WideString csT = pDict->GetUnicodeText("T");
978 csSub += csFieldName[iPos ++]; 980 if (csT == csSub) {
979 } 981 bFind = TRUE;
980 int iCount = pArray->GetCount();
981 FX_BOOL bFind = FALSE;
982 for (int i = 0; i < iCount; i ++) {
983 pDict = pArray->GetDict(i);
984 if (pDict == NULL) {
985 continue;
986 }
987 CFX_WideString csT = pDict->GetUnicodeText("T");
988 if (csT == csSub) {
989 bFind = TRUE;
990 break;
991 }
992 }
993 if (!bFind) {
994 return NULL;
995 }
996 if (iPos >= iLength) {
997 break; 982 break;
998 } 983 }
999 pArray = pDict->GetArray("Kids");
1000 } 984 }
1001 if (pDict == NULL) { 985 if (!bFind) {
1002 return NULL; 986 return NULL;
1003 } else {
1004 pArray = pDict->GetArray("Kids");
1005 if (pArray == NULL) {
1006 return pDict;
1007 } else {
1008 return pArray->GetDict(index);
1009 }
1010 } 987 }
988 if (iPos >= iLength) {
989 break;
990 }
991 pArray = pDict->GetArray("Kids");
1011 } 992 }
993 if (!pDict) {
994 return nullptr;
995 }
996 pArray = pDict->GetArray("Kids");
997 return pArray ? pArray->GetDict(index) : pDict;
1012 } 998 }
1013 FX_BOOL CPDF_InterForm::NeedConstructAP() 999 FX_BOOL CPDF_InterForm::NeedConstructAP()
1014 { 1000 {
1015 if (m_pFormDict == NULL) { 1001 if (m_pFormDict == NULL) {
1016 return FALSE; 1002 return FALSE;
1017 } 1003 }
1018 return m_pFormDict->GetBoolean("NeedAppearances"); 1004 return m_pFormDict->GetBoolean("NeedAppearances");
1019 } 1005 }
1020 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP) 1006 void CPDF_InterForm::NeedConstructAP(FX_BOOL bNeedAP)
1021 { 1007 {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 continue; 1618 continue;
1633 } 1619 }
1634 CPDF_FormControl* pControl = NULL; 1620 CPDF_FormControl* pControl = NULL;
1635 if (m_ControlMap.Lookup(pAnnotDict, (void*&)pControl)) { 1621 if (m_ControlMap.Lookup(pAnnotDict, (void*&)pControl)) {
1636 return iNewPage; 1622 return iNewPage;
1637 } 1623 }
1638 } 1624 }
1639 } while (TRUE); 1625 } while (TRUE);
1640 return -1; 1626 return -1;
1641 } 1627 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_basic.cpp ('k') | core/src/fpdfdoc/doc_formcontrol.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698