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), |
| 150 | m_isolate(NULL), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | m_pDocument(NULL), |
| 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 | |
| 382 | CPDFSDK_InterForm* pInterForm = |
| 383 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | CFX_ByteTextBuf textBuf; |
| 385 | if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 386 | return FALSE; |
| 387 | |
| 388 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | CPDFDoc_Environment* pEnv = pContext->GetReaderApp(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 391 | |
| 392 | pRuntime->BeginBlock(); |
| 393 | pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 394 | cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), |
| 395 | cMsg.c_str()); |
| 396 | pRuntime->EndBlock(); |
| 397 | return TRUE; |
| 398 | } |
| 399 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 400 | FX_BOOL Document::print(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 401 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | CJS_Value& vRet, |
| 403 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | FX_BOOL bUI = TRUE; |
| 405 | int nStart = 0; |
| 406 | int nEnd = 0; |
| 407 | FX_BOOL bSilent = FALSE; |
| 408 | FX_BOOL bShrinkToFit = FALSE; |
| 409 | FX_BOOL bPrintAsImage = FALSE; |
| 410 | FX_BOOL bReverse = FALSE; |
| 411 | FX_BOOL bAnnotations = FALSE; |
| 412 | |
| 413 | int nlength = params.size(); |
| 414 | if (nlength == 9) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 415 | if (params[8].GetType() == CJS_Value::VT_fxobject) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 416 | v8::Local<v8::Object> pObj = params[8].ToV8Object(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 417 | { |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 418 | if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | if (CJS_Object* pJSObj = params[8].ToCJSObject()) { |
| 420 | if (PrintParamsObj* pprintparamsObj = |
| 421 | (PrintParamsObj*)pJSObj->GetEmbedObject()) { |
| 422 | bUI = pprintparamsObj->bUI; |
| 423 | nStart = pprintparamsObj->nStart; |
| 424 | nEnd = pprintparamsObj->nEnd; |
| 425 | bSilent = pprintparamsObj->bSilent; |
| 426 | bShrinkToFit = pprintparamsObj->bShrinkToFit; |
| 427 | bPrintAsImage = pprintparamsObj->bPrintAsImage; |
| 428 | bReverse = pprintparamsObj->bReverse; |
| 429 | bAnnotations = pprintparamsObj->bAnnotations; |
| 430 | } |
| 431 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 432 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | } else { |
| 436 | if (nlength >= 1) |
| 437 | bUI = params[0].ToBool(); |
| 438 | if (nlength >= 2) |
| 439 | nStart = params[1].ToInt(); |
| 440 | if (nlength >= 3) |
| 441 | nEnd = params[2].ToInt(); |
| 442 | if (nlength >= 4) |
| 443 | bSilent = params[3].ToBool(); |
| 444 | if (nlength >= 5) |
| 445 | bShrinkToFit = params[4].ToBool(); |
| 446 | if (nlength >= 6) |
| 447 | bPrintAsImage = params[5].ToBool(); |
| 448 | if (nlength >= 7) |
| 449 | bReverse = params[6].ToBool(); |
| 450 | if (nlength >= 8) |
| 451 | bAnnotations = params[7].ToBool(); |
| 452 | } |
| 453 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv()) { |
| 455 | pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, |
| 456 | bReverse, bAnnotations); |
| 457 | return TRUE; |
| 458 | } |
| 459 | return FALSE; |
| 460 | } |
| 461 | |
| 462 | // removes the specified field from the document. |
| 463 | // comment: |
| 464 | // note: if the filed name is not retional, adobe is dumb for it. |
| 465 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 466 | FX_BOOL Document::removeField(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 467 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | CJS_Value& vRet, |
| 469 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 471 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) |
| 472 | return FALSE; |
| 473 | |
| 474 | CJS_Context* pContext = (CJS_Context*)cc; |
| 475 | if (params.size() != 1) { |
| 476 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 477 | return FALSE; |
| 478 | } |
| 479 | |
| 480 | CFX_WideString sFieldName = params[0].ToCFXWideString(); |
| 481 | CPDFSDK_InterForm* pInterForm = |
| 482 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
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 | std::vector<CPDFSDK_Widget*> widgets; |
| 485 | pInterForm->GetWidgets(sFieldName, &widgets); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 487 | if (widgets.empty()) |
| 488 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 489 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 490 | for (CPDFSDK_Widget* pWidget : widgets) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 491 | CFX_FloatRect rcAnnot = pWidget->GetRect(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 492 | --rcAnnot.left; |
| 493 | --rcAnnot.bottom; |
| 494 | ++rcAnnot.right; |
| 495 | ++rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 497 | CFX_RectArray aRefresh; |
| 498 | aRefresh.Add(rcAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 500 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 501 | ASSERT(pPage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 502 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 503 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); |
| 504 | pPageView->DeleteAnnot(pWidget); |
| 505 | pPageView->UpdateRects(aRefresh); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 507 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | |
| 509 | return TRUE; |
| 510 | } |
| 511 | |
| 512 | // reset filed values within a document. |
| 513 | // comment: |
| 514 | // note: if the fields names r not rational, aodbe is dumb for it. |
| 515 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 516 | FX_BOOL Document::resetForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 517 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 518 | CJS_Value& vRet, |
| 519 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || |
| 521 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 522 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
| 523 | return FALSE; |
| 524 | |
| 525 | CPDFSDK_InterForm* pInterForm = |
| 526 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 528 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 529 | CJS_Array aName(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 530 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 531 | if (params.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | pPDFForm->ResetForm(TRUE); |
| 533 | m_pDocument->SetChangeMark(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 534 | return TRUE; |
| 535 | } |
| 536 | |
| 537 | switch (params[0].GetType()) { |
| 538 | default: |
| 539 | aName.Attach(params[0].ToV8Array()); |
| 540 | break; |
| 541 | case CJS_Value::VT_string: |
| 542 | aName.SetElement(0, params[0]); |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | std::vector<CPDF_FormField*> aFields; |
| 547 | for (int i = 0, isz = aName.GetLength(); i < isz; ++i) { |
| 548 | CJS_Value valElement(pRuntime); |
| 549 | aName.GetElement(i, valElement); |
| 550 | CFX_WideString swVal = valElement.ToCFXWideString(); |
| 551 | for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 552 | aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 553 | } |
| 554 | |
| 555 | if (!aFields.empty()) { |
| 556 | pPDFForm->ResetForm(aFields, TRUE, TRUE); |
| 557 | m_pDocument->SetChangeMark(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | return TRUE; |
| 561 | } |
| 562 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 563 | FX_BOOL Document::saveAs(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 564 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | CJS_Value& vRet, |
| 566 | CFX_WideString& sError) { |
| 567 | // Unsafe, not supported. |
| 568 | return TRUE; |
| 569 | } |
| 570 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 571 | FX_BOOL Document::submitForm(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 572 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 573 | CJS_Value& vRet, |
| 574 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 575 | CJS_Context* pContext = (CJS_Context*)cc; |
| 576 | int nSize = params.size(); |
| 577 | if (nSize < 1) { |
| 578 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 579 | return FALSE; |
| 580 | } |
| 581 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 582 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 583 | v8::Isolate* isolate = pRuntime->GetIsolate(); |
| 584 | CJS_Array aFields(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | CFX_WideString strURL; |
| 586 | FX_BOOL bFDF = TRUE; |
| 587 | FX_BOOL bEmpty = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 588 | |
| 589 | CJS_Value v = params[0]; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 590 | if (v.GetType() == CJS_Value::VT_string) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 591 | strURL = params[0].ToCFXWideString(); |
| 592 | if (nSize > 1) |
| 593 | bFDF = params[1].ToBool(); |
| 594 | if (nSize > 2) |
| 595 | bEmpty = params[2].ToBool(); |
| 596 | if (nSize > 3) |
| 597 | aFields.Attach(params[3].ToV8Array()); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 598 | } else if (v.GetType() == CJS_Value::VT_object) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 599 | v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 600 | v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"cURL"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | if (!pValue.IsEmpty()) |
| 602 | strURL = |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 603 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
| 604 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 605 | pValue = FXJS_GetObjectElement(isolate, pObj, L"bFDF"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 606 | bFDF = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 607 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 608 | pValue = FXJS_GetObjectElement(isolate, pObj, L"bEmpty"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 609 | bEmpty = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool(); |
| 610 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 611 | pValue = FXJS_GetObjectElement(isolate, pObj, L"aFields"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | aFields.Attach( |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 613 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 616 | CPDFSDK_InterForm* pInterForm = |
| 617 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
| 618 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
Tom Sepez | 007e6c0 | 2016-02-26 14:31:56 -0800 | [diff] [blame] | 619 | if (aFields.GetLength() == 0 && bEmpty) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 620 | if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | pRuntime->BeginBlock(); |
| 622 | pInterForm->SubmitForm(strURL, FALSE); |
| 623 | pRuntime->EndBlock(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 624 | } |
| 625 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 628 | std::vector<CPDF_FormField*> fieldObjects; |
| 629 | for (int i = 0, sz = aFields.GetLength(); i < sz; ++i) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 630 | CJS_Value valName(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | aFields.GetElement(i, valName); |
| 632 | |
| 633 | CFX_WideString sName = valName.ToCFXWideString(); |
| 634 | CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 635 | for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 636 | CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 637 | if (!bEmpty && pField->GetValue().IsEmpty()) |
| 638 | continue; |
| 639 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 640 | fieldObjects.push_back(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 644 | if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | pRuntime->BeginBlock(); |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 646 | pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | pRuntime->EndBlock(); |
| 648 | } |
| 649 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 652 | void Document::AttachDoc(CPDFSDK_Document* pDoc) { |
| 653 | m_pDocument = pDoc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | CPDFSDK_Document* Document::GetReaderDoc() { |
| 657 | return m_pDocument; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 660 | FX_BOOL Document::bookmarkRoot(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 661 | CJS_PropValue& vp, |
| 662 | CFX_WideString& sError) { |
| 663 | return TRUE; |
| 664 | } |
| 665 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 666 | FX_BOOL Document::mailDoc(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 667 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | CJS_Value& vRet, |
| 669 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | FX_BOOL bUI = TRUE; |
| 671 | CFX_WideString cTo = L""; |
| 672 | CFX_WideString cCc = L""; |
| 673 | CFX_WideString cBcc = L""; |
| 674 | CFX_WideString cSubject = L""; |
| 675 | CFX_WideString cMsg = L""; |
| 676 | |
| 677 | if (params.size() >= 1) |
| 678 | bUI = params[0].ToBool(); |
| 679 | if (params.size() >= 2) |
| 680 | cTo = params[1].ToCFXWideString(); |
| 681 | if (params.size() >= 3) |
| 682 | cCc = params[2].ToCFXWideString(); |
| 683 | if (params.size() >= 4) |
| 684 | cBcc = params[3].ToCFXWideString(); |
| 685 | if (params.size() >= 5) |
| 686 | cSubject = params[4].ToCFXWideString(); |
| 687 | if (params.size() >= 6) |
| 688 | cMsg = params[5].ToCFXWideString(); |
| 689 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 690 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 691 | v8::Isolate* isolate = pRuntime->GetIsolate(); |
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 | if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 694 | v8::Local<v8::Object> pObj = params[0].ToV8Object(); |
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 | v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 697 | bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToInt(); |
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"cTo"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 700 | cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 702 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 703 | cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 705 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 706 | cBcc = |
| 707 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 709 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | cSubject = |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 711 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 712 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 713 | pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg"); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 714 | cMsg = |
| 715 | CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | pRuntime->BeginBlock(); |
| 719 | CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); |
| 720 | pEnv->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), |
| 721 | cBcc.c_str(), cMsg.c_str()); |
| 722 | pRuntime->EndBlock(); |
| 723 | |
| 724 | return TRUE; |
| 725 | } |
| 726 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 727 | FX_BOOL Document::author(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 728 | CJS_PropValue& vp, |
| 729 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 730 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 731 | if (!pDictionary) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 732 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 733 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 734 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 735 | vp << pDictionary->GetUnicodeTextBy("Author"); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 736 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | } else { |
| 738 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 739 | return FALSE; |
| 740 | |
| 741 | CFX_WideString csAuthor; |
| 742 | vp >> csAuthor; |
| 743 | pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor)); |
| 744 | m_pDocument->SetChangeMark(); |
| 745 | return TRUE; |
| 746 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 749 | FX_BOOL Document::info(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | CJS_PropValue& vp, |
| 751 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 752 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 753 | if (!pDictionary) |
| 754 | return FALSE; |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 755 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 756 | CFX_WideString cwAuthor = pDictionary->GetUnicodeTextBy("Author"); |
| 757 | CFX_WideString cwTitle = pDictionary->GetUnicodeTextBy("Title"); |
| 758 | CFX_WideString cwSubject = pDictionary->GetUnicodeTextBy("Subject"); |
| 759 | CFX_WideString cwKeywords = pDictionary->GetUnicodeTextBy("Keywords"); |
| 760 | CFX_WideString cwCreator = pDictionary->GetUnicodeTextBy("Creator"); |
| 761 | CFX_WideString cwProducer = pDictionary->GetUnicodeTextBy("Producer"); |
| 762 | CFX_WideString cwCreationDate = pDictionary->GetUnicodeTextBy("CreationDate"); |
| 763 | CFX_WideString cwModDate = pDictionary->GetUnicodeTextBy("ModDate"); |
| 764 | CFX_WideString cwTrapped = pDictionary->GetUnicodeTextBy("Trapped"); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 765 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | v8::Isolate* isolate = GetIsolate(cc); |
| 767 | if (vp.IsGetting()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 768 | CJS_Context* pContext = (CJS_Context*)cc; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 769 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | 808a99e | 2015-09-10 12:28:37 -0700 | [diff] [blame] | 770 | v8::Local<v8::Object> pObj = |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 771 | FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 772 | FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); |
| 773 | FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); |
| 774 | FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); |
| 775 | FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); |
| 776 | FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); |
| 777 | FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); |
| 778 | FXJS_PutObjectString(isolate, pObj, L"CreationDate", |
| 779 | cwCreationDate.c_str()); |
| 780 | FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); |
| 781 | FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 782 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 783 | // It's to be compatible to non-standard info dictionary. |
Oliver Chang | 3f1c71f | 2016-01-11 08:45:31 -0800 | [diff] [blame] | 784 | for (const auto& it : *pDictionary) { |
| 785 | const CFX_ByteString& bsKey = it.first; |
| 786 | CPDF_Object* pValueObj = it.second; |
tsepez | 6fe7d21 | 2016-04-06 10:51:14 -0700 | [diff] [blame] | 787 | CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsByteStringC()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 788 | if (pValueObj->IsString() || pValueObj->IsName()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 789 | FXJS_PutObjectString(isolate, pObj, wsKey.c_str(), |
| 790 | pValueObj->GetUnicodeText().c_str()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 791 | } else if (pValueObj->IsNumber()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 792 | FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(), |
| 793 | (float)pValueObj->GetNumber()); |
Dan Sinclair | 710c909 | 2015-10-21 15:46:10 -0400 | [diff] [blame] | 794 | } else if (pValueObj->IsBoolean()) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 795 | FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 796 | !!pValueObj->GetInteger()); |
Dan Sinclair | 05d9e93 | 2015-10-20 16:44:57 -0400 | [diff] [blame] | 797 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 798 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 799 | vp << pObj; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | } |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 801 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 804 | FX_BOOL Document::creationDate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 805 | CJS_PropValue& vp, |
| 806 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 807 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 808 | if (!pDictionary) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 809 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 810 | |
| 811 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 812 | vp << pDictionary->GetUnicodeTextBy("CreationDate"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | } else { |
| 814 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 815 | return FALSE; |
| 816 | |
| 817 | CFX_WideString csCreationDate; |
| 818 | vp >> csCreationDate; |
| 819 | pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate)); |
| 820 | m_pDocument->SetChangeMark(); |
| 821 | } |
| 822 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 825 | FX_BOOL Document::creator(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 826 | CJS_PropValue& vp, |
| 827 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 828 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 829 | if (!pDictionary) |
| 830 | return FALSE; |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 831 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 832 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 833 | vp << pDictionary->GetUnicodeTextBy("Creator"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | } else { |
| 835 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 836 | return FALSE; |
| 837 | |
| 838 | CFX_WideString csCreator; |
| 839 | vp >> csCreator; |
| 840 | pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator)); |
| 841 | m_pDocument->SetChangeMark(); |
| 842 | } |
| 843 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 846 | FX_BOOL Document::delay(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | CJS_PropValue& vp, |
| 848 | CFX_WideString& sError) { |
| 849 | if (vp.IsGetting()) { |
| 850 | vp << m_bDelay; |
| 851 | } else { |
| 852 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 853 | return FALSE; |
| 854 | |
| 855 | vp >> m_bDelay; |
| 856 | if (m_bDelay) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 857 | m_DelayData.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | } else { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 859 | std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
| 860 | DelayDataToProcess.swap(m_DelayData); |
| 861 | for (const auto& pData : DelayDataToProcess) |
| 862 | Field::DoDelay(m_pDocument, pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | return TRUE; |
| 866 | } |
| 867 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 868 | FX_BOOL Document::keywords(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 869 | CJS_PropValue& vp, |
| 870 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 871 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | if (!pDictionary) |
| 873 | return FALSE; |
| 874 | |
| 875 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 876 | vp << pDictionary->GetUnicodeTextBy("Keywords"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | } else { |
| 878 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 879 | return FALSE; |
| 880 | |
| 881 | CFX_WideString csKeywords; |
| 882 | vp >> csKeywords; |
| 883 | pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords)); |
| 884 | m_pDocument->SetChangeMark(); |
| 885 | } |
| 886 | return TRUE; |
| 887 | } |
| 888 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 889 | FX_BOOL Document::modDate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | CJS_PropValue& vp, |
| 891 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 892 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | if (!pDictionary) |
| 894 | return FALSE; |
| 895 | |
| 896 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 897 | vp << pDictionary->GetUnicodeTextBy("ModDate"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 898 | } else { |
| 899 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 900 | return FALSE; |
| 901 | |
| 902 | CFX_WideString csmodDate; |
| 903 | vp >> csmodDate; |
| 904 | pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate)); |
| 905 | m_pDocument->SetChangeMark(); |
| 906 | } |
| 907 | return TRUE; |
| 908 | } |
| 909 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 910 | FX_BOOL Document::producer(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | CJS_PropValue& vp, |
| 912 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 913 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | if (!pDictionary) |
| 915 | return FALSE; |
| 916 | |
| 917 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 918 | vp << pDictionary->GetUnicodeTextBy("Producer"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | } else { |
| 920 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 921 | return FALSE; |
| 922 | |
| 923 | CFX_WideString csproducer; |
| 924 | vp >> csproducer; |
| 925 | pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer)); |
| 926 | m_pDocument->SetChangeMark(); |
| 927 | } |
| 928 | return TRUE; |
| 929 | } |
| 930 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 931 | FX_BOOL Document::subject(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 932 | CJS_PropValue& vp, |
| 933 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 934 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 935 | if (!pDictionary) |
| 936 | return FALSE; |
| 937 | |
| 938 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 939 | vp << pDictionary->GetUnicodeTextBy("Subject"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 940 | } else { |
| 941 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 942 | return FALSE; |
| 943 | |
| 944 | CFX_WideString cssubject; |
| 945 | vp >> cssubject; |
| 946 | pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject)); |
| 947 | m_pDocument->SetChangeMark(); |
| 948 | } |
| 949 | return TRUE; |
| 950 | } |
| 951 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 952 | FX_BOOL Document::title(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 953 | CJS_PropValue& vp, |
| 954 | CFX_WideString& sError) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 955 | if (!m_pDocument || !m_pDocument->GetUnderlyingDocument()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 956 | return FALSE; |
| 957 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 958 | CPDF_Dictionary* pDictionary = m_pDocument->GetPDFDocument()->GetInfo(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 959 | if (!pDictionary) |
| 960 | return FALSE; |
| 961 | |
| 962 | if (vp.IsGetting()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 963 | vp << pDictionary->GetUnicodeTextBy("Title"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 964 | } else { |
| 965 | if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) |
| 966 | return FALSE; |
| 967 | |
| 968 | CFX_WideString cstitle; |
| 969 | vp >> cstitle; |
| 970 | pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); |
| 971 | m_pDocument->SetChangeMark(); |
| 972 | } |
| 973 | return TRUE; |
| 974 | } |
| 975 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 976 | FX_BOOL Document::numPages(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | CJS_PropValue& vp, |
| 978 | CFX_WideString& sError) { |
| 979 | if (vp.IsSetting()) { |
| 980 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 981 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 982 | return FALSE; |
| 983 | } |
| 984 | vp << m_pDocument->GetPageCount(); |
| 985 | return TRUE; |
| 986 | } |
| 987 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 988 | FX_BOOL Document::external(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 989 | CJS_PropValue& vp, |
| 990 | CFX_WideString& sError) { |
| 991 | // In Chrome case,should always return true. |
| 992 | if (vp.IsGetting()) { |
| 993 | vp << true; |
| 994 | } |
| 995 | return TRUE; |
| 996 | } |
| 997 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 998 | FX_BOOL Document::filesize(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 999 | CJS_PropValue& vp, |
| 1000 | CFX_WideString& sError) { |
| 1001 | if (vp.IsSetting()) { |
| 1002 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1003 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1004 | return FALSE; |
| 1005 | } |
| 1006 | vp << 0; |
| 1007 | return TRUE; |
| 1008 | } |
| 1009 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1010 | FX_BOOL Document::mouseX(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | CJS_PropValue& vp, |
| 1012 | CFX_WideString& sError) { |
| 1013 | return TRUE; |
| 1014 | } |
| 1015 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1016 | FX_BOOL Document::mouseY(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1017 | CJS_PropValue& vp, |
| 1018 | CFX_WideString& sError) { |
| 1019 | return TRUE; |
| 1020 | } |
| 1021 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1022 | FX_BOOL Document::baseURL(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1023 | CJS_PropValue& vp, |
| 1024 | CFX_WideString& sError) { |
| 1025 | if (vp.IsGetting()) { |
| 1026 | vp << m_cwBaseURL; |
| 1027 | } else { |
| 1028 | vp >> m_cwBaseURL; |
| 1029 | } |
| 1030 | return TRUE; |
| 1031 | } |
| 1032 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1033 | FX_BOOL Document::calculate(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | CJS_PropValue& vp, |
| 1035 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1036 | CPDFSDK_InterForm* pInterForm = |
| 1037 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1038 | |
| 1039 | if (vp.IsGetting()) { |
| 1040 | if (pInterForm->IsCalculateEnabled()) |
| 1041 | vp << true; |
| 1042 | else |
| 1043 | vp << false; |
| 1044 | } else { |
| 1045 | bool bCalculate; |
| 1046 | vp >> bCalculate; |
| 1047 | |
| 1048 | pInterForm->EnableCalculate(bCalculate); |
| 1049 | } |
| 1050 | |
| 1051 | return TRUE; |
| 1052 | } |
| 1053 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1054 | FX_BOOL Document::documentFileName(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1055 | CJS_PropValue& vp, |
| 1056 | CFX_WideString& sError) { |
| 1057 | if (vp.IsSetting()) { |
| 1058 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1059 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1060 | return FALSE; |
| 1061 | } |
| 1062 | CFX_WideString wsFilePath = m_pDocument->GetPath(); |
| 1063 | int32_t i = wsFilePath.GetLength() - 1; |
| 1064 | for (; i >= 0; i--) { |
| 1065 | if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1066 | break; |
| 1067 | } |
| 1068 | if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1069 | vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1070 | } else { |
| 1071 | vp << L""; |
| 1072 | } |
| 1073 | return TRUE; |
| 1074 | } |
| 1075 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1076 | FX_BOOL Document::path(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1077 | CJS_PropValue& vp, |
| 1078 | CFX_WideString& sError) { |
| 1079 | if (vp.IsSetting()) { |
| 1080 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1081 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1082 | return FALSE; |
| 1083 | } |
| 1084 | vp << app::SysPathToPDFPath(m_pDocument->GetPath()); |
| 1085 | return TRUE; |
| 1086 | } |
| 1087 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1088 | FX_BOOL Document::pageWindowRect(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1089 | CJS_PropValue& vp, |
| 1090 | CFX_WideString& sError) { |
| 1091 | return TRUE; |
| 1092 | } |
| 1093 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1094 | FX_BOOL Document::layout(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1095 | CJS_PropValue& vp, |
| 1096 | CFX_WideString& sError) { |
| 1097 | return TRUE; |
| 1098 | } |
| 1099 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1100 | FX_BOOL Document::addLink(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1101 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1102 | CJS_Value& vRet, |
| 1103 | CFX_WideString& sError) { |
| 1104 | return TRUE; |
| 1105 | } |
| 1106 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1107 | FX_BOOL Document::closeDoc(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1108 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1109 | CJS_Value& vRet, |
| 1110 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1111 | return TRUE; |
| 1112 | } |
| 1113 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1114 | FX_BOOL Document::getPageBox(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1115 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1116 | CJS_Value& vRet, |
| 1117 | CFX_WideString& sError) { |
| 1118 | return TRUE; |
| 1119 | } |
| 1120 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1121 | FX_BOOL Document::getAnnot(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1122 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1123 | CJS_Value& vRet, |
| 1124 | CFX_WideString& sError) { |
| 1125 | return TRUE; |
| 1126 | } |
| 1127 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1128 | FX_BOOL Document::getAnnots(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1129 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1130 | CJS_Value& vRet, |
| 1131 | CFX_WideString& sError) { |
| 1132 | vRet.SetNull(); |
| 1133 | return TRUE; |
| 1134 | } |
| 1135 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1136 | FX_BOOL Document::getAnnot3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1137 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1138 | CJS_Value& vRet, |
| 1139 | CFX_WideString& sError) { |
| 1140 | vRet.SetNull(); |
| 1141 | return TRUE; |
| 1142 | } |
| 1143 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1144 | FX_BOOL Document::getAnnots3D(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1145 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1146 | CJS_Value& vRet, |
| 1147 | CFX_WideString& sError) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1148 | vRet = CJS_Value::VT_undefined; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1149 | return TRUE; |
| 1150 | } |
| 1151 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1152 | FX_BOOL Document::getOCGs(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1153 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1154 | CJS_Value& vRet, |
| 1155 | CFX_WideString& sError) { |
| 1156 | return TRUE; |
| 1157 | } |
| 1158 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1159 | FX_BOOL Document::getLinks(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1160 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1161 | CJS_Value& vRet, |
| 1162 | CFX_WideString& sError) { |
| 1163 | return TRUE; |
| 1164 | } |
| 1165 | |
| 1166 | bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| 1167 | return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
| 1168 | rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| 1169 | } |
| 1170 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1171 | FX_BOOL Document::addIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1172 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1173 | CJS_Value& vRet, |
| 1174 | CFX_WideString& sError) { |
| 1175 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1176 | if (params.size() != 2) { |
| 1177 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1178 | return FALSE; |
| 1179 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1180 | CFX_WideString swIconName = params[0].ToCFXWideString(); |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1181 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1182 | if (params[1].GetType() != CJS_Value::VT_object) { |
Tom Sepez | aecd9d0 | 2015-08-31 15:04:12 -0700 | [diff] [blame] | 1183 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1184 | return FALSE; |
| 1185 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1186 | |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 1187 | v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); |
| 1188 | if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1189 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1190 | return FALSE; |
| 1191 | } |
| 1192 | |
| 1193 | CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); |
| 1194 | if (!pEmbedObj) { |
| 1195 | sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); |
| 1196 | return FALSE; |
| 1197 | } |
| 1198 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1199 | m_IconList.push_back(std::unique_ptr<IconElement>( |
| 1200 | new IconElement(swIconName, (Icon*)pEmbedObj))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1201 | return TRUE; |
| 1202 | } |
| 1203 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1204 | FX_BOOL Document::icons(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1205 | CJS_PropValue& vp, |
| 1206 | CFX_WideString& sError) { |
| 1207 | if (vp.IsSetting()) { |
| 1208 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1209 | sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); |
| 1210 | return FALSE; |
| 1211 | } |
| 1212 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1213 | if (m_IconList.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1214 | vp.SetNull(); |
| 1215 | return TRUE; |
| 1216 | } |
| 1217 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1218 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1219 | CJS_Array Icons(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1220 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1221 | int i = 0; |
| 1222 | for (const auto& pIconElement : m_IconList) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1223 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1224 | pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1225 | if (pObj.IsEmpty()) |
| 1226 | return FALSE; |
| 1227 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 1228 | CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1229 | if (!pJS_Icon) |
| 1230 | return FALSE; |
| 1231 | |
| 1232 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1233 | if (!pIcon) |
| 1234 | return FALSE; |
| 1235 | |
| 1236 | pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1237 | pIcon->SetIconName(pIconElement->IconName); |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1238 | Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | vp << Icons; |
| 1242 | return TRUE; |
| 1243 | } |
| 1244 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1245 | FX_BOOL Document::getIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1246 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1247 | CJS_Value& vRet, |
| 1248 | CFX_WideString& sError) { |
| 1249 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1250 | if (params.size() != 1) { |
| 1251 | sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1252 | return FALSE; |
| 1253 | } |
| 1254 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1255 | if (m_IconList.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1256 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1257 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1258 | CFX_WideString swIconName = params[0].ToCFXWideString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1259 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1260 | |
Tom Sepez | 6ba32d9 | 2016-01-05 16:26:32 -0800 | [diff] [blame] | 1261 | for (const auto& pIconElement : m_IconList) { |
| 1262 | if (pIconElement->IconName == swIconName) { |
| 1263 | Icon* pRetIcon = pIconElement->IconStream; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1264 | |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1265 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1266 | pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1267 | if (pObj.IsEmpty()) |
| 1268 | return FALSE; |
| 1269 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 1270 | CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1271 | if (!pJS_Icon) |
| 1272 | return FALSE; |
| 1273 | |
| 1274 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1275 | if (!pIcon) |
| 1276 | return FALSE; |
| 1277 | |
| 1278 | pIcon->SetIconName(swIconName); |
| 1279 | pIcon->SetStream(pRetIcon->GetStream()); |
| 1280 | vRet = pJS_Icon; |
| 1281 | return TRUE; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | return FALSE; |
| 1286 | } |
| 1287 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1288 | FX_BOOL Document::removeIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1289 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1290 | CJS_Value& vRet, |
| 1291 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1292 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1293 | return TRUE; |
| 1294 | } |
| 1295 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1296 | FX_BOOL Document::createDataObject(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1297 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1298 | CJS_Value& vRet, |
| 1299 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1300 | // Unsafe, not implemented. |
| 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::media(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::calculateNow(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_MODIFY) || |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1315 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1316 | m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1317 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1318 | |
| 1319 | CPDFSDK_InterForm* pInterForm = |
| 1320 | (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1321 | pInterForm->OnCalculate(); |
| 1322 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1325 | FX_BOOL Document::Collab(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1326 | CJS_PropValue& vp, |
| 1327 | CFX_WideString& sError) { |
| 1328 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1331 | FX_BOOL Document::getPageNthWord(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1332 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1333 | CJS_Value& vRet, |
| 1334 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1335 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1336 | return FALSE; |
Tom Sepez | e5350ef | 2015-04-23 18:14:26 -0700 | [diff] [blame] | 1337 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 1338 | int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; |
| 1339 | int nWordNo = params.size() > 1 ? params[1].ToInt() : 0; |
| 1340 | bool bStrip = params.size() > 2 ? params[2].ToBool() : true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1341 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1342 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1343 | if (!pDocument) |
| 1344 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1345 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1346 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1347 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1348 | sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1349 | return FALSE; |
| 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 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1353 | if (!pPageDict) |
| 1354 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1355 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1356 | CPDF_Page page; |
| 1357 | page.Load(pDocument, pPageDict); |
Tom Sepez | b5b2a91 | 2016-01-21 11:04:37 -0800 | [diff] [blame] | 1358 | page.ParseContent(nullptr); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1359 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1360 | int nWords = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1361 | CFX_WideString swRet; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1362 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1363 | if (pPageObj->IsText()) { |
| 1364 | CPDF_TextObject* pTextObj = pPageObj->AsText(); |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1365 | int nObjWords = CountWords(pTextObj); |
| 1366 | if (nWords + nObjWords >= nWordNo) { |
| 1367 | swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1368 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1369 | } |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1370 | nWords += nObjWords; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1371 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1372 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1373 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1374 | if (bStrip) { |
| 1375 | swRet.TrimLeft(); |
| 1376 | swRet.TrimRight(); |
| 1377 | } |
| 1378 | |
| 1379 | vRet = swRet.c_str(); |
| 1380 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1383 | FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1384 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1385 | CJS_Value& vRet, |
| 1386 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1387 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1388 | return FALSE; |
| 1389 | |
| 1390 | return FALSE; |
| 1391 | } |
| 1392 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1393 | FX_BOOL Document::getPageNumWords(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1394 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1395 | CJS_Value& vRet, |
| 1396 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1397 | if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) |
| 1398 | return FALSE; |
| 1399 | |
Lei Zhang | dd734de | 2015-11-11 10:16:52 -0800 | [diff] [blame] | 1400 | int nPageNo = params.size() > 0 ? params[0].ToInt() : 0; |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1401 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1402 | CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1403 | if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1404 | sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); |
| 1405 | return FALSE; |
| 1406 | } |
| 1407 | |
| 1408 | CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1409 | if (!pPageDict) |
| 1410 | return FALSE; |
| 1411 | |
| 1412 | CPDF_Page page; |
| 1413 | page.Load(pDocument, pPageDict); |
Tom Sepez | b5b2a91 | 2016-01-21 11:04:37 -0800 | [diff] [blame] | 1414 | page.ParseContent(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1415 | |
| 1416 | int nWords = 0; |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1417 | for (auto& pPageObj : *page.GetPageObjectList()) { |
Wei Li | 7cf13c9 | 2016-02-19 11:53:03 -0800 | [diff] [blame] | 1418 | if (pPageObj->IsText()) |
| 1419 | nWords += CountWords(pPageObj->AsText()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | vRet = nWords; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1423 | return TRUE; |
| 1424 | } |
| 1425 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1426 | FX_BOOL Document::getPrintParams(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1427 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1428 | CJS_Value& vRet, |
| 1429 | CFX_WideString& sError) { |
| 1430 | CJS_Context* pContext = (CJS_Context*)cc; |
| 1431 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 1432 | v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1433 | pRuntime->GetIsolate(), pRuntime, CJS_PrintParamsObj::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1434 | |
| 1435 | // Not implemented yet. |
| 1436 | |
| 1437 | vRet = pRetObj; |
| 1438 | return TRUE; |
| 1439 | } |
| 1440 | |
| 1441 | #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1442 | |
| 1443 | int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1444 | if (!pTextObj) |
| 1445 | return 0; |
| 1446 | |
| 1447 | int nWords = 0; |
| 1448 | |
| 1449 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1450 | if (!pFont) |
| 1451 | return 0; |
| 1452 | |
| 1453 | FX_BOOL bIsLatin = FALSE; |
| 1454 | |
| 1455 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1456 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1457 | FX_FLOAT kerning; |
| 1458 | |
| 1459 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1460 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1461 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1462 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1463 | if (swUnicode.GetLength() > 0) |
| 1464 | unicode = swUnicode[0]; |
| 1465 | |
| 1466 | if (ISLATINWORD(unicode) && bIsLatin) |
| 1467 | continue; |
| 1468 | |
| 1469 | bIsLatin = ISLATINWORD(unicode); |
| 1470 | if (unicode != 0x20) |
| 1471 | nWords++; |
| 1472 | } |
| 1473 | |
| 1474 | return nWords; |
| 1475 | } |
| 1476 | |
| 1477 | CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1478 | int nWordIndex) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1479 | CFX_WideString swRet; |
| 1480 | |
| 1481 | CPDF_Font* pFont = pTextObj->GetFont(); |
| 1482 | if (!pFont) |
| 1483 | return L""; |
| 1484 | |
| 1485 | int nWords = 0; |
| 1486 | FX_BOOL bIsLatin = FALSE; |
| 1487 | |
| 1488 | for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 1489 | uint32_t charcode = CPDF_Font::kInvalidCharCode; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1490 | FX_FLOAT kerning; |
| 1491 | |
| 1492 | pTextObj->GetCharInfo(i, charcode, kerning); |
| 1493 | CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1494 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1495 | uint16_t unicode = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1496 | if (swUnicode.GetLength() > 0) |
| 1497 | unicode = swUnicode[0]; |
| 1498 | |
| 1499 | if (ISLATINWORD(unicode) && bIsLatin) { |
| 1500 | } else { |
| 1501 | bIsLatin = ISLATINWORD(unicode); |
| 1502 | if (unicode != 0x20) |
| 1503 | nWords++; |
| 1504 | } |
| 1505 | |
| 1506 | if (nWords - 1 == nWordIndex) |
| 1507 | swRet += unicode; |
| 1508 | } |
| 1509 | |
| 1510 | return swRet; |
| 1511 | } |
| 1512 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1513 | FX_BOOL Document::zoom(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1514 | CJS_PropValue& vp, |
| 1515 | CFX_WideString& sError) { |
| 1516 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /** |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1520 | (none, NoVary) |
| 1521 | (fitP, FitPage) |
| 1522 | (fitW, FitWidth) |
| 1523 | (fitH, FitHeight) |
| 1524 | (fitV, FitVisibleWidth) |
| 1525 | (pref, Preferred) |
| 1526 | (refW, ReflowWidth) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1527 | */ |
| 1528 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1529 | FX_BOOL Document::zoomType(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1530 | CJS_PropValue& vp, |
| 1531 | CFX_WideString& sError) { |
Tom Sepez | c6ab172 | 2015-02-05 15:27:25 -0800 | [diff] [blame] | 1532 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1535 | FX_BOOL Document::deletePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1536 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1537 | CJS_Value& vRet, |
| 1538 | CFX_WideString& sError) { |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 1539 | // Unsafe, no supported. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1540 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1541 | } |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1542 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1543 | FX_BOOL Document::extractPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1544 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1545 | CJS_Value& vRet, |
| 1546 | CFX_WideString& sError) { |
| 1547 | // Unsafe, not supported. |
| 1548 | return TRUE; |
| 1549 | } |
| 1550 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1551 | FX_BOOL Document::insertPages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1552 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1553 | CJS_Value& vRet, |
| 1554 | CFX_WideString& sError) { |
| 1555 | // Unsafe, not supported. |
| 1556 | return TRUE; |
| 1557 | } |
| 1558 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1559 | FX_BOOL Document::replacePages(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1560 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1561 | CJS_Value& vRet, |
| 1562 | CFX_WideString& sError) { |
| 1563 | // Unsafe, not supported. |
| 1564 | return TRUE; |
| 1565 | } |
| 1566 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1567 | FX_BOOL Document::getURL(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 1568 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1569 | CJS_Value& vRet, |
| 1570 | CFX_WideString& sError) { |
| 1571 | // Unsafe, not supported. |
| 1572 | return TRUE; |
| 1573 | } |
| 1574 | |
| 1575 | void Document::AddDelayData(CJS_DelayData* pData) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1576 | m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1580 | int nControlIndex) { |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1581 | std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1582 | auto iter = m_DelayData.begin(); |
| 1583 | while (iter != m_DelayData.end()) { |
| 1584 | auto old = iter++; |
| 1585 | if ((*old)->sFieldName == sFieldName && |
| 1586 | (*old)->nControlIndex == nControlIndex) { |
| 1587 | DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1588 | m_DelayData.erase(old); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | |
Tom Sepez | 56c1019 | 2016-03-15 12:34:17 -0700 | [diff] [blame] | 1592 | for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1593 | Field::DoDelay(m_pDocument, pData.get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1596 | CJS_Document* Document::GetCJSDoc() const { |
| 1597 | return static_cast<CJS_Document*>(m_pJSObject); |
JUN FANG | 33f6f0d | 2015-04-06 12:39:51 -0700 | [diff] [blame] | 1598 | } |