John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 7 | #include "fpdfsdk/src/javascript/Document.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame^] | 9 | #include <vector> |
| 10 | |
Tom Sepez | 310438f | 2016-03-08 13:10:55 -0800 | [diff] [blame] | 11 | #include "core/include/fpdfapi/cpdf_document.h" |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame^] | 12 | #include "fpdfsdk/include/fsdk_mgr.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 13 | #include "fpdfsdk/include/javascript/IJavaScript.h" |
Dan Sinclair | efbc191 | 2016-02-17 16:54:43 -0500 | [diff] [blame] | 14 | #include "fpdfsdk/src/javascript/Field.h" |
| 15 | #include "fpdfsdk/src/javascript/Icon.h" |
| 16 | #include "fpdfsdk/src/javascript/JS_Context.h" |
| 17 | #include "fpdfsdk/src/javascript/JS_Define.h" |
| 18 | #include "fpdfsdk/src/javascript/JS_EventHandler.h" |
| 19 | #include "fpdfsdk/src/javascript/JS_Object.h" |
| 20 | #include "fpdfsdk/src/javascript/JS_Runtime.h" |
| 21 | #include "fpdfsdk/src/javascript/JS_Value.h" |
| 22 | #include "fpdfsdk/src/javascript/app.h" |
| 23 | #include "fpdfsdk/src/javascript/resource.h" |
Lei Zhang | 8241df7 | 2015-11-06 14:38:48 -0800 | [diff] [blame] | 24 | #include "third_party/base/numerics/safe_math.h" |
Chris Palmer | 9108ad2 | 2014-06-26 16:01:46 -0700 | [diff] [blame] | 25 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 26 | static v8::Isolate* GetIsolate(IJS_Context* cc) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | return pRuntime->GetIsolate(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) |
| 33 | END_JS_STATIC_CONST() |
| 34 | |
| 35 | BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
| 36 | END_JS_STATIC_PROP() |
| 37 | |
| 38 | BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
| 39 | END_JS_STATIC_METHOD() |
| 40 | |
| 41 | IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) |
| 42 | |
| 43 | PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | : CJS_EmbedObj(pJSObject) { |
| 45 | bUI = TRUE; |
| 46 | nStart = 0; |
| 47 | nEnd = 0; |
| 48 | bSilent = FALSE; |
| 49 | bShrinkToFit = FALSE; |
| 50 | bPrintAsImage = FALSE; |
| 51 | bReverse = FALSE; |
| 52 | bAnnotations = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /* ---------------------- Document ---------------------- */ |
| 56 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | #define MINWIDTH 5.0f |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | #define MINHEIGHT 5.0f |
| 59 | |
| 60 | BEGIN_JS_STATIC_CONST(CJS_Document) |
| 61 | END_JS_STATIC_CONST() |
| 62 | |
| 63 | BEGIN_JS_STATIC_PROP(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | JS_STATIC_PROP_ENTRY(ADBE) |
| 65 | JS_STATIC_PROP_ENTRY(author) |
| 66 | JS_STATIC_PROP_ENTRY(baseURL) |
| 67 | JS_STATIC_PROP_ENTRY(bookmarkRoot) |
| 68 | JS_STATIC_PROP_ENTRY(calculate) |
| 69 | JS_STATIC_PROP_ENTRY(Collab) |
| 70 | JS_STATIC_PROP_ENTRY(creationDate) |
| 71 | JS_STATIC_PROP_ENTRY(creator) |
| 72 | JS_STATIC_PROP_ENTRY(delay) |
| 73 | JS_STATIC_PROP_ENTRY(dirty) |
| 74 | JS_STATIC_PROP_ENTRY(documentFileName) |
| 75 | JS_STATIC_PROP_ENTRY(external) |
| 76 | JS_STATIC_PROP_ENTRY(filesize) |
| 77 | JS_STATIC_PROP_ENTRY(icons) |
| 78 | JS_STATIC_PROP_ENTRY(info) |
| 79 | JS_STATIC_PROP_ENTRY(keywords) |
| 80 | JS_STATIC_PROP_ENTRY(layout) |
| 81 | JS_STATIC_PROP_ENTRY(media) |
| 82 | JS_STATIC_PROP_ENTRY(modDate) |
| 83 | JS_STATIC_PROP_ENTRY(mouseX) |
| 84 | JS_STATIC_PROP_ENTRY(mouseY) |
| 85 | JS_STATIC_PROP_ENTRY(numFields) |
| 86 | JS_STATIC_PROP_ENTRY(numPages) |
| 87 | JS_STATIC_PROP_ENTRY(pageNum) |
| 88 | JS_STATIC_PROP_ENTRY(pageWindowRect) |
| 89 | JS_STATIC_PROP_ENTRY(path) |
| 90 | JS_STATIC_PROP_ENTRY(producer) |
| 91 | JS_STATIC_PROP_ENTRY(subject) |
| 92 | JS_STATIC_PROP_ENTRY(title) |
| 93 | JS_STATIC_PROP_ENTRY(zoom) |
| 94 | JS_STATIC_PROP_ENTRY(zoomType) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | END_JS_STATIC_PROP() |
| 96 | |
| 97 | BEGIN_JS_STATIC_METHOD(CJS_Document) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | JS_STATIC_METHOD_ENTRY(addAnnot) |
| 99 | JS_STATIC_METHOD_ENTRY(addField) |
| 100 | JS_STATIC_METHOD_ENTRY(addLink) |
| 101 | JS_STATIC_METHOD_ENTRY(addIcon) |
| 102 | JS_STATIC_METHOD_ENTRY(calculateNow) |
| 103 | JS_STATIC_METHOD_ENTRY(closeDoc) |
| 104 | JS_STATIC_METHOD_ENTRY(createDataObject) |
| 105 | JS_STATIC_METHOD_ENTRY(deletePages) |
| 106 | JS_STATIC_METHOD_ENTRY(exportAsText) |
| 107 | JS_STATIC_METHOD_ENTRY(exportAsFDF) |
| 108 | JS_STATIC_METHOD_ENTRY(exportAsXFDF) |
| 109 | JS_STATIC_METHOD_ENTRY(extractPages) |
| 110 | JS_STATIC_METHOD_ENTRY(getAnnot) |
| 111 | JS_STATIC_METHOD_ENTRY(getAnnots) |
| 112 | JS_STATIC_METHOD_ENTRY(getAnnot3D) |
| 113 | JS_STATIC_METHOD_ENTRY(getAnnots3D) |
| 114 | JS_STATIC_METHOD_ENTRY(getField) |
| 115 | JS_STATIC_METHOD_ENTRY(getIcon) |
| 116 | JS_STATIC_METHOD_ENTRY(getLinks) |
| 117 | JS_STATIC_METHOD_ENTRY(getNthFieldName) |
| 118 | JS_STATIC_METHOD_ENTRY(getOCGs) |
| 119 | JS_STATIC_METHOD_ENTRY(getPageBox) |
| 120 | JS_STATIC_METHOD_ENTRY(getPageNthWord) |
| 121 | JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) |
| 122 | JS_STATIC_METHOD_ENTRY(getPageNumWords) |
| 123 | JS_STATIC_METHOD_ENTRY(getPrintParams) |
| 124 | JS_STATIC_METHOD_ENTRY(getURL) |
| 125 | JS_STATIC_METHOD_ENTRY(importAnFDF) |
| 126 | JS_STATIC_METHOD_ENTRY(importAnXFDF) |
| 127 | JS_STATIC_METHOD_ENTRY(importTextData) |
| 128 | JS_STATIC_METHOD_ENTRY(insertPages) |
| 129 | JS_STATIC_METHOD_ENTRY(mailForm) |
| 130 | JS_STATIC_METHOD_ENTRY(print) |
| 131 | JS_STATIC_METHOD_ENTRY(removeField) |
| 132 | JS_STATIC_METHOD_ENTRY(replacePages) |
| 133 | JS_STATIC_METHOD_ENTRY(resetForm) |
| 134 | JS_STATIC_METHOD_ENTRY(removeIcon) |
| 135 | JS_STATIC_METHOD_ENTRY(saveAs) |
| 136 | JS_STATIC_METHOD_ENTRY(submitForm) |
| 137 | JS_STATIC_METHOD_ENTRY(mailDoc) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 138 | END_JS_STATIC_METHOD() |
| 139 | |
| 140 | IMPLEMENT_JS_CLASS(CJS_Document, Document) |
| 141 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 142 | void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| 143 | CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 144 | Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
| 145 | pDoc->AttachDoc(pRuntime->GetReaderDocument()); |
| 146 | pDoc->SetIsolate(pRuntime->GetIsolate()); |
| 147 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 148 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | /* --------------------------------- Document --------------------------------- |
| 150 | */ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 151 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | Document::Document(CJS_Object* pJSObject) |
| 153 | : CJS_EmbedObj(pJSObject), |
| 154 | m_isolate(NULL), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | m_pDocument(NULL), |
| 156 | m_cwBaseURL(L""), |
| 157 | m_bDelay(FALSE) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 158 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | Document::~Document() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 160 | for (int i = 0; i < m_DelayData.GetSize(); i++) { |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 161 | delete m_DelayData.GetAt(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | } |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 163 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 164 | m_DelayData.RemoveAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | // the total number of fileds in document. |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 168 | FX_BOOL Document::numFields(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | CJS_PropValue& vp, |
| 170 | CFX_WideString& sError) { |
| 171 | if (vp.IsSetting()) { |
| 172 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 173 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 174 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | } |
| 176 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 177 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 178 | vp << (int)pPDFForm->CountFields(); |
| 179 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 182 | FX_BOOL Document::dirty(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | CJS_PropValue& vp, |
| 184 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | if (vp.IsGetting()) { |
| 186 | if (m_pDocument->GetChangeMark()) |
| 187 | vp << true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 188 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | vp << false; |
| 190 | } else { |
| 191 | bool bChanged = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 192 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | vp >> bChanged; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 195 | if (bChanged) |
| 196 | m_pDocument->SetChangeMark(); |
| 197 | else |
| 198 | m_pDocument->ClearChangeMark(); |
| 199 | } |
| 200 | |
| 201 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 204 | FX_BOOL Document::ADBE(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | CJS_PropValue& vp, |
| 206 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | if (vp.IsGetting()) { |
| 208 | vp.SetNull(); |
| 209 | } else { |
| 210 | } |
| 211 | |
| 212 | return TRUE; |
| 213 | } |
| 214 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 215 | FX_BOOL Document::pageNum(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | CJS_PropValue& vp, |
| 217 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 218 | if (vp.IsGetting()) { |
| 219 | if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { |
| 220 | vp << pPageView->GetPageIndex(); |
| 221 | } |
| 222 | } else { |
| 223 | int iPageCount = m_pDocument->GetPageCount(); |
| 224 | int iPageNum = 0; |
| 225 | vp >> iPageNum; |
| 226 | |
| 227 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 228 | if (iPageNum >= 0 && iPageNum < iPageCount) { |
| 229 | pEnv->JS_docgotoPage(iPageNum); |
| 230 | } else if (iPageNum >= iPageCount) { |
| 231 | pEnv->JS_docgotoPage(iPageCount - 1); |
| 232 | } else if (iPageNum < 0) { |
| 233 | pEnv->JS_docgotoPage(0); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return TRUE; |
| 238 | } |
| 239 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 240 | FX_BOOL Document::addAnnot(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 241 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | CJS_Value& vRet, |
| 243 | CFX_WideString& sError) { |
| 244 | // Not supported. |
| 245 | return TRUE; |
| 246 | } |
| 247 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 248 | FX_BOOL Document::addField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 249 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | CJS_Value& vRet, |
| 251 | CFX_WideString& sError) { |
| 252 | // Not supported. |
| 253 | return TRUE; |
| 254 | } |
| 255 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 256 | FX_BOOL Document::exportAsText(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 257 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | CJS_Value& vRet, |
| 259 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 260 | // Unsafe, not supported. |
| 261 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 264 | FX_BOOL Document::exportAsFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 265 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | CJS_Value& vRet, |
| 267 | CFX_WideString& sError) { |
| 268 | // Unsafe, not supported. |
| 269 | return TRUE; |
| 270 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 271 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 272 | FX_BOOL Document::exportAsXFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 273 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | CJS_Value& vRet, |
| 275 | CFX_WideString& sError) { |
| 276 | // Unsafe, not supported. |
| 277 | return TRUE; |
| 278 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 279 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | // Maps a field object in PDF document to a JavaScript variable |
| 281 | // comment: |
| 282 | // note: the paremter cName, this is clue how to treat if the cName is not a |
| 283 | // valiable filed name in this document |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 284 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 285 | FX_BOOL Document::getField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 286 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | CJS_Value& vRet, |
| 288 | CFX_WideString& sError) { |
| 289 | CJS_Context* pContext = (CJS_Context*)cc; |
| 290 | if (params.size() < 1) { |
| 291 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 292 | return FALSE; |
| 293 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 294 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | CFX_WideString wideName = params[0].ToCFXWideString(); |
| 296 | |
| 297 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 298 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 299 | if (pPDFForm->CountFields(wideName) <= 0) { |
| 300 | vRet.SetNull(); |
| 301 | return TRUE; |
| 302 | } |
| 303 | |
| 304 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 305 | v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 306 | pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | |
| 308 | v8::Isolate* isolate = GetIsolate(cc); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 309 | CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | Field* pField = (Field*)pJSField->GetEmbedObject(); |
| 311 | pField->AttachField(this, wideName); |
| 312 | |
| 313 | vRet = pJSField; |
| 314 | return TRUE; |
| 315 | } |
| 316 | |
| 317 | // Gets the name of the nth field in the document |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 318 | FX_BOOL Document::getNthFieldName(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 319 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | CJS_Value& vRet, |
| 321 | CFX_WideString& sError) { |
| 322 | CJS_Context* pContext = (CJS_Context*)cc; |
| 323 | if (params.size() != 1) { |
| 324 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 325 | return FALSE; |
| 326 | } |
| 327 | |
| 328 | int nIndex = params[0].ToInt(); |
| 329 | if (nIndex < 0) { |
| 330 | sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 331 | return FALSE; |
| 332 | } |
| 333 | |
| 334 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
| 335 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 336 | CPDF_FormField* pField = pPDFForm->GetField(nIndex); |
| 337 | if (!pField) |
| 338 | return FALSE; |
| 339 | |
| 340 | vRet = pField->GetFullName().c_str(); |
| 341 | return TRUE; |
| 342 | } |
| 343 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 344 | FX_BOOL Document::importAnFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 345 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | CJS_Value& vRet, |
| 347 | CFX_WideString& sError) { |
| 348 | // Unsafe, not supported. |
| 349 | return TRUE; |
| 350 | } |
| 351 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 352 | FX_BOOL Document::importAnXFDF(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 353 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | CJS_Value& vRet, |
| 355 | CFX_WideString& sError) { |
| 356 | // Unsafe, not supported. |
| 357 | return TRUE; |
| 358 | } |
| 359 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 360 | FX_BOOL Document::importTextData(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 361 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 362 | CJS_Value& vRet, |
| 363 | CFX_WideString& sError) { |
| 364 | // Unsafe, not supported. |
| 365 | return TRUE; |
| 366 | } |
| 367 | |
| 368 | // exports the form data and mails the resulting fdf file as an attachment to |
| 369 | // all recipients. |
| 370 | // comment: need reader supports |
| 371 | // note: |
| 372 | // int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string |
| 373 | // cbcc,string cSubject,string cms); |
| 374 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 375 | FX_BOOL Document::mailForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 376 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | CJS_Value& vRet, |
| 378 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 380 | return FALSE; |
| 381 | |
| 382 | int iLength = params.size(); |
| 383 | |
| 384 | FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; |
| 385 | CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; |
| 386 | CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; |
| 387 | CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; |
| 388 | CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; |
| 389 | CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; |
| 390 | |
| 391 | CPDFSDK_InterForm* pInterForm = |
| 392 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | CFX_ByteTextBuf textBuf; |
| 394 | if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 395 | return FALSE; |
| 396 | |
| 397 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 399 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | |
| 401 | pRuntime->BeginBlock(); |
| 402 | pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 403 | cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 404 | cMsg.c_str()); |
| 405 | pRuntime->EndBlock(); |
| 406 | return TRUE; |
| 407 | } |
| 408 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 409 | FX_BOOL Document::print(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 410 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | CJS_Value& vRet, |
| 412 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | FX_BOOL bUI = TRUE; |
| 414 | int nStart = 0; |
| 415 | int nEnd = 0; |
| 416 | FX_BOOL bSilent = FALSE; |
| 417 | FX_BOOL bShrinkToFit = FALSE; |
| 418 | FX_BOOL bPrintAsImage = FALSE; |
| 419 | FX_BOOL bReverse = FALSE; |
| 420 | FX_BOOL bAnnotations = FALSE; |
| 421 | |
| 422 | int nlength = params.size(); |
| 423 | if (nlength == 9) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 424 | if (params[8].GetType() == CJS_Value::VT_fxobject) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 425 | v8::Local<v8::Object> pObj = params[8].ToV8Object(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 426 | { |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 427 | if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | if (CJS_Object* pJSObj = params[8].ToCJSObject()) { |
| 429 | if (PrintParamsObj* pprintparamsObj = |
| 430 | (PrintParamsObj*)pJSObj->GetEmbedObject()) { |
| 431 | bUI = pprintparamsObj->bUI; |
| 432 | nStart = pprintparamsObj->nStart; |
| 433 | nEnd = pprintparamsObj->nEnd; |
| 434 | bSilent = pprintparamsObj->bSilent; |
| 435 | bShrinkToFit = pprintparamsObj->bShrinkToFit; |
| 436 | bPrintAsImage = pprintparamsObj->bPrintAsImage; |
| 437 | bReverse = pprintparamsObj->bReverse; |
| 438 | bAnnotations = pprintparamsObj->bAnnotations; |
| 439 | } |
| 440 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 441 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | } else { |
| 445 | if (nlength >= 1) |
| 446 | bUI = params[0].ToBool(); |
| 447 | if (nlength >= 2) |
| 448 | nStart = params[1].ToInt(); |
| 449 | if (nlength >= 3) |
| 450 | nEnd = params[2].ToInt(); |
| 451 | if (nlength >= 4) |
| 452 | bSilent = params[3].ToBool(); |
| 453 | if (nlength >= 5) |
| 454 | bShrinkToFit = params[4].ToBool(); |
| 455 | if (nlength >= 6) |
| 456 | bPrintAsImage = params[5].ToBool(); |
| 457 | if (nlength >= 7) |
| 458 | bReverse = params[6].ToBool(); |
| 459 | if (nlength >= 8) |
| 460 | bAnnotations = params[7].ToBool(); |
| 461 | } |
| 462 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { |
| 464 | pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, |
| 465 | bReverse, bAnnotations); |
| 466 | return TRUE; |
| 467 | } |
| 468 | return FALSE; |
| 469 | } |
| 470 | |
| 471 | // removes the specified field from the document. |
| 472 | // comment: |
| 473 | // note: if the filed name is not retional, adobe is dumb for it. |
| 474 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 475 | FX_BOOL Document::removeField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 476 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | CJS_Value& vRet, |
| 478 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 480 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) |
| 481 | return FALSE; |
| 482 | |
| 483 | CJS_Context* pContext = (CJS_Context*)cc; |
| 484 | if (params.size() != 1) { |
| 485 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 486 | return FALSE; |
| 487 | } |
| 488 | |
| 489 | CFX_WideString sFieldName = params[0].ToCFXWideString(); |
| 490 | CPDFSDK_InterForm* pInterForm = |
| 491 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 492 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 493 | std::vector<CPDFSDK_Widget*> widgets; |
| 494 | pInterForm->GetWidgets(sFieldName, &widgets); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 496 | if (widgets.empty()) |
| 497 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 498 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 499 | for (CPDFSDK_Widget* pWidget : widgets) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 500 | CFX_FloatRect rcAnnot = pWidget->GetRect(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 501 | --rcAnnot.left; |
| 502 | --rcAnnot.bottom; |
| 503 | ++rcAnnot.right; |
| 504 | ++rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 506 | CFX_RectArray aRefresh; |
| 507 | aRefresh.Add(rcAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 509 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 510 | ASSERT(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 511 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 512 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); |
| 513 | pPageView->DeleteAnnot(pWidget); |
| 514 | pPageView->UpdateRects(aRefresh); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 515 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 516 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 517 | |
| 518 | return TRUE; |
| 519 | } |
| 520 | |
| 521 | // reset filed values within a document. |
| 522 | // comment: |
| 523 | // note: if the fields names r not rational, aodbe is dumb for it. |
| 524 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 525 | FX_BOOL Document::resetForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 526 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | CJS_Value& vRet, |
| 528 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 530 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 531 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
| 532 | return FALSE; |
| 533 | |
| 534 | CPDFSDK_InterForm* pInterForm = |
| 535 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 536 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 537 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 538 | CJS_Array aName(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 540 | if (params.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | pPDFForm->ResetForm(TRUE); |
| 542 | m_pDocument->SetChangeMark(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 543 | return TRUE; |
| 544 | } |
| 545 | |
| 546 | switch (params[0].GetType()) { |
| 547 | default: |
| 548 | aName.Attach(params[0].ToV8Array()); |
| 549 | break; |
| 550 | case CJS_Value::VT_string: |
| 551 | aName.SetElement(0, params[0]); |
| 552 | break; |
| 553 | } |
| 554 | |
| 555 | std::vector<CPDF_FormField*> aFields; |
| 556 | for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { |
| 557 | CJS_Value valElement(pRuntime); |
| 558 | aName.GetElement(i, valElement); |
| 559 | CFX_WideString swVal = valElement.ToCFXWideString(); |
| 560 | for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 561 | aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 562 | } |
| 563 | |
| 564 | if (!aFields.empty()) { |
| 565 | pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 566 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | return TRUE; |
| 570 | } |
| 571 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 572 | FX_BOOL Document::saveAs(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 573 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 574 | CJS_Value& vRet, |
| 575 | CFX_WideString& sError) { |
| 576 | // Unsafe, not supported. |
| 577 | return TRUE; |
| 578 | } |
| 579 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 580 | FX_BOOL Document::submitForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 581 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 582 | CJS_Value& vRet, |
| 583 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | CJS_Context* pContext = (CJS_Context*)cc; |
| 585 | int nSize = params.size(); |
| 586 | if (nSize < 1) { |
| 587 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 588 | return FALSE; |
| 589 | } |
| 590 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 591 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 592 | v8::Isolate* isolate = pRuntime->GetIsolate(); |
| 593 | CJS_Array aFields(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | CFX_WideString strURL; |
| 595 | FX_BOOL bFDF = TRUE; |
| 596 | FX_BOOL bEmpty = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 597 | |
| 598 | CJS_Value v = params[0]; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 599 | if (v.GetType() == CJS_Value::VT_string) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 600 | strURL = params[0].ToCFXWideString(); |
| 601 | if (nSize > 1) |
| 602 | bFDF = params[1].ToBool(); |
| 603 | if (nSize > 2) |
| 604 | bEmpty = params[2].ToBool(); |
| 605 | if (nSize > 3) |
| 606 | aFields.Attach(params[3].ToV8Array()); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 607 | } else if (v.GetType() == CJS_Value::VT_object) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 608 | v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 609 | v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | if (!pValue.IsEmpty()) |
| 611 | strURL = |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 612 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
| 613 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 614 | pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 615 | bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 616 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 617 | pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 618 | bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 619 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 620 | pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | aFields.Attach( |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 622 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 625 | CPDFSDK_InterForm* pInterForm = |
| 626 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
| 627 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
Tom Sepez | 007e6c0 | 2016-02-26 14:31:56 -0800 | [diff] [blame] | 628 | if (aFields.GetLength() == 0 && bEmpty) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 629 | if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | pRuntime->BeginBlock(); |
| 631 | pInterForm->SubmitForm(strURL, FALSE); |
| 632 | pRuntime->EndBlock(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 633 | } |
| 634 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 637 | std::vector<CPDF_FormField*> fieldObjects; |
| 638 | for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 639 | CJS_Value valName(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | aFields.GetElement(i, valName); |
| 641 | |
| 642 | CFX_WideString sName = valName.ToCFXWideString(); |
| 643 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 644 | for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 645 | CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 646 | if (!bEmpty && pField->GetValue().IsEmpty()) |
| 647 | continue; |
| 648 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 649 | fieldObjects.push_back(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 653 | if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | pRuntime->BeginBlock(); |
| 655 | pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); |
| 656 | pRuntime->EndBlock(); |
| 657 | } |
| 658 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | void Document::AttachDoc(CPDFSDK_Document* pDoc) { |
| 662 | m_pDocument = pDoc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 665 | CPDFSDK_Document* Document::GetReaderDoc() { |
| 666 | return m_pDocument; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 669 | FX_BOOL Document::bookmarkRoot(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | CJS_PropValue& vp, |
| 671 | CFX_WideString& sError) { |
| 672 | return TRUE; |
| 673 | } |
| 674 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 675 | FX_BOOL Document::mailDoc(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 676 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 677 | CJS_Value& vRet, |
| 678 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | FX_BOOL bUI = TRUE; |
| 680 | CFX_WideString cTo = L""; |
| 681 | CFX_WideString cCc = L""; |
| 682 | CFX_WideString cBcc = L""; |
| 683 | CFX_WideString cSubject = L""; |
| 684 | CFX_WideString cMsg = L""; |
| 685 | |
| 686 | if (params.size() >= 1) |
| 687 | bUI = params[0].ToBool(); |
| 688 | if (params.size() >= 2) |
| 689 | cTo = params[1].ToCFXWideString(); |
| 690 | if (params.size() >= 3) |
| 691 | cCc = params[2].ToCFXWideString(); |
| 692 | if (params.size() >= 4) |
| 693 | cBcc = params[3].ToCFXWideString(); |
| 694 | if (params.size() >= 5) |
| 695 | cSubject = params[4].ToCFXWideString(); |
| 696 | if (params.size() >= 6) |
| 697 | cMsg = params[5].ToCFXWideString(); |
| 698 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 699 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 700 | v8::Isolate* isolate = pRuntime->GetIsolate(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 702 | if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 703 | v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 705 | v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 706 | bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 708 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 709 | cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 711 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 712 | cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 713 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 714 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 715 | cBcc = |
| 716 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 718 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | cSubject = |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 720 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 722 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 723 | cMsg = |
| 724 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | pRuntime->BeginBlock(); |
| 728 | CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); |
| 729 | pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), |
| 730 | cBcc.c_str(), cMsg.c_str()); |
| 731 | pRuntime->EndBlock(); |
| 732 | |
| 733 | return TRUE; |
| 734 | } |
| 735 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 736 | FX_BOOL Document::author(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | CJS_PropValue& vp, |
| 738 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 739 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 740 | if (!pDictionary) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 741 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 742 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 744 | vp << pDictionary->GetUnicodeTextBy("Author"); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 745 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 746 | } else { |
| 747 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 748 | return FALSE; |
| 749 | |
| 750 | CFX_WideString csAuthor; |
| 751 | vp >> csAuthor; |
| 752 | pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); |
| 753 | m_pDocument->SetChangeMark(); |
| 754 | return TRUE; |
| 755 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 758 | FX_BOOL Document::info(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | CJS_PropValue& vp, |
| 760 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 761 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | if (!pDictionary) |
| 763 | return FALSE; |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 764 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 765 | CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); |
| 766 | CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); |
| 767 | CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); |
| 768 | CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); |
| 769 | CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); |
| 770 | CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); |
| 771 | CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); |
| 772 | CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); |
| 773 | CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 774 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 775 | v8::Isolate* isolate = GetIsolate(cc); |
| 776 | if (vp.IsGetting()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 777 | CJS_Context* pContext = (CJS_Context*)cc; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 778 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 779 | v8::Local<v8::Object> pObj = |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 780 | FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 781 | FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); |
| 782 | FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); |
| 783 | FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); |
| 784 | FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); |
| 785 | FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); |
| 786 | FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); |
| 787 | FXJS_PutObjectString(isolate, pObj, L"CreationDate", |
| 788 | cwCreationDate.c_str()); |
| 789 | FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); |
| 790 | FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 791 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 792 | // It's to be compatible to non-standard info dictionary. |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 793 | for (const auto& it : *pDictionary) { |
| 794 | const CFX_ByteString& bsKey = it.first; |
| 795 | CPDF_Object* pValueObj = it.second; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 797 | |
| 798 | if (pValueObj->IsString() || pValueObj->IsName()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 799 | FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), |
| 800 | pValueObj->GetUnicodeText().c_str()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 801 | } else if (pValueObj->IsNumber()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 802 | FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), |
| 803 | (float)pValueObj->GetNumber()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 804 | } else if (pValueObj->IsBoolean()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 805 | FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), |
| 806 | (bool)pValueObj->GetInteger()); |
Dan Sinclair | 05d9e93 | 2015-10-20 16:44:57 -0400 | [diff] [blame] | 807 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 808 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | vp << pObj; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | } |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 811 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 814 | FX_BOOL Document::creationDate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 815 | CJS_PropValue& vp, |
| 816 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 817 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 818 | if (!pDictionary) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 819 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | |
| 821 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 822 | vp << pDictionary->GetUnicodeTextBy("CreationDate"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | } else { |
| 824 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 825 | return FALSE; |
| 826 | |
| 827 | CFX_WideString csCreationDate; |
| 828 | vp >> csCreationDate; |
| 829 | pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); |
| 830 | m_pDocument->SetChangeMark(); |
| 831 | } |
| 832 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 835 | FX_BOOL Document::creator(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 836 | CJS_PropValue& vp, |
| 837 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 838 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | if (!pDictionary) |
| 840 | return FALSE; |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 841 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 843 | vp << pDictionary->GetUnicodeTextBy("Creator"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | } else { |
| 845 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 846 | return FALSE; |
| 847 | |
| 848 | CFX_WideString csCreator; |
| 849 | vp >> csCreator; |
| 850 | pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); |
| 851 | m_pDocument->SetChangeMark(); |
| 852 | } |
| 853 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 854 | } |
| 855 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 856 | FX_BOOL Document::delay(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | CJS_PropValue& vp, |
| 858 | CFX_WideString& sError) { |
| 859 | if (vp.IsGetting()) { |
| 860 | vp << m_bDelay; |
| 861 | } else { |
| 862 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 863 | return FALSE; |
| 864 | |
| 865 | vp >> m_bDelay; |
| 866 | if (m_bDelay) { |
| 867 | for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) |
| 868 | delete m_DelayData.GetAt(i); |
| 869 | |
| 870 | m_DelayData.RemoveAll(); |
| 871 | } else { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 872 | CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { |
| 874 | if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 875 | DelayDataToProcess.Add(pData); |
| 876 | m_DelayData.SetAt(i, NULL); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | m_DelayData.RemoveAll(); |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 880 | for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { |
| 881 | CJS_DelayData* pData = DelayDataToProcess.GetAt(i); |
| 882 | Field::DoDelay(m_pDocument, pData); |
| 883 | DelayDataToProcess.SetAt(i, NULL); |
| 884 | delete pData; |
| 885 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | return TRUE; |
| 889 | } |
| 890 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 891 | FX_BOOL Document::keywords(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 892 | CJS_PropValue& vp, |
| 893 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 894 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | if (!pDictionary) |
| 896 | return FALSE; |
| 897 | |
| 898 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 899 | vp << pDictionary->GetUnicodeTextBy("Keywords"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | } else { |
| 901 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 902 | return FALSE; |
| 903 | |
| 904 | CFX_WideString csKeywords; |
| 905 | vp >> csKeywords; |
| 906 | pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); |
| 907 | m_pDocument->SetChangeMark(); |
| 908 | } |
| 909 | return TRUE; |
| 910 | } |
| 911 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 912 | FX_BOOL Document::modDate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | CJS_PropValue& vp, |
| 914 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 915 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | if (!pDictionary) |
| 917 | return FALSE; |
| 918 | |
| 919 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 920 | vp << pDictionary->GetUnicodeTextBy("ModDate"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 921 | } else { |
| 922 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 923 | return FALSE; |
| 924 | |
| 925 | CFX_WideString csmodDate; |
| 926 | vp >> csmodDate; |
| 927 | pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); |
| 928 | m_pDocument->SetChangeMark(); |
| 929 | } |
| 930 | return TRUE; |
| 931 | } |
| 932 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 933 | FX_BOOL Document::producer(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 934 | CJS_PropValue& vp, |
| 935 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 936 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 937 | if (!pDictionary) |
| 938 | return FALSE; |
| 939 | |
| 940 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 941 | vp << pDictionary->GetUnicodeTextBy("Producer"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 942 | } else { |
| 943 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 944 | return FALSE; |
| 945 | |
| 946 | CFX_WideString csproducer; |
| 947 | vp >> csproducer; |
| 948 | pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); |
| 949 | m_pDocument->SetChangeMark(); |
| 950 | } |
| 951 | return TRUE; |
| 952 | } |
| 953 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 954 | FX_BOOL Document::subject(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | CJS_PropValue& vp, |
| 956 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 957 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | if (!pDictionary) |
| 959 | return FALSE; |
| 960 | |
| 961 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 962 | vp << pDictionary->GetUnicodeTextBy("Subject"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 963 | } else { |
| 964 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 965 | return FALSE; |
| 966 | |
| 967 | CFX_WideString cssubject; |
| 968 | vp >> cssubject; |
| 969 | pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); |
| 970 | m_pDocument->SetChangeMark(); |
| 971 | } |
| 972 | return TRUE; |
| 973 | } |
| 974 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 975 | FX_BOOL Document::title(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 976 | CJS_PropValue& vp, |
| 977 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 978 | if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 979 | return FALSE; |
| 980 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 981 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 982 | if (!pDictionary) |
| 983 | return FALSE; |
| 984 | |
| 985 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 986 | vp << pDictionary->GetUnicodeTextBy("Title"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 987 | } else { |
| 988 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 989 | return FALSE; |
| 990 | |
| 991 | CFX_WideString cstitle; |
| 992 | vp >> cstitle; |
| 993 | pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); |
| 994 | m_pDocument->SetChangeMark(); |
| 995 | } |
| 996 | return TRUE; |
| 997 | } |
| 998 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 999 | FX_BOOL Document::numPages(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1000 | CJS_PropValue& vp, |
| 1001 | CFX_WideString& sError) { |
| 1002 | if (vp.IsSetting()) { |
| 1003 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1004 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1005 | return FALSE; |
| 1006 | } |
| 1007 | vp << m_pDocument->GetPageCount(); |
| 1008 | return TRUE; |
| 1009 | } |
| 1010 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1011 | FX_BOOL Document::external(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | CJS_PropValue& vp, |
| 1013 | CFX_WideString& sError) { |
| 1014 | // In Chrome case,should always return true. |
| 1015 | if (vp.IsGetting()) { |
| 1016 | vp << true; |
| 1017 | } |
| 1018 | return TRUE; |
| 1019 | } |
| 1020 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1021 | FX_BOOL Document::filesize(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1022 | CJS_PropValue& vp, |
| 1023 | CFX_WideString& sError) { |
| 1024 | if (vp.IsSetting()) { |
| 1025 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1026 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1027 | return FALSE; |
| 1028 | } |
| 1029 | vp << 0; |
| 1030 | return TRUE; |
| 1031 | } |
| 1032 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1033 | FX_BOOL Document::mouseX(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | CJS_PropValue& vp, |
| 1035 | CFX_WideString& sError) { |
| 1036 | return TRUE; |
| 1037 | } |
| 1038 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1039 | FX_BOOL Document::mouseY(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1040 | CJS_PropValue& vp, |
| 1041 | CFX_WideString& sError) { |
| 1042 | return TRUE; |
| 1043 | } |
| 1044 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1045 | FX_BOOL Document::baseURL(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1046 | CJS_PropValue& vp, |
| 1047 | CFX_WideString& sError) { |
| 1048 | if (vp.IsGetting()) { |
| 1049 | vp << m_cwBaseURL; |
| 1050 | } else { |
| 1051 | vp >> m_cwBaseURL; |
| 1052 | } |
| 1053 | return TRUE; |
| 1054 | } |
| 1055 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1056 | FX_BOOL Document::calculate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1057 | CJS_PropValue& vp, |
| 1058 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | CPDFSDK_InterForm* pInterForm = |
| 1060 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1061 | |
| 1062 | if (vp.IsGetting()) { |
| 1063 | if (pInterForm->IsCalculateEnabled()) |
| 1064 | vp << true; |
| 1065 | else |
| 1066 | vp << false; |
| 1067 | } else { |
| 1068 | bool bCalculate; |
| 1069 | vp >> bCalculate; |
| 1070 | |
| 1071 | pInterForm->EnableCalculate(bCalculate); |
| 1072 | } |
| 1073 | |
| 1074 | return TRUE; |
| 1075 | } |
| 1076 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1077 | FX_BOOL Document::documentFileName(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1078 | CJS_PropValue& vp, |
| 1079 | CFX_WideString& sError) { |
| 1080 | if (vp.IsSetting()) { |
| 1081 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1082 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1083 | return FALSE; |
| 1084 | } |
| 1085 | CFX_WideString wsFilePath = m_pDocument->GetPath(); |
| 1086 | int32_t i = wsFilePath.GetLength() - 1; |
| 1087 | for (; i >= 0; i--) { |
| 1088 | if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1089 | break; |
| 1090 | } |
| 1091 | if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1092 | vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1093 | } else { |
| 1094 | vp << L""; |
| 1095 | } |
| 1096 | return TRUE; |
| 1097 | } |
| 1098 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1099 | FX_BOOL Document::path(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1100 | CJS_PropValue& vp, |
| 1101 | CFX_WideString& sError) { |
| 1102 | if (vp.IsSetting()) { |
| 1103 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1104 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1105 | return FALSE; |
| 1106 | } |
| 1107 | vp << app::SysPathToPDFPath(m_pDocument->GetPath()); |
| 1108 | return TRUE; |
| 1109 | } |
| 1110 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1111 | FX_BOOL Document::pageWindowRect(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1112 | CJS_PropValue& vp, |
| 1113 | CFX_WideString& sError) { |
| 1114 | return TRUE; |
| 1115 | } |
| 1116 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1117 | FX_BOOL Document::layout(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1118 | CJS_PropValue& vp, |
| 1119 | CFX_WideString& sError) { |
| 1120 | return TRUE; |
| 1121 | } |
| 1122 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1123 | FX_BOOL Document::addLink(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1124 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1125 | CJS_Value& vRet, |
| 1126 | CFX_WideString& sError) { |
| 1127 | return TRUE; |
| 1128 | } |
| 1129 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1130 | FX_BOOL Document::closeDoc(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1131 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1132 | CJS_Value& vRet, |
| 1133 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1134 | return TRUE; |
| 1135 | } |
| 1136 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1137 | FX_BOOL Document::getPageBox(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1138 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1139 | CJS_Value& vRet, |
| 1140 | CFX_WideString& sError) { |
| 1141 | return TRUE; |
| 1142 | } |
| 1143 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1144 | FX_BOOL Document::getAnnot(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1145 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1146 | CJS_Value& vRet, |
| 1147 | CFX_WideString& sError) { |
| 1148 | return TRUE; |
| 1149 | } |
| 1150 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1151 | FX_BOOL Document::getAnnots(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1152 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1153 | CJS_Value& vRet, |
| 1154 | CFX_WideString& sError) { |
| 1155 | vRet.SetNull(); |
| 1156 | return TRUE; |
| 1157 | } |
| 1158 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1159 | FX_BOOL Document::getAnnot3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1160 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1161 | CJS_Value& vRet, |
| 1162 | CFX_WideString& sError) { |
| 1163 | vRet.SetNull(); |
| 1164 | return TRUE; |
| 1165 | } |
| 1166 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1167 | FX_BOOL Document::getAnnots3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1168 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1169 | CJS_Value& vRet, |
| 1170 | CFX_WideString& sError) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1171 | vRet = CJS_Value::VT_undefined; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1172 | return TRUE; |
| 1173 | } |
| 1174 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1175 | FX_BOOL Document::getOCGs(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1176 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1177 | CJS_Value& vRet, |
| 1178 | CFX_WideString& sError) { |
| 1179 | return TRUE; |
| 1180 | } |
| 1181 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1182 | FX_BOOL Document::getLinks(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1183 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | CJS_Value& vRet, |
| 1185 | CFX_WideString& sError) { |
| 1186 | return TRUE; |
| 1187 | } |
| 1188 | |
| 1189 | bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| 1190 | return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
| 1191 | rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| 1192 | } |
| 1193 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1194 | FX_BOOL Document::addIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1195 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1196 | CJS_Value& vRet, |
| 1197 | CFX_WideString& sError) { |
| 1198 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1199 | if (params.size() != 2) { |
| 1200 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1201 | return FALSE; |
| 1202 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1203 | CFX_WideString swIconName = params[0].ToCFXWideString(); |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1204 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1205 | if (params[1].GetType() != CJS_Value::VT_object) { |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1206 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1207 | return FALSE; |
| 1208 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1209 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 1210 | v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); |
| 1211 | if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1212 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1213 | return FALSE; |
| 1214 | } |
| 1215 | |
| 1216 | CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); |
| 1217 | if (!pEmbedObj) { |
| 1218 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1219 | return FALSE; |
| 1220 | } |
| 1221 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1222 | m_IconList.push_back(std::unique_ptr<IconElement>( |
| 1223 | new IconElement(swIconName, (Icon*)pEmbedObj))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1224 | return TRUE; |
| 1225 | } |
| 1226 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1227 | FX_BOOL Document::icons(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1228 | CJS_PropValue& vp, |
| 1229 | CFX_WideString& sError) { |
| 1230 | if (vp.IsSetting()) { |
| 1231 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1232 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1233 | return FALSE; |
| 1234 | } |
| 1235 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1236 | if (m_IconList.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1237 | vp.SetNull(); |
| 1238 | return TRUE; |
| 1239 | } |
| 1240 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1241 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1242 | CJS_Array Icons(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1243 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1244 | int i = 0; |
| 1245 | for (const auto& pIconElement : m_IconList) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1246 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1247 | pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1248 | if (pObj.IsEmpty()) |
| 1249 | return FALSE; |
| 1250 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 1251 | CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1252 | if (!pJS_Icon) |
| 1253 | return FALSE; |
| 1254 | |
| 1255 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1256 | if (!pIcon) |
| 1257 | return FALSE; |
| 1258 | |
| 1259 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1260 | pIcon->SetIconName(pIconElement->IconName); |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1261 | Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | vp << Icons; |
| 1265 | return TRUE; |
| 1266 | } |
| 1267 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1268 | FX_BOOL Document::getIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1269 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1270 | CJS_Value& vRet, |
| 1271 | CFX_WideString& sError) { |
| 1272 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1273 | if (params.size() != 1) { |
| 1274 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1275 | return FALSE; |
| 1276 | } |
| 1277 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1278 | if (m_IconList.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1279 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1280 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1281 | CFX_WideString swIconName = params[0].ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1282 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1283 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1284 | for (const auto& pIconElement : m_IconList) { |
| 1285 | if (pIconElement->IconName == swIconName) { |
| 1286 | Icon* pRetIcon = pIconElement->IconStream; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1287 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1288 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1289 | pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1290 | if (pObj.IsEmpty()) |
| 1291 | return FALSE; |
| 1292 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 1293 | CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1294 | if (!pJS_Icon) |
| 1295 | return FALSE; |
| 1296 | |
| 1297 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1298 | if (!pIcon) |
| 1299 | return FALSE; |
| 1300 | |
| 1301 | pIcon->SetIconName(swIconName); |
| 1302 | pIcon->SetStream(pRetIcon->GetStream()); |
| 1303 | vRet = pJS_Icon; |
| 1304 | return TRUE; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | return FALSE; |
| 1309 | } |
| 1310 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1311 | FX_BOOL Document::removeIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1312 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1313 | CJS_Value& vRet, |
| 1314 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1315 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1316 | return TRUE; |
| 1317 | } |
| 1318 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1319 | FX_BOOL Document::createDataObject(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1320 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1321 | CJS_Value& vRet, |
| 1322 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1323 | // Unsafe, not implemented. |
| 1324 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1327 | FX_BOOL Document::media(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1328 | CJS_PropValue& vp, |
| 1329 | CFX_WideString& sError) { |
| 1330 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1333 | FX_BOOL Document::calculateNow(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1334 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1335 | CJS_Value& vRet, |
| 1336 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1337 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1338 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1339 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1340 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1341 | |
| 1342 | CPDFSDK_InterForm* pInterForm = |
| 1343 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1344 | pInterForm->OnCalculate(); |
| 1345 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1348 | FX_BOOL Document::Collab(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1349 | CJS_PropValue& vp, |
| 1350 | CFX_WideString& sError) { |
| 1351 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1354 | FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1355 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1356 | CJS_Value& vRet, |
| 1357 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1358 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1359 | return FALSE; |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 1360 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 1361 | int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; |
| 1362 | int nWordNo = params.size() > 1 ? params[1].ToInt() : 0; |
| 1363 | bool bStrip = params.size() > 2 ? params[2].ToBool() : true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1364 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1365 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1366 | if (!pDocument) |
| 1367 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1368 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1369 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1370 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1371 | sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1372 | return FALSE; |
| 1373 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1374 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1375 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1376 | if (!pPageDict) |
| 1377 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1378 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1379 | CPDF_Page page; |
| 1380 | page.Load(pDocument, pPageDict); |
Tom Sepez | b5b2a91 | 2016-01-21 11:04:37 -0800 | [diff] [blame] | 1381 | page.ParseContent(nullptr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1382 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1383 | int nWords = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1384 | CFX_WideString swRet; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1385 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1386 | if (pPageObj->IsText()) { |
| 1387 | CPDF_TextObject* pTextObj = pPageObj->AsText(); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1388 | int nObjWords = CountWords(pTextObj); |
| 1389 | if (nWords + nObjWords >= nWordNo) { |
| 1390 | swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1391 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1392 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1393 | nWords += nObjWords; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1394 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1395 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1396 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1397 | if (bStrip) { |
| 1398 | swRet.TrimLeft(); |
| 1399 | swRet.TrimRight(); |
| 1400 | } |
| 1401 | |
| 1402 | vRet = swRet.c_str(); |
| 1403 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1406 | FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1407 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | CJS_Value& vRet, |
| 1409 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1410 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1411 | return FALSE; |
| 1412 | |
| 1413 | return FALSE; |
| 1414 | } |
| 1415 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1416 | FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1417 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1418 | CJS_Value& vRet, |
| 1419 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1420 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1421 | return FALSE; |
| 1422 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 1423 | int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1424 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1425 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1426 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1427 | sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1428 | return FALSE; |
| 1429 | } |
| 1430 | |
| 1431 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1432 | if (!pPageDict) |
| 1433 | return FALSE; |
| 1434 | |
| 1435 | CPDF_Page page; |
| 1436 | page.Load(pDocument, pPageDict); |
Tom Sepez | b5b2a91 | 2016-01-21 11:04:37 -0800 | [diff] [blame] | 1437 | page.ParseContent(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1438 | |
| 1439 | int nWords = 0; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1440 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1441 | if (pPageObj->IsText()) |
| 1442 | nWords += CountWords(pPageObj->AsText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | vRet = nWords; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1446 | return TRUE; |
| 1447 | } |
| 1448 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1449 | FX_BOOL Document::getPrintParams(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1450 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1451 | CJS_Value& vRet, |
| 1452 | CFX_WideString& sError) { |
| 1453 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1454 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1455 | v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1456 | pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1457 | |
| 1458 | // Not implemented yet. |
| 1459 | |
| 1460 | vRet = pRetObj; |
| 1461 | return TRUE; |
| 1462 | } |
| 1463 | |
| 1464 | #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1465 | |
| 1466 | int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1467 | if (!pTextObj) |
| 1468 | return 0; |
| 1469 | |
| 1470 | int nWords = 0; |
| 1471 | |
| 1472 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1473 | if (!pFont) |
| 1474 | return 0; |
| 1475 | |
| 1476 | FX_BOOL bIsLatin = FALSE; |
| 1477 | |
| 1478 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
| 1479 | FX_DWORD charcode = -1; |
| 1480 | FX_FLOAT kerning; |
| 1481 | |
| 1482 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1483 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1484 | |
| 1485 | FX_WORD unicode = 0; |
| 1486 | if (swUnicode.GetLength() > 0) |
| 1487 | unicode = swUnicode[0]; |
| 1488 | |
| 1489 | if (ISLATINWORD(unicode) && bIsLatin) |
| 1490 | continue; |
| 1491 | |
| 1492 | bIsLatin = ISLATINWORD(unicode); |
| 1493 | if (unicode != 0x20) |
| 1494 | nWords++; |
| 1495 | } |
| 1496 | |
| 1497 | return nWords; |
| 1498 | } |
| 1499 | |
| 1500 | CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1501 | int nWordIndex) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1502 | CFX_WideString swRet; |
| 1503 | |
| 1504 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1505 | if (!pFont) |
| 1506 | return L""; |
| 1507 | |
| 1508 | int nWords = 0; |
| 1509 | FX_BOOL bIsLatin = FALSE; |
| 1510 | |
| 1511 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
| 1512 | FX_DWORD charcode = -1; |
| 1513 | FX_FLOAT kerning; |
| 1514 | |
| 1515 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1516 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1517 | |
| 1518 | FX_WORD unicode = 0; |
| 1519 | if (swUnicode.GetLength() > 0) |
| 1520 | unicode = swUnicode[0]; |
| 1521 | |
| 1522 | if (ISLATINWORD(unicode) && bIsLatin) { |
| 1523 | } else { |
| 1524 | bIsLatin = ISLATINWORD(unicode); |
| 1525 | if (unicode != 0x20) |
| 1526 | nWords++; |
| 1527 | } |
| 1528 | |
| 1529 | if (nWords - 1 == nWordIndex) |
| 1530 | swRet += unicode; |
| 1531 | } |
| 1532 | |
| 1533 | return swRet; |
| 1534 | } |
| 1535 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1536 | FX_BOOL Document::zoom(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1537 | CJS_PropValue& vp, |
| 1538 | CFX_WideString& sError) { |
| 1539 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /** |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1543 | (none, NoVary) |
| 1544 | (fitP, FitPage) |
| 1545 | (fitW, FitWidth) |
| 1546 | (fitH, FitHeight) |
| 1547 | (fitV, FitVisibleWidth) |
| 1548 | (pref, Preferred) |
| 1549 | (refW, ReflowWidth) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1550 | */ |
| 1551 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1552 | FX_BOOL Document::zoomType(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1553 | CJS_PropValue& vp, |
| 1554 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1555 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1558 | FX_BOOL Document::deletePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1559 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1560 | CJS_Value& vRet, |
| 1561 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1562 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1563 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1564 | } |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1565 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1566 | FX_BOOL Document::extractPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1567 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1568 | CJS_Value& vRet, |
| 1569 | CFX_WideString& sError) { |
| 1570 | // Unsafe, not supported. |
| 1571 | return TRUE; |
| 1572 | } |
| 1573 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1574 | FX_BOOL Document::insertPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1575 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1576 | CJS_Value& vRet, |
| 1577 | CFX_WideString& sError) { |
| 1578 | // Unsafe, not supported. |
| 1579 | return TRUE; |
| 1580 | } |
| 1581 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1582 | FX_BOOL Document::replacePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1583 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1584 | CJS_Value& vRet, |
| 1585 | CFX_WideString& sError) { |
| 1586 | // Unsafe, not supported. |
| 1587 | return TRUE; |
| 1588 | } |
| 1589 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1590 | FX_BOOL Document::getURL(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1591 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1592 | CJS_Value& vRet, |
| 1593 | CFX_WideString& sError) { |
| 1594 | // Unsafe, not supported. |
| 1595 | return TRUE; |
| 1596 | } |
| 1597 | |
| 1598 | void Document::AddDelayData(CJS_DelayData* pData) { |
| 1599 | m_DelayData.Add(pData); |
| 1600 | } |
| 1601 | |
| 1602 | void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1603 | int nControlIndex) { |
| 1604 | CFX_DWordArray DelArray; |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1605 | CFX_ArrayTemplate<CJS_DelayData*> DelayDataForFieldAndControlIndex; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1606 | |
| 1607 | for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { |
| 1608 | if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { |
| 1609 | if (pData->sFieldName == sFieldName && |
| 1610 | pData->nControlIndex == nControlIndex) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1611 | DelayDataForFieldAndControlIndex.Add(pData); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1612 | m_DelayData.SetAt(i, NULL); |
| 1613 | DelArray.Add(i); |
| 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | |
| 1618 | for (int j = DelArray.GetSize() - 1; j >= 0; j--) { |
| 1619 | m_DelayData.RemoveAt(DelArray[j]); |
| 1620 | } |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1621 | |
| 1622 | for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; |
| 1623 | i++) { |
| 1624 | CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); |
| 1625 | Field::DoDelay(m_pDocument, pData); |
| 1626 | DelayDataForFieldAndControlIndex.SetAt(i, NULL); |
| 1627 | delete pData; |
| 1628 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1631 | CJS_Document* Document::GetCJSDoc() const { |
| 1632 | return static_cast<CJS_Document*>(m_pJSObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1633 | } |