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 17 matching lines...) Expand all Loading... |
28 m_pInterForm(pInterForm), | 28 m_pInterForm(pInterForm), |
29 m_nAppAge(0), | 29 m_nAppAge(0), |
30 m_nValueAge(0) { | 30 m_nValueAge(0) { |
31 ASSERT(m_pInterForm); | 31 ASSERT(m_pInterForm); |
32 } | 32 } |
33 | 33 |
34 CPDFSDK_Widget::~CPDFSDK_Widget() {} | 34 CPDFSDK_Widget::~CPDFSDK_Widget() {} |
35 | 35 |
36 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( | 36 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( |
37 CPDF_Annot::AppearanceMode mode) { | 37 CPDF_Annot::AppearanceMode mode) { |
38 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); | 38 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
39 if (!pAP) | 39 if (!pAP) |
40 return FALSE; | 40 return FALSE; |
41 | 41 |
42 // Choose the right sub-ap | 42 // Choose the right sub-ap |
43 const FX_CHAR* ap_entry = "N"; | 43 const FX_CHAR* ap_entry = "N"; |
44 if (mode == CPDF_Annot::Down) | 44 if (mode == CPDF_Annot::Down) |
45 ap_entry = "D"; | 45 ap_entry = "D"; |
46 else if (mode == CPDF_Annot::Rollover) | 46 else if (mode == CPDF_Annot::Rollover) |
47 ap_entry = "R"; | 47 ap_entry = "R"; |
48 if (!pAP->KeyExist(ap_entry)) | 48 if (!pAP->KeyExist(ap_entry)) |
49 ap_entry = "N"; | 49 ap_entry = "N"; |
50 | 50 |
51 // Get the AP stream or subdirectory | 51 // Get the AP stream or subdirectory |
52 CPDF_Object* psub = pAP->GetElementValue(ap_entry); | 52 CPDF_Object* psub = pAP->GetElementValue(ap_entry); |
53 if (!psub) | 53 if (!psub) |
54 return FALSE; | 54 return FALSE; |
55 | 55 |
56 int nFieldType = GetFieldType(); | 56 int nFieldType = GetFieldType(); |
57 switch (nFieldType) { | 57 switch (nFieldType) { |
58 case FIELDTYPE_PUSHBUTTON: | 58 case FIELDTYPE_PUSHBUTTON: |
59 case FIELDTYPE_COMBOBOX: | 59 case FIELDTYPE_COMBOBOX: |
60 case FIELDTYPE_LISTBOX: | 60 case FIELDTYPE_LISTBOX: |
61 case FIELDTYPE_TEXTFIELD: | 61 case FIELDTYPE_TEXTFIELD: |
62 case FIELDTYPE_SIGNATURE: | 62 case FIELDTYPE_SIGNATURE: |
63 return psub->IsStream(); | 63 return psub->IsStream(); |
64 case FIELDTYPE_CHECKBOX: | 64 case FIELDTYPE_CHECKBOX: |
65 case FIELDTYPE_RADIOBUTTON: | 65 case FIELDTYPE_RADIOBUTTON: |
66 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { | 66 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
67 return pSubDict->GetStream(GetAppState()) != NULL; | 67 return pSubDict->GetStreamBy(GetAppState()) != NULL; |
68 } | 68 } |
69 return FALSE; | 69 return FALSE; |
70 } | 70 } |
71 return TRUE; | 71 return TRUE; |
72 } | 72 } |
73 | 73 |
74 int CPDFSDK_Widget::GetFieldType() const { | 74 int CPDFSDK_Widget::GetFieldType() const { |
75 return GetFormField()->GetFieldType(); | 75 return GetFormField()->GetFieldType(); |
76 } | 76 } |
77 | 77 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 } | 465 } |
466 if (pControl->HasMKEntry("RI")) { | 466 if (pControl->HasMKEntry("RI")) { |
467 pRolloverIcon = pControl->GetRolloverIcon(); | 467 pRolloverIcon = pControl->GetRolloverIcon(); |
468 } | 468 } |
469 if (pControl->HasMKEntry("IX")) { | 469 if (pControl->HasMKEntry("IX")) { |
470 pDownIcon = pControl->GetDownIcon(); | 470 pDownIcon = pControl->GetDownIcon(); |
471 } | 471 } |
472 | 472 |
473 if (pNormalIcon) { | 473 if (pNormalIcon) { |
474 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { | 474 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
475 if (pImageDict->GetString("Name").IsEmpty()) | 475 if (pImageDict->GetStringBy("Name").IsEmpty()) |
476 pImageDict->SetAtString("Name", "ImgA"); | 476 pImageDict->SetAtString("Name", "ImgA"); |
477 } | 477 } |
478 } | 478 } |
479 | 479 |
480 if (pRolloverIcon) { | 480 if (pRolloverIcon) { |
481 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { | 481 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
482 if (pImageDict->GetString("Name").IsEmpty()) | 482 if (pImageDict->GetStringBy("Name").IsEmpty()) |
483 pImageDict->SetAtString("Name", "ImgB"); | 483 pImageDict->SetAtString("Name", "ImgB"); |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 if (pDownIcon) { | 487 if (pDownIcon) { |
488 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { | 488 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
489 if (pImageDict->GetString("Name").IsEmpty()) | 489 if (pImageDict->GetStringBy("Name").IsEmpty()) |
490 pImageDict->SetAtString("Name", "ImgC"); | 490 pImageDict->SetAtString("Name", "ImgC"); |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 CPDF_IconFit iconFit = pControl->GetIconFit(); | 494 CPDF_IconFit iconFit = pControl->GetIconFit(); |
495 | 495 |
496 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); | 496 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
497 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); | 497 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
498 | 498 |
499 CBA_FontMap font_map(this, pEnv->GetSysHandler()); | 499 CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); | 1310 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
1311 | 1311 |
1312 return crFill; | 1312 return crFill; |
1313 } | 1313 } |
1314 | 1314 |
1315 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, | 1315 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
1316 CPDF_Stream* pImage) { | 1316 CPDF_Stream* pImage) { |
1317 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); | 1317 CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
1318 ASSERT(pDoc); | 1318 ASSERT(pDoc); |
1319 | 1319 |
1320 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP"); | 1320 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
1321 CPDF_Stream* pStream = pAPDict->GetStream(sAPType); | 1321 CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType); |
1322 CPDF_Dictionary* pStreamDict = pStream->GetDict(); | 1322 CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
1323 CFX_ByteString sImageAlias = "IMG"; | 1323 CFX_ByteString sImageAlias = "IMG"; |
1324 | 1324 |
1325 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { | 1325 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
1326 sImageAlias = pImageDict->GetString("Name"); | 1326 sImageAlias = pImageDict->GetStringBy("Name"); |
1327 if (sImageAlias.IsEmpty()) | 1327 if (sImageAlias.IsEmpty()) |
1328 sImageAlias = "IMG"; | 1328 sImageAlias = "IMG"; |
1329 } | 1329 } |
1330 | 1330 |
1331 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); | 1331 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
1332 if (!pStreamResList) { | 1332 if (!pStreamResList) { |
1333 pStreamResList = new CPDF_Dictionary(); | 1333 pStreamResList = new CPDF_Dictionary(); |
1334 pStreamDict->SetAt("Resources", pStreamResList); | 1334 pStreamDict->SetAt("Resources", pStreamResList); |
1335 } | 1335 } |
1336 | 1336 |
1337 if (pStreamResList) { | 1337 if (pStreamResList) { |
1338 CPDF_Dictionary* pXObject = new CPDF_Dictionary; | 1338 CPDF_Dictionary* pXObject = new CPDF_Dictionary; |
1339 pXObject->SetAtReference(sImageAlias, pDoc, pImage); | 1339 pXObject->SetAtReference(sImageAlias, pDoc, pImage); |
1340 pStreamResList->SetAt("XObject", pXObject); | 1340 pStreamResList->SetAt("XObject", pXObject); |
1341 } | 1341 } |
1342 } | 1342 } |
1343 | 1343 |
1344 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { | 1344 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
1345 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) { | 1345 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) { |
1346 pAPDict->RemoveAt(sAPType); | 1346 pAPDict->RemoveAt(sAPType); |
1347 } | 1347 } |
1348 } | 1348 } |
1349 | 1349 |
1350 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, | 1350 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
1351 PDFSDK_FieldAction& data, | 1351 PDFSDK_FieldAction& data, |
1352 CPDFSDK_PageView* pPageView) { | 1352 CPDFSDK_PageView* pPageView) { |
1353 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); | 1353 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
1354 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); | 1354 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
1355 CPDF_Action action = GetAAction(type); | 1355 CPDF_Action action = GetAAction(type); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 if (it != m_Map.end()) | 1465 if (it != m_Map.end()) |
1466 pWidget = it->second; | 1466 pWidget = it->second; |
1467 | 1467 |
1468 if (pWidget) | 1468 if (pWidget) |
1469 return pWidget; | 1469 return pWidget; |
1470 | 1470 |
1471 CPDF_Dictionary* pControlDict = pControl->GetWidget(); | 1471 CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
1472 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); | 1472 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
1473 CPDFSDK_PageView* pPage = nullptr; | 1473 CPDFSDK_PageView* pPage = nullptr; |
1474 | 1474 |
1475 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) { | 1475 if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
1476 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); | 1476 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
1477 if (nPageIndex >= 0) { | 1477 if (nPageIndex >= 0) { |
1478 pPage = m_pDocument->GetPageView(nPageIndex); | 1478 pPage = m_pDocument->GetPageView(nPageIndex); |
1479 } | 1479 } |
1480 } | 1480 } |
1481 | 1481 |
1482 if (!pPage) { | 1482 if (!pPage) { |
1483 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); | 1483 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
1484 if (nPageIndex >= 0) { | 1484 if (nPageIndex >= 0) { |
1485 pPage = m_pDocument->GetPageView(nPageIndex); | 1485 pPage = m_pDocument->GetPageView(nPageIndex); |
(...skipping 27 matching lines...) Expand all Loading... |
1513 } | 1513 } |
1514 } | 1514 } |
1515 | 1515 |
1516 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( | 1516 int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
1517 CPDF_Document* pDocument, | 1517 CPDF_Document* pDocument, |
1518 CPDF_Dictionary* pAnnotDict) const { | 1518 CPDF_Dictionary* pAnnotDict) const { |
1519 ASSERT(pAnnotDict); | 1519 ASSERT(pAnnotDict); |
1520 | 1520 |
1521 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { | 1521 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { |
1522 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { | 1522 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { |
1523 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots")) { | 1523 if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) { |
1524 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { | 1524 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { |
1525 CPDF_Object* pDict = pAnnots->GetElementValue(j); | 1525 CPDF_Object* pDict = pAnnots->GetElementValue(j); |
1526 if (pAnnotDict == pDict) { | 1526 if (pAnnotDict == pDict) { |
1527 return i; | 1527 return i; |
1528 } | 1528 } |
1529 } | 1529 } |
1530 } | 1530 } |
1531 } | 1531 } |
1532 } | 1532 } |
1533 | 1533 |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 | 1805 |
1806 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, | 1806 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
1807 CFX_WideString csTxtFile) { | 1807 CFX_WideString csTxtFile) { |
1808 return TRUE; | 1808 return TRUE; |
1809 } | 1809 } |
1810 | 1810 |
1811 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, | 1811 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
1812 FX_STRSIZE& nBufSize) { | 1812 FX_STRSIZE& nBufSize) { |
1813 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); | 1813 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
1814 if (pFDF) { | 1814 if (pFDF) { |
1815 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); | 1815 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
1816 if (!pMainDict) | 1816 if (!pMainDict) |
1817 return FALSE; | 1817 return FALSE; |
1818 | 1818 |
1819 // Get fields | 1819 // Get fields |
1820 CPDF_Array* pFields = pMainDict->GetArray("Fields"); | 1820 CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
1821 if (!pFields) | 1821 if (!pFields) |
1822 return FALSE; | 1822 return FALSE; |
1823 | 1823 |
1824 CFX_ByteTextBuf fdfEncodedData; | 1824 CFX_ByteTextBuf fdfEncodedData; |
1825 | 1825 |
1826 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { | 1826 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { |
1827 CPDF_Dictionary* pField = pFields->GetDict(i); | 1827 CPDF_Dictionary* pField = pFields->GetDictAt(i); |
1828 if (!pField) | 1828 if (!pField) |
1829 continue; | 1829 continue; |
1830 CFX_WideString name; | 1830 CFX_WideString name; |
1831 name = pField->GetUnicodeText("T"); | 1831 name = pField->GetUnicodeTextBy("T"); |
1832 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); | 1832 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
1833 CFX_ByteString csBValue = pField->GetString("V"); | 1833 CFX_ByteString csBValue = pField->GetStringBy("V"); |
1834 CFX_WideString csWValue = PDF_DecodeText(csBValue); | 1834 CFX_WideString csWValue = PDF_DecodeText(csBValue); |
1835 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); | 1835 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
1836 | 1836 |
1837 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); | 1837 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
1838 name_b.ReleaseBuffer(); | 1838 name_b.ReleaseBuffer(); |
1839 fdfEncodedData = fdfEncodedData << "="; | 1839 fdfEncodedData = fdfEncodedData << "="; |
1840 fdfEncodedData = fdfEncodedData | 1840 fdfEncodedData = fdfEncodedData |
1841 << csValue_b.GetBuffer(csValue_b.GetLength()); | 1841 << csValue_b.GetBuffer(csValue_b.GetLength()); |
1842 csValue_b.ReleaseBuffer(); | 1842 csValue_b.ReleaseBuffer(); |
1843 if (i != pFields->GetCount() - 1) | 1843 if (i != pFields->GetCount() - 1) |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 } | 2077 } |
2078 | 2078 |
2079 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, | 2079 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, |
2080 const CFX_ByteString& sType, | 2080 const CFX_ByteString& sType, |
2081 const CFX_ByteString& sSubType) | 2081 const CFX_ByteString& sSubType) |
2082 : m_pPageView(pPageView), | 2082 : m_pPageView(pPageView), |
2083 m_sType(sType), | 2083 m_sType(sType), |
2084 m_sSubType(sSubType), | 2084 m_sSubType(sSubType), |
2085 m_nTabs(BAI_STRUCTURE) { | 2085 m_nTabs(BAI_STRUCTURE) { |
2086 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); | 2086 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
2087 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs"); | 2087 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
2088 | 2088 |
2089 if (sTabs == "R") { | 2089 if (sTabs == "R") { |
2090 m_nTabs = BAI_ROW; | 2090 m_nTabs = BAI_ROW; |
2091 } else if (sTabs == "C") { | 2091 } else if (sTabs == "C") { |
2092 m_nTabs = BAI_COLUMN; | 2092 m_nTabs = BAI_COLUMN; |
2093 } else { | 2093 } else { |
2094 m_nTabs = BAI_STRUCTURE; | 2094 m_nTabs = BAI_STRUCTURE; |
2095 } | 2095 } |
2096 | 2096 |
2097 GenerateResults(); | 2097 GenerateResults(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 break; | 2292 break; |
2293 } | 2293 } |
2294 } | 2294 } |
2295 } | 2295 } |
2296 | 2296 |
2297 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { | 2297 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { |
2298 CPDF_Rect rcAnnot; | 2298 CPDF_Rect rcAnnot; |
2299 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 2299 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
2300 return rcAnnot; | 2300 return rcAnnot; |
2301 } | 2301 } |
OLD | NEW |