]> git.ipfire.org Git - thirdparty/cups.git/blob - pdftops/XpdfPluginAPI.cxx
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / XpdfPluginAPI.cxx
1 //========================================================================
2 //
3 // XpdfPluginAPI.cc
4 //
5 // Copyright 2004 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <config.h>
10
11 #ifdef ENABLE_PLUGINS
12
13 #include "gmem.h"
14 #include "GlobalParams.h"
15 #include "Object.h"
16 #include "PDFDoc.h"
17 #ifdef WIN32
18 #include "WinPDFCore.h"
19 #else
20 #include "XPDFCore.h"
21 #endif
22 #include "XpdfPluginAPI.h"
23
24 //------------------------------------------------------------------------
25
26 //~ This should use a pool of Objects; change xpdfFreeObj to match.
27 static Object *allocObj() {
28 return (Object *)gmalloc(sizeof(Object));
29 }
30
31 //------------------------------------------------------------------------
32 // Document access functions
33 //------------------------------------------------------------------------
34
35 XpdfObject _xpdfGetInfoDict(XpdfDoc doc) {
36 Object *obj;
37
38 obj = allocObj();
39 return (XpdfObject)((PDFDoc *)doc)->getDocInfo(obj);
40 }
41
42 XpdfObject _xpdfGetCatalog(XpdfDoc doc) {
43 Object *obj;
44
45 obj = allocObj();
46 return (XpdfObject)((PDFDoc *)doc)->getXRef()->getCatalog(obj);
47 }
48
49 #ifdef _WIN32
50
51 HWND _xpdfWin32GetWindow(XpdfDoc doc) {
52 WinPDFCore *core;
53
54 if (!(core = (WinPDFCore *)((PDFDoc *)doc)->getGUIData())) {
55 return NULL;
56 }
57 return core->getDrawFrame();
58 }
59
60 #else
61
62 Widget _xpdfXGetWindow(XpdfDoc doc) {
63 XPDFCore *core;
64
65 if (!(core = (XPDFCore *)((PDFDoc *)doc)->getGUIData())) {
66 return NULL;
67 }
68 return core->getWidget();
69 }
70
71 #endif
72
73 //------------------------------------------------------------------------
74 // Object access functions.
75 //------------------------------------------------------------------------
76
77 XpdfBool _xpdfObjIsBool(XpdfObject obj) {
78 return (XpdfBool)((Object *)obj)->isBool();
79 }
80
81 XpdfBool _xpdfObjIsInt(XpdfObject obj) {
82 return (XpdfBool)((Object *)obj)->isInt();
83 }
84
85 XpdfBool _xpdfObjIsReal(XpdfObject obj) {
86 return (XpdfBool)((Object *)obj)->isReal();
87 }
88
89 XpdfBool _xpdfObjIsNumber(XpdfObject obj) {
90 return (XpdfBool)((Object *)obj)->isNum();
91 }
92
93 XpdfBool _xpdfObjIsString(XpdfObject obj) {
94 return (XpdfBool)((Object *)obj)->isString();
95 }
96
97 XpdfBool _xpdfObjIsName(XpdfObject obj) {
98 return (XpdfBool)((Object *)obj)->isName();
99 }
100
101 XpdfBool _xpdfObjIsNull(XpdfObject obj) {
102 return (XpdfBool)((Object *)obj)->isNull();
103 }
104
105 XpdfBool _xpdfObjIsArray(XpdfObject obj) {
106 return (XpdfBool)((Object *)obj)->isArray();
107 }
108
109 XpdfBool _xpdfObjIsDict(XpdfObject obj) {
110 return (XpdfBool)((Object *)obj)->isDict();
111 }
112
113 XpdfBool _xpdfObjIsStream(XpdfObject obj) {
114 return (XpdfBool)((Object *)obj)->isStream();
115 }
116
117 XpdfBool _xpdfObjIsRef(XpdfObject obj) {
118 return (XpdfBool)((Object *)obj)->isRef();
119 }
120
121 XpdfBool _xpdfBoolValue(XpdfObject obj) {
122 return (XpdfBool)((Object *)obj)->getBool();
123 }
124
125 int _xpdfIntValue(XpdfObject obj) {
126 if (!((Object *)obj)->isInt()) {
127 return 0;
128 }
129 return ((Object *)obj)->getInt();
130 }
131
132 double _xpdfRealValue(XpdfObject obj) {
133 if (!((Object *)obj)->isReal()) {
134 return 0;
135 }
136 return ((Object *)obj)->getReal();
137 }
138
139 double _xpdfNumberValue(XpdfObject obj) {
140 if (!((Object *)obj)->isNum()) {
141 return 0;
142 }
143 return ((Object *)obj)->getNum();
144 }
145
146 int _xpdfStringLength(XpdfObject obj) {
147 if (!((Object *)obj)->isString()) {
148 return 0;
149 }
150 return ((Object *)obj)->getString()->getLength();
151 }
152
153 char *_xpdfStringValue(XpdfObject obj) {
154 if (!((Object *)obj)->isString()) {
155 return 0;
156 }
157 return ((Object *)obj)->getString()->getCString();
158 }
159
160 char *_xpdfNameValue(XpdfObject obj) {
161 if (!((Object *)obj)->isName()) {
162 return NULL;
163 }
164 return ((Object *)obj)->getName();
165 }
166
167 int _xpdfArrayLength(XpdfObject obj) {
168 if (!((Object *)obj)->isArray()) {
169 return 0;
170 }
171 return ((Object *)obj)->arrayGetLength();
172 }
173
174 XpdfObject _xpdfArrayGet(XpdfObject obj, int idx) {
175 Object *elem;
176
177 elem = allocObj();
178 if (!((Object *)obj)->isArray()) {
179 return (XpdfObject)elem->initNull();
180 }
181 return (XpdfObject)((Object *)obj)->arrayGet(idx, elem);
182 }
183
184 XpdfObject _xpdfDictGet(XpdfObject obj, char *key) {
185 Object *elem;
186
187 elem = allocObj();
188 if (!((Object *)obj)->isDict()) {
189 return (XpdfObject)elem->initNull();
190 }
191 return (XpdfObject)((Object *)obj)->dictLookup(key, elem);
192 }
193
194 void _xpdfFreeObj(XpdfObject obj) {
195 ((Object *)obj)->free();
196 gfree(obj);
197 }
198
199 //------------------------------------------------------------------------
200 // Memory allocation functions
201 //------------------------------------------------------------------------
202
203 void *_xpdfMalloc(int size) {
204 return gmalloc(size);
205 }
206
207 void *_xpdfRealloc(void *p, int size) {
208 return grealloc(p, size);
209 }
210
211 void _xpdfFree(void *p) {
212 gfree(p);
213 }
214
215 //------------------------------------------------------------------------
216 // Security handlers
217 //------------------------------------------------------------------------
218
219 void _xpdfRegisterSecurityHandler(XpdfSecurityHandler *handler) {
220 if (handler->version <= xpdfPluginAPIVersion) {
221 globalParams->addSecurityHandler(handler);
222 }
223 }
224
225 //------------------------------------------------------------------------
226
227 XpdfPluginVecTable xpdfPluginVecTable = {
228 xpdfPluginAPIVersion,
229 &_xpdfGetInfoDict,
230 &_xpdfGetCatalog,
231 #ifdef _WIN32
232 &_xpdfWin32GetWindow,
233 #else
234 &_xpdfXGetWindow,
235 #endif
236 &_xpdfObjIsBool,
237 &_xpdfObjIsInt,
238 &_xpdfObjIsReal,
239 &_xpdfObjIsString,
240 &_xpdfObjIsName,
241 &_xpdfObjIsNull,
242 &_xpdfObjIsArray,
243 &_xpdfObjIsDict,
244 &_xpdfObjIsStream,
245 &_xpdfObjIsRef,
246 &_xpdfBoolValue,
247 &_xpdfIntValue,
248 &_xpdfRealValue,
249 &_xpdfStringLength,
250 &_xpdfStringValue,
251 &_xpdfNameValue,
252 &_xpdfArrayLength,
253 &_xpdfArrayGet,
254 &_xpdfDictGet,
255 &_xpdfFreeObj,
256 &_xpdfMalloc,
257 &_xpdfRealloc,
258 &_xpdfFree,
259 &_xpdfRegisterSecurityHandler,
260 };
261
262 #endif // ENABLE_PLUGINS