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