~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/XpdfPluginAPI.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

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