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