• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef _DOCUMENT_H_
8 #define _DOCUMENT_H_
9 
10 
11 
12 class PrintParamsObj : public CJS_EmbedObj
13 {
14 public:
15 	PrintParamsObj(CJS_Object* pJSObject);
~PrintParamsObj()16 	virtual ~PrintParamsObj(){}
17 
18 public:
19 	FX_BOOL bUI;
20 	int nStart;
21 	int nEnd;
22 	FX_BOOL bSilent;
23 	FX_BOOL bShrinkToFit;
24 	FX_BOOL bPrintAsImage;
25 	FX_BOOL bReverse;
26 	FX_BOOL bAnnotations;
27 };
28 
29 class CJS_PrintParamsObj : public CJS_Object
30 {
31 public:
CJS_PrintParamsObj(JSFXObject pObject)32 	CJS_PrintParamsObj(JSFXObject pObject) : CJS_Object(pObject) {}
~CJS_PrintParamsObj()33 	virtual ~CJS_PrintParamsObj(){}
34 
35 	DECLARE_JS_CLASS(CJS_PrintParamsObj);
36 };
37 
38 
39 class Icon;
40 class Field;
41 
42 struct IconElement
43 {
IconElementIconElement44 	IconElement() : IconName(L""), IconStream(NULL), NextIcon(NULL){}
~IconElementIconElement45 	virtual ~IconElement()
46 	{
47 	}
48 	CFX_WideString	IconName;
49 	IconElement*	NextIcon;
50 	Icon*			IconStream;
51 };
52 
53 class IconTree
54 {
55 public:
IconTree()56 	IconTree():m_pHead(NULL), m_pEnd(NULL), m_iLength(0)
57 	{
58 
59 	}
60 
~IconTree()61 	virtual ~IconTree()
62 	{
63 	}
64 
65 public:
66 	void			InsertIconElement(IconElement* pNewIcon);
67 	void			DeleteIconElement(CFX_WideString swIconName);
68 	void			DeleteIconTree();
69 	int				GetLength();
70 	IconElement*	operator[](int iIndex);
71 
72 private:
73 	IconElement*	m_pHead;
74 	IconElement*	m_pEnd;
75 	int				m_iLength;
76 };
77 
78 struct CJS_DelayData;
79 struct CJS_DelayAnnot;
80 struct CJS_AnnotObj;
81 
82 class Document : public CJS_EmbedObj
83 {
84 public:
85 	Document(CJS_Object* pJSObject);
86 	virtual ~Document();
87 
88 public:
89 	FX_BOOL	ADBE(OBJ_PROP_PARAMS);
90 	FX_BOOL	author(OBJ_PROP_PARAMS);
91 	FX_BOOL	baseURL(OBJ_PROP_PARAMS);
92 	FX_BOOL	bookmarkRoot(OBJ_PROP_PARAMS);
93 	FX_BOOL	calculate(OBJ_PROP_PARAMS);
94 	FX_BOOL	Collab(OBJ_PROP_PARAMS);
95 	FX_BOOL	creationDate(OBJ_PROP_PARAMS);
96 	FX_BOOL	creator(OBJ_PROP_PARAMS);
97 	FX_BOOL	delay(OBJ_PROP_PARAMS);
98 	FX_BOOL	dirty(OBJ_PROP_PARAMS);
99 	FX_BOOL	documentFileName(OBJ_PROP_PARAMS);
100 	FX_BOOL external(OBJ_PROP_PARAMS);
101 	FX_BOOL	filesize(OBJ_PROP_PARAMS);
102 	FX_BOOL	icons(OBJ_PROP_PARAMS);
103 	FX_BOOL	info(OBJ_PROP_PARAMS);
104 	FX_BOOL	keywords(OBJ_PROP_PARAMS);
105 	FX_BOOL	layout(OBJ_PROP_PARAMS);
106 	FX_BOOL	media(OBJ_PROP_PARAMS);
107 	FX_BOOL	modDate(OBJ_PROP_PARAMS);
108 	FX_BOOL	mouseX(OBJ_PROP_PARAMS);
109 	FX_BOOL	mouseY(OBJ_PROP_PARAMS);
110 	FX_BOOL	numFields(OBJ_PROP_PARAMS);
111 	FX_BOOL	numPages(OBJ_PROP_PARAMS);
112 	FX_BOOL	pageNum(OBJ_PROP_PARAMS);
113 	FX_BOOL	pageWindowRect(OBJ_PROP_PARAMS);
114 	FX_BOOL	path(OBJ_PROP_PARAMS);
115 	FX_BOOL	producer(OBJ_PROP_PARAMS);
116 	FX_BOOL	subject(OBJ_PROP_PARAMS);
117 	FX_BOOL	title(OBJ_PROP_PARAMS);
118 	FX_BOOL	zoom(OBJ_PROP_PARAMS);
119 	FX_BOOL	zoomType(OBJ_PROP_PARAMS);
120 
121 	FX_BOOL addAnnot(OBJ_METHOD_PARAMS);
122 	FX_BOOL	addField(OBJ_METHOD_PARAMS);
123 	FX_BOOL	addLink(OBJ_METHOD_PARAMS);
124 	FX_BOOL	addIcon(OBJ_METHOD_PARAMS);
125 	FX_BOOL	calculateNow(OBJ_METHOD_PARAMS);
126 	FX_BOOL	closeDoc(OBJ_METHOD_PARAMS);
127 	FX_BOOL	createDataObject(OBJ_METHOD_PARAMS);
128 	FX_BOOL deletePages(OBJ_METHOD_PARAMS);
129 	FX_BOOL	exportAsText(OBJ_METHOD_PARAMS);
130 	FX_BOOL	exportAsFDF(OBJ_METHOD_PARAMS);
131 	FX_BOOL	exportAsXFDF(OBJ_METHOD_PARAMS);
132 	FX_BOOL extractPages(OBJ_METHOD_PARAMS);
133 	FX_BOOL	getAnnot(OBJ_METHOD_PARAMS);
134 	FX_BOOL	getAnnots(OBJ_METHOD_PARAMS);
135 	FX_BOOL	getAnnot3D(OBJ_METHOD_PARAMS);
136 	FX_BOOL	getAnnots3D(OBJ_METHOD_PARAMS);
137 	FX_BOOL	getField(OBJ_METHOD_PARAMS);
138 	FX_BOOL	getIcon(OBJ_METHOD_PARAMS);
139 	FX_BOOL	getLinks(OBJ_METHOD_PARAMS);
140 	FX_BOOL	getNthFieldName(OBJ_METHOD_PARAMS);
141 	FX_BOOL	getOCGs(OBJ_METHOD_PARAMS);
142 	FX_BOOL	getPageBox(OBJ_METHOD_PARAMS);
143 	FX_BOOL	getPageNthWord(OBJ_METHOD_PARAMS);
144 	FX_BOOL	getPageNthWordQuads(OBJ_METHOD_PARAMS);
145 	FX_BOOL	getPageNumWords(OBJ_METHOD_PARAMS);
146 	FX_BOOL getPrintParams(OBJ_METHOD_PARAMS);
147 	FX_BOOL getURL(OBJ_METHOD_PARAMS);
148 	FX_BOOL	importAnFDF(OBJ_METHOD_PARAMS);
149 	FX_BOOL	importAnXFDF(OBJ_METHOD_PARAMS);
150 	FX_BOOL	importTextData(OBJ_METHOD_PARAMS);
151 	FX_BOOL insertPages(OBJ_METHOD_PARAMS);
152 	FX_BOOL	mailForm(OBJ_METHOD_PARAMS);
153 	FX_BOOL	print(OBJ_METHOD_PARAMS);
154 	FX_BOOL	removeField(OBJ_METHOD_PARAMS);
155 	FX_BOOL replacePages(OBJ_METHOD_PARAMS);
156 	FX_BOOL	resetForm(OBJ_METHOD_PARAMS);
157 	FX_BOOL	saveAs(OBJ_METHOD_PARAMS);
158 	FX_BOOL	submitForm(OBJ_METHOD_PARAMS);
159 	FX_BOOL	mailDoc(OBJ_METHOD_PARAMS);
160 	FX_BOOL	removeIcon(OBJ_METHOD_PARAMS);
161 
162 public:
163 	void AttachDoc(CPDFSDK_Document* pDoc);
164 	CPDFSDK_Document* GetReaderDoc();
165 
166 	static FX_BOOL				ExtractFileName(CPDFSDK_Document* pDoc, CFX_ByteString& strFileName);
167 	static FX_BOOL				ExtractFolderName(CPDFSDK_Document* pDoc, CFX_ByteString& strFolderName);
168 
169 public:
170 	void						AddDelayData(CJS_DelayData* pData);
171 	void						DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex);
172 
173 	void						AddDelayAnnotData(CJS_AnnotObj *pData);
174 	void						DoAnnotDelay();
SetIsolate(v8::Isolate * isolate)175 	void						SetIsolate(v8::Isolate* isolate) {m_isolate = isolate;}
176 
177 private:
178 	CFX_WideString				ReversalStr(CFX_WideString cbFrom);
179 	CFX_WideString				CutString(CFX_WideString cbFrom);
180 	bool						IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect);
181 	int							CountWords(CPDF_TextObject* pTextObj);
182 	CFX_WideString				GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex);
183 
184 	FX_BOOL						ParserParams(JSObject *pObj,CJS_AnnotObj& annotobj);
185 
186 private:
187 	v8::Isolate*					m_isolate;
188 	IconTree*					m_pIconTree;
189 	CPDFSDK_Document*			m_pDocument;
190 	CFX_WideString				m_cwBaseURL;
191 
192 	FX_BOOL								m_bDelay;
193 	CFX_ArrayTemplate<CJS_DelayData*>	m_DelayData;
194 	CFX_ArrayTemplate<CJS_AnnotObj*>	m_DelayAnnotData;
195 };
196 
197 class CJS_Document : public CJS_Object
198 {
199 public:
CJS_Document(JSFXObject pObject)200 	CJS_Document(JSFXObject pObject) : CJS_Object(pObject) {};
~CJS_Document()201 	virtual ~CJS_Document(){};
202 
203 	virtual FX_BOOL	InitInstance(IFXJS_Context* cc);
204 
205 	DECLARE_JS_CLASS(CJS_Document);
206 
207 	JS_STATIC_PROP(ADBE, Document);
208 	JS_STATIC_PROP(author, Document);
209 	JS_STATIC_PROP(baseURL, Document);
210 	JS_STATIC_PROP(bookmarkRoot, Document);
211 	JS_STATIC_PROP(calculate, Document);
212 	JS_STATIC_PROP(Collab, Document);
213 	JS_STATIC_PROP(creationDate, Document);
214 	JS_STATIC_PROP(creator, Document);
215 	JS_STATIC_PROP(delay, Document);
216 	JS_STATIC_PROP(dirty, Document);
217 	JS_STATIC_PROP(documentFileName, Document);
218 	JS_STATIC_PROP(external, Document);
219 	JS_STATIC_PROP(filesize, Document);
220 	JS_STATIC_PROP(icons, Document);
221 	JS_STATIC_PROP(info, Document);
222 	JS_STATIC_PROP(keywords, Document);
223 	JS_STATIC_PROP(layout, Document);
224 	JS_STATIC_PROP(media, Document);
225 	JS_STATIC_PROP(modDate, Document);
226 	JS_STATIC_PROP(mouseX, Document);
227 	JS_STATIC_PROP(mouseY, Document);
228 	JS_STATIC_PROP(numFields, Document);
229 	JS_STATIC_PROP(numPages, Document);
230 	JS_STATIC_PROP(pageNum, Document);
231 	JS_STATIC_PROP(pageWindowRect, Document);
232 	JS_STATIC_PROP(path, Document);
233 	JS_STATIC_PROP(producer, Document);
234 	JS_STATIC_PROP(subject, Document);
235 	JS_STATIC_PROP(title, Document);
236 	JS_STATIC_PROP(zoom, Document);
237 	JS_STATIC_PROP(zoomType, Document);
238 
239 	JS_STATIC_METHOD(addAnnot,Document);
240 	JS_STATIC_METHOD(addField, Document);
241 	JS_STATIC_METHOD(addLink, Document);
242 	JS_STATIC_METHOD(addIcon, Document);
243 	JS_STATIC_METHOD(calculateNow, Document);
244 	JS_STATIC_METHOD(closeDoc, Document);
245 	JS_STATIC_METHOD(createDataObject, Document);
246 	JS_STATIC_METHOD(deletePages, Document);
247 	JS_STATIC_METHOD(exportAsText, Document);
248 	JS_STATIC_METHOD(exportAsFDF, Document);
249 	JS_STATIC_METHOD(exportAsXFDF, Document);
250 	JS_STATIC_METHOD(extractPages, Document);
251 	JS_STATIC_METHOD(getAnnot, Document);
252 	JS_STATIC_METHOD(getAnnots, Document);
253 	JS_STATIC_METHOD(getAnnot3D, Document);
254 	JS_STATIC_METHOD(getAnnots3D, Document);
255 	JS_STATIC_METHOD(getField, Document);
256 	JS_STATIC_METHOD(getIcon, Document);
257 	JS_STATIC_METHOD(getLinks, Document);
258 	JS_STATIC_METHOD(getNthFieldName, Document);
259 	JS_STATIC_METHOD(getOCGs, Document);
260 	JS_STATIC_METHOD(getPageBox, Document);
261 	JS_STATIC_METHOD(getPageNthWord, Document);
262 	JS_STATIC_METHOD(getPageNthWordQuads, Document);
263 	JS_STATIC_METHOD(getPageNumWords, Document);
264 	JS_STATIC_METHOD(getPrintParams, Document);
265 	JS_STATIC_METHOD(getURL, Document);
266 	JS_STATIC_METHOD(importAnFDF, Document);
267 	JS_STATIC_METHOD(importAnXFDF, Document);
268 	JS_STATIC_METHOD(importTextData, Document);
269 	JS_STATIC_METHOD(insertPages, Document);
270 	JS_STATIC_METHOD(mailForm, Document);
271 	JS_STATIC_METHOD(print, Document);
272 	JS_STATIC_METHOD(removeField, Document);
273 	JS_STATIC_METHOD(replacePages, Document);
274 	JS_STATIC_METHOD(removeIcon, Document);
275 	JS_STATIC_METHOD(resetForm, Document);
276 	JS_STATIC_METHOD(saveAs, Document);
277 	JS_STATIC_METHOD(submitForm, Document);
278 	JS_STATIC_METHOD(mailDoc, Document);
279 };
280 
281 #endif//_DOCUMENT_H_
282 
283