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/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 JS_STATIC_PROP_ENTRY(pageWindowRect) | 91 JS_STATIC_PROP_ENTRY(pageWindowRect) |
92 JS_STATIC_PROP_ENTRY(path) | 92 JS_STATIC_PROP_ENTRY(path) |
93 JS_STATIC_PROP_ENTRY(producer) | 93 JS_STATIC_PROP_ENTRY(producer) |
94 JS_STATIC_PROP_ENTRY(subject) | 94 JS_STATIC_PROP_ENTRY(subject) |
95 JS_STATIC_PROP_ENTRY(title) | 95 JS_STATIC_PROP_ENTRY(title) |
96 JS_STATIC_PROP_ENTRY(zoom) | 96 JS_STATIC_PROP_ENTRY(zoom) |
97 JS_STATIC_PROP_ENTRY(zoomType) | 97 JS_STATIC_PROP_ENTRY(zoomType) |
98 END_JS_STATIC_PROP() | 98 END_JS_STATIC_PROP() |
99 | 99 |
100 BEGIN_JS_STATIC_METHOD(CJS_Document) | 100 BEGIN_JS_STATIC_METHOD(CJS_Document) |
101 » JS_STATIC_METHOD_ENTRY(addAnnot,0) | 101 » JS_STATIC_METHOD_ENTRY(addAnnot) |
102 » JS_STATIC_METHOD_ENTRY(addField, 4) | 102 » JS_STATIC_METHOD_ENTRY(addField) |
103 » JS_STATIC_METHOD_ENTRY(addLink, 0) | 103 » JS_STATIC_METHOD_ENTRY(addLink) |
104 » JS_STATIC_METHOD_ENTRY(addIcon, 0) | 104 » JS_STATIC_METHOD_ENTRY(addIcon) |
105 » JS_STATIC_METHOD_ENTRY(calculateNow, 0) | 105 » JS_STATIC_METHOD_ENTRY(calculateNow) |
106 » JS_STATIC_METHOD_ENTRY(closeDoc, 0) | 106 » JS_STATIC_METHOD_ENTRY(closeDoc) |
107 » JS_STATIC_METHOD_ENTRY(createDataObject, 0) | 107 » JS_STATIC_METHOD_ENTRY(createDataObject) |
108 » JS_STATIC_METHOD_ENTRY(deletePages, 2) | 108 » JS_STATIC_METHOD_ENTRY(deletePages) |
109 » JS_STATIC_METHOD_ENTRY(exportAsText, 3) | 109 » JS_STATIC_METHOD_ENTRY(exportAsText) |
110 » JS_STATIC_METHOD_ENTRY(exportAsFDF, 6) | 110 » JS_STATIC_METHOD_ENTRY(exportAsFDF) |
111 » JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5) | 111 » JS_STATIC_METHOD_ENTRY(exportAsXFDF) |
112 » JS_STATIC_METHOD_ENTRY(extractPages, 3) | 112 » JS_STATIC_METHOD_ENTRY(extractPages) |
113 » JS_STATIC_METHOD_ENTRY(getAnnot, 0) | 113 » JS_STATIC_METHOD_ENTRY(getAnnot) |
114 » JS_STATIC_METHOD_ENTRY(getAnnots, 2) | 114 » JS_STATIC_METHOD_ENTRY(getAnnots) |
115 » JS_STATIC_METHOD_ENTRY(getAnnot3D, 2) | 115 » JS_STATIC_METHOD_ENTRY(getAnnot3D) |
116 » JS_STATIC_METHOD_ENTRY(getAnnots3D, 1) | 116 » JS_STATIC_METHOD_ENTRY(getAnnots3D) |
117 » JS_STATIC_METHOD_ENTRY(getField, 1) | 117 » JS_STATIC_METHOD_ENTRY(getField) |
118 » JS_STATIC_METHOD_ENTRY(getIcon, 0) | 118 » JS_STATIC_METHOD_ENTRY(getIcon) |
119 » JS_STATIC_METHOD_ENTRY(getLinks, 0) | 119 » JS_STATIC_METHOD_ENTRY(getLinks) |
120 » JS_STATIC_METHOD_ENTRY(getNthFieldName, 1) | 120 » JS_STATIC_METHOD_ENTRY(getNthFieldName) |
121 » JS_STATIC_METHOD_ENTRY(getOCGs, 0) | 121 » JS_STATIC_METHOD_ENTRY(getOCGs) |
122 » JS_STATIC_METHOD_ENTRY(getPageBox, 0) | 122 » JS_STATIC_METHOD_ENTRY(getPageBox) |
123 » JS_STATIC_METHOD_ENTRY(getPageNthWord, 3) | 123 » JS_STATIC_METHOD_ENTRY(getPageNthWord) |
124 » JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2) | 124 » JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) |
125 » JS_STATIC_METHOD_ENTRY(getPageNumWords, 1) | 125 » JS_STATIC_METHOD_ENTRY(getPageNumWords) |
126 » JS_STATIC_METHOD_ENTRY(getPrintParams, 0) | 126 » JS_STATIC_METHOD_ENTRY(getPrintParams) |
127 » JS_STATIC_METHOD_ENTRY(getURL, 2) | 127 » JS_STATIC_METHOD_ENTRY(getURL) |
128 » JS_STATIC_METHOD_ENTRY(importAnFDF, 1) | 128 » JS_STATIC_METHOD_ENTRY(importAnFDF) |
129 » JS_STATIC_METHOD_ENTRY(importAnXFDF, 1) | 129 » JS_STATIC_METHOD_ENTRY(importAnXFDF) |
130 » JS_STATIC_METHOD_ENTRY(importTextData, 2) | 130 » JS_STATIC_METHOD_ENTRY(importTextData) |
131 » JS_STATIC_METHOD_ENTRY(insertPages, 4) | 131 » JS_STATIC_METHOD_ENTRY(insertPages) |
132 » JS_STATIC_METHOD_ENTRY(mailForm, 6) | 132 » JS_STATIC_METHOD_ENTRY(mailForm) |
133 » JS_STATIC_METHOD_ENTRY(print, 9) | 133 » JS_STATIC_METHOD_ENTRY(print) |
134 » JS_STATIC_METHOD_ENTRY(removeField, 1) | 134 » JS_STATIC_METHOD_ENTRY(removeField) |
135 » JS_STATIC_METHOD_ENTRY(replacePages, 4) | 135 » JS_STATIC_METHOD_ENTRY(replacePages) |
136 » JS_STATIC_METHOD_ENTRY(resetForm, 1) | 136 » JS_STATIC_METHOD_ENTRY(resetForm) |
137 » JS_STATIC_METHOD_ENTRY(removeIcon, 0) | 137 » JS_STATIC_METHOD_ENTRY(removeIcon) |
138 » JS_STATIC_METHOD_ENTRY(saveAs, 5) | 138 » JS_STATIC_METHOD_ENTRY(saveAs) |
139 » JS_STATIC_METHOD_ENTRY(submitForm, 23) | 139 » JS_STATIC_METHOD_ENTRY(submitForm) |
140 » JS_STATIC_METHOD_ENTRY(mailDoc, 0) | 140 » JS_STATIC_METHOD_ENTRY(mailDoc) |
141 END_JS_STATIC_METHOD() | 141 END_JS_STATIC_METHOD() |
142 | 142 |
143 IMPLEMENT_JS_CLASS(CJS_Document, Document) | 143 IMPLEMENT_JS_CLASS(CJS_Document, Document) |
144 | 144 |
145 FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc) | 145 FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc) |
146 { | 146 { |
147 CJS_Context* pContext = (CJS_Context*)cc; | 147 CJS_Context* pContext = (CJS_Context*)cc; |
148 ASSERT(pContext != NULL); | 148 ASSERT(pContext != NULL); |
149 | 149 |
150 Document* pDoc = (Document*)GetEmbedObject(); | 150 Document* pDoc = (Document*)GetEmbedObject(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 // Unsafe, not supported. | 314 // Unsafe, not supported. |
315 return TRUE; | 315 return TRUE; |
316 } | 316 } |
317 | 317 |
318 //Maps a field object in PDF document to a JavaScript variable | 318 //Maps a field object in PDF document to a JavaScript variable |
319 //comment: | 319 //comment: |
320 //note: the paremter cName, this is clue how to treat if the cName is not a vali able filed name in this document | 320 //note: the paremter cName, this is clue how to treat if the cName is not a vali able filed name in this document |
321 | 321 |
322 FX_BOOL Document::getField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError) | 322 FX_BOOL Document::getField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_ Value& vRet, CFX_WideString& sError) |
323 { | 323 { |
324 » v8::Isolate* isolate = GetIsolate(cc); | 324 » CJS_Context* pContext = (CJS_Context*)cc; |
325 » ASSERT(m_pDocument != NULL); | 325 » if (params.size() < 1) { |
326 | 326 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
327 » if (params.size() < 1) return FALSE; | 327 » » return FALSE; |
328 » } | |
328 | 329 |
329 CFX_WideString wideName = params[0].ToCFXWideString(); | 330 CFX_WideString wideName = params[0].ToCFXWideString(); |
330 | 331 |
331 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 332 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
332 ASSERT(pInterForm != NULL); | |
333 | |
334 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 333 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
335 ASSERT(pPDFForm != NULL); | |
336 | |
337 if (pPDFForm->CountFields(wideName) <= 0) | 334 if (pPDFForm->CountFields(wideName) <= 0) |
338 { | 335 { |
339 vRet.SetNull(); | 336 vRet.SetNull(); |
340 return TRUE; | 337 return TRUE; |
341 } | 338 } |
342 | 339 |
343 CJS_Context* pContext = (CJS_Context*)cc; | |
344 ASSERT(pContext != NULL); | |
345 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 340 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
346 » ASSERT(pRuntime != NULL); | 341 » JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObj DefnID(*pRuntime, L"Field")); |
347 | 342 |
348 » JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetOb jDefnID(*pRuntime, L"Field")); | 343 » v8::Isolate* isolate = GetIsolate(cc); |
344 » CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj); | |
345 » Field* pField = (Field *)pJSField->GetEmbedObject(); | |
346 » pField->AttachField(this, wideName); | |
349 | 347 |
350 CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj); | |
351 ASSERT(pJSField != NULL); | |
352 | |
353 Field * pField = (Field *)pJSField->GetEmbedObject(); | |
354 ASSERT(pField != NULL); | |
355 | |
356 pField->AttachField(this, wideName); | |
357 vRet = pJSField; | 348 vRet = pJSField; |
358 | |
359 return TRUE; | 349 return TRUE; |
360 } | 350 } |
361 | 351 |
362 //Gets the name of the nth field in the document | 352 //Gets the name of the nth field in the document |
363 FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, const CJS_Parameters& param s, CJS_Value& vRet, CFX_WideString& sError) | 353 FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, const CJS_Parameters& param s, CJS_Value& vRet, CFX_WideString& sError) |
364 { | 354 { |
365 » ASSERT(m_pDocument != NULL); | 355 » CJS_Context* pContext = (CJS_Context*)cc; |
356 » if (params.size() != 1) { | |
357 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
358 » » return FALSE; | |
359 » } | |
366 | 360 |
367 » int nIndex = params.size() > 0 ? params[0].ToInt() : -1; | 361 » int nIndex = params[0].ToInt(); |
368 » if (nIndex == -1) return FALSE; | 362 » if (nIndex < 0) { |
363 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); | |
364 » » return FALSE; | |
365 » } | |
369 | 366 |
370 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 367 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
371 ASSERT(pInterForm != NULL); | |
372 | |
373 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 368 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
374 ASSERT(pPDFForm != NULL); | |
375 | |
376 CPDF_FormField* pField = pPDFForm->GetField(nIndex); | 369 CPDF_FormField* pField = pPDFForm->GetField(nIndex); |
377 if (!pField) | 370 if (!pField) |
378 return FALSE; | 371 return FALSE; |
379 | 372 |
380 vRet = pField->GetFullName(); | 373 vRet = pField->GetFullName(); |
381 return TRUE; | 374 return TRUE; |
382 } | 375 } |
383 | 376 |
384 FX_BOOL Document::importAnFDF(IFXJS_Context* cc, const CJS_Parameters& params, C JS_Value& vRet, CFX_WideString& sError) | 377 FX_BOOL Document::importAnFDF(IFXJS_Context* cc, const CJS_Parameters& params, C JS_Value& vRet, CFX_WideString& sError) |
385 { | 378 { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 //comment: | 509 //comment: |
517 //note: if the filed name is not retional, adobe is dumb for it. | 510 //note: if the filed name is not retional, adobe is dumb for it. |
518 | 511 |
519 FX_BOOL Document::removeField(IFXJS_Context* cc, const CJS_Parameters& params, C JS_Value& vRet, CFX_WideString& sError) | 512 FX_BOOL Document::removeField(IFXJS_Context* cc, const CJS_Parameters& params, C JS_Value& vRet, CFX_WideString& sError) |
520 { | 513 { |
521 ASSERT(m_pDocument != NULL); | 514 ASSERT(m_pDocument != NULL); |
522 | 515 |
523 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || | 516 if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
524 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE; | 517 m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE; |
525 | 518 |
526 » if (params.size() < 1) | 519 » CJS_Context* pContext = (CJS_Context*)cc; |
527 » » return TRUE; | 520 » if (params.size() != 1) { |
521 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
522 » » return FALSE; | |
523 » } | |
528 | 524 |
529 CFX_WideString sFieldName = params[0].ToCFXWideString(); | 525 CFX_WideString sFieldName = params[0].ToCFXWideString(); |
530 | |
531 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInte rForm(); | 526 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInte rForm(); |
532 ASSERT(pInterForm != NULL); | 527 ASSERT(pInterForm != NULL); |
533 | 528 |
534 CFX_PtrArray widgets; | 529 CFX_PtrArray widgets; |
535 pInterForm->GetWidgets(sFieldName, widgets); | 530 pInterForm->GetWidgets(sFieldName, widgets); |
536 | 531 |
537 int nSize = widgets.GetSize(); | 532 int nSize = widgets.GetSize(); |
538 | 533 |
539 if (nSize > 0) | 534 if (nSize > 0) |
540 { | 535 { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
634 FX_BOOL Document::saveAs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError) | 629 FX_BOOL Document::saveAs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Va lue& vRet, CFX_WideString& sError) |
635 { | 630 { |
636 // Unsafe, not supported. | 631 // Unsafe, not supported. |
637 return TRUE; | 632 return TRUE; |
638 } | 633 } |
639 | 634 |
640 | 635 |
641 FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError) | 636 FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError) |
642 { | 637 { |
643 ASSERT(m_pDocument != NULL); | 638 ASSERT(m_pDocument != NULL); |
644 | 639 » CJS_Context* pContext = (CJS_Context*)cc; |
brucedawson
2015/05/01 17:16:36
This newly added pContext variable now shadows two
| |
645 //» if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; | |
646 | |
647 int nSize = params.size(); | 640 int nSize = params.size(); |
648 » if (nSize < 1) return FALSE; | 641 » if (nSize < 1) { |
642 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
643 » » return FALSE; | |
644 » } | |
649 | 645 |
650 CFX_WideString strURL; | 646 CFX_WideString strURL; |
651 FX_BOOL bFDF = TRUE; | 647 FX_BOOL bFDF = TRUE; |
652 FX_BOOL bEmpty = FALSE; | 648 FX_BOOL bEmpty = FALSE; |
653 v8::Isolate* isolate = GetIsolate(cc); | 649 v8::Isolate* isolate = GetIsolate(cc); |
654 CJS_Array aFields(isolate); | 650 CJS_Array aFields(isolate); |
655 | 651 |
656 CJS_Value v = params[0]; | 652 CJS_Value v = params[0]; |
657 if (v.GetType() == VT_string) | 653 if (v.GetType() == VT_string) |
658 { | 654 { |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1450 | 1446 |
1451 continue; | 1447 continue; |
1452 } | 1448 } |
1453 | 1449 |
1454 pTemp = pTemp->NextIcon; | 1450 pTemp = pTemp->NextIcon; |
1455 } | 1451 } |
1456 } | 1452 } |
1457 | 1453 |
1458 FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) | 1454 FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) |
1459 { | 1455 { |
1460 if (params.size() != 2)return FALSE; | |
1461 | |
1462 CJS_Context* pContext = (CJS_Context*)cc; | 1456 CJS_Context* pContext = (CJS_Context*)cc; |
1463 » ASSERT(pContext != NULL); | 1457 » if (params.size() != 2) { |
1464 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1458 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1465 » ASSERT(pRuntime != NULL); | 1459 » » return FALSE; |
1460 » } | |
1466 | 1461 |
1467 CFX_WideString swIconName = params[0].ToCFXWideString(); | 1462 CFX_WideString swIconName = params[0].ToCFXWideString(); |
1463 JSFXObject pJSIcon = params[1].ToV8Object(); | |
1468 | 1464 |
1469 » JSFXObject pJSIcon = params[1].ToV8Object(); | 1465 » CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1470 » if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) ret urn FALSE; | 1466 » if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) { |
1467 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | |
1468 » » return FALSE; | |
1469 » } | |
1471 | 1470 |
1472 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); | 1471 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); |
1473 » if (!pEmbedObj)return FALSE; | 1472 » if (!pEmbedObj) { |
1473 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); | |
1474 » » return FALSE; | |
1475 » } | |
1476 | |
1474 Icon* pIcon = (Icon*)pEmbedObj; | 1477 Icon* pIcon = (Icon*)pEmbedObj; |
1475 | |
1476 if (!m_pIconTree) | 1478 if (!m_pIconTree) |
1477 m_pIconTree = new IconTree(); | 1479 m_pIconTree = new IconTree(); |
1478 | 1480 |
1479 IconElement* pNewIcon = new IconElement(); | 1481 IconElement* pNewIcon = new IconElement(); |
1480 pNewIcon->IconName = swIconName; | 1482 pNewIcon->IconName = swIconName; |
1481 pNewIcon->NextIcon = NULL; | 1483 pNewIcon->NextIcon = NULL; |
1482 pNewIcon->IconStream = pIcon; | 1484 pNewIcon->IconStream = pIcon; |
1483 m_pIconTree->InsertIconElement(pNewIcon); | 1485 m_pIconTree->InsertIconElement(pNewIcon); |
1484 return TRUE; | 1486 return TRUE; |
1485 } | 1487 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1522 pIcon->SetIconName(pIconElement->IconName); | 1524 pIcon->SetIconName(pIconElement->IconName); |
1523 Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon)); | 1525 Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon)); |
1524 } | 1526 } |
1525 | 1527 |
1526 vp << Icons; | 1528 vp << Icons; |
1527 return TRUE; | 1529 return TRUE; |
1528 } | 1530 } |
1529 | 1531 |
1530 FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) | 1532 FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_V alue& vRet, CFX_WideString& sError) |
1531 { | 1533 { |
1532 » if (params.size() != 1)return FALSE; | 1534 » CJS_Context* pContext = (CJS_Context *)cc; |
1535 » if (params.size() != 1) { | |
1536 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1537 » » return FALSE; | |
1538 » } | |
1539 | |
1533 if(!m_pIconTree) | 1540 if(!m_pIconTree) |
1534 return FALSE; | 1541 return FALSE; |
1535 CFX_WideString swIconName = params[0].ToCFXWideString(); | 1542 CFX_WideString swIconName = params[0].ToCFXWideString(); |
1536 int iIconCounts = m_pIconTree->GetLength(); | 1543 int iIconCounts = m_pIconTree->GetLength(); |
1537 | 1544 |
1538 CJS_Context* pContext = (CJS_Context *)cc; | |
1539 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1545 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1540 | 1546 |
1541 for (int i = 0; i < iIconCounts; i++) | 1547 for (int i = 0; i < iIconCounts; i++) |
1542 { | 1548 { |
1543 if ((*m_pIconTree)[i]->IconName == swIconName) | 1549 if ((*m_pIconTree)[i]->IconName == swIconName) |
1544 { | 1550 { |
1545 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; | 1551 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; |
1546 | 1552 |
1547 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContex t, JS_GetObjDefnID(*pRuntime, L"Icon")); | 1553 JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContex t, JS_GetObjDefnID(*pRuntime, L"Icon")); |
1548 if (pObj.IsEmpty()) return FALSE; | 1554 if (pObj.IsEmpty()) return FALSE; |
1549 | 1555 |
1550 CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); | 1556 CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj); |
1551 if (!pJS_Icon) return FALSE; | 1557 if (!pJS_Icon) return FALSE; |
1552 | 1558 |
1553 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1559 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
1554 if (!pIcon)return FALSE; | 1560 if (!pIcon)return FALSE; |
1555 | 1561 |
1556 pIcon->SetIconName(swIconName); | 1562 pIcon->SetIconName(swIconName); |
1557 pIcon->SetStream(pRetIcon->GetStream()); | 1563 pIcon->SetStream(pRetIcon->GetStream()); |
1558 vRet = pJS_Icon; | 1564 vRet = pJS_Icon; |
1559 return TRUE; | 1565 return TRUE; |
1560 } | 1566 } |
1561 } | 1567 } |
1562 | 1568 |
1563 return FALSE; | 1569 return FALSE; |
1564 } | 1570 } |
1565 | 1571 |
1566 FX_BOOL Document::removeIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError) | 1572 FX_BOOL Document::removeIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJ S_Value& vRet, CFX_WideString& sError) |
1567 { | 1573 { |
1568 » if (params.size() != 1)return FALSE; | 1574 » CJS_Context* pContext = (CJS_Context *)cc; |
1575 » if (params.size() != 1) { | |
1576 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1577 » » return FALSE; | |
1578 » } | |
1579 | |
1569 if(!m_pIconTree) | 1580 if(!m_pIconTree) |
1570 return FALSE; | 1581 return FALSE; |
1571 CFX_WideString swIconName = params[0].ToCFXWideString(); | 1582 CFX_WideString swIconName = params[0].ToCFXWideString(); |
1572 return TRUE; | 1583 return TRUE; |
1573 } | 1584 } |
1574 | 1585 |
1575 FX_BOOL Document::createDataObject(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, CFX_WideString& sError) | 1586 FX_BOOL Document::createDataObject(IFXJS_Context* cc, const CJS_Parameters& para ms, CJS_Value& vRet, CFX_WideString& sError) |
1576 { | 1587 { |
1577 // Unsafe, not implemented. | 1588 // Unsafe, not implemented. |
1578 return TRUE; | 1589 return TRUE; |
(...skipping 29 matching lines...) Expand all Loading... | |
1608 | 1619 |
1609 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; | 1620 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; |
1610 | 1621 |
1611 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; | 1622 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; |
1612 int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; | 1623 int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; |
1613 bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; | 1624 bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; |
1614 | 1625 |
1615 CPDF_Document* pDocument = m_pDocument->GetDocument(); | 1626 CPDF_Document* pDocument = m_pDocument->GetDocument(); |
1616 if (!pDocument) return FALSE; | 1627 if (!pDocument) return FALSE; |
1617 | 1628 |
1629 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1618 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) | 1630 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) |
1619 { | 1631 { |
1620 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1632 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
1621 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1622 return FALSE; | 1633 return FALSE; |
1623 } | 1634 } |
1624 | 1635 |
1625 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1636 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
1626 if (!pPageDict) return FALSE; | 1637 if (!pPageDict) return FALSE; |
1627 | 1638 |
1628 CPDF_Page page; | 1639 CPDF_Page page; |
1629 page.Load(pDocument, pPageDict); | 1640 page.Load(pDocument, pPageDict); |
1630 page.StartParse(); | 1641 page.StartParse(); |
1631 page.ParseContent(); | 1642 page.ParseContent(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1678 { | 1689 { |
1679 ASSERT(m_pDocument != NULL); | 1690 ASSERT(m_pDocument != NULL); |
1680 | 1691 |
1681 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; | 1692 if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; |
1682 | 1693 |
1683 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; | 1694 int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; |
1684 | 1695 |
1685 CPDF_Document* pDocument = m_pDocument->GetDocument(); | 1696 CPDF_Document* pDocument = m_pDocument->GetDocument(); |
1686 ASSERT(pDocument != NULL); | 1697 ASSERT(pDocument != NULL); |
1687 | 1698 |
1699 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | |
1688 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) | 1700 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) |
1689 { | 1701 { |
1690 » » CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1702 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
1691 » » sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
1692 return FALSE; | 1703 return FALSE; |
1693 } | 1704 } |
1694 | 1705 |
1695 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1706 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
1696 if (!pPageDict) return FALSE; | 1707 if (!pPageDict) return FALSE; |
1697 | 1708 |
1698 CPDF_Page page; | 1709 CPDF_Page page; |
1699 page.Load(pDocument, pPageDict); | 1710 page.Load(pDocument, pPageDict); |
1700 page.StartParse(); | 1711 page.StartParse(); |
1701 page.ParseContent(); | 1712 page.ParseContent(); |
(...skipping 15 matching lines...) Expand all Loading... | |
1717 } | 1728 } |
1718 | 1729 |
1719 vRet = nWords; | 1730 vRet = nWords; |
1720 | 1731 |
1721 return TRUE; | 1732 return TRUE; |
1722 } | 1733 } |
1723 | 1734 |
1724 FX_BOOL Document::getPrintParams(IFXJS_Context* cc, const CJS_Parameters& params , CJS_Value& vRet, CFX_WideString& sError) | 1735 FX_BOOL Document::getPrintParams(IFXJS_Context* cc, const CJS_Parameters& params , CJS_Value& vRet, CFX_WideString& sError) |
1725 { | 1736 { |
1726 CJS_Context* pContext = (CJS_Context*)cc; | 1737 CJS_Context* pContext = (CJS_Context*)cc; |
1727 ASSERT(pContext != NULL); | |
1728 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1738 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
1729 ASSERT(pRuntime != NULL); | |
1730 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"PrintParamsObj")); | 1739 JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDe fnID(*pRuntime, L"PrintParamsObj")); |
1731 » //not implemented yet. | 1740 |
1741 » // Not implemented yet. | |
1742 | |
1732 vRet = pRetObj; | 1743 vRet = pRetObj; |
1733 | |
1734 return TRUE; | 1744 return TRUE; |
1735 } | 1745 } |
1736 | 1746 |
1737 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) | 1747 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
1738 | 1748 |
1739 int Document::CountWords(CPDF_TextObject* pTextObj) | 1749 int Document::CountWords(CPDF_TextObject* pTextObj) |
1740 { | 1750 { |
1741 if (!pTextObj) return 0; | 1751 if (!pTextObj) return 0; |
1742 | 1752 |
1743 int nWords = 0; | 1753 int nWords = 0; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1951 { | 1961 { |
1952 m_DelayData.RemoveAt(DelArray[j]); | 1962 m_DelayData.RemoveAt(DelArray[j]); |
1953 } | 1963 } |
1954 } | 1964 } |
1955 | 1965 |
1956 CJS_Document* Document::GetCJSDoc() const | 1966 CJS_Document* Document::GetCJSDoc() const |
1957 { | 1967 { |
1958 return static_cast<CJS_Document*>(m_pJSObject); | 1968 return static_cast<CJS_Document*>(m_pJSObject); |
1959 } | 1969 } |
1960 | 1970 |
OLD | NEW |