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