| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) | 41 BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj) |
| 42 END_JS_STATIC_PROP() | 42 END_JS_STATIC_PROP() |
| 43 | 43 |
| 44 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) | 44 BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj) |
| 45 END_JS_STATIC_METHOD() | 45 END_JS_STATIC_METHOD() |
| 46 | 46 |
| 47 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) | 47 IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj) |
| 48 | 48 |
| 49 PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) | 49 PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject) |
| 50 : CJS_EmbedObj(pJSObject) { | 50 : CJS_EmbedObj(pJSObject) { |
| 51 bUI = TRUE; | 51 bUI = true; |
| 52 nStart = 0; | 52 nStart = 0; |
| 53 nEnd = 0; | 53 nEnd = 0; |
| 54 bSilent = FALSE; | 54 bSilent = false; |
| 55 bShrinkToFit = FALSE; | 55 bShrinkToFit = false; |
| 56 bPrintAsImage = FALSE; | 56 bPrintAsImage = false; |
| 57 bReverse = FALSE; | 57 bReverse = false; |
| 58 bAnnotations = TRUE; | 58 bAnnotations = true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 #define MINWIDTH 5.0f | 61 #define MINWIDTH 5.0f |
| 62 #define MINHEIGHT 5.0f | 62 #define MINHEIGHT 5.0f |
| 63 | 63 |
| 64 BEGIN_JS_STATIC_CONST(CJS_Document) | 64 BEGIN_JS_STATIC_CONST(CJS_Document) |
| 65 END_JS_STATIC_CONST() | 65 END_JS_STATIC_CONST() |
| 66 | 66 |
| 67 BEGIN_JS_STATIC_PROP(CJS_Document) | 67 BEGIN_JS_STATIC_PROP(CJS_Document) |
| 68 JS_STATIC_PROP_ENTRY(ADBE) | 68 JS_STATIC_PROP_ENTRY(ADBE) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { | 149 void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { |
| 150 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | 150 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 151 Document* pDoc = static_cast<Document*>(GetEmbedObject()); | 151 Document* pDoc = static_cast<Document*>(GetEmbedObject()); |
| 152 pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv()); | 152 pDoc->SetFormFillEnv(pRuntime->GetFormFillEnv()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 Document::Document(CJS_Object* pJSObject) | 155 Document::Document(CJS_Object* pJSObject) |
| 156 : CJS_EmbedObj(pJSObject), | 156 : CJS_EmbedObj(pJSObject), |
| 157 m_pFormFillEnv(nullptr), | 157 m_pFormFillEnv(nullptr), |
| 158 m_cwBaseURL(L""), | 158 m_cwBaseURL(L""), |
| 159 m_bDelay(FALSE) {} | 159 m_bDelay(false) {} |
| 160 | 160 |
| 161 Document::~Document() { | 161 Document::~Document() { |
| 162 } | 162 } |
| 163 | 163 |
| 164 // the total number of fileds in document. | 164 // the total number of fileds in document. |
| 165 FX_BOOL Document::numFields(IJS_Context* cc, | 165 bool Document::numFields(IJS_Context* cc, |
| 166 CJS_PropValue& vp, | 166 CJS_PropValue& vp, |
| 167 CFX_WideString& sError) { | 167 CFX_WideString& sError) { |
| 168 if (vp.IsSetting()) { | 168 if (vp.IsSetting()) { |
| 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 169 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 170 return FALSE; | 170 return false; |
| 171 } | 171 } |
| 172 if (!m_pFormFillEnv) { | 172 if (!m_pFormFillEnv) { |
| 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 173 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 174 return FALSE; | 174 return false; |
| 175 } | 175 } |
| 176 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 176 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 177 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 178 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); | 178 vp << static_cast<int>(pPDFForm->CountFields(CFX_WideString())); |
| 179 return TRUE; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 FX_BOOL Document::dirty(IJS_Context* cc, | 182 bool Document::dirty(IJS_Context* cc, |
| 183 CJS_PropValue& vp, | 183 CJS_PropValue& vp, |
| 184 CFX_WideString& sError) { | 184 CFX_WideString& sError) { |
| 185 if (!m_pFormFillEnv) { | 185 if (!m_pFormFillEnv) { |
| 186 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 186 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 187 return FALSE; | 187 return false; |
| 188 } | 188 } |
| 189 if (vp.IsGetting()) { | 189 if (vp.IsGetting()) { |
| 190 vp << !!m_pFormFillEnv->GetChangeMark(); | 190 vp << !!m_pFormFillEnv->GetChangeMark(); |
| 191 } else { | 191 } else { |
| 192 bool bChanged = false; | 192 bool bChanged = false; |
| 193 vp >> bChanged; | 193 vp >> bChanged; |
| 194 | 194 |
| 195 if (bChanged) | 195 if (bChanged) |
| 196 m_pFormFillEnv->SetChangeMark(); | 196 m_pFormFillEnv->SetChangeMark(); |
| 197 else | 197 else |
| 198 m_pFormFillEnv->ClearChangeMark(); | 198 m_pFormFillEnv->ClearChangeMark(); |
| 199 } | 199 } |
| 200 return TRUE; | 200 return true; |
| 201 } | 201 } |
| 202 | 202 |
| 203 FX_BOOL Document::ADBE(IJS_Context* cc, | 203 bool Document::ADBE(IJS_Context* cc, |
| 204 CJS_PropValue& vp, | 204 CJS_PropValue& vp, |
| 205 CFX_WideString& sError) { | 205 CFX_WideString& sError) { |
| 206 if (vp.IsGetting()) | 206 if (vp.IsGetting()) |
| 207 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); | 207 vp.GetJSValue()->SetNull(CJS_Runtime::FromContext(cc)); |
| 208 | 208 |
| 209 return TRUE; | 209 return true; |
| 210 } | 210 } |
| 211 | 211 |
| 212 FX_BOOL Document::pageNum(IJS_Context* cc, | 212 bool Document::pageNum(IJS_Context* cc, |
| 213 CJS_PropValue& vp, | 213 CJS_PropValue& vp, |
| 214 CFX_WideString& sError) { | 214 CFX_WideString& sError) { |
| 215 if (!m_pFormFillEnv) { | 215 if (!m_pFormFillEnv) { |
| 216 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 216 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 217 return FALSE; | 217 return false; |
| 218 } | 218 } |
| 219 if (vp.IsGetting()) { | 219 if (vp.IsGetting()) { |
| 220 if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { | 220 if (CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetCurrentView()) { |
| 221 vp << pPageView->GetPageIndex(); | 221 vp << pPageView->GetPageIndex(); |
| 222 } | 222 } |
| 223 } else { | 223 } else { |
| 224 int iPageCount = m_pFormFillEnv->GetPageCount(); | 224 int iPageCount = m_pFormFillEnv->GetPageCount(); |
| 225 int iPageNum = 0; | 225 int iPageNum = 0; |
| 226 vp >> iPageNum; | 226 vp >> iPageNum; |
| 227 | 227 |
| 228 if (iPageNum >= 0 && iPageNum < iPageCount) { | 228 if (iPageNum >= 0 && iPageNum < iPageCount) { |
| 229 m_pFormFillEnv->JS_docgotoPage(iPageNum); | 229 m_pFormFillEnv->JS_docgotoPage(iPageNum); |
| 230 } else if (iPageNum >= iPageCount) { | 230 } else if (iPageNum >= iPageCount) { |
| 231 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); | 231 m_pFormFillEnv->JS_docgotoPage(iPageCount - 1); |
| 232 } else if (iPageNum < 0) { | 232 } else if (iPageNum < 0) { |
| 233 m_pFormFillEnv->JS_docgotoPage(0); | 233 m_pFormFillEnv->JS_docgotoPage(0); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 return TRUE; | 237 return true; |
| 238 } | 238 } |
| 239 | 239 |
| 240 FX_BOOL Document::addAnnot(IJS_Context* cc, | 240 bool Document::addAnnot(IJS_Context* cc, |
| 241 const std::vector<CJS_Value>& params, |
| 242 CJS_Value& vRet, |
| 243 CFX_WideString& sError) { |
| 244 // Not supported. |
| 245 return true; |
| 246 } |
| 247 |
| 248 bool Document::addField(IJS_Context* cc, |
| 249 const std::vector<CJS_Value>& params, |
| 250 CJS_Value& vRet, |
| 251 CFX_WideString& sError) { |
| 252 // Not supported. |
| 253 return true; |
| 254 } |
| 255 |
| 256 bool Document::exportAsText(IJS_Context* cc, |
| 257 const std::vector<CJS_Value>& params, |
| 258 CJS_Value& vRet, |
| 259 CFX_WideString& sError) { |
| 260 // Unsafe, not supported. |
| 261 return true; |
| 262 } |
| 263 |
| 264 bool Document::exportAsFDF(IJS_Context* cc, |
| 241 const std::vector<CJS_Value>& params, | 265 const std::vector<CJS_Value>& params, |
| 242 CJS_Value& vRet, | 266 CJS_Value& vRet, |
| 243 CFX_WideString& sError) { | 267 CFX_WideString& sError) { |
| 244 // Not supported. | 268 // Unsafe, not supported. |
| 245 return TRUE; | 269 return true; |
| 246 } | 270 } |
| 247 | 271 |
| 248 FX_BOOL Document::addField(IJS_Context* cc, | 272 bool Document::exportAsXFDF(IJS_Context* cc, |
| 249 const std::vector<CJS_Value>& params, | 273 const std::vector<CJS_Value>& params, |
| 250 CJS_Value& vRet, | 274 CJS_Value& vRet, |
| 251 CFX_WideString& sError) { | 275 CFX_WideString& sError) { |
| 252 // Not supported. | |
| 253 return TRUE; | |
| 254 } | |
| 255 | |
| 256 FX_BOOL Document::exportAsText(IJS_Context* cc, | |
| 257 const std::vector<CJS_Value>& params, | |
| 258 CJS_Value& vRet, | |
| 259 CFX_WideString& sError) { | |
| 260 // Unsafe, not supported. | 276 // Unsafe, not supported. |
| 261 return TRUE; | 277 return true; |
| 262 } | |
| 263 | |
| 264 FX_BOOL Document::exportAsFDF(IJS_Context* cc, | |
| 265 const std::vector<CJS_Value>& params, | |
| 266 CJS_Value& vRet, | |
| 267 CFX_WideString& sError) { | |
| 268 // Unsafe, not supported. | |
| 269 return TRUE; | |
| 270 } | |
| 271 | |
| 272 FX_BOOL Document::exportAsXFDF(IJS_Context* cc, | |
| 273 const std::vector<CJS_Value>& params, | |
| 274 CJS_Value& vRet, | |
| 275 CFX_WideString& sError) { | |
| 276 // Unsafe, not supported. | |
| 277 return TRUE; | |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Maps a field object in PDF document to a JavaScript variable | 280 // Maps a field object in PDF document to a JavaScript variable |
| 281 // comment: | 281 // comment: |
| 282 // note: the paremter cName, this is clue how to treat if the cName is not a | 282 // note: the paremter cName, this is clue how to treat if the cName is not a |
| 283 // valiable filed name in this document | 283 // valiable filed name in this document |
| 284 | 284 |
| 285 FX_BOOL Document::getField(IJS_Context* cc, | 285 bool Document::getField(IJS_Context* cc, |
| 286 const std::vector<CJS_Value>& params, | 286 const std::vector<CJS_Value>& params, |
| 287 CJS_Value& vRet, | 287 CJS_Value& vRet, |
| 288 CFX_WideString& sError) { | 288 CFX_WideString& sError) { |
| 289 if (params.size() < 1) { | 289 if (params.size() < 1) { |
| 290 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 290 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 291 return FALSE; | 291 return false; |
| 292 } | 292 } |
| 293 if (!m_pFormFillEnv) { | 293 if (!m_pFormFillEnv) { |
| 294 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 294 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 295 return FALSE; | 295 return false; |
| 296 } | 296 } |
| 297 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 297 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 298 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 298 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 299 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 299 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 300 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 300 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 301 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 301 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 302 if (pPDFForm->CountFields(wideName) <= 0) { | 302 if (pPDFForm->CountFields(wideName) <= 0) { |
| 303 vRet.SetNull(pRuntime); | 303 vRet.SetNull(pRuntime); |
| 304 return TRUE; | 304 return true; |
| 305 } | 305 } |
| 306 | 306 |
| 307 v8::Local<v8::Object> pFieldObj = | 307 v8::Local<v8::Object> pFieldObj = |
| 308 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); | 308 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
| 309 CJS_Field* pJSField = | 309 CJS_Field* pJSField = |
| 310 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); | 310 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj)); |
| 311 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); | 311 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
| 312 pField->AttachField(this, wideName); | 312 pField->AttachField(this, wideName); |
| 313 | 313 |
| 314 vRet = CJS_Value(pRuntime, pJSField); | 314 vRet = CJS_Value(pRuntime, pJSField); |
| 315 return TRUE; | 315 return true; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Gets the name of the nth field in the document | 318 // Gets the name of the nth field in the document |
| 319 FX_BOOL Document::getNthFieldName(IJS_Context* cc, | 319 bool Document::getNthFieldName(IJS_Context* cc, |
| 320 const std::vector<CJS_Value>& params, | 320 const std::vector<CJS_Value>& params, |
| 321 CJS_Value& vRet, | 321 CJS_Value& vRet, |
| 322 CFX_WideString& sError) { | 322 CFX_WideString& sError) { |
| 323 if (params.size() != 1) { | 323 if (params.size() != 1) { |
| 324 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 324 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 325 return FALSE; | 325 return false; |
| 326 } | 326 } |
| 327 if (!m_pFormFillEnv) { | 327 if (!m_pFormFillEnv) { |
| 328 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 328 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 329 return FALSE; | 329 return false; |
| 330 } | 330 } |
| 331 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 331 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 332 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 332 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 333 int nIndex = params[0].ToInt(pRuntime); | 333 int nIndex = params[0].ToInt(pRuntime); |
| 334 if (nIndex < 0) { | 334 if (nIndex < 0) { |
| 335 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 335 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 336 return FALSE; | 336 return false; |
| 337 } | 337 } |
| 338 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 338 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 339 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 339 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 340 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); | 340 CPDF_FormField* pField = pPDFForm->GetField(nIndex, CFX_WideString()); |
| 341 if (!pField) | 341 if (!pField) |
| 342 return FALSE; | 342 return false; |
| 343 | 343 |
| 344 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); | 344 vRet = CJS_Value(pRuntime, pField->GetFullName().c_str()); |
| 345 return TRUE; | 345 return true; |
| 346 } | 346 } |
| 347 | 347 |
| 348 FX_BOOL Document::importAnFDF(IJS_Context* cc, | 348 bool Document::importAnFDF(IJS_Context* cc, |
| 349 const std::vector<CJS_Value>& params, |
| 350 CJS_Value& vRet, |
| 351 CFX_WideString& sError) { |
| 352 // Unsafe, not supported. |
| 353 return true; |
| 354 } |
| 355 |
| 356 bool Document::importAnXFDF(IJS_Context* cc, |
| 357 const std::vector<CJS_Value>& params, |
| 358 CJS_Value& vRet, |
| 359 CFX_WideString& sError) { |
| 360 // Unsafe, not supported. |
| 361 return true; |
| 362 } |
| 363 |
| 364 bool Document::importTextData(IJS_Context* cc, |
| 349 const std::vector<CJS_Value>& params, | 365 const std::vector<CJS_Value>& params, |
| 350 CJS_Value& vRet, | 366 CJS_Value& vRet, |
| 351 CFX_WideString& sError) { | 367 CFX_WideString& sError) { |
| 352 // Unsafe, not supported. | 368 // Unsafe, not supported. |
| 353 return TRUE; | 369 return true; |
| 354 } | |
| 355 | |
| 356 FX_BOOL Document::importAnXFDF(IJS_Context* cc, | |
| 357 const std::vector<CJS_Value>& params, | |
| 358 CJS_Value& vRet, | |
| 359 CFX_WideString& sError) { | |
| 360 // Unsafe, not supported. | |
| 361 return TRUE; | |
| 362 } | |
| 363 | |
| 364 FX_BOOL Document::importTextData(IJS_Context* cc, | |
| 365 const std::vector<CJS_Value>& params, | |
| 366 CJS_Value& vRet, | |
| 367 CFX_WideString& sError) { | |
| 368 // Unsafe, not supported. | |
| 369 return TRUE; | |
| 370 } | 370 } |
| 371 | 371 |
| 372 // exports the form data and mails the resulting fdf file as an attachment to | 372 // exports the form data and mails the resulting fdf file as an attachment to |
| 373 // all recipients. | 373 // all recipients. |
| 374 // comment: need reader supports | 374 // comment: need reader supports |
| 375 FX_BOOL Document::mailForm(IJS_Context* cc, | 375 bool Document::mailForm(IJS_Context* cc, |
| 376 const std::vector<CJS_Value>& params, | 376 const std::vector<CJS_Value>& params, |
| 377 CJS_Value& vRet, | 377 CJS_Value& vRet, |
| 378 CFX_WideString& sError) { | 378 CFX_WideString& sError) { |
| 379 if (!m_pFormFillEnv) { | 379 if (!m_pFormFillEnv) { |
| 380 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 380 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 381 return FALSE; | 381 return false; |
| 382 } | 382 } |
| 383 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { | 383 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 384 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 384 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 385 return FALSE; | 385 return false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 388 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 389 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 389 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 390 | 390 |
| 391 int iLength = params.size(); | 391 int iLength = params.size(); |
| 392 FX_BOOL bUI = iLength > 0 ? params[0].ToBool(pRuntime) : TRUE; | 392 bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true; |
| 393 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; | 393 CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; |
| 394 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; | 394 CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; |
| 395 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; | 395 CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; |
| 396 CFX_WideString cSubject = | 396 CFX_WideString cSubject = |
| 397 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; | 397 iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; |
| 398 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; | 398 CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; |
| 399 | 399 |
| 400 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 400 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 401 CFX_ByteTextBuf textBuf; | 401 CFX_ByteTextBuf textBuf; |
| 402 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) | 402 if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) |
| 403 return FALSE; | 403 return false; |
| 404 | 404 |
| 405 pRuntime->BeginBlock(); | 405 pRuntime->BeginBlock(); |
| 406 CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv(); | 406 CPDFSDK_FormFillEnvironment* pFormFillEnv = pContext->GetFormFillEnv(); |
| 407 pFormFillEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, | 407 pFormFillEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, |
| 408 cTo.c_str(), cSubject.c_str(), cCc.c_str(), | 408 cTo.c_str(), cSubject.c_str(), cCc.c_str(), |
| 409 cBcc.c_str(), cMsg.c_str()); | 409 cBcc.c_str(), cMsg.c_str()); |
| 410 pRuntime->EndBlock(); | 410 pRuntime->EndBlock(); |
| 411 return TRUE; | 411 return true; |
| 412 } | 412 } |
| 413 | 413 |
| 414 FX_BOOL Document::print(IJS_Context* cc, | 414 bool Document::print(IJS_Context* cc, |
| 415 const std::vector<CJS_Value>& params, | 415 const std::vector<CJS_Value>& params, |
| 416 CJS_Value& vRet, | 416 CJS_Value& vRet, |
| 417 CFX_WideString& sError) { | 417 CFX_WideString& sError) { |
| 418 if (!m_pFormFillEnv) { | 418 if (!m_pFormFillEnv) { |
| 419 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 419 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 420 return FALSE; | 420 return false; |
| 421 } | 421 } |
| 422 | 422 |
| 423 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 423 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 424 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 424 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 425 | 425 |
| 426 FX_BOOL bUI = TRUE; | 426 bool bUI = true; |
| 427 int nStart = 0; | 427 int nStart = 0; |
| 428 int nEnd = 0; | 428 int nEnd = 0; |
| 429 FX_BOOL bSilent = FALSE; | 429 bool bSilent = false; |
| 430 FX_BOOL bShrinkToFit = FALSE; | 430 bool bShrinkToFit = false; |
| 431 FX_BOOL bPrintAsImage = FALSE; | 431 bool bPrintAsImage = false; |
| 432 FX_BOOL bReverse = FALSE; | 432 bool bReverse = false; |
| 433 FX_BOOL bAnnotations = FALSE; | 433 bool bAnnotations = false; |
| 434 | 434 |
| 435 int nlength = params.size(); | 435 int nlength = params.size(); |
| 436 if (nlength == 9) { | 436 if (nlength == 9) { |
| 437 if (params[8].GetType() == CJS_Value::VT_object) { | 437 if (params[8].GetType() == CJS_Value::VT_object) { |
| 438 v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); | 438 v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); |
| 439 if (CFXJS_Engine::GetObjDefnID(pObj) == | 439 if (CFXJS_Engine::GetObjDefnID(pObj) == |
| 440 CJS_PrintParamsObj::g_nObjDefnID) { | 440 CJS_PrintParamsObj::g_nObjDefnID) { |
| 441 if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { | 441 if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { |
| 442 if (PrintParamsObj* pprintparamsObj = | 442 if (PrintParamsObj* pprintparamsObj = |
| 443 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { | 443 static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 468 bPrintAsImage = params[5].ToBool(pRuntime); | 468 bPrintAsImage = params[5].ToBool(pRuntime); |
| 469 if (nlength >= 7) | 469 if (nlength >= 7) |
| 470 bReverse = params[6].ToBool(pRuntime); | 470 bReverse = params[6].ToBool(pRuntime); |
| 471 if (nlength >= 8) | 471 if (nlength >= 8) |
| 472 bAnnotations = params[7].ToBool(pRuntime); | 472 bAnnotations = params[7].ToBool(pRuntime); |
| 473 } | 473 } |
| 474 | 474 |
| 475 if (m_pFormFillEnv) { | 475 if (m_pFormFillEnv) { |
| 476 m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, | 476 m_pFormFillEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, |
| 477 bPrintAsImage, bReverse, bAnnotations); | 477 bPrintAsImage, bReverse, bAnnotations); |
| 478 return TRUE; | 478 return true; |
| 479 } | 479 } |
| 480 return FALSE; | 480 return false; |
| 481 } | 481 } |
| 482 | 482 |
| 483 // removes the specified field from the document. | 483 // removes the specified field from the document. |
| 484 // comment: | 484 // comment: |
| 485 // note: if the filed name is not rational, adobe is dumb for it. | 485 // note: if the filed name is not rational, adobe is dumb for it. |
| 486 | 486 |
| 487 FX_BOOL Document::removeField(IJS_Context* cc, | 487 bool Document::removeField(IJS_Context* cc, |
| 488 const std::vector<CJS_Value>& params, | 488 const std::vector<CJS_Value>& params, |
| 489 CJS_Value& vRet, | 489 CJS_Value& vRet, |
| 490 CFX_WideString& sError) { | 490 CFX_WideString& sError) { |
| 491 if (params.size() != 1) { | 491 if (params.size() != 1) { |
| 492 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 492 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 493 return FALSE; | 493 return false; |
| 494 } | 494 } |
| 495 if (!m_pFormFillEnv) { | 495 if (!m_pFormFillEnv) { |
| 496 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 496 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 497 return FALSE; | 497 return false; |
| 498 } | 498 } |
| 499 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || | 499 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 500 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { | 500 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM))) { |
| 501 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 501 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 502 return FALSE; | 502 return false; |
| 503 } | 503 } |
| 504 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 504 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 505 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 505 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 506 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); | 506 CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime); |
| 507 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 507 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 508 std::vector<CPDFSDK_Widget*> widgets; | 508 std::vector<CPDFSDK_Widget*> widgets; |
| 509 pInterForm->GetWidgets(sFieldName, &widgets); | 509 pInterForm->GetWidgets(sFieldName, &widgets); |
| 510 if (widgets.empty()) | 510 if (widgets.empty()) |
| 511 return TRUE; | 511 return true; |
| 512 | 512 |
| 513 for (CPDFSDK_Widget* pWidget : widgets) { | 513 for (CPDFSDK_Widget* pWidget : widgets) { |
| 514 CFX_FloatRect rcAnnot = pWidget->GetRect(); | 514 CFX_FloatRect rcAnnot = pWidget->GetRect(); |
| 515 --rcAnnot.left; | 515 --rcAnnot.left; |
| 516 --rcAnnot.bottom; | 516 --rcAnnot.bottom; |
| 517 ++rcAnnot.right; | 517 ++rcAnnot.right; |
| 518 ++rcAnnot.top; | 518 ++rcAnnot.top; |
| 519 | 519 |
| 520 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); | 520 std::vector<CFX_FloatRect> aRefresh(1, rcAnnot); |
| 521 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 521 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
| 522 ASSERT(pPage); | 522 ASSERT(pPage); |
| 523 | 523 |
| 524 // If there is currently no pageview associated with the page being used | 524 // If there is currently no pageview associated with the page being used |
| 525 // do not create one. We may be in the process of tearing down the document | 525 // do not create one. We may be in the process of tearing down the document |
| 526 // and creating a new pageview at this point will cause bad things. | 526 // and creating a new pageview at this point will cause bad things. |
| 527 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); | 527 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, false); |
| 528 if (pPageView) { | 528 if (pPageView) { |
| 529 #if PDF_ENABLE_XFA | 529 #if PDF_ENABLE_XFA |
| 530 pPageView->DeleteAnnot(pWidget); | 530 pPageView->DeleteAnnot(pWidget); |
| 531 #endif // PDF_ENABLE_XFA | 531 #endif // PDF_ENABLE_XFA |
| 532 pPageView->UpdateRects(aRefresh); | 532 pPageView->UpdateRects(aRefresh); |
| 533 } | 533 } |
| 534 } | 534 } |
| 535 m_pFormFillEnv->SetChangeMark(); | 535 m_pFormFillEnv->SetChangeMark(); |
| 536 | 536 |
| 537 return TRUE; | 537 return true; |
| 538 } | 538 } |
| 539 | 539 |
| 540 // reset filed values within a document. | 540 // reset filed values within a document. |
| 541 // comment: | 541 // comment: |
| 542 // note: if the fields names r not rational, aodbe is dumb for it. | 542 // note: if the fields names r not rational, aodbe is dumb for it. |
| 543 | 543 |
| 544 FX_BOOL Document::resetForm(IJS_Context* cc, | 544 bool Document::resetForm(IJS_Context* cc, |
| 545 const std::vector<CJS_Value>& params, | 545 const std::vector<CJS_Value>& params, |
| 546 CJS_Value& vRet, | 546 CJS_Value& vRet, |
| 547 CFX_WideString& sError) { | 547 CFX_WideString& sError) { |
| 548 if (!m_pFormFillEnv) { | 548 if (!m_pFormFillEnv) { |
| 549 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 549 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 550 return FALSE; | 550 return false; |
| 551 } | 551 } |
| 552 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || | 552 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 553 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || | 553 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 554 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { | 554 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 555 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 555 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 556 return FALSE; | 556 return false; |
| 557 } | 557 } |
| 558 | 558 |
| 559 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 559 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 560 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 560 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 561 CJS_Array aName; | 561 CJS_Array aName; |
| 562 | 562 |
| 563 if (params.empty()) { | 563 if (params.empty()) { |
| 564 pPDFForm->ResetForm(TRUE); | 564 pPDFForm->ResetForm(true); |
| 565 m_pFormFillEnv->SetChangeMark(); | 565 m_pFormFillEnv->SetChangeMark(); |
| 566 return TRUE; | 566 return true; |
| 567 } | 567 } |
| 568 | 568 |
| 569 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 569 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 570 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 570 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 571 | 571 |
| 572 switch (params[0].GetType()) { | 572 switch (params[0].GetType()) { |
| 573 default: | 573 default: |
| 574 aName.Attach(params[0].ToV8Array(pRuntime)); | 574 aName.Attach(params[0].ToV8Array(pRuntime)); |
| 575 break; | 575 break; |
| 576 case CJS_Value::VT_string: | 576 case CJS_Value::VT_string: |
| 577 aName.SetElement(pRuntime, 0, params[0]); | 577 aName.SetElement(pRuntime, 0, params[0]); |
| 578 break; | 578 break; |
| 579 } | 579 } |
| 580 | 580 |
| 581 std::vector<CPDF_FormField*> aFields; | 581 std::vector<CPDF_FormField*> aFields; |
| 582 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { | 582 for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { |
| 583 CJS_Value valElement(pRuntime); | 583 CJS_Value valElement(pRuntime); |
| 584 aName.GetElement(pRuntime, i, valElement); | 584 aName.GetElement(pRuntime, i, valElement); |
| 585 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); | 585 CFX_WideString swVal = valElement.ToCFXWideString(pRuntime); |
| 586 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) | 586 for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) |
| 587 aFields.push_back(pPDFForm->GetField(j, swVal)); | 587 aFields.push_back(pPDFForm->GetField(j, swVal)); |
| 588 } | 588 } |
| 589 | 589 |
| 590 if (!aFields.empty()) { | 590 if (!aFields.empty()) { |
| 591 pPDFForm->ResetForm(aFields, TRUE, TRUE); | 591 pPDFForm->ResetForm(aFields, true, true); |
| 592 m_pFormFillEnv->SetChangeMark(); | 592 m_pFormFillEnv->SetChangeMark(); |
| 593 } | 593 } |
| 594 | 594 |
| 595 return TRUE; | 595 return true; |
| 596 } | 596 } |
| 597 | 597 |
| 598 FX_BOOL Document::saveAs(IJS_Context* cc, | 598 bool Document::saveAs(IJS_Context* cc, |
| 599 const std::vector<CJS_Value>& params, | 599 const std::vector<CJS_Value>& params, |
| 600 CJS_Value& vRet, | 600 CJS_Value& vRet, |
| 601 CFX_WideString& sError) { | 601 CFX_WideString& sError) { |
| 602 // Unsafe, not supported. | 602 // Unsafe, not supported. |
| 603 return TRUE; | 603 return true; |
| 604 } | 604 } |
| 605 | 605 |
| 606 FX_BOOL Document::syncAnnotScan(IJS_Context* cc, | 606 bool Document::syncAnnotScan(IJS_Context* cc, |
| 607 const std::vector<CJS_Value>& params, | |
| 608 CJS_Value& vRet, | |
| 609 CFX_WideString& sError) { | |
| 610 return TRUE; | |
| 611 } | |
| 612 | |
| 613 FX_BOOL Document::submitForm(IJS_Context* cc, | |
| 614 const std::vector<CJS_Value>& params, | 607 const std::vector<CJS_Value>& params, |
| 615 CJS_Value& vRet, | 608 CJS_Value& vRet, |
| 616 CFX_WideString& sError) { | 609 CFX_WideString& sError) { |
| 610 return true; |
| 611 } |
| 612 |
| 613 bool Document::submitForm(IJS_Context* cc, |
| 614 const std::vector<CJS_Value>& params, |
| 615 CJS_Value& vRet, |
| 616 CFX_WideString& sError) { |
| 617 int nSize = params.size(); | 617 int nSize = params.size(); |
| 618 if (nSize < 1) { | 618 if (nSize < 1) { |
| 619 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 619 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 620 return FALSE; | 620 return false; |
| 621 } | 621 } |
| 622 if (!m_pFormFillEnv) { | 622 if (!m_pFormFillEnv) { |
| 623 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 623 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 624 return FALSE; | 624 return false; |
| 625 } | 625 } |
| 626 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 626 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 627 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 627 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 628 CJS_Array aFields; | 628 CJS_Array aFields; |
| 629 CFX_WideString strURL; | 629 CFX_WideString strURL; |
| 630 FX_BOOL bFDF = TRUE; | 630 bool bFDF = true; |
| 631 FX_BOOL bEmpty = FALSE; | 631 bool bEmpty = false; |
| 632 CJS_Value v = params[0]; | 632 CJS_Value v = params[0]; |
| 633 if (v.GetType() == CJS_Value::VT_string) { | 633 if (v.GetType() == CJS_Value::VT_string) { |
| 634 strURL = params[0].ToCFXWideString(pRuntime); | 634 strURL = params[0].ToCFXWideString(pRuntime); |
| 635 if (nSize > 1) | 635 if (nSize > 1) |
| 636 bFDF = params[1].ToBool(pRuntime); | 636 bFDF = params[1].ToBool(pRuntime); |
| 637 if (nSize > 2) | 637 if (nSize > 2) |
| 638 bEmpty = params[2].ToBool(pRuntime); | 638 bEmpty = params[2].ToBool(pRuntime); |
| 639 if (nSize > 3) | 639 if (nSize > 3) |
| 640 aFields.Attach(params[3].ToV8Array(pRuntime)); | 640 aFields.Attach(params[3].ToV8Array(pRuntime)); |
| 641 } else if (v.GetType() == CJS_Value::VT_object) { | 641 } else if (v.GetType() == CJS_Value::VT_object) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 652 | 652 |
| 653 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); | 653 pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); |
| 654 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); | 654 aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); |
| 655 } | 655 } |
| 656 | 656 |
| 657 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 657 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 658 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 658 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 659 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { | 659 if (aFields.GetLength(pRuntime) == 0 && bEmpty) { |
| 660 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { | 660 if (pPDFInterForm->CheckRequiredFields(nullptr, true)) { |
| 661 pRuntime->BeginBlock(); | 661 pRuntime->BeginBlock(); |
| 662 pInterForm->SubmitForm(strURL, FALSE); | 662 pInterForm->SubmitForm(strURL, false); |
| 663 pRuntime->EndBlock(); | 663 pRuntime->EndBlock(); |
| 664 } | 664 } |
| 665 return TRUE; | 665 return true; |
| 666 } | 666 } |
| 667 | 667 |
| 668 std::vector<CPDF_FormField*> fieldObjects; | 668 std::vector<CPDF_FormField*> fieldObjects; |
| 669 for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { | 669 for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { |
| 670 CJS_Value valName(pRuntime); | 670 CJS_Value valName(pRuntime); |
| 671 aFields.GetElement(pRuntime, i, valName); | 671 aFields.GetElement(pRuntime, i, valName); |
| 672 | 672 |
| 673 CFX_WideString sName = valName.ToCFXWideString(pRuntime); | 673 CFX_WideString sName = valName.ToCFXWideString(pRuntime); |
| 674 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); | 674 CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); |
| 675 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { | 675 for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { |
| 676 CPDF_FormField* pField = pPDFForm->GetField(j, sName); | 676 CPDF_FormField* pField = pPDFForm->GetField(j, sName); |
| 677 if (!bEmpty && pField->GetValue().IsEmpty()) | 677 if (!bEmpty && pField->GetValue().IsEmpty()) |
| 678 continue; | 678 continue; |
| 679 | 679 |
| 680 fieldObjects.push_back(pField); | 680 fieldObjects.push_back(pField); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { | 684 if (pPDFInterForm->CheckRequiredFields(&fieldObjects, true)) { |
| 685 pRuntime->BeginBlock(); | 685 pRuntime->BeginBlock(); |
| 686 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); | 686 pInterForm->SubmitFields(strURL, fieldObjects, true, !bFDF); |
| 687 pRuntime->EndBlock(); | 687 pRuntime->EndBlock(); |
| 688 } | 688 } |
| 689 return TRUE; | 689 return true; |
| 690 } | 690 } |
| 691 | 691 |
| 692 void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { | 692 void Document::SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv) { |
| 693 m_pFormFillEnv.Reset(pFormFillEnv); | 693 m_pFormFillEnv.Reset(pFormFillEnv); |
| 694 } | 694 } |
| 695 | 695 |
| 696 FX_BOOL Document::bookmarkRoot(IJS_Context* cc, | 696 bool Document::bookmarkRoot(IJS_Context* cc, |
| 697 CJS_PropValue& vp, | 697 CJS_PropValue& vp, |
| 698 CFX_WideString& sError) { | 698 CFX_WideString& sError) { |
| 699 return TRUE; | 699 return true; |
| 700 } | 700 } |
| 701 | 701 |
| 702 FX_BOOL Document::mailDoc(IJS_Context* cc, | 702 bool Document::mailDoc(IJS_Context* cc, |
| 703 const std::vector<CJS_Value>& params, | 703 const std::vector<CJS_Value>& params, |
| 704 CJS_Value& vRet, | 704 CJS_Value& vRet, |
| 705 CFX_WideString& sError) { | 705 CFX_WideString& sError) { |
| 706 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 706 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 707 | 707 |
| 708 // TODO(tsepez): Check maximum number of allowed params. | 708 // TODO(tsepez): Check maximum number of allowed params. |
| 709 | 709 |
| 710 FX_BOOL bUI = TRUE; | 710 bool bUI = true; |
| 711 CFX_WideString cTo = L""; | 711 CFX_WideString cTo = L""; |
| 712 CFX_WideString cCc = L""; | 712 CFX_WideString cCc = L""; |
| 713 CFX_WideString cBcc = L""; | 713 CFX_WideString cBcc = L""; |
| 714 CFX_WideString cSubject = L""; | 714 CFX_WideString cSubject = L""; |
| 715 CFX_WideString cMsg = L""; | 715 CFX_WideString cMsg = L""; |
| 716 | 716 |
| 717 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 717 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 718 | 718 |
| 719 if (params.size() >= 1) | 719 if (params.size() >= 1) |
| 720 bUI = params[0].ToBool(pRuntime); | 720 bUI = params[0].ToBool(pRuntime); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 750 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); | 750 pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); |
| 751 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); | 751 cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); |
| 752 } | 752 } |
| 753 | 753 |
| 754 pRuntime->BeginBlock(); | 754 pRuntime->BeginBlock(); |
| 755 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); | 755 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv(); |
| 756 pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), | 756 pFormFillEnv->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), cSubject.c_str(), |
| 757 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); | 757 cCc.c_str(), cBcc.c_str(), cMsg.c_str()); |
| 758 pRuntime->EndBlock(); | 758 pRuntime->EndBlock(); |
| 759 | 759 |
| 760 return TRUE; | 760 return true; |
| 761 } | 761 } |
| 762 | 762 |
| 763 FX_BOOL Document::author(IJS_Context* cc, | 763 bool Document::author(IJS_Context* cc, |
| 764 CJS_PropValue& vp, | 764 CJS_PropValue& vp, |
| 765 CFX_WideString& sError) { | 765 CFX_WideString& sError) { |
| 766 return getPropertyInternal(cc, vp, "Author", sError); | 766 return getPropertyInternal(cc, vp, "Author", sError); |
| 767 } | 767 } |
| 768 | 768 |
| 769 FX_BOOL Document::info(IJS_Context* cc, | 769 bool Document::info(IJS_Context* cc, |
| 770 CJS_PropValue& vp, | 770 CJS_PropValue& vp, |
| 771 CFX_WideString& sError) { | 771 CFX_WideString& sError) { |
| 772 if (vp.IsSetting()) { | 772 if (vp.IsSetting()) { |
| 773 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 773 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 774 return FALSE; | 774 return false; |
| 775 } | 775 } |
| 776 if (!m_pFormFillEnv) { | 776 if (!m_pFormFillEnv) { |
| 777 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 777 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 778 return FALSE; | 778 return false; |
| 779 } | 779 } |
| 780 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); | 780 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
| 781 if (!pDictionary) | 781 if (!pDictionary) |
| 782 return FALSE; | 782 return false; |
| 783 | 783 |
| 784 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); | 784 CFX_WideString cwAuthor = pDictionary->GetUnicodeTextFor("Author"); |
| 785 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); | 785 CFX_WideString cwTitle = pDictionary->GetUnicodeTextFor("Title"); |
| 786 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); | 786 CFX_WideString cwSubject = pDictionary->GetUnicodeTextFor("Subject"); |
| 787 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); | 787 CFX_WideString cwKeywords = pDictionary->GetUnicodeTextFor("Keywords"); |
| 788 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); | 788 CFX_WideString cwCreator = pDictionary->GetUnicodeTextFor("Creator"); |
| 789 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); | 789 CFX_WideString cwProducer = pDictionary->GetUnicodeTextFor("Producer"); |
| 790 CFX_WideString cwCreationDate = | 790 CFX_WideString cwCreationDate = |
| 791 pDictionary->GetUnicodeTextFor("CreationDate"); | 791 pDictionary->GetUnicodeTextFor("CreationDate"); |
| 792 CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate"); | 792 CFX_WideString cwModDate = pDictionary->GetUnicodeTextFor("ModDate"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 813 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); | 813 CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC()); |
| 814 if (pValueObj->IsString() || pValueObj->IsName()) { | 814 if (pValueObj->IsString() || pValueObj->IsName()) { |
| 815 pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText()); | 815 pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText()); |
| 816 } else if (pValueObj->IsNumber()) { | 816 } else if (pValueObj->IsNumber()) { |
| 817 pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber()); | 817 pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber()); |
| 818 } else if (pValueObj->IsBoolean()) { | 818 } else if (pValueObj->IsBoolean()) { |
| 819 pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger()); | 819 pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger()); |
| 820 } | 820 } |
| 821 } | 821 } |
| 822 vp << pObj; | 822 vp << pObj; |
| 823 return TRUE; | 823 return true; |
| 824 } | 824 } |
| 825 | 825 |
| 826 FX_BOOL Document::getPropertyInternal(IJS_Context* cc, | 826 bool Document::getPropertyInternal(IJS_Context* cc, |
| 827 CJS_PropValue& vp, | 827 CJS_PropValue& vp, |
| 828 const CFX_ByteString& propName, | 828 const CFX_ByteString& propName, |
| 829 CFX_WideString& sError) { | 829 CFX_WideString& sError) { |
| 830 if (!m_pFormFillEnv) { | 830 if (!m_pFormFillEnv) { |
| 831 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 831 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 832 return FALSE; | 832 return false; |
| 833 } | 833 } |
| 834 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); | 834 CPDF_Dictionary* pDictionary = m_pFormFillEnv->GetPDFDocument()->GetInfo(); |
| 835 if (!pDictionary) | 835 if (!pDictionary) |
| 836 return FALSE; | 836 return false; |
| 837 | 837 |
| 838 if (vp.IsGetting()) { | 838 if (vp.IsGetting()) { |
| 839 vp << pDictionary->GetUnicodeTextFor(propName); | 839 vp << pDictionary->GetUnicodeTextFor(propName); |
| 840 } else { | 840 } else { |
| 841 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { | 841 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
| 842 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 842 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 843 return FALSE; | 843 return false; |
| 844 } | 844 } |
| 845 CFX_WideString csProperty; | 845 CFX_WideString csProperty; |
| 846 vp >> csProperty; | 846 vp >> csProperty; |
| 847 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); | 847 pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty)); |
| 848 m_pFormFillEnv->SetChangeMark(); | 848 m_pFormFillEnv->SetChangeMark(); |
| 849 } | 849 } |
| 850 return TRUE; | 850 return true; |
| 851 } | 851 } |
| 852 | 852 |
| 853 FX_BOOL Document::creationDate(IJS_Context* cc, | 853 bool Document::creationDate(IJS_Context* cc, |
| 854 CJS_PropValue& vp, | 854 CJS_PropValue& vp, |
| 855 CFX_WideString& sError) { | 855 CFX_WideString& sError) { |
| 856 return getPropertyInternal(cc, vp, "CreationDate", sError); | 856 return getPropertyInternal(cc, vp, "CreationDate", sError); |
| 857 } | 857 } |
| 858 | 858 |
| 859 FX_BOOL Document::creator(IJS_Context* cc, | 859 bool Document::creator(IJS_Context* cc, |
| 860 CJS_PropValue& vp, | 860 CJS_PropValue& vp, |
| 861 CFX_WideString& sError) { | 861 CFX_WideString& sError) { |
| 862 return getPropertyInternal(cc, vp, "Creator", sError); | 862 return getPropertyInternal(cc, vp, "Creator", sError); |
| 863 } | 863 } |
| 864 | 864 |
| 865 FX_BOOL Document::delay(IJS_Context* cc, | 865 bool Document::delay(IJS_Context* cc, |
| 866 CJS_PropValue& vp, | 866 CJS_PropValue& vp, |
| 867 CFX_WideString& sError) { | 867 CFX_WideString& sError) { |
| 868 if (!m_pFormFillEnv) { | 868 if (!m_pFormFillEnv) { |
| 869 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 869 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 870 return FALSE; | 870 return false; |
| 871 } | 871 } |
| 872 if (vp.IsGetting()) { | 872 if (vp.IsGetting()) { |
| 873 vp << m_bDelay; | 873 vp << m_bDelay; |
| 874 } else { | 874 } else { |
| 875 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { | 875 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY)) { |
| 876 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 876 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 877 return FALSE; | 877 return false; |
| 878 } | 878 } |
| 879 vp >> m_bDelay; | 879 vp >> m_bDelay; |
| 880 if (m_bDelay) { | 880 if (m_bDelay) { |
| 881 m_DelayData.clear(); | 881 m_DelayData.clear(); |
| 882 } else { | 882 } else { |
| 883 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; | 883 std::list<std::unique_ptr<CJS_DelayData>> DelayDataToProcess; |
| 884 DelayDataToProcess.swap(m_DelayData); | 884 DelayDataToProcess.swap(m_DelayData); |
| 885 for (const auto& pData : DelayDataToProcess) | 885 for (const auto& pData : DelayDataToProcess) |
| 886 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); | 886 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 return TRUE; | 889 return true; |
| 890 } | 890 } |
| 891 | 891 |
| 892 FX_BOOL Document::keywords(IJS_Context* cc, | 892 bool Document::keywords(IJS_Context* cc, |
| 893 CJS_PropValue& vp, | 893 CJS_PropValue& vp, |
| 894 CFX_WideString& sError) { | 894 CFX_WideString& sError) { |
| 895 return getPropertyInternal(cc, vp, "Keywords", sError); | 895 return getPropertyInternal(cc, vp, "Keywords", sError); |
| 896 } | 896 } |
| 897 | 897 |
| 898 FX_BOOL Document::modDate(IJS_Context* cc, | 898 bool Document::modDate(IJS_Context* cc, |
| 899 CJS_PropValue& vp, | 899 CJS_PropValue& vp, |
| 900 CFX_WideString& sError) { | 900 CFX_WideString& sError) { |
| 901 return getPropertyInternal(cc, vp, "ModDate", sError); | 901 return getPropertyInternal(cc, vp, "ModDate", sError); |
| 902 } | 902 } |
| 903 | 903 |
| 904 FX_BOOL Document::producer(IJS_Context* cc, | 904 bool Document::producer(IJS_Context* cc, |
| 905 CJS_PropValue& vp, | 905 CJS_PropValue& vp, |
| 906 CFX_WideString& sError) { | 906 CFX_WideString& sError) { |
| 907 return getPropertyInternal(cc, vp, "Producer", sError); | 907 return getPropertyInternal(cc, vp, "Producer", sError); |
| 908 } | 908 } |
| 909 | 909 |
| 910 FX_BOOL Document::subject(IJS_Context* cc, | 910 bool Document::subject(IJS_Context* cc, |
| 911 CJS_PropValue& vp, | 911 CJS_PropValue& vp, |
| 912 CFX_WideString& sError) { | 912 CFX_WideString& sError) { |
| 913 return getPropertyInternal(cc, vp, "Subject", sError); | 913 return getPropertyInternal(cc, vp, "Subject", sError); |
| 914 } | 914 } |
| 915 | 915 |
| 916 FX_BOOL Document::title(IJS_Context* cc, | 916 bool Document::title(IJS_Context* cc, |
| 917 CJS_PropValue& vp, | 917 CJS_PropValue& vp, |
| 918 CFX_WideString& sError) { | 918 CFX_WideString& sError) { |
| 919 if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { | 919 if (!m_pFormFillEnv || !m_pFormFillEnv->GetUnderlyingDocument()) { |
| 920 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 920 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 921 return FALSE; | 921 return false; |
| 922 } | 922 } |
| 923 return getPropertyInternal(cc, vp, "Title", sError); | 923 return getPropertyInternal(cc, vp, "Title", sError); |
| 924 } | 924 } |
| 925 | 925 |
| 926 FX_BOOL Document::numPages(IJS_Context* cc, | 926 bool Document::numPages(IJS_Context* cc, |
| 927 CJS_PropValue& vp, | 927 CJS_PropValue& vp, |
| 928 CFX_WideString& sError) { | 928 CFX_WideString& sError) { |
| 929 if (vp.IsSetting()) { | 929 if (vp.IsSetting()) { |
| 930 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 930 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 931 return FALSE; | 931 return false; |
| 932 } | 932 } |
| 933 if (!m_pFormFillEnv) { | 933 if (!m_pFormFillEnv) { |
| 934 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 934 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 935 return FALSE; | 935 return false; |
| 936 } | 936 } |
| 937 vp << m_pFormFillEnv->GetPageCount(); | 937 vp << m_pFormFillEnv->GetPageCount(); |
| 938 return TRUE; | 938 return true; |
| 939 } | 939 } |
| 940 | 940 |
| 941 FX_BOOL Document::external(IJS_Context* cc, | 941 bool Document::external(IJS_Context* cc, |
| 942 CJS_PropValue& vp, | 942 CJS_PropValue& vp, |
| 943 CFX_WideString& sError) { | 943 CFX_WideString& sError) { |
| 944 // In Chrome case, should always return true. | 944 // In Chrome case, should always return true. |
| 945 if (vp.IsGetting()) { | 945 if (vp.IsGetting()) { |
| 946 vp << true; | 946 vp << true; |
| 947 } | 947 } |
| 948 return TRUE; | 948 return true; |
| 949 } | 949 } |
| 950 | 950 |
| 951 FX_BOOL Document::filesize(IJS_Context* cc, | 951 bool Document::filesize(IJS_Context* cc, |
| 952 CJS_PropValue& vp, | 952 CJS_PropValue& vp, |
| 953 CFX_WideString& sError) { | 953 CFX_WideString& sError) { |
| 954 if (vp.IsSetting()) { | 954 if (vp.IsSetting()) { |
| 955 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 955 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 956 return FALSE; | 956 return false; |
| 957 } | 957 } |
| 958 vp << 0; | 958 vp << 0; |
| 959 return TRUE; | 959 return true; |
| 960 } | 960 } |
| 961 | 961 |
| 962 FX_BOOL Document::mouseX(IJS_Context* cc, | 962 bool Document::mouseX(IJS_Context* cc, |
| 963 CJS_PropValue& vp, | 963 CJS_PropValue& vp, |
| 964 CFX_WideString& sError) { | 964 CFX_WideString& sError) { |
| 965 return TRUE; | 965 return true; |
| 966 } | 966 } |
| 967 | 967 |
| 968 FX_BOOL Document::mouseY(IJS_Context* cc, | 968 bool Document::mouseY(IJS_Context* cc, |
| 969 CJS_PropValue& vp, | 969 CJS_PropValue& vp, |
| 970 CFX_WideString& sError) { | 970 CFX_WideString& sError) { |
| 971 return TRUE; | 971 return true; |
| 972 } | 972 } |
| 973 | 973 |
| 974 FX_BOOL Document::URL(IJS_Context* cc, | 974 bool Document::URL(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
| 975 CJS_PropValue& vp, | |
| 976 CFX_WideString& sError) { | |
| 977 if (vp.IsSetting()) { | 975 if (vp.IsSetting()) { |
| 978 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 976 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 979 return FALSE; | 977 return false; |
| 980 } | 978 } |
| 981 if (!m_pFormFillEnv) { | 979 if (!m_pFormFillEnv) { |
| 982 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 980 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 983 return FALSE; | 981 return false; |
| 984 } | 982 } |
| 985 vp << m_pFormFillEnv->JS_docGetFilePath(); | 983 vp << m_pFormFillEnv->JS_docGetFilePath(); |
| 986 return TRUE; | 984 return true; |
| 987 } | 985 } |
| 988 | 986 |
| 989 FX_BOOL Document::baseURL(IJS_Context* cc, | 987 bool Document::baseURL(IJS_Context* cc, |
| 990 CJS_PropValue& vp, | 988 CJS_PropValue& vp, |
| 991 CFX_WideString& sError) { | 989 CFX_WideString& sError) { |
| 992 if (vp.IsGetting()) { | 990 if (vp.IsGetting()) { |
| 993 vp << m_cwBaseURL; | 991 vp << m_cwBaseURL; |
| 994 } else { | 992 } else { |
| 995 vp >> m_cwBaseURL; | 993 vp >> m_cwBaseURL; |
| 996 } | 994 } |
| 997 return TRUE; | 995 return true; |
| 998 } | 996 } |
| 999 | 997 |
| 1000 FX_BOOL Document::calculate(IJS_Context* cc, | 998 bool Document::calculate(IJS_Context* cc, |
| 1001 CJS_PropValue& vp, | 999 CJS_PropValue& vp, |
| 1002 CFX_WideString& sError) { | 1000 CFX_WideString& sError) { |
| 1003 if (!m_pFormFillEnv) { | 1001 if (!m_pFormFillEnv) { |
| 1004 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1002 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1005 return FALSE; | 1003 return false; |
| 1006 } | 1004 } |
| 1007 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); | 1005 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1008 if (vp.IsGetting()) { | 1006 if (vp.IsGetting()) { |
| 1009 vp << !!pInterForm->IsCalculateEnabled(); | 1007 vp << !!pInterForm->IsCalculateEnabled(); |
| 1010 } else { | 1008 } else { |
| 1011 bool bCalculate; | 1009 bool bCalculate; |
| 1012 vp >> bCalculate; | 1010 vp >> bCalculate; |
| 1013 pInterForm->EnableCalculate(bCalculate); | 1011 pInterForm->EnableCalculate(bCalculate); |
| 1014 } | 1012 } |
| 1015 return TRUE; | 1013 return true; |
| 1016 } | 1014 } |
| 1017 | 1015 |
| 1018 FX_BOOL Document::documentFileName(IJS_Context* cc, | 1016 bool Document::documentFileName(IJS_Context* cc, |
| 1019 CJS_PropValue& vp, | 1017 CJS_PropValue& vp, |
| 1020 CFX_WideString& sError) { | 1018 CFX_WideString& sError) { |
| 1021 if (vp.IsSetting()) { | 1019 if (vp.IsSetting()) { |
| 1022 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1020 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 1023 return FALSE; | 1021 return false; |
| 1024 } | 1022 } |
| 1025 if (!m_pFormFillEnv) { | 1023 if (!m_pFormFillEnv) { |
| 1026 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1024 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1027 return FALSE; | 1025 return false; |
| 1028 } | 1026 } |
| 1029 CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); | 1027 CFX_WideString wsFilePath = m_pFormFillEnv->JS_docGetFilePath(); |
| 1030 int32_t i = wsFilePath.GetLength() - 1; | 1028 int32_t i = wsFilePath.GetLength() - 1; |
| 1031 for (; i >= 0; i--) { | 1029 for (; i >= 0; i--) { |
| 1032 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') | 1030 if (wsFilePath.GetAt(i) == L'\\' || wsFilePath.GetAt(i) == L'/') |
| 1033 break; | 1031 break; |
| 1034 } | 1032 } |
| 1035 if (i >= 0 && i < wsFilePath.GetLength() - 1) { | 1033 if (i >= 0 && i < wsFilePath.GetLength() - 1) { |
| 1036 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); | 1034 vp << (wsFilePath.GetBuffer(wsFilePath.GetLength()) + i + 1); |
| 1037 } else { | 1035 } else { |
| 1038 vp << L""; | 1036 vp << L""; |
| 1039 } | 1037 } |
| 1040 return TRUE; | 1038 return true; |
| 1041 } | 1039 } |
| 1042 | 1040 |
| 1043 FX_BOOL Document::path(IJS_Context* cc, | 1041 bool Document::path(IJS_Context* cc, |
| 1044 CJS_PropValue& vp, | 1042 CJS_PropValue& vp, |
| 1045 CFX_WideString& sError) { | 1043 CFX_WideString& sError) { |
| 1046 if (vp.IsSetting()) { | 1044 if (vp.IsSetting()) { |
| 1047 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1045 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 1048 return FALSE; | 1046 return false; |
| 1049 } | 1047 } |
| 1050 if (!m_pFormFillEnv) { | 1048 if (!m_pFormFillEnv) { |
| 1051 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1049 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1052 return FALSE; | 1050 return false; |
| 1053 } | 1051 } |
| 1054 vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); | 1052 vp << app::SysPathToPDFPath(m_pFormFillEnv->JS_docGetFilePath()); |
| 1055 return TRUE; | 1053 return true; |
| 1056 } | 1054 } |
| 1057 | 1055 |
| 1058 FX_BOOL Document::pageWindowRect(IJS_Context* cc, | 1056 bool Document::pageWindowRect(IJS_Context* cc, |
| 1059 CJS_PropValue& vp, | 1057 CJS_PropValue& vp, |
| 1060 CFX_WideString& sError) { | 1058 CFX_WideString& sError) { |
| 1061 return TRUE; | 1059 return true; |
| 1062 } | 1060 } |
| 1063 | 1061 |
| 1064 FX_BOOL Document::layout(IJS_Context* cc, | 1062 bool Document::layout(IJS_Context* cc, |
| 1065 CJS_PropValue& vp, | 1063 CJS_PropValue& vp, |
| 1066 CFX_WideString& sError) { | 1064 CFX_WideString& sError) { |
| 1067 return TRUE; | 1065 return true; |
| 1068 } | 1066 } |
| 1069 | 1067 |
| 1070 FX_BOOL Document::addLink(IJS_Context* cc, | 1068 bool Document::addLink(IJS_Context* cc, |
| 1069 const std::vector<CJS_Value>& params, |
| 1070 CJS_Value& vRet, |
| 1071 CFX_WideString& sError) { |
| 1072 return true; |
| 1073 } |
| 1074 |
| 1075 bool Document::closeDoc(IJS_Context* cc, |
| 1076 const std::vector<CJS_Value>& params, |
| 1077 CJS_Value& vRet, |
| 1078 CFX_WideString& sError) { |
| 1079 return true; |
| 1080 } |
| 1081 |
| 1082 bool Document::getPageBox(IJS_Context* cc, |
| 1071 const std::vector<CJS_Value>& params, | 1083 const std::vector<CJS_Value>& params, |
| 1072 CJS_Value& vRet, | 1084 CJS_Value& vRet, |
| 1073 CFX_WideString& sError) { | 1085 CFX_WideString& sError) { |
| 1074 return TRUE; | 1086 return true; |
| 1075 } | 1087 } |
| 1076 | 1088 |
| 1077 FX_BOOL Document::closeDoc(IJS_Context* cc, | 1089 bool Document::getAnnot(IJS_Context* cc, |
| 1078 const std::vector<CJS_Value>& params, | 1090 const std::vector<CJS_Value>& params, |
| 1079 CJS_Value& vRet, | 1091 CJS_Value& vRet, |
| 1080 CFX_WideString& sError) { | 1092 CFX_WideString& sError) { |
| 1081 return TRUE; | |
| 1082 } | |
| 1083 | |
| 1084 FX_BOOL Document::getPageBox(IJS_Context* cc, | |
| 1085 const std::vector<CJS_Value>& params, | |
| 1086 CJS_Value& vRet, | |
| 1087 CFX_WideString& sError) { | |
| 1088 return TRUE; | |
| 1089 } | |
| 1090 | |
| 1091 FX_BOOL Document::getAnnot(IJS_Context* cc, | |
| 1092 const std::vector<CJS_Value>& params, | |
| 1093 CJS_Value& vRet, | |
| 1094 CFX_WideString& sError) { | |
| 1095 if (params.size() != 2) { | 1093 if (params.size() != 2) { |
| 1096 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1094 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1097 return FALSE; | 1095 return false; |
| 1098 } | 1096 } |
| 1099 if (!m_pFormFillEnv) { | 1097 if (!m_pFormFillEnv) { |
| 1100 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1098 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1101 return FALSE; | 1099 return false; |
| 1102 } | 1100 } |
| 1103 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1101 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1104 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1102 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1105 int nPageNo = params[0].ToInt(pRuntime); | 1103 int nPageNo = params[0].ToInt(pRuntime); |
| 1106 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); | 1104 CFX_WideString swAnnotName = params[1].ToCFXWideString(pRuntime); |
| 1107 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); | 1105 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); |
| 1108 if (!pPageView) | 1106 if (!pPageView) |
| 1109 return FALSE; | 1107 return false; |
| 1110 | 1108 |
| 1111 CPDFSDK_AnnotIterator annotIterator(pPageView, false); | 1109 CPDFSDK_AnnotIterator annotIterator(pPageView, false); |
| 1112 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; | 1110 CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr; |
| 1113 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { | 1111 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { |
| 1114 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); | 1112 CPDFSDK_BAAnnot* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); |
| 1115 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { | 1113 if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) { |
| 1116 pSDKBAAnnot = pBAAnnot; | 1114 pSDKBAAnnot = pBAAnnot; |
| 1117 break; | 1115 break; |
| 1118 } | 1116 } |
| 1119 } | 1117 } |
| 1120 | 1118 |
| 1121 if (!pSDKBAAnnot) | 1119 if (!pSDKBAAnnot) |
| 1122 return FALSE; | 1120 return false; |
| 1123 | 1121 |
| 1124 v8::Local<v8::Object> pObj = | 1122 v8::Local<v8::Object> pObj = |
| 1125 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); | 1123 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1126 if (pObj.IsEmpty()) | 1124 if (pObj.IsEmpty()) |
| 1127 return FALSE; | 1125 return false; |
| 1128 | 1126 |
| 1129 CJS_Annot* pJS_Annot = | 1127 CJS_Annot* pJS_Annot = |
| 1130 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); | 1128 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1131 if (!pJS_Annot) | 1129 if (!pJS_Annot) |
| 1132 return FALSE; | 1130 return false; |
| 1133 | 1131 |
| 1134 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); | 1132 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1135 if (!pAnnot) | 1133 if (!pAnnot) |
| 1136 return FALSE; | 1134 return false; |
| 1137 | 1135 |
| 1138 pAnnot->SetSDKAnnot(pSDKBAAnnot); | 1136 pAnnot->SetSDKAnnot(pSDKBAAnnot); |
| 1139 | 1137 |
| 1140 vRet = CJS_Value(pRuntime, pJS_Annot); | 1138 vRet = CJS_Value(pRuntime, pJS_Annot); |
| 1141 return TRUE; | 1139 return true; |
| 1142 } | 1140 } |
| 1143 | 1141 |
| 1144 FX_BOOL Document::getAnnots(IJS_Context* cc, | 1142 bool Document::getAnnots(IJS_Context* cc, |
| 1145 const std::vector<CJS_Value>& params, | 1143 const std::vector<CJS_Value>& params, |
| 1146 CJS_Value& vRet, | 1144 CJS_Value& vRet, |
| 1147 CFX_WideString& sError) { | 1145 CFX_WideString& sError) { |
| 1148 if (!m_pFormFillEnv) { | 1146 if (!m_pFormFillEnv) { |
| 1149 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1147 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1150 return FALSE; | 1148 return false; |
| 1151 } | 1149 } |
| 1152 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1150 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1153 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1151 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1154 | 1152 |
| 1155 // TODO(tonikitoo): Add support supported parameters as per | 1153 // TODO(tonikitoo): Add support supported parameters as per |
| 1156 // the PDF spec. | 1154 // the PDF spec. |
| 1157 | 1155 |
| 1158 int nPageNo = m_pFormFillEnv->GetPageCount(); | 1156 int nPageNo = m_pFormFillEnv->GetPageCount(); |
| 1159 CJS_Array annots; | 1157 CJS_Array annots; |
| 1160 | 1158 |
| 1161 for (int i = 0; i < nPageNo; ++i) { | 1159 for (int i = 0; i < nPageNo; ++i) { |
| 1162 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); | 1160 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(i); |
| 1163 if (!pPageView) | 1161 if (!pPageView) |
| 1164 return FALSE; | 1162 return false; |
| 1165 | 1163 |
| 1166 CPDFSDK_AnnotIterator annotIterator(pPageView, false); | 1164 CPDFSDK_AnnotIterator annotIterator(pPageView, false); |
| 1167 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { | 1165 while (CPDFSDK_Annot* pSDKAnnotCur = annotIterator.Next()) { |
| 1168 CPDFSDK_BAAnnot* pSDKBAAnnot = | 1166 CPDFSDK_BAAnnot* pSDKBAAnnot = |
| 1169 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); | 1167 static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur); |
| 1170 if (!pSDKBAAnnot) | 1168 if (!pSDKBAAnnot) |
| 1171 return FALSE; | 1169 return false; |
| 1172 | 1170 |
| 1173 v8::Local<v8::Object> pObj = | 1171 v8::Local<v8::Object> pObj = |
| 1174 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); | 1172 pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); |
| 1175 if (pObj.IsEmpty()) | 1173 if (pObj.IsEmpty()) |
| 1176 return FALSE; | 1174 return false; |
| 1177 | 1175 |
| 1178 CJS_Annot* pJS_Annot = | 1176 CJS_Annot* pJS_Annot = |
| 1179 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); | 1177 static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj)); |
| 1180 if (!pJS_Annot) | 1178 if (!pJS_Annot) |
| 1181 return FALSE; | 1179 return false; |
| 1182 | 1180 |
| 1183 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); | 1181 Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject()); |
| 1184 if (!pAnnot) | 1182 if (!pAnnot) |
| 1185 return FALSE; | 1183 return false; |
| 1186 | 1184 |
| 1187 pAnnot->SetSDKAnnot(pSDKBAAnnot); | 1185 pAnnot->SetSDKAnnot(pSDKBAAnnot); |
| 1188 annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); | 1186 annots.SetElement(pRuntime, i, CJS_Value(pRuntime, pJS_Annot)); |
| 1189 } | 1187 } |
| 1190 } | 1188 } |
| 1191 | 1189 |
| 1192 vRet = CJS_Value(pRuntime, annots); | 1190 vRet = CJS_Value(pRuntime, annots); |
| 1193 return TRUE; | 1191 return true; |
| 1194 } | 1192 } |
| 1195 | 1193 |
| 1196 FX_BOOL Document::getAnnot3D(IJS_Context* cc, | 1194 bool Document::getAnnot3D(IJS_Context* cc, |
| 1197 const std::vector<CJS_Value>& params, | |
| 1198 CJS_Value& vRet, | |
| 1199 CFX_WideString& sError) { | |
| 1200 vRet.SetNull(CJS_Runtime::FromContext(cc)); | |
| 1201 return TRUE; | |
| 1202 } | |
| 1203 | |
| 1204 FX_BOOL Document::getAnnots3D(IJS_Context* cc, | |
| 1205 const std::vector<CJS_Value>& params, | |
| 1206 CJS_Value& vRet, | |
| 1207 CFX_WideString& sError) { | |
| 1208 return TRUE; | |
| 1209 } | |
| 1210 | |
| 1211 FX_BOOL Document::getOCGs(IJS_Context* cc, | |
| 1212 const std::vector<CJS_Value>& params, | 1195 const std::vector<CJS_Value>& params, |
| 1213 CJS_Value& vRet, | 1196 CJS_Value& vRet, |
| 1214 CFX_WideString& sError) { | 1197 CFX_WideString& sError) { |
| 1215 return TRUE; | 1198 vRet.SetNull(CJS_Runtime::FromContext(cc)); |
| 1199 return true; |
| 1216 } | 1200 } |
| 1217 | 1201 |
| 1218 FX_BOOL Document::getLinks(IJS_Context* cc, | 1202 bool Document::getAnnots3D(IJS_Context* cc, |
| 1219 const std::vector<CJS_Value>& params, | 1203 const std::vector<CJS_Value>& params, |
| 1220 CJS_Value& vRet, | 1204 CJS_Value& vRet, |
| 1221 CFX_WideString& sError) { | 1205 CFX_WideString& sError) { |
| 1222 return TRUE; | 1206 return true; |
| 1207 } |
| 1208 |
| 1209 bool Document::getOCGs(IJS_Context* cc, |
| 1210 const std::vector<CJS_Value>& params, |
| 1211 CJS_Value& vRet, |
| 1212 CFX_WideString& sError) { |
| 1213 return true; |
| 1214 } |
| 1215 |
| 1216 bool Document::getLinks(IJS_Context* cc, |
| 1217 const std::vector<CJS_Value>& params, |
| 1218 CJS_Value& vRet, |
| 1219 CFX_WideString& sError) { |
| 1220 return true; |
| 1223 } | 1221 } |
| 1224 | 1222 |
| 1225 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { | 1223 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { |
| 1226 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && | 1224 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && |
| 1227 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); | 1225 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); |
| 1228 } | 1226 } |
| 1229 | 1227 |
| 1230 FX_BOOL Document::addIcon(IJS_Context* cc, | 1228 bool Document::addIcon(IJS_Context* cc, |
| 1231 const std::vector<CJS_Value>& params, | 1229 const std::vector<CJS_Value>& params, |
| 1232 CJS_Value& vRet, | 1230 CJS_Value& vRet, |
| 1233 CFX_WideString& sError) { | 1231 CFX_WideString& sError) { |
| 1234 if (params.size() != 2) { | 1232 if (params.size() != 2) { |
| 1235 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1233 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1236 return FALSE; | 1234 return false; |
| 1237 } | 1235 } |
| 1238 | 1236 |
| 1239 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1237 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1240 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1238 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1241 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1239 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
| 1242 | 1240 |
| 1243 if (params[1].GetType() != CJS_Value::VT_object) { | 1241 if (params[1].GetType() != CJS_Value::VT_object) { |
| 1244 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1242 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
| 1245 return FALSE; | 1243 return false; |
| 1246 } | 1244 } |
| 1247 | 1245 |
| 1248 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); | 1246 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(pRuntime); |
| 1249 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { | 1247 if (pRuntime->GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { |
| 1250 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1248 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
| 1251 return FALSE; | 1249 return false; |
| 1252 } | 1250 } |
| 1253 | 1251 |
| 1254 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); | 1252 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject(pRuntime)->GetEmbedObject(); |
| 1255 if (!pEmbedObj) { | 1253 if (!pEmbedObj) { |
| 1256 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); | 1254 sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); |
| 1257 return FALSE; | 1255 return false; |
| 1258 } | 1256 } |
| 1259 | 1257 |
| 1260 m_Icons.push_back(pdfium::MakeUnique<IconElement>( | 1258 m_Icons.push_back(pdfium::MakeUnique<IconElement>( |
| 1261 swIconName, static_cast<Icon*>(pEmbedObj))); | 1259 swIconName, static_cast<Icon*>(pEmbedObj))); |
| 1262 return TRUE; | 1260 return true; |
| 1263 } | 1261 } |
| 1264 | 1262 |
| 1265 FX_BOOL Document::icons(IJS_Context* cc, | 1263 bool Document::icons(IJS_Context* cc, |
| 1266 CJS_PropValue& vp, | 1264 CJS_PropValue& vp, |
| 1267 CFX_WideString& sError) { | 1265 CFX_WideString& sError) { |
| 1268 if (vp.IsSetting()) { | 1266 if (vp.IsSetting()) { |
| 1269 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); | 1267 sError = JSGetStringFromID(IDS_STRING_JSREADONLY); |
| 1270 return FALSE; | 1268 return false; |
| 1271 } | 1269 } |
| 1272 | 1270 |
| 1273 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1271 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1274 if (m_Icons.empty()) { | 1272 if (m_Icons.empty()) { |
| 1275 vp.GetJSValue()->SetNull(pRuntime); | 1273 vp.GetJSValue()->SetNull(pRuntime); |
| 1276 return TRUE; | 1274 return true; |
| 1277 } | 1275 } |
| 1278 | 1276 |
| 1279 CJS_Array Icons; | 1277 CJS_Array Icons; |
| 1280 | 1278 |
| 1281 int i = 0; | 1279 int i = 0; |
| 1282 for (const auto& pIconElement : m_Icons) { | 1280 for (const auto& pIconElement : m_Icons) { |
| 1283 v8::Local<v8::Object> pObj = | 1281 v8::Local<v8::Object> pObj = |
| 1284 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1282 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1285 if (pObj.IsEmpty()) | 1283 if (pObj.IsEmpty()) |
| 1286 return FALSE; | 1284 return false; |
| 1287 | 1285 |
| 1288 CJS_Icon* pJS_Icon = | 1286 CJS_Icon* pJS_Icon = |
| 1289 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1287 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1290 if (!pJS_Icon) | 1288 if (!pJS_Icon) |
| 1291 return FALSE; | 1289 return false; |
| 1292 | 1290 |
| 1293 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); | 1291 Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject()); |
| 1294 if (!pIcon) | 1292 if (!pIcon) |
| 1295 return FALSE; | 1293 return false; |
| 1296 | 1294 |
| 1297 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1295 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1298 pIcon->SetIconName(pIconElement->IconName); | 1296 pIcon->SetIconName(pIconElement->IconName); |
| 1299 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); | 1297 Icons.SetElement(pRuntime, i++, CJS_Value(pRuntime, pJS_Icon)); |
| 1300 } | 1298 } |
| 1301 | 1299 |
| 1302 vp << Icons; | 1300 vp << Icons; |
| 1303 return TRUE; | 1301 return true; |
| 1304 } | 1302 } |
| 1305 | 1303 |
| 1306 FX_BOOL Document::getIcon(IJS_Context* cc, | 1304 bool Document::getIcon(IJS_Context* cc, |
| 1307 const std::vector<CJS_Value>& params, | 1305 const std::vector<CJS_Value>& params, |
| 1308 CJS_Value& vRet, | 1306 CJS_Value& vRet, |
| 1309 CFX_WideString& sError) { | 1307 CFX_WideString& sError) { |
| 1310 if (params.size() != 1) { | 1308 if (params.size() != 1) { |
| 1311 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1309 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1312 return FALSE; | 1310 return false; |
| 1313 } | 1311 } |
| 1314 | 1312 |
| 1315 if (m_Icons.empty()) | 1313 if (m_Icons.empty()) |
| 1316 return FALSE; | 1314 return false; |
| 1317 | 1315 |
| 1318 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1316 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1319 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); | 1317 CFX_WideString swIconName = params[0].ToCFXWideString(pRuntime); |
| 1320 | 1318 |
| 1321 for (const auto& pIconElement : m_Icons) { | 1319 for (const auto& pIconElement : m_Icons) { |
| 1322 if (pIconElement->IconName != swIconName) | 1320 if (pIconElement->IconName != swIconName) |
| 1323 continue; | 1321 continue; |
| 1324 | 1322 |
| 1325 v8::Local<v8::Object> pObj = | 1323 v8::Local<v8::Object> pObj = |
| 1326 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); | 1324 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
| 1327 if (pObj.IsEmpty()) | 1325 if (pObj.IsEmpty()) |
| 1328 return FALSE; | 1326 return false; |
| 1329 | 1327 |
| 1330 CJS_Icon* pJS_Icon = | 1328 CJS_Icon* pJS_Icon = |
| 1331 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); | 1329 static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
| 1332 if (!pJS_Icon) | 1330 if (!pJS_Icon) |
| 1333 return FALSE; | 1331 return false; |
| 1334 | 1332 |
| 1335 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 1333 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
| 1336 if (!pIcon) | 1334 if (!pIcon) |
| 1337 return FALSE; | 1335 return false; |
| 1338 | 1336 |
| 1339 pIcon->SetIconName(swIconName); | 1337 pIcon->SetIconName(swIconName); |
| 1340 pIcon->SetStream(pIconElement->IconStream->GetStream()); | 1338 pIcon->SetStream(pIconElement->IconStream->GetStream()); |
| 1341 | 1339 |
| 1342 vRet = CJS_Value(pRuntime, pJS_Icon); | 1340 vRet = CJS_Value(pRuntime, pJS_Icon); |
| 1343 return TRUE; | 1341 return true; |
| 1344 } | 1342 } |
| 1345 | 1343 |
| 1346 return FALSE; | 1344 return false; |
| 1347 } | 1345 } |
| 1348 | 1346 |
| 1349 FX_BOOL Document::removeIcon(IJS_Context* cc, | 1347 bool Document::removeIcon(IJS_Context* cc, |
| 1350 const std::vector<CJS_Value>& params, | 1348 const std::vector<CJS_Value>& params, |
| 1351 CJS_Value& vRet, | 1349 CJS_Value& vRet, |
| 1352 CFX_WideString& sError) { | 1350 CFX_WideString& sError) { |
| 1353 // Unsafe, no supported. | 1351 // Unsafe, no supported. |
| 1354 return TRUE; | 1352 return true; |
| 1355 } | 1353 } |
| 1356 | 1354 |
| 1357 FX_BOOL Document::createDataObject(IJS_Context* cc, | 1355 bool Document::createDataObject(IJS_Context* cc, |
| 1358 const std::vector<CJS_Value>& params, | 1356 const std::vector<CJS_Value>& params, |
| 1359 CJS_Value& vRet, | 1357 CJS_Value& vRet, |
| 1360 CFX_WideString& sError) { | 1358 CFX_WideString& sError) { |
| 1361 // Unsafe, not implemented. | 1359 // Unsafe, not implemented. |
| 1362 return TRUE; | 1360 return true; |
| 1363 } | 1361 } |
| 1364 | 1362 |
| 1365 FX_BOOL Document::media(IJS_Context* cc, | 1363 bool Document::media(IJS_Context* cc, |
| 1366 CJS_PropValue& vp, | 1364 CJS_PropValue& vp, |
| 1367 CFX_WideString& sError) { | 1365 CFX_WideString& sError) { |
| 1368 return TRUE; | 1366 return true; |
| 1369 } | 1367 } |
| 1370 | 1368 |
| 1371 FX_BOOL Document::calculateNow(IJS_Context* cc, | 1369 bool Document::calculateNow(IJS_Context* cc, |
| 1372 const std::vector<CJS_Value>& params, | 1370 const std::vector<CJS_Value>& params, |
| 1373 CJS_Value& vRet, | 1371 CJS_Value& vRet, |
| 1374 CFX_WideString& sError) { | 1372 CFX_WideString& sError) { |
| 1375 if (!m_pFormFillEnv) { | 1373 if (!m_pFormFillEnv) { |
| 1376 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1374 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1377 return FALSE; | 1375 return false; |
| 1378 } | 1376 } |
| 1379 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || | 1377 if (!(m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY) || |
| 1380 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || | 1378 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 1381 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { | 1379 m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM))) { |
| 1382 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1380 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1383 return FALSE; | 1381 return false; |
| 1384 } | 1382 } |
| 1385 m_pFormFillEnv->GetInterForm()->OnCalculate(); | 1383 m_pFormFillEnv->GetInterForm()->OnCalculate(); |
| 1386 return TRUE; | 1384 return true; |
| 1387 } | 1385 } |
| 1388 | 1386 |
| 1389 FX_BOOL Document::Collab(IJS_Context* cc, | 1387 bool Document::Collab(IJS_Context* cc, |
| 1390 CJS_PropValue& vp, | 1388 CJS_PropValue& vp, |
| 1391 CFX_WideString& sError) { | 1389 CFX_WideString& sError) { |
| 1392 return TRUE; | 1390 return true; |
| 1393 } | 1391 } |
| 1394 | 1392 |
| 1395 FX_BOOL Document::getPageNthWord(IJS_Context* cc, | 1393 bool Document::getPageNthWord(IJS_Context* cc, |
| 1396 const std::vector<CJS_Value>& params, | 1394 const std::vector<CJS_Value>& params, |
| 1397 CJS_Value& vRet, | 1395 CJS_Value& vRet, |
| 1398 CFX_WideString& sError) { | 1396 CFX_WideString& sError) { |
| 1399 if (!m_pFormFillEnv) { | 1397 if (!m_pFormFillEnv) { |
| 1400 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1398 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1401 return FALSE; | 1399 return false; |
| 1402 } | 1400 } |
| 1403 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { | 1401 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1404 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1402 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1405 return FALSE; | 1403 return false; |
| 1406 } | 1404 } |
| 1407 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1405 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1408 | 1406 |
| 1409 // TODO(tsepez): check maximum allowable params. | 1407 // TODO(tsepez): check maximum allowable params. |
| 1410 | 1408 |
| 1411 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1409 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1412 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; | 1410 int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; |
| 1413 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; | 1411 bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; |
| 1414 | 1412 |
| 1415 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); | 1413 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1416 if (!pDocument) | 1414 if (!pDocument) |
| 1417 return FALSE; | 1415 return false; |
| 1418 | 1416 |
| 1419 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1417 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1420 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 1418 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 1421 return FALSE; | 1419 return false; |
| 1422 } | 1420 } |
| 1423 | 1421 |
| 1424 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1422 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1425 if (!pPageDict) | 1423 if (!pPageDict) |
| 1426 return FALSE; | 1424 return false; |
| 1427 | 1425 |
| 1428 CPDF_Page page(pDocument, pPageDict, true); | 1426 CPDF_Page page(pDocument, pPageDict, true); |
| 1429 page.ParseContent(); | 1427 page.ParseContent(); |
| 1430 | 1428 |
| 1431 int nWords = 0; | 1429 int nWords = 0; |
| 1432 CFX_WideString swRet; | 1430 CFX_WideString swRet; |
| 1433 for (auto& pPageObj : *page.GetPageObjectList()) { | 1431 for (auto& pPageObj : *page.GetPageObjectList()) { |
| 1434 if (pPageObj->IsText()) { | 1432 if (pPageObj->IsText()) { |
| 1435 CPDF_TextObject* pTextObj = pPageObj->AsText(); | 1433 CPDF_TextObject* pTextObj = pPageObj->AsText(); |
| 1436 int nObjWords = CountWords(pTextObj); | 1434 int nObjWords = CountWords(pTextObj); |
| 1437 if (nWords + nObjWords >= nWordNo) { | 1435 if (nWords + nObjWords >= nWordNo) { |
| 1438 swRet = GetObjWordStr(pTextObj, nWordNo - nWords); | 1436 swRet = GetObjWordStr(pTextObj, nWordNo - nWords); |
| 1439 break; | 1437 break; |
| 1440 } | 1438 } |
| 1441 nWords += nObjWords; | 1439 nWords += nObjWords; |
| 1442 } | 1440 } |
| 1443 } | 1441 } |
| 1444 | 1442 |
| 1445 if (bStrip) { | 1443 if (bStrip) { |
| 1446 swRet.TrimLeft(); | 1444 swRet.TrimLeft(); |
| 1447 swRet.TrimRight(); | 1445 swRet.TrimRight(); |
| 1448 } | 1446 } |
| 1449 | 1447 |
| 1450 vRet = CJS_Value(pRuntime, swRet.c_str()); | 1448 vRet = CJS_Value(pRuntime, swRet.c_str()); |
| 1451 return TRUE; | 1449 return true; |
| 1452 } | 1450 } |
| 1453 | 1451 |
| 1454 FX_BOOL Document::getPageNthWordQuads(IJS_Context* cc, | 1452 bool Document::getPageNthWordQuads(IJS_Context* cc, |
| 1455 const std::vector<CJS_Value>& params, | 1453 const std::vector<CJS_Value>& params, |
| 1456 CJS_Value& vRet, | 1454 CJS_Value& vRet, |
| 1457 CFX_WideString& sError) { | 1455 CFX_WideString& sError) { |
| 1458 if (!m_pFormFillEnv) { | 1456 if (!m_pFormFillEnv) { |
| 1459 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1457 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1460 return FALSE; | 1458 return false; |
| 1461 } | 1459 } |
| 1462 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { | 1460 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1463 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1461 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1464 return FALSE; | 1462 return false; |
| 1465 } | 1463 } |
| 1466 return FALSE; | 1464 return false; |
| 1467 } | 1465 } |
| 1468 | 1466 |
| 1469 FX_BOOL Document::getPageNumWords(IJS_Context* cc, | 1467 bool Document::getPageNumWords(IJS_Context* cc, |
| 1470 const std::vector<CJS_Value>& params, | 1468 const std::vector<CJS_Value>& params, |
| 1471 CJS_Value& vRet, | 1469 CJS_Value& vRet, |
| 1472 CFX_WideString& sError) { | 1470 CFX_WideString& sError) { |
| 1473 if (!m_pFormFillEnv) { | 1471 if (!m_pFormFillEnv) { |
| 1474 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1472 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1475 return FALSE; | 1473 return false; |
| 1476 } | 1474 } |
| 1477 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { | 1475 if (!m_pFormFillEnv->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) { |
| 1478 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); | 1476 sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); |
| 1479 return FALSE; | 1477 return false; |
| 1480 } | 1478 } |
| 1481 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1479 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1482 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; | 1480 int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; |
| 1483 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); | 1481 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1484 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { | 1482 if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { |
| 1485 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); | 1483 sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); |
| 1486 return FALSE; | 1484 return false; |
| 1487 } | 1485 } |
| 1488 | 1486 |
| 1489 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); | 1487 CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); |
| 1490 if (!pPageDict) | 1488 if (!pPageDict) |
| 1491 return FALSE; | 1489 return false; |
| 1492 | 1490 |
| 1493 CPDF_Page page(pDocument, pPageDict, true); | 1491 CPDF_Page page(pDocument, pPageDict, true); |
| 1494 page.ParseContent(); | 1492 page.ParseContent(); |
| 1495 | 1493 |
| 1496 int nWords = 0; | 1494 int nWords = 0; |
| 1497 for (auto& pPageObj : *page.GetPageObjectList()) { | 1495 for (auto& pPageObj : *page.GetPageObjectList()) { |
| 1498 if (pPageObj->IsText()) | 1496 if (pPageObj->IsText()) |
| 1499 nWords += CountWords(pPageObj->AsText()); | 1497 nWords += CountWords(pPageObj->AsText()); |
| 1500 } | 1498 } |
| 1501 | 1499 |
| 1502 vRet = CJS_Value(pRuntime, nWords); | 1500 vRet = CJS_Value(pRuntime, nWords); |
| 1503 return TRUE; | 1501 return true; |
| 1504 } | 1502 } |
| 1505 | 1503 |
| 1506 FX_BOOL Document::getPrintParams(IJS_Context* cc, | 1504 bool Document::getPrintParams(IJS_Context* cc, |
| 1507 const std::vector<CJS_Value>& params, | 1505 const std::vector<CJS_Value>& params, |
| 1508 CJS_Value& vRet, | 1506 CJS_Value& vRet, |
| 1509 CFX_WideString& sError) { | 1507 CFX_WideString& sError) { |
| 1510 CJS_Context* pContext = (CJS_Context*)cc; | 1508 CJS_Context* pContext = (CJS_Context*)cc; |
| 1511 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 1509 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 1512 v8::Local<v8::Object> pRetObj = | 1510 v8::Local<v8::Object> pRetObj = |
| 1513 pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); | 1511 pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); |
| 1514 | 1512 |
| 1515 // Not implemented yet. | 1513 // Not implemented yet. |
| 1516 | 1514 |
| 1517 vRet = CJS_Value(pRuntime, pRetObj); | 1515 vRet = CJS_Value(pRuntime, pRetObj); |
| 1518 return TRUE; | 1516 return true; |
| 1519 } | 1517 } |
| 1520 | 1518 |
| 1521 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) | 1519 #define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) |
| 1522 | 1520 |
| 1523 int Document::CountWords(CPDF_TextObject* pTextObj) { | 1521 int Document::CountWords(CPDF_TextObject* pTextObj) { |
| 1524 if (!pTextObj) | 1522 if (!pTextObj) |
| 1525 return 0; | 1523 return 0; |
| 1526 | 1524 |
| 1527 int nWords = 0; | 1525 int nWords = 0; |
| 1528 | 1526 |
| 1529 CPDF_Font* pFont = pTextObj->GetFont(); | 1527 CPDF_Font* pFont = pTextObj->GetFont(); |
| 1530 if (!pFont) | 1528 if (!pFont) |
| 1531 return 0; | 1529 return 0; |
| 1532 | 1530 |
| 1533 FX_BOOL bIsLatin = FALSE; | 1531 bool bIsLatin = false; |
| 1534 | 1532 |
| 1535 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { | 1533 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
| 1536 uint32_t charcode = CPDF_Font::kInvalidCharCode; | 1534 uint32_t charcode = CPDF_Font::kInvalidCharCode; |
| 1537 FX_FLOAT kerning; | 1535 FX_FLOAT kerning; |
| 1538 | 1536 |
| 1539 pTextObj->GetCharInfo(i, charcode, kerning); | 1537 pTextObj->GetCharInfo(i, charcode, kerning); |
| 1540 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); | 1538 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1541 | 1539 |
| 1542 uint16_t unicode = 0; | 1540 uint16_t unicode = 0; |
| 1543 if (swUnicode.GetLength() > 0) | 1541 if (swUnicode.GetLength() > 0) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1556 | 1554 |
| 1557 CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, | 1555 CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, |
| 1558 int nWordIndex) { | 1556 int nWordIndex) { |
| 1559 CFX_WideString swRet; | 1557 CFX_WideString swRet; |
| 1560 | 1558 |
| 1561 CPDF_Font* pFont = pTextObj->GetFont(); | 1559 CPDF_Font* pFont = pTextObj->GetFont(); |
| 1562 if (!pFont) | 1560 if (!pFont) |
| 1563 return L""; | 1561 return L""; |
| 1564 | 1562 |
| 1565 int nWords = 0; | 1563 int nWords = 0; |
| 1566 FX_BOOL bIsLatin = FALSE; | 1564 bool bIsLatin = false; |
| 1567 | 1565 |
| 1568 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { | 1566 for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { |
| 1569 uint32_t charcode = CPDF_Font::kInvalidCharCode; | 1567 uint32_t charcode = CPDF_Font::kInvalidCharCode; |
| 1570 FX_FLOAT kerning; | 1568 FX_FLOAT kerning; |
| 1571 | 1569 |
| 1572 pTextObj->GetCharInfo(i, charcode, kerning); | 1570 pTextObj->GetCharInfo(i, charcode, kerning); |
| 1573 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); | 1571 CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); |
| 1574 | 1572 |
| 1575 uint16_t unicode = 0; | 1573 uint16_t unicode = 0; |
| 1576 if (swUnicode.GetLength() > 0) | 1574 if (swUnicode.GetLength() > 0) |
| 1577 unicode = swUnicode[0]; | 1575 unicode = swUnicode[0]; |
| 1578 | 1576 |
| 1579 if (ISLATINWORD(unicode) && bIsLatin) { | 1577 if (ISLATINWORD(unicode) && bIsLatin) { |
| 1580 } else { | 1578 } else { |
| 1581 bIsLatin = ISLATINWORD(unicode); | 1579 bIsLatin = ISLATINWORD(unicode); |
| 1582 if (unicode != 0x20) | 1580 if (unicode != 0x20) |
| 1583 nWords++; | 1581 nWords++; |
| 1584 } | 1582 } |
| 1585 | 1583 |
| 1586 if (nWords - 1 == nWordIndex) | 1584 if (nWords - 1 == nWordIndex) |
| 1587 swRet += unicode; | 1585 swRet += unicode; |
| 1588 } | 1586 } |
| 1589 | 1587 |
| 1590 return swRet; | 1588 return swRet; |
| 1591 } | 1589 } |
| 1592 | 1590 |
| 1593 FX_BOOL Document::zoom(IJS_Context* cc, | 1591 bool Document::zoom(IJS_Context* cc, |
| 1594 CJS_PropValue& vp, | 1592 CJS_PropValue& vp, |
| 1595 CFX_WideString& sError) { | 1593 CFX_WideString& sError) { |
| 1596 return TRUE; | 1594 return true; |
| 1597 } | 1595 } |
| 1598 | 1596 |
| 1599 /** | 1597 /** |
| 1600 (none, NoVary) | 1598 (none, NoVary) |
| 1601 (fitP, FitPage) | 1599 (fitP, FitPage) |
| 1602 (fitW, FitWidth) | 1600 (fitW, FitWidth) |
| 1603 (fitH, FitHeight) | 1601 (fitH, FitHeight) |
| 1604 (fitV, FitVisibleWidth) | 1602 (fitV, FitVisibleWidth) |
| 1605 (pref, Preferred) | 1603 (pref, Preferred) |
| 1606 (refW, ReflowWidth) | 1604 (refW, ReflowWidth) |
| 1607 */ | 1605 */ |
| 1608 | 1606 |
| 1609 FX_BOOL Document::zoomType(IJS_Context* cc, | 1607 bool Document::zoomType(IJS_Context* cc, |
| 1610 CJS_PropValue& vp, | 1608 CJS_PropValue& vp, |
| 1611 CFX_WideString& sError) { | 1609 CFX_WideString& sError) { |
| 1612 return TRUE; | 1610 return true; |
| 1613 } | 1611 } |
| 1614 | 1612 |
| 1615 FX_BOOL Document::deletePages(IJS_Context* cc, | 1613 bool Document::deletePages(IJS_Context* cc, |
| 1616 const std::vector<CJS_Value>& params, | 1614 const std::vector<CJS_Value>& params, |
| 1617 CJS_Value& vRet, | 1615 CJS_Value& vRet, |
| 1618 CFX_WideString& sError) { | 1616 CFX_WideString& sError) { |
| 1619 // Unsafe, no supported. | 1617 // Unsafe, no supported. |
| 1620 return TRUE; | 1618 return true; |
| 1621 } | 1619 } |
| 1622 | 1620 |
| 1623 FX_BOOL Document::extractPages(IJS_Context* cc, | 1621 bool Document::extractPages(IJS_Context* cc, |
| 1624 const std::vector<CJS_Value>& params, | 1622 const std::vector<CJS_Value>& params, |
| 1625 CJS_Value& vRet, | 1623 CJS_Value& vRet, |
| 1626 CFX_WideString& sError) { | 1624 CFX_WideString& sError) { |
| 1627 // Unsafe, not supported. | 1625 // Unsafe, not supported. |
| 1628 return TRUE; | 1626 return true; |
| 1629 } | 1627 } |
| 1630 | 1628 |
| 1631 FX_BOOL Document::insertPages(IJS_Context* cc, | 1629 bool Document::insertPages(IJS_Context* cc, |
| 1632 const std::vector<CJS_Value>& params, | 1630 const std::vector<CJS_Value>& params, |
| 1633 CJS_Value& vRet, | 1631 CJS_Value& vRet, |
| 1634 CFX_WideString& sError) { | 1632 CFX_WideString& sError) { |
| 1635 // Unsafe, not supported. | 1633 // Unsafe, not supported. |
| 1636 return TRUE; | 1634 return true; |
| 1637 } | 1635 } |
| 1638 | 1636 |
| 1639 FX_BOOL Document::replacePages(IJS_Context* cc, | 1637 bool Document::replacePages(IJS_Context* cc, |
| 1640 const std::vector<CJS_Value>& params, | 1638 const std::vector<CJS_Value>& params, |
| 1641 CJS_Value& vRet, | 1639 CJS_Value& vRet, |
| 1642 CFX_WideString& sError) { | 1640 CFX_WideString& sError) { |
| 1643 // Unsafe, not supported. | 1641 // Unsafe, not supported. |
| 1644 return TRUE; | 1642 return true; |
| 1645 } | 1643 } |
| 1646 | 1644 |
| 1647 FX_BOOL Document::getURL(IJS_Context* cc, | 1645 bool Document::getURL(IJS_Context* cc, |
| 1648 const std::vector<CJS_Value>& params, | 1646 const std::vector<CJS_Value>& params, |
| 1649 CJS_Value& vRet, | 1647 CJS_Value& vRet, |
| 1650 CFX_WideString& sError) { | 1648 CFX_WideString& sError) { |
| 1651 // Unsafe, not supported. | 1649 // Unsafe, not supported. |
| 1652 return TRUE; | 1650 return true; |
| 1653 } | 1651 } |
| 1654 | 1652 |
| 1655 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, | 1653 bool Document::gotoNamedDest(IJS_Context* cc, |
| 1656 const std::vector<CJS_Value>& params, | 1654 const std::vector<CJS_Value>& params, |
| 1657 CJS_Value& vRet, | 1655 CJS_Value& vRet, |
| 1658 CFX_WideString& sError) { | 1656 CFX_WideString& sError) { |
| 1659 if (params.size() != 1) { | 1657 if (params.size() != 1) { |
| 1660 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1658 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1661 return FALSE; | 1659 return false; |
| 1662 } | 1660 } |
| 1663 if (!m_pFormFillEnv) { | 1661 if (!m_pFormFillEnv) { |
| 1664 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); | 1662 sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); |
| 1665 return FALSE; | 1663 return false; |
| 1666 } | 1664 } |
| 1667 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1665 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1668 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); | 1666 CFX_WideString wideName = params[0].ToCFXWideString(pRuntime); |
| 1669 CFX_ByteString utf8Name = wideName.UTF8Encode(); | 1667 CFX_ByteString utf8Name = wideName.UTF8Encode(); |
| 1670 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); | 1668 CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); |
| 1671 if (!pDocument) | 1669 if (!pDocument) |
| 1672 return FALSE; | 1670 return false; |
| 1673 | 1671 |
| 1674 CPDF_NameTree nameTree(pDocument, "Dests"); | 1672 CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1675 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); | 1673 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1676 if (!destArray) | 1674 if (!destArray) |
| 1677 return FALSE; | 1675 return false; |
| 1678 | 1676 |
| 1679 CPDF_Dest dest(destArray); | 1677 CPDF_Dest dest(destArray); |
| 1680 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); | 1678 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1681 | 1679 |
| 1682 std::unique_ptr<float[]> scrollPositionArray; | 1680 std::unique_ptr<float[]> scrollPositionArray; |
| 1683 int scrollPositionArraySize = 0; | 1681 int scrollPositionArraySize = 0; |
| 1684 | 1682 |
| 1685 if (arrayObject) { | 1683 if (arrayObject) { |
| 1686 scrollPositionArray.reset(new float[arrayObject->GetCount()]); | 1684 scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1687 int j = 0; | 1685 int j = 0; |
| 1688 for (size_t i = 2; i < arrayObject->GetCount(); i++) | 1686 for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1689 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); | 1687 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1690 scrollPositionArraySize = j; | 1688 scrollPositionArraySize = j; |
| 1691 } | 1689 } |
| 1692 | 1690 |
| 1693 pRuntime->BeginBlock(); | 1691 pRuntime->BeginBlock(); |
| 1694 m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), | 1692 m_pFormFillEnv->DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1695 scrollPositionArray.get(), | 1693 scrollPositionArray.get(), |
| 1696 scrollPositionArraySize); | 1694 scrollPositionArraySize); |
| 1697 pRuntime->EndBlock(); | 1695 pRuntime->EndBlock(); |
| 1698 | 1696 |
| 1699 return TRUE; | 1697 return true; |
| 1700 } | 1698 } |
| 1701 | 1699 |
| 1702 void Document::AddDelayData(CJS_DelayData* pData) { | 1700 void Document::AddDelayData(CJS_DelayData* pData) { |
| 1703 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); | 1701 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
| 1704 } | 1702 } |
| 1705 | 1703 |
| 1706 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | 1704 void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1707 int nControlIndex) { | 1705 int nControlIndex) { |
| 1708 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; | 1706 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1709 auto iter = m_DelayData.begin(); | 1707 auto iter = m_DelayData.begin(); |
| 1710 while (iter != m_DelayData.end()) { | 1708 while (iter != m_DelayData.end()) { |
| 1711 auto old = iter++; | 1709 auto old = iter++; |
| 1712 if ((*old)->sFieldName == sFieldName && | 1710 if ((*old)->sFieldName == sFieldName && |
| 1713 (*old)->nControlIndex == nControlIndex) { | 1711 (*old)->nControlIndex == nControlIndex) { |
| 1714 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); | 1712 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1715 m_DelayData.erase(old); | 1713 m_DelayData.erase(old); |
| 1716 } | 1714 } |
| 1717 } | 1715 } |
| 1718 | 1716 |
| 1719 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1717 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1720 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); | 1718 Field::DoDelay(m_pFormFillEnv.Get(), pData.get()); |
| 1721 } | 1719 } |
| 1722 | 1720 |
| 1723 CJS_Document* Document::GetCJSDoc() const { | 1721 CJS_Document* Document::GetCJSDoc() const { |
| 1724 return static_cast<CJS_Document*>(m_pJSObject); | 1722 return static_cast<CJS_Document*>(m_pJSObject); |
| 1725 } | 1723 } |
| OLD | NEW |