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