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 "fpdfsdk/include/fsdk_baseform.h" | 7 #include "fpdfsdk/include/fsdk_baseform.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 452 |
453 pFormField->SetValue(L"", TRUE); | 453 pFormField->SetValue(L"", TRUE); |
454 } break; | 454 } break; |
455 } | 455 } |
456 } | 456 } |
457 } | 457 } |
458 #endif // PDF_ENABLE_XFA | 458 #endif // PDF_ENABLE_XFA |
459 | 459 |
460 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( | 460 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( |
461 CPDF_Annot::AppearanceMode mode) { | 461 CPDF_Annot::AppearanceMode mode) { |
462 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); | 462 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
463 if (!pAP) | 463 if (!pAP) |
464 return FALSE; | 464 return FALSE; |
465 | 465 |
466 // Choose the right sub-ap | 466 // Choose the right sub-ap |
467 const FX_CHAR* ap_entry = "N"; | 467 const FX_CHAR* ap_entry = "N"; |
468 if (mode == CPDF_Annot::Down) | 468 if (mode == CPDF_Annot::Down) |
469 ap_entry = "D"; | 469 ap_entry = "D"; |
470 else if (mode == CPDF_Annot::Rollover) | 470 else if (mode == CPDF_Annot::Rollover) |
471 ap_entry = "R"; | 471 ap_entry = "R"; |
472 if (!pAP->KeyExist(ap_entry)) | 472 if (!pAP->KeyExist(ap_entry)) |
473 ap_entry = "N"; | 473 ap_entry = "N"; |
474 | 474 |
475 // Get the AP stream or subdirectory | 475 // Get the AP stream or subdirectory |
476 CPDF_Object* psub = pAP->GetElementValue(ap_entry); | 476 CPDF_Object* psub = pAP->GetElementValue(ap_entry); |
477 if (!psub) | 477 if (!psub) |
478 return FALSE; | 478 return FALSE; |
479 | 479 |
480 int nFieldType = GetFieldType(); | 480 int nFieldType = GetFieldType(); |
481 switch (nFieldType) { | 481 switch (nFieldType) { |
482 case FIELDTYPE_PUSHBUTTON: | 482 case FIELDTYPE_PUSHBUTTON: |
483 case FIELDTYPE_COMBOBOX: | 483 case FIELDTYPE_COMBOBOX: |
484 case FIELDTYPE_LISTBOX: | 484 case FIELDTYPE_LISTBOX: |
485 case FIELDTYPE_TEXTFIELD: | 485 case FIELDTYPE_TEXTFIELD: |
486 case FIELDTYPE_SIGNATURE: | 486 case FIELDTYPE_SIGNATURE: |
487 return psub->IsStream(); | 487 return psub->IsStream(); |
488 case FIELDTYPE_CHECKBOX: | 488 case FIELDTYPE_CHECKBOX: |
489 case FIELDTYPE_RADIOBUTTON: | 489 case FIELDTYPE_RADIOBUTTON: |
490 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { | 490 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
491 return pSubDict->GetStream(GetAppState()) != NULL; | 491 return pSubDict->GetStreamBy(GetAppState()) != NULL; |
492 } | 492 } |
493 return FALSE; | 493 return FALSE; |
494 } | 494 } |
495 return TRUE; | 495 return TRUE; |
496 } | 496 } |
497 | 497 |
498 int CPDFSDK_Widget::GetFieldType() const { | 498 int CPDFSDK_Widget::GetFieldType() const { |
499 return GetFormField()->GetFieldType(); | 499 return GetFormField()->GetFieldType(); |
500 } | 500 } |
501 | 501 |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 986 } |
987 if (pControl->HasMKEntry("RI")) { | 987 if (pControl->HasMKEntry("RI")) { |
988 pRolloverIcon = pControl->GetRolloverIcon(); | 988 pRolloverIcon = pControl->GetRolloverIcon(); |
989 } | 989 } |
990 if (pControl->HasMKEntry("IX")) { | 990 if (pControl->HasMKEntry("IX")) { |
991 pDownIcon = pControl->GetDownIcon(); | 991 pDownIcon = pControl->GetDownIcon(); |
992 } | 992 } |
993 | 993 |
994 if (pNormalIcon) { | 994 if (pNormalIcon) { |
995 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { | 995 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
996 if (pImageDict->GetString("Name").IsEmpty()) | 996 if (pImageDict->GetStringBy("Name").IsEmpty()) |
997 pImageDict->SetAtString("Name", "ImgA"); | 997 pImageDict->SetAtString("Name", "ImgA"); |
998 } | 998 } |
999 } | 999 } |
1000 | 1000 |
1001 if (pRolloverIcon) { | 1001 if (pRolloverIcon) { |
1002 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { | 1002 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
1003 if (pImageDict->GetString("Name").IsEmpty()) | 1003 if (pImageDict->GetStringBy("Name").IsEmpty()) |
1004 pImageDict->SetAtString("Name", "ImgB"); | 1004 pImageDict->SetAtString("Name", "ImgB"); |
1005 } | 1005 } |
1006 } | 1006 } |
1007 | 1007 |
1008 if (pDownIcon) { | 1008 if (pDownIcon) { |
1009 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { | 1009 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
1010 if (pImageDict->GetString("Name").IsEmpty()) | 1010 if (pImageDict->GetStringBy("Name").IsEmpty()) |
1011 pImageDict->SetAtString("Name", "ImgC"); | 1011 pImageDict->SetAtString("Name", "ImgC"); |
1012 } | 1012 } |
1013 } | 1013 } |
1014 | 1014 |
1015 CPDF_IconFit iconFit = pControl->GetIconFit(); | 1015 CPDF_IconFit iconFit = pControl->GetIconFit(); |
1016 | 1016 |
1017 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 1017 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
1018 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 1018 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
1019 | 1019 |
1020 CBA_FontMap font_map(this, pEnv->GetSysHandler()); | 1020 CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); | 1839 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
1840 | 1840 |
1841 return crFill; | 1841 return crFill; |
1842 } | 1842 } |
1843 | 1843 |
1844 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, | 1844 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
1845 CPDF_Stream* pImage) { | 1845 CPDF_Stream* pImage) { |
1846 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | 1846 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
1847 ASSERT(pDoc); | 1847 ASSERT(pDoc); |
1848 | 1848 |
1849 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP"); | 1849 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
1850 CPDF_Stream* pStream = pAPDict->GetStream(sAPType); | 1850 CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType); |
1851 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 1851 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
1852 CFX_ByteString sImageAlias = "IMG"; | 1852 CFX_ByteString sImageAlias = "IMG"; |
1853 | 1853 |
1854 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { | 1854 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
1855 sImageAlias = pImageDict->GetString("Name"); | 1855 sImageAlias = pImageDict->GetStringBy("Name"); |
1856 if (sImageAlias.IsEmpty()) | 1856 if (sImageAlias.IsEmpty()) |
1857 sImageAlias = "IMG"; | 1857 sImageAlias = "IMG"; |
1858 } | 1858 } |
1859 | 1859 |
1860 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | 1860 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
1861 if (!pStreamResList) { | 1861 if (!pStreamResList) { |
1862 pStreamResList = new CPDF_Dictionary(); | 1862 pStreamResList = new CPDF_Dictionary(); |
1863 pStreamDict->SetAt("Resources", pStreamResList); | 1863 pStreamDict->SetAt("Resources", pStreamResList); |
1864 } | 1864 } |
1865 | 1865 |
1866 if (pStreamResList) { | 1866 if (pStreamResList) { |
1867 CPDF_Dictionary* pXObject = new CPDF_Dictionary; | 1867 CPDF_Dictionary* pXObject = new CPDF_Dictionary; |
1868 pXObject->SetAtReference(sImageAlias, pDoc, pImage); | 1868 pXObject->SetAtReference(sImageAlias, pDoc, pImage); |
1869 pStreamResList->SetAt("XObject", pXObject); | 1869 pStreamResList->SetAt("XObject", pXObject); |
1870 } | 1870 } |
1871 } | 1871 } |
1872 | 1872 |
1873 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { | 1873 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
1874 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) { | 1874 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) { |
1875 pAPDict->RemoveAt(sAPType); | 1875 pAPDict->RemoveAt(sAPType); |
1876 } | 1876 } |
1877 } | 1877 } |
1878 | 1878 |
1879 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, | 1879 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
1880 PDFSDK_FieldAction& data, | 1880 PDFSDK_FieldAction& data, |
1881 CPDFSDK_PageView* pPageView) { | 1881 CPDFSDK_PageView* pPageView) { |
1882 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); | 1882 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
1883 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); | 1883 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
1884 | 1884 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 if (it != m_Map.end()) | 2071 if (it != m_Map.end()) |
2072 pWidget = it->second; | 2072 pWidget = it->second; |
2073 | 2073 |
2074 if (pWidget) | 2074 if (pWidget) |
2075 return pWidget; | 2075 return pWidget; |
2076 | 2076 |
2077 CPDF_Dictionary* pControlDict = pControl->GetWidget(); | 2077 CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
2078 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 2078 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
2079 CPDFSDK_PageView* pPage = nullptr; | 2079 CPDFSDK_PageView* pPage = nullptr; |
2080 | 2080 |
2081 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) { | 2081 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
2082 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); | 2082 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
2083 if (nPageIndex >= 0) { | 2083 if (nPageIndex >= 0) { |
2084 pPage = m_pDocument->GetPageView(nPageIndex); | 2084 pPage = m_pDocument->GetPageView(nPageIndex); |
2085 } | 2085 } |
2086 } | 2086 } |
2087 | 2087 |
2088 if (!pPage) { | 2088 if (!pPage) { |
2089 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); | 2089 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
2090 if (nPageIndex >= 0) { | 2090 if (nPageIndex >= 0) { |
2091 pPage = m_pDocument->GetPageView(nPageIndex); | 2091 pPage = m_pDocument->GetPageView(nPageIndex); |
(...skipping 27 matching lines...) Expand all Loading... |
2119 } | 2119 } |
2120 } | 2120 } |
2121 | 2121 |
2122 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( | 2122 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
2123 CPDF_Document* pDocument, | 2123 CPDF_Document* pDocument, |
2124 CPDF_Dictionary* pAnnotDict) const { | 2124 CPDF_Dictionary* pAnnotDict) const { |
2125 ASSERT(pAnnotDict); | 2125 ASSERT(pAnnotDict); |
2126 | 2126 |
2127 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { | 2127 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { |
2128 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { | 2128 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { |
2129 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots")) { | 2129 if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) { |
2130 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { | 2130 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { |
2131 CPDF_Object* pDict = pAnnots->GetElementValue(j); | 2131 CPDF_Object* pDict = pAnnots->GetElementValue(j); |
2132 if (pAnnotDict == pDict) { | 2132 if (pAnnotDict == pDict) { |
2133 return i; | 2133 return i; |
2134 } | 2134 } |
2135 } | 2135 } |
2136 } | 2136 } |
2137 } | 2137 } |
2138 } | 2138 } |
2139 | 2139 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 | 2443 |
2444 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, | 2444 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
2445 CFX_WideString csTxtFile) { | 2445 CFX_WideString csTxtFile) { |
2446 return TRUE; | 2446 return TRUE; |
2447 } | 2447 } |
2448 | 2448 |
2449 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, | 2449 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
2450 FX_STRSIZE& nBufSize) { | 2450 FX_STRSIZE& nBufSize) { |
2451 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); | 2451 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
2452 if (pFDF) { | 2452 if (pFDF) { |
2453 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); | 2453 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
2454 if (!pMainDict) | 2454 if (!pMainDict) |
2455 return FALSE; | 2455 return FALSE; |
2456 | 2456 |
2457 // Get fields | 2457 // Get fields |
2458 CPDF_Array* pFields = pMainDict->GetArray("Fields"); | 2458 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
2459 if (!pFields) | 2459 if (!pFields) |
2460 return FALSE; | 2460 return FALSE; |
2461 | 2461 |
2462 CFX_ByteTextBuf fdfEncodedData; | 2462 CFX_ByteTextBuf fdfEncodedData; |
2463 | 2463 |
2464 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { | 2464 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { |
2465 CPDF_Dictionary* pField = pFields->GetDict(i); | 2465 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
2466 if (!pField) | 2466 if (!pField) |
2467 continue; | 2467 continue; |
2468 CFX_WideString name; | 2468 CFX_WideString name; |
2469 name = pField->GetUnicodeText("T"); | 2469 name = pField->GetUnicodeTextBy("T"); |
2470 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); | 2470 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
2471 CFX_ByteString csBValue = pField->GetString("V"); | 2471 CFX_ByteString csBValue = pField->GetStringBy("V"); |
2472 CFX_WideString csWValue = PDF_DecodeText(csBValue); | 2472 CFX_WideString csWValue = PDF_DecodeText(csBValue); |
2473 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); | 2473 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
2474 | 2474 |
2475 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); | 2475 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
2476 name_b.ReleaseBuffer(); | 2476 name_b.ReleaseBuffer(); |
2477 fdfEncodedData = fdfEncodedData << "="; | 2477 fdfEncodedData = fdfEncodedData << "="; |
2478 fdfEncodedData = fdfEncodedData | 2478 fdfEncodedData = fdfEncodedData |
2479 << csValue_b.GetBuffer(csValue_b.GetLength()); | 2479 << csValue_b.GetBuffer(csValue_b.GetLength()); |
2480 csValue_b.ReleaseBuffer(); | 2480 csValue_b.ReleaseBuffer(); |
2481 if (i != pFields->GetCount() - 1) | 2481 if (i != pFields->GetCount() - 1) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 } | 2739 } |
2740 | 2740 |
2741 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, | 2741 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, |
2742 const CFX_ByteString& sType, | 2742 const CFX_ByteString& sType, |
2743 const CFX_ByteString& sSubType) | 2743 const CFX_ByteString& sSubType) |
2744 : m_pPageView(pPageView), | 2744 : m_pPageView(pPageView), |
2745 m_sType(sType), | 2745 m_sType(sType), |
2746 m_sSubType(sSubType), | 2746 m_sSubType(sSubType), |
2747 m_nTabs(BAI_STRUCTURE) { | 2747 m_nTabs(BAI_STRUCTURE) { |
2748 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); | 2748 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
2749 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs"); | 2749 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
2750 | 2750 |
2751 if (sTabs == "R") { | 2751 if (sTabs == "R") { |
2752 m_nTabs = BAI_ROW; | 2752 m_nTabs = BAI_ROW; |
2753 } else if (sTabs == "C") { | 2753 } else if (sTabs == "C") { |
2754 m_nTabs = BAI_COLUMN; | 2754 m_nTabs = BAI_COLUMN; |
2755 } else { | 2755 } else { |
2756 m_nTabs = BAI_STRUCTURE; | 2756 m_nTabs = BAI_STRUCTURE; |
2757 } | 2757 } |
2758 | 2758 |
2759 GenerateResults(); | 2759 GenerateResults(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2954 break; | 2954 break; |
2955 } | 2955 } |
2956 } | 2956 } |
2957 } | 2957 } |
2958 | 2958 |
2959 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { | 2959 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { |
2960 CPDF_Rect rcAnnot; | 2960 CPDF_Rect rcAnnot; |
2961 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2961 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
2962 return rcAnnot; | 2962 return rcAnnot; |
2963 } | 2963 } |
OLD | NEW |