| 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 "Document.h" | 7 #include "Document.h" |
| 8 | 8 |
| 9 #include "../../../third_party/base/numerics/safe_math.h" | 9 #include "../../../third_party/base/numerics/safe_math.h" |
| 10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. | 10 #include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment. |
| (...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 (pValueObj->GetType() == PDFOBJ_NAME)) | 854 (pValueObj->GetType() == PDFOBJ_NAME)) |
| 855 FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), | 855 FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), |
| 856 pValueObj->GetUnicodeText().c_str()); | 856 pValueObj->GetUnicodeText().c_str()); |
| 857 if (pValueObj->GetType() == PDFOBJ_NUMBER) | 857 if (pValueObj->GetType() == PDFOBJ_NUMBER) |
| 858 FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), | 858 FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), |
| 859 (float)pValueObj->GetNumber()); | 859 (float)pValueObj->GetNumber()); |
| 860 if (pValueObj->GetType() == PDFOBJ_BOOLEAN) | 860 if (pValueObj->GetType() == PDFOBJ_BOOLEAN) |
| 861 FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), | 861 FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), |
| 862 (bool)pValueObj->GetInteger()); | 862 (bool)pValueObj->GetInteger()); |
| 863 } | 863 } |
| 864 | |
| 865 vp << pObj; | 864 vp << pObj; |
| 866 return TRUE; | |
| 867 } else { | |
| 868 return TRUE; | |
| 869 } | 865 } |
| 866 return TRUE; |
| 870 } | 867 } |
| 871 | 868 |
| 872 FX_BOOL Document::creationDate(IJS_Context* cc, | 869 FX_BOOL Document::creationDate(IJS_Context* cc, |
| 873 CJS_PropValue& vp, | 870 CJS_PropValue& vp, |
| 874 CFX_WideString& sError) { | 871 CFX_WideString& sError) { |
| 875 CPDF_Dictionary* pDictionary = | 872 CPDF_Dictionary* pDictionary = |
| 876 m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); | 873 m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); |
| 877 if (!pDictionary) | 874 if (!pDictionary) |
| 878 return FALSE; | 875 return FALSE; |
| 879 | 876 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) | 919 if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 923 return FALSE; | 920 return FALSE; |
| 924 | 921 |
| 925 vp >> m_bDelay; | 922 vp >> m_bDelay; |
| 926 if (m_bDelay) { | 923 if (m_bDelay) { |
| 927 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) | 924 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) |
| 928 delete m_DelayData.GetAt(i); | 925 delete m_DelayData.GetAt(i); |
| 929 | 926 |
| 930 m_DelayData.RemoveAll(); | 927 m_DelayData.RemoveAll(); |
| 931 } else { | 928 } else { |
| 929 CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; |
| 932 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | 930 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { |
| 933 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | 931 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { |
| 934 Field::DoDelay(m_pDocument, pData); | 932 DelayDataToProcess.Add(pData); |
| 935 delete m_DelayData.GetAt(i); | 933 m_DelayData.SetAt(i, NULL); |
| 936 } | 934 } |
| 937 } | 935 } |
| 938 m_DelayData.RemoveAll(); | 936 m_DelayData.RemoveAll(); |
| 937 for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { |
| 938 CJS_DelayData* pData = DelayDataToProcess.GetAt(i); |
| 939 Field::DoDelay(m_pDocument, pData); |
| 940 DelayDataToProcess.SetAt(i, NULL); |
| 941 delete pData; |
| 942 } |
| 939 } | 943 } |
| 940 } | 944 } |
| 941 return TRUE; | 945 return TRUE; |
| 942 } | 946 } |
| 943 | 947 |
| 944 FX_BOOL Document::keywords(IJS_Context* cc, | 948 FX_BOOL Document::keywords(IJS_Context* cc, |
| 945 CJS_PropValue& vp, | 949 CJS_PropValue& vp, |
| 946 CFX_WideString& sError) { | 950 CFX_WideString& sError) { |
| 947 CPDF_Dictionary* pDictionary = | 951 CPDF_Dictionary* pDictionary = |
| 948 m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); | 952 m_pDocument->GetDocument()->GetPDFDoc()->GetInfo(); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 if (iIndex >= 0 && iIndex <= m_iLength) { | 1337 if (iIndex >= 0 && iIndex <= m_iLength) { |
| 1334 IconElement* pTemp = m_pHead; | 1338 IconElement* pTemp = m_pHead; |
| 1335 for (int i = 0; i < iIndex; i++) { | 1339 for (int i = 0; i < iIndex; i++) { |
| 1336 pTemp = pTemp->NextIcon; | 1340 pTemp = pTemp->NextIcon; |
| 1337 } | 1341 } |
| 1338 return pTemp; | 1342 return pTemp; |
| 1339 } | 1343 } |
| 1340 return NULL; | 1344 return NULL; |
| 1341 } | 1345 } |
| 1342 | 1346 |
| 1343 void IconTree::DeleteIconElement(CFX_WideString swIconName) { | |
| 1344 IconElement* pTemp = m_pHead; | |
| 1345 int iLoopCount = m_iLength; | |
| 1346 for (int i = 0; i < iLoopCount - 1; i++) { | |
| 1347 if (pTemp == m_pEnd) | |
| 1348 break; | |
| 1349 | |
| 1350 if (m_pHead->IconName == swIconName) { | |
| 1351 m_pHead = m_pHead->NextIcon; | |
| 1352 delete pTemp; | |
| 1353 m_iLength--; | |
| 1354 pTemp = m_pHead; | |
| 1355 } | |
| 1356 if (pTemp->NextIcon->IconName == swIconName) { | |
| 1357 if (pTemp->NextIcon == m_pEnd) { | |
| 1358 m_pEnd = pTemp; | |
| 1359 delete pTemp->NextIcon; | |
| 1360 m_iLength--; | |
| 1361 pTemp->NextIcon = NULL; | |
| 1362 } else { | |
| 1363 IconElement* pElement = pTemp->NextIcon; | |
| 1364 pTemp->NextIcon = pTemp->NextIcon->NextIcon; | |
| 1365 delete pElement; | |
| 1366 m_iLength--; | |
| 1367 pElement = NULL; | |
| 1368 } | |
| 1369 | |
| 1370 continue; | |
| 1371 } | |
| 1372 | |
| 1373 pTemp = pTemp->NextIcon; | |
| 1374 } | |
| 1375 } | |
| 1376 | |
| 1377 FX_BOOL Document::addIcon(IJS_Context* cc, | 1347 FX_BOOL Document::addIcon(IJS_Context* cc, |
| 1378 const CJS_Parameters& params, | 1348 const CJS_Parameters& params, |
| 1379 CJS_Value& vRet, | 1349 CJS_Value& vRet, |
| 1380 CFX_WideString& sError) { | 1350 CFX_WideString& sError) { |
| 1381 CJS_Context* pContext = (CJS_Context*)cc; | 1351 CJS_Context* pContext = (CJS_Context*)cc; |
| 1382 if (params.size() != 2) { | 1352 if (params.size() != 2) { |
| 1383 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1353 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1384 return FALSE; | 1354 return FALSE; |
| 1385 } | 1355 } |
| 1386 CFX_WideString swIconName = params[0].ToCFXWideString(); | 1356 CFX_WideString swIconName = params[0].ToCFXWideString(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 } | 1468 } |
| 1499 } | 1469 } |
| 1500 | 1470 |
| 1501 return FALSE; | 1471 return FALSE; |
| 1502 } | 1472 } |
| 1503 | 1473 |
| 1504 FX_BOOL Document::removeIcon(IJS_Context* cc, | 1474 FX_BOOL Document::removeIcon(IJS_Context* cc, |
| 1505 const CJS_Parameters& params, | 1475 const CJS_Parameters& params, |
| 1506 CJS_Value& vRet, | 1476 CJS_Value& vRet, |
| 1507 CFX_WideString& sError) { | 1477 CFX_WideString& sError) { |
| 1508 CJS_Context* pContext = (CJS_Context*)cc; | 1478 // Unsafe, no supported. |
| 1509 if (params.size() != 1) { | |
| 1510 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
| 1511 return FALSE; | |
| 1512 } | |
| 1513 | |
| 1514 if (!m_pIconTree) | |
| 1515 return FALSE; | |
| 1516 CFX_WideString swIconName = params[0].ToCFXWideString(); | |
| 1517 return TRUE; | 1479 return TRUE; |
| 1518 } | 1480 } |
| 1519 | 1481 |
| 1520 FX_BOOL Document::createDataObject(IJS_Context* cc, | 1482 FX_BOOL Document::createDataObject(IJS_Context* cc, |
| 1521 const CJS_Parameters& params, | 1483 const CJS_Parameters& params, |
| 1522 CJS_Value& vRet, | 1484 CJS_Value& vRet, |
| 1523 CFX_WideString& sError) { | 1485 CFX_WideString& sError) { |
| 1524 // Unsafe, not implemented. | 1486 // Unsafe, not implemented. |
| 1525 return TRUE; | 1487 return TRUE; |
| 1526 } | 1488 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1632 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | 1594 FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
| 1633 const CJS_Parameters& params, | 1595 const CJS_Parameters& params, |
| 1634 CJS_Value& vRet, | 1596 CJS_Value& vRet, |
| 1635 CFX_WideString& sError) { | 1597 CFX_WideString& sError) { |
| 1636 ASSERT(m_pDocument != NULL); | 1598 ASSERT(m_pDocument != NULL); |
| 1637 | 1599 |
| 1638 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) | 1600 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1639 return FALSE; | 1601 return FALSE; |
| 1640 | 1602 |
| 1641 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; | 1603 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; |
| 1604 |
| 1642 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); | 1605 CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc(); |
| 1606 ASSERT(pDocument != NULL); |
| 1607 |
| 1643 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1608 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1644 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1609 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1645 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | 1610 sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1646 return FALSE; | 1611 return FALSE; |
| 1647 } | 1612 } |
| 1648 | 1613 |
| 1649 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1614 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1650 if (!pPageDict) | 1615 if (!pPageDict) |
| 1651 return FALSE; | 1616 return FALSE; |
| 1652 | 1617 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 FX_BOOL Document::zoomType(IJS_Context* cc, | 1746 FX_BOOL Document::zoomType(IJS_Context* cc, |
| 1782 CJS_PropValue& vp, | 1747 CJS_PropValue& vp, |
| 1783 CFX_WideString& sError) { | 1748 CFX_WideString& sError) { |
| 1784 return TRUE; | 1749 return TRUE; |
| 1785 } | 1750 } |
| 1786 | 1751 |
| 1787 FX_BOOL Document::deletePages(IJS_Context* cc, | 1752 FX_BOOL Document::deletePages(IJS_Context* cc, |
| 1788 const CJS_Parameters& params, | 1753 const CJS_Parameters& params, |
| 1789 CJS_Value& vRet, | 1754 CJS_Value& vRet, |
| 1790 CFX_WideString& sError) { | 1755 CFX_WideString& sError) { |
| 1791 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 1756 // Unsafe, no supported. |
| 1792 m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) | |
| 1793 return FALSE; | |
| 1794 | |
| 1795 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1796 v8::Isolate* isolate = pRuntime->GetIsolate(); | |
| 1797 | |
| 1798 int iSize = params.size(); | |
| 1799 int nStart = 0; | |
| 1800 int nEnd = 0; | |
| 1801 if (iSize < 1) { | |
| 1802 } else if (iSize == 1) { | |
| 1803 if (params[0].GetType() == CJS_Value::VT_object) { | |
| 1804 v8::Local<v8::Object> pObj = params[0].ToV8Object(); | |
| 1805 v8::Local<v8::Value> pValue = | |
| 1806 FXJS_GetObjectElement(isolate, pObj, L"nStart"); | |
| 1807 nStart = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt(); | |
| 1808 pValue = FXJS_GetObjectElement(isolate, pObj, L"nEnd"); | |
| 1809 nEnd = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt(); | |
| 1810 } else { | |
| 1811 nStart = params[0].ToInt(); | |
| 1812 } | |
| 1813 } else { | |
| 1814 nStart = params[0].ToInt(); | |
| 1815 nEnd = params[1].ToInt(); | |
| 1816 } | |
| 1817 | |
| 1818 int nTotal = m_pDocument->GetPageCount(); | |
| 1819 if (nStart < 0) | |
| 1820 nStart = 0; | |
| 1821 if (nStart >= nTotal) | |
| 1822 nStart = nTotal - 1; | |
| 1823 | |
| 1824 if (nEnd < 0) | |
| 1825 nEnd = 0; | |
| 1826 if (nEnd >= nTotal) | |
| 1827 nEnd = nTotal - 1; | |
| 1828 | |
| 1829 if (nEnd < nStart) | |
| 1830 nEnd = nStart; | |
| 1831 | |
| 1832 return TRUE; | 1757 return TRUE; |
| 1833 } | 1758 } |
| 1834 | 1759 |
| 1835 FX_BOOL Document::extractPages(IJS_Context* cc, | 1760 FX_BOOL Document::extractPages(IJS_Context* cc, |
| 1836 const CJS_Parameters& params, | 1761 const CJS_Parameters& params, |
| 1837 CJS_Value& vRet, | 1762 CJS_Value& vRet, |
| 1838 CFX_WideString& sError) { | 1763 CFX_WideString& sError) { |
| 1839 // Unsafe, not supported. | 1764 // Unsafe, not supported. |
| 1840 return TRUE; | 1765 return TRUE; |
| 1841 } | 1766 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1864 return TRUE; | 1789 return TRUE; |
| 1865 } | 1790 } |
| 1866 | 1791 |
| 1867 void Document::AddDelayData(CJS_DelayData* pData) { | 1792 void Document::AddDelayData(CJS_DelayData* pData) { |
| 1868 m_DelayData.Add(pData); | 1793 m_DelayData.Add(pData); |
| 1869 } | 1794 } |
| 1870 | 1795 |
| 1871 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | 1796 void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1872 int nControlIndex) { | 1797 int nControlIndex) { |
| 1873 CFX_DWordArray DelArray; | 1798 CFX_DWordArray DelArray; |
| 1799 CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex; |
| 1874 | 1800 |
| 1875 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { | 1801 for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { |
| 1876 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { | 1802 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { |
| 1877 if (pData->sFieldName == sFieldName && | 1803 if (pData->sFieldName == sFieldName && |
| 1878 pData->nControlIndex == nControlIndex) { | 1804 pData->nControlIndex == nControlIndex) { |
| 1879 Field::DoDelay(m_pDocument, pData); | 1805 DelayDataForFieldAndControlIndex.Add(pData); |
| 1880 delete pData; | |
| 1881 m_DelayData.SetAt(i, NULL); | 1806 m_DelayData.SetAt(i, NULL); |
| 1882 DelArray.Add(i); | 1807 DelArray.Add(i); |
| 1883 } | 1808 } |
| 1884 } | 1809 } |
| 1885 } | 1810 } |
| 1886 | 1811 |
| 1887 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1812 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
| 1888 m_DelayData.RemoveAt(DelArray[j]); | 1813 m_DelayData.RemoveAt(DelArray[j]); |
| 1889 } | 1814 } |
| 1815 |
| 1816 for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; |
| 1817 i++) { |
| 1818 CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); |
| 1819 Field::DoDelay(m_pDocument, pData); |
| 1820 DelayDataForFieldAndControlIndex.SetAt(i, NULL); |
| 1821 delete pData; |
| 1822 } |
| 1890 } | 1823 } |
| 1891 | 1824 |
| 1892 void Document::AddDelayAnnotData(CJS_AnnotObj* pData) { | 1825 void Document::AddDelayAnnotData(CJS_AnnotObj* pData) { |
| 1893 m_DelayAnnotData.Add(pData); | 1826 m_DelayAnnotData.Add(pData); |
| 1894 } | 1827 } |
| 1895 | 1828 |
| 1896 void Document::DoAnnotDelay() { | 1829 void Document::DoAnnotDelay() { |
| 1897 CFX_DWordArray DelArray; | 1830 CFX_DWordArray DelArray; |
| 1898 | 1831 |
| 1899 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { | 1832 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
| 1900 m_DelayData.RemoveAt(DelArray[j]); | 1833 m_DelayData.RemoveAt(DelArray[j]); |
| 1901 } | 1834 } |
| 1902 } | 1835 } |
| 1903 | 1836 |
| 1904 CJS_Document* Document::GetCJSDoc() const { | 1837 CJS_Document* Document::GetCJSDoc() const { |
| 1905 return static_cast<CJS_Document*>(m_pJSObject); | 1838 return static_cast<CJS_Document*>(m_pJSObject); |
| 1906 } | 1839 } |
| OLD | NEW |