summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/Document.h
blob: 49ac75b7460c4f5a11ed748d4ede7f7c88f57dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef FPDFSDK_JAVASCRIPT_DOCUMENT_H_
#define FPDFSDK_JAVASCRIPT_DOCUMENT_H_

#include <list>
#include <memory>
#include <vector>

#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/page/cpdf_textobject.h"
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fpdfsdk/javascript/JS_Define.h"

class PrintParamsObj : public CJS_EmbedObj {
 public:
  explicit PrintParamsObj(CJS_Object* pJSObject);
  ~PrintParamsObj() override {}

 public:
  bool bUI;
  int nStart;
  int nEnd;
  bool bSilent;
  bool bShrinkToFit;
  bool bPrintAsImage;
  bool bReverse;
  bool bAnnotations;
};

class CJS_PrintParamsObj : public CJS_Object {
 public:
  explicit CJS_PrintParamsObj(v8::Local<v8::Object> pObject)
      : CJS_Object(pObject) {}
  ~CJS_PrintParamsObj() override {}

  DECLARE_JS_CLASS();
};

struct CJS_AnnotObj;
struct CJS_DelayAnnot;
struct CJS_DelayData;

class Document : public CJS_EmbedObj {
 public:
  explicit Document(CJS_Object* pJSObject);
  ~Document() override;

