]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/XpdfPluginAPI.cxx
Merge changes from CUPS 1.4svn-r7199.
[thirdparty/cups.git] / pdftops / XpdfPluginAPI.cxx
CommitLineData
ef416fc2 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.
27static Object *allocObj() {
28 return (Object *)gmalloc(sizeof(Object));
29}
30
31//------------------------------------------------------------------------
32// Document access functions
33//------------------------------------------------------------------------
34
35XpdfObject _xpdfGetInfoDict(XpdfDoc doc) {
36 Object *obj;
37
38 obj = allocObj();
39 return (XpdfObject)((PDFDoc *)doc)->getDocInfo(obj);
40}
41
42XpdfObject _xpdfGetCatalog(XpdfDoc doc) {
43 Object *obj;
44
45 obj = allocObj();
46 return (XpdfObject)((PDFDoc *)doc)->getXRef()->getCatalog(obj);
47}
48
49#ifdef _WIN32
50
51HWND _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
62Widget _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
77XpdfBool _xpdfObjIsBool(XpdfObject obj) {
78 return (XpdfBool)((Object *)obj)->isBool();
79}
80
81XpdfBool _xpdfObjIsInt(XpdfObject obj) {
82 return (XpdfBool)((Object *)obj)->isInt();
83}
84
85XpdfBool _xpdfObjIsReal(XpdfObject obj) {
86 return (XpdfBool)((Object *)obj)->isReal();
87}
88
89XpdfBool _xpdfObjIsNumber(XpdfObject obj) {
90 return (XpdfBool)((Object *)obj)->isNum();
91}
92
93XpdfBool _xpdfObjIsString(XpdfObject obj) {
94 return (XpdfBool)((Object *)obj)->isString();
95}
96
97XpdfBool _xpdfObjIsName(XpdfObject obj) {
98 return (XpdfBool)((Object *)obj)->isName();
99}
100
101XpdfBool _xpdfObjIsNull(XpdfObject obj) {
102 return (XpdfBool)((Object *)obj)->isNull();
103}
104
105XpdfBool _xpdfObjIsArray(XpdfObject obj) {
106 return (XpdfBool)((Object *)obj)->isArray();
107}
108
109XpdfBool _xpdfObjIsDict(XpdfObject obj) {
110 return (XpdfBool)((Object *)obj)->isDict();
111}
112
113XpdfBool _xpdfObjIsStream(XpdfObject obj) {
114 return (XpdfBool)((Object *)obj)->isStream();
115}
116
117XpdfBool _xpdfObjIsRef(XpdfObject obj) {
118 return (XpdfBool)((Object *)obj)->isRef();
119}
120
121XpdfBool _xpdfBoolValue(XpdfObject obj) {
122 return (XpdfBool)((Object *)obj)->getBool();
123}
124
125int _xpdfIntValue(XpdfObject obj) {
126 if (!((Object *)obj)->isInt()) {
127 return 0;
128 }
129 return ((Object *)obj)->getInt();
130}
131
132double _xpdfRealValue(XpdfObject obj) {
133 if (!((Object *)obj)->isReal()) {
134 return 0;
135 }
136 return ((Object *)obj)->getReal();
137}
138
139double _xpdfNumberValue(XpdfObject obj) {
140 if (!((Object *)obj)->isNum()) {
141 return 0;
142 }
143 return ((Object *)obj)->getNum();
144}
145
146int _xpdfStringLength(XpdfObject obj) {
147 if (!((Object *)obj)->isString()) {
148 return 0;
149 }
150 return ((Object *)obj)->getString()->getLength();
151}
152
153char *_xpdfStringValue(XpdfObject obj) {
154 if (!((Object *)obj)->isString()) {
155 return 0;
156 }
157 return ((Object *)obj)->getString()->getCString();
158}
159
160char *_xpdfNameValue(XpdfObject obj) {
161 if (!((Object *)obj)->isName()) {
162 return NULL;
163 }
164 return ((Object *)obj)->getName();
165}
166
167int _xpdfArrayLength(XpdfObject obj) {
168 if (!((Object *)obj)->isArray()) {
169 return 0;
170 }
171 return ((Object *)obj)->arrayGetLength();
172}
173
174XpdfObject _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
184XpdfObject _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
194void _xpdfFreeObj(XpdfObject obj) {
195 ((Object *)obj)->free();
196 gfree(obj);
197}
198
199//------------------------------------------------------------------------
200// Memory allocation functions
201//------------------------------------------------------------------------
202
203void *_xpdfMalloc(int size) {
204 return gmalloc(size);
205}
206
207void *_xpdfRealloc(void *p, int size) {
208 return grealloc(p, size);
209}
210
211void _xpdfFree(void *p) {
212 gfree(p);
213}
214
215//------------------------------------------------------------------------
216// Security handlers
217//------------------------------------------------------------------------
218
219void _xpdfRegisterSecurityHandler(XpdfSecurityHandler *handler) {
220 if (handler->version <= xpdfPluginAPIVersion) {
221 globalParams->addSecurityHandler(handler);
222 }
223}
224
225//------------------------------------------------------------------------
226
227XpdfPluginVecTable 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