  bool get_ADBE(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_ADBE(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError);

  bool get_author(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_author(CJS_Runtime* pRuntime,
                  const CJS_Value& vp,
                  WideString* sError);

  bool get_base_URL(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_base_URL(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_bookmark_root(CJS_Runtime* pRuntime,
                         CJS_Value* vp,
                         WideString* sError);
  bool set_bookmark_root(CJS_Runtime* pRuntime,
                         const CJS_Value& vp,
                         WideString* sError);

  bool get_calculate(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_calculate(CJS_Runtime* pRuntime,
                     const CJS_Value& vp,
                     WideString* sError);

  bool get_collab(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_collab(CJS_Runtime* pRuntime,
                  const CJS_Value& vp,
                  WideString* sError);

  bool get_creation_date(CJS_Runtime* pRuntime,
                         CJS_Value* vp,
                         WideString* sError);
  bool set_creation_date(CJS_Runtime* pRuntime,
                         const CJS_Value& vp,
                         WideString* sError);

  bool get_creator(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_creator(CJS_Runtime* pRuntime,
                   const CJS_Value& vp,
                   WideString* sError);

  bool get_delay(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_delay(CJS_Runtime* pRuntime,
                 const CJS_Value& vp,
                 WideString* sError);

  bool get_dirty(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_dirty(CJS_Runtime* pRuntime,
                 const CJS_Value& vp,
                 WideString* sError);

  bool get_document_file_name(CJS_Runtime* pRuntime,
                              CJS_Value* vp,
                              WideString* sError);
  bool set_document_file_name(CJS_Runtime* pRuntime,
                              const CJS_Value& vp,
                              WideString* sError);

  bool get_external(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_external(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_filesize(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_filesize(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_icons(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_icons(CJS_Runtime* pRuntime,
                 const CJS_Value& vp,
                 WideString* sError);

  bool get_info(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_info(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError);

  bool get_keywords(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_keywords(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_layout(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_layout(CJS_Runtime* pRuntime,
                  const CJS_Value& vp,
                  WideString* sError);

  bool get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_media(CJS_Runtime* pRuntime,
                 const CJS_Value& vp,
                 WideString* sError);

  bool get_mod_date(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_mod_date(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_mouse_x(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_mouse_x(CJS_Runtime* pRuntime,
                   const CJS_Value& vp,
                   WideString* sError);

  bool get_mouse_y(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_mouse_y(CJS_Runtime* pRuntime,
                   const CJS_Value& vp,
                   WideString* sError);

  bool get_num_fields(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_num_fields(CJS_Runtime* pRuntime,
                      const CJS_Value& vp,
                      WideString* sError);

  bool get_num_pages(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_num_pages(CJS_Runtime* pRuntime,
                     const CJS_Value& vp,
                     WideString* sError);

  bool get_page_num(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_page_num(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_page_window_rect(CJS_Runtime* pRuntime,
                            CJS_Value* vp,
                            WideString* sError);
  bool set_page_window_rect(CJS_Runtime* pRuntime,
                            const CJS_Value& vp,
                            WideString* sError);

  bool get_path(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_path(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError);

  bool get_producer(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_producer(CJS_Runtime* pRuntime,
                    const CJS_Value& vp,
                    WideString* sError);

  bool get_subject(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_subject(CJS_Runtime* pRuntime,
                   const CJS_Value& vp,
                   WideString* sError);

  bool get_title(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_title(CJS_Runtime* pRuntime,
                 const CJS_Value& vp,
                 WideString* sError);

  bool get_zoom(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_zoom(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError);

  bool get_zoom_type(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_zoom_type(CJS_Runtime* pRuntime,
                     const CJS_Value& vp,
                     WideString* sError);

  bool get_URL(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError);
  bool set_URL(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError);

  bool addAnnot(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool addField(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool addLink(CJS_Runtime* pRuntime,
               const std::vector<CJS_Value>& params,
               CJS_Value& vRet,
               WideString& sError);
  bool addIcon(CJS_Runtime* pRuntime,
               const std::vector<CJS_Value>& params,
               CJS_Value& vRet,
               WideString& sError);
  bool calculateNow(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool closeDoc(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool createDataObject(CJS_Runtime* pRuntime,
                        const std::vector<CJS_Value>& params,
                        CJS_Value& vRet,
                        WideString& sError);
  bool deletePages(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool exportAsText(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool exportAsFDF(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool exportAsXFDF(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool extractPages(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool getAnnot(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool getAnnots(CJS_Runtime* pRuntime,
                 const std::vector<CJS_Value>& params,
                 CJS_Value& vRet,
                 WideString& sError);
  bool getAnnot3D(CJS_Runtime* pRuntime,
                  const std::vector<CJS_Value>& params,
                  CJS_Value& vRet,
                  WideString& sError);
  bool getAnnots3D(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool getField(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool getIcon(CJS_Runtime* pRuntime,
               const std::vector<CJS_Value>& params,
               CJS_Value& vRet,
               WideString& sError);
  bool getLinks(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool getNthFieldName(CJS_Runtime* pRuntime,
                       const std::vector<CJS_Value>& params,
                       CJS_Value& vRet,
                       WideString& sError);
  bool getOCGs(CJS_Runtime* pRuntime,
               const std::vector<CJS_Value>& params,
               CJS_Value& vRet,
               WideString& sError);
  bool getPageBox(CJS_Runtime* pRuntime,
                  const std::vector<CJS_Value>& params,
                  CJS_Value& vRet,
                  WideString& sError);
  bool getPageNthWord(CJS_Runtime* pRuntime,
                      const std::vector<CJS_Value>& params,
                      CJS_Value& vRet,
                      WideString& sError);
  bool getPageNthWordQuads(CJS_Runtime* pRuntime,
                           const std::vector<CJS_Value>& params,
                           CJS_Value& vRet,
                           WideString& sError);
  bool getPageNumWords(CJS_Runtime* pRuntime,
                       const std::vector<CJS_Value>& params,
                       CJS_Value& vRet,
                       WideString& sError);
  bool getPrintParams(CJS_Runtime* pRuntime,
                      const std::vector<CJS_Value>& params,
                      CJS_Value& vRet,
                      WideString& sError);
  bool getURL(CJS_Runtime* pRuntime,
              const std::vector<CJS_Value>& params,
              CJS_Value& vRet,
              WideString& sError);
  bool gotoNamedDest(CJS_Runtime* pRuntime,
                     const std::vector<CJS_Value>& params,
                     CJS_Value& vRet,
                     WideString& sError);
  bool importAnFDF(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool importAnXFDF(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool importTextData(CJS_Runtime* pRuntime,
                      const std::vector<CJS_Value>& params,
                      CJS_Value& vRet,
                      WideString& sError);
  bool insertPages(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool mailForm(CJS_Runtime* pRuntime,
                const std::vector<CJS_Value>& params,
                CJS_Value& vRet,
                WideString& sError);
  bool print(CJS_Runtime* pRuntime,
             const std::vector<CJS_Value>& params,
             CJS_Value& vRet,
             WideString& sError);
  bool removeField(CJS_Runtime* pRuntime,
                   const std::vector<CJS_Value>& params,
                   CJS_Value& vRet,
                   WideString& sError);
  bool replacePages(CJS_Runtime* pRuntime,
                    const std::vector<CJS_Value>& params,
                    CJS_Value& vRet,
                    WideString& sError);
  bool resetForm(CJS_Runtime* pRuntime,
                 const std::vector<CJS_Value>& params,
                 CJS_Value& vRet,
                 WideString& sError);
  bool saveAs(CJS_Runtime* pRuntime,
              const std::vector<CJS_Value>& params,
              CJS_Value& vRet,
              WideString& sError);
  bool submitForm(CJS_Runtime* pRuntime,
                  const std::vector<CJS_Value>& params,
                  CJS_Value& vRet,
                  WideString& sError);
  bool syncAnnotScan(CJS_Runtime* pRuntime,
                     const std::vector<CJS_Value>& params,
                     CJS_Value& vRet,
                     WideString& sError);
  bool mailDoc(CJS_Runtime* pRuntime,
               const std::vector<CJS_Value>& params,
               CJS_Value& vRet,
               WideString& sError);
  bool removeIcon(CJS_Runtime* pRuntime,
                  const std::vector<CJS_Value>& params,
                  CJS_Value& vRet,
                  WideString& sError);

  void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
  CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
    return m_pFormFillEnv.Get();
  }
  void AddDelayData(CJS_DelayData* pData);
  void DoFieldDelay(const WideString& sFieldName, int nControlIndex);
  CJS_Document* GetCJSDoc() const;

 private:
  bool IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect);
  int CountWords(CPDF_TextObject* pTextObj);
  WideString GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex);

  bool getPropertyInternal(CJS_Runtime* pRuntime,
                           CJS_Value* vp,
                           const ByteString& propName,
                           WideString* sError);
  bool setPropertyInternal(CJS_Runtime* pRuntime,
                           const CJS_Value& vp,
                           const ByteString& propName,
                           WideString* sError);

  CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
  WideString m_cwBaseURL;
  std::list<std::unique_ptr<CJS_DelayData>> m_DelayData;
  // Needs to be a std::list for iterator stability.
  std::list<WideString> m_IconNames;
  bool m_bDelay;
};

class CJS_Document : public CJS_Object {
 public:
  explicit CJS_Document(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
  ~CJS_Document() override {}

  // CJS_Object
  void InitInstance(IJS_Runtime* pIRuntime) override;

  DECLARE_JS_CLASS();

  JS_STATIC_PROP(ADBE, ADBE, Document);
  JS_STATIC_PROP(author, author, Document);
  JS_STATIC_PROP(baseURL, base_URL, Document);
  JS_STATIC_PROP(bookmarkRoot, bookmark_root, Document);
  JS_STATIC_PROP(calculate, calculate, Document);
  JS_STATIC_PROP(Collab, collab, Document);
  JS_STATIC_PROP(creationDate, creation_date, Document);
  JS_STATIC_PROP(creator, creator, Document);
  JS_STATIC_PROP(delay, delay, Document);
  JS_STATIC_PROP(dirty, dirty, Document);
  JS_STATIC_PROP(documentFileName, document_file_name, Document);
  JS_STATIC_PROP(external, external, Document);
  JS_STATIC_PROP(filesize, filesize, Document);
  JS_STATIC_PROP(icons, icons, Document);
  JS_STATIC_PROP(info, info, Document);
  JS_STATIC_PROP(keywords, keywords, Document);
  JS_STATIC_PROP(layout, layout, Document);
  JS_STATIC_PROP(media, media, Document);
  JS_STATIC_PROP(modDate, mod_date, Document);
  JS_STATIC_PROP(mouseX, mouse_x, Document);
  JS_STATIC_PROP(mouseY, mouse_y, Document);
  JS_STATIC_PROP(numFields, num_fields, Document);
  JS_STATIC_PROP(numPages, num_pages, Document);
  JS_STATIC_PROP(pageNum, page_num, Document);
  JS_STATIC_PROP(pageWindowRect, page_window_rect, Document);
  JS_STATIC_PROP(path, path, Document);
  JS_STATIC_PROP(producer, producer, Document);
  JS_STATIC_PROP(subject, subject, Document);
  JS_STATIC_PROP(title, title, Document);
  JS_STATIC_PROP(URL, URL, Document);
  JS_STATIC_PROP(zoom, zoom, Document);
  JS_STATIC_PROP(zoomType, zoom_type, Document);

  JS_STATIC_METHOD(addAnnot, Document);
  JS_STATIC_METHOD(addField, Document);
  JS_STATIC_METHOD(addLink, Document);
  JS_STATIC_METHOD(addIcon, Document);
  JS_STATIC_METHOD(calculateNow, Document);
  JS_STATIC_METHOD(closeDoc, Document);
  JS_STATIC_METHOD(createDataObject, Document);
  JS_STATIC_METHOD(deletePages, Document);
  JS_STATIC_METHOD(exportAsText, Document);
  JS_STATIC_METHOD(exportAsFDF, Document);
  JS_STATIC_METHOD(exportAsXFDF, Document);
  JS_STATIC_METHOD(extractPages, Document);
  JS_STATIC_METHOD(getAnnot, Document);
  JS_STATIC_METHOD(getAnnots, Document);
  JS_STATIC_METHOD(getAnnot3D, Document);
  JS_STATIC_METHOD(getAnnots3D, Document);
  JS_STATIC_METHOD(getField, Document);
  JS_STATIC_METHOD(getIcon, Document);
  JS_STATIC_METHOD(getLinks, Document);
  JS_STATIC_METHOD(getNthFieldName, Document);
  JS_STATIC_METHOD(getOCGs, Document);
  JS_STATIC_METHOD(getPageBox, Document);
  JS_STATIC_METHOD(getPageNthWord, Document);
  JS_STATIC_METHOD(getPageNthWordQuads, Document);
  JS_STATIC_METHOD(getPageNumWords, Document);
  JS_STATIC_METHOD(getPrintParams, Document);
  JS_STATIC_METHOD(getURL, Document);
  JS_STATIC_METHOD(gotoNamedDest, Document);
  JS_STATIC_METHOD(importAnFDF, Document);
  JS_STATIC_METHOD(importAnXFDF, Document);
  JS_STATIC_METHOD(importTextData, Document);
  JS_STATIC_METHOD(insertPages, Document);
  JS_STATIC_METHOD(mailForm, Document);
  JS_STATIC_METHOD(print, Document);
  JS_STATIC_METHOD(removeField, Document);
  JS_STATIC_METHOD(replacePages, Document);
  JS_STATIC_METHOD(removeIcon, Document);
  JS_STATIC_METHOD(resetForm, Document);
  JS_STATIC_METHOD(saveAs, Document);
  JS_STATIC_METHOD(submitForm, Document);
  JS_STATIC_METHOD(syncAnnotScan, Document);
  JS_STATIC_METHOD(mailDoc, Document);
};

#endif  // FPDFSDK_JAVASCRIPT_DOCUMENT_H_