-
Notifications
You must be signed in to change notification settings - Fork 0
/
poppler.override
641 lines (562 loc) · 18.2 KB
/
poppler.override
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
/* -*- Mode: C; c-basic-offset: 4 -*-
* Copyright (C) 2007-2008, Gian Mario Tagliaretti
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
%%
headers
#include <Python.h>
#include "pygobject.h"
#include <glib/poppler.h>
#include <pycairo.h>
#include "pypoppler-private.h"
#ifndef POPPLER_TYPE_ACTION_ANY
#define POPPLER_TYPE_ACTION_ANY (_poppler_action_any_get_type ())
static GType _poppler_action_any_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionAny",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_GOTO_DEST
#define POPPLER_TYPE_ACTION_GOTO_DEST (_poppler_action_goto_dest_get_type ())
static GType _poppler_action_goto_dest_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionGotoDest",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_GOTO_DEST
#define POPPLER_TYPE_ACTION_GOTO_DEST (_poppler_action_goto_dest_get_type ())
static GType _poppler_action_goto_dest_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionGotoDest",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_GOTO_REMOTE
#define POPPLER_TYPE_ACTION_GOTO_REMOTE (_poppler_action_goto_remote_get_type ())
static GType _poppler_action_goto_remote_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionGotoRemote",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_LAUNCH
#define POPPLER_TYPE_ACTION_LAUNCH (_poppler_action_launch_get_type ())
static GType _poppler_action_launch_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionLaunch",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_URI
#define POPPLER_TYPE_ACTION_URI (_poppler_action_uri_get_type ())
static GType _poppler_action_uri_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionUri",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_NAMED
#define POPPLER_TYPE_ACTION_NAMED (_poppler_action_named_get_type ())
static GType _poppler_action_named_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionNamed",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
#ifndef POPPLER_TYPE_ACTION_MOVIE
#define POPPLER_TYPE_ACTION_MOVIE (_poppler_action_movie_get_type ())
static GType _poppler_action_movie_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
{
our_type = g_boxed_type_register_static ("PopplerActionMovie",
(GBoxedCopyFunc)poppler_action_copy,
(GBoxedFreeFunc)poppler_action_free);
}
return our_type;
}
#endif
static PyObject *
_poppler_action_to_poppler_action_typed (PopplerAction * action)
{
if (!action)/*TODO: Should we raise an exception in this case?*/
{
Py_INCREF(Py_None);
return Py_None;
}
GType boxed_type;
switch (action->type)
{
case POPPLER_ACTION_NONE:/*TODO: Is this the right behaviour?*/
Py_INCREF(Py_None);
return Py_None;
case POPPLER_ACTION_GOTO_DEST:
boxed_type = POPPLER_TYPE_ACTION_GOTO_DEST;
break;
case POPPLER_ACTION_GOTO_REMOTE:
boxed_type = POPPLER_TYPE_ACTION_GOTO_REMOTE;
break;
case POPPLER_ACTION_LAUNCH:
boxed_type = POPPLER_TYPE_ACTION_LAUNCH;
break;
case POPPLER_ACTION_URI:
boxed_type = POPPLER_TYPE_ACTION_URI;
break;
case POPPLER_ACTION_NAMED:
boxed_type = POPPLER_TYPE_ACTION_NAMED;
break;
case POPPLER_ACTION_MOVIE:
boxed_type = POPPLER_TYPE_ACTION_MOVIE;
break;
default:
boxed_type = POPPLER_TYPE_ACTION_ANY;
}
return pyg_boxed_new (boxed_type, action, TRUE, TRUE);
}
extern Pycairo_CAPI_t *Pycairo_CAPI;
static PyObject *
_glist_to_pylist_objs (GList *source)
{
GList *iter;
PyObject *dest = PyList_New (0);
for (iter = source; iter != NULL; iter = iter->next)
{
PyObject *item = pygobject_new ((GObject *)iter->data);
PyList_Append (dest, item);
Py_DECREF (item);
}
return dest;
}
static PyObject *
_glist_to_pylist_boxed (GList *source, GType boxed_type)
{
GList *iter;
PyObject *dest = PyList_New (0);
for (iter = source; iter != NULL; iter = iter->next)
{
PyObject *item = pyg_boxed_new (boxed_type, iter->data,
TRUE, TRUE);
PyList_Append (dest, item);
Py_DECREF (item);
}
return dest;
}
%%
init
%%
modulename poppler
%%
import gobject.GObject as PyGObject_Type
%%
ignore
poppler_page_free_link_mapping
poppler_page_free_image_mapping
poppler_page_free_form_field_mapping
poppler_page_free_annot_mapping
%%
ignore-glob
*_get_type
_*
*_copy
*_free
%%
override poppler_document_get_attachments noargs
static PyObject *
_wrap_poppler_document_get_attachments(PyGObject *self)
{
GList *item_list;
PyObject *ret;
item_list = poppler_document_get_attachments(POPPLER_DOCUMENT(self->obj));
ret = _glist_to_pylist_objs(item_list);
g_list_free(item_list);
return ret;
}
%%
override poppler_page_find_text kwargs
static PyObject *
_wrap_poppler_page_find_text(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "text", NULL };
const gchar *text;
GList *item_list;
PyObject *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"s",
kwlist,
&text)) {
return NULL;
}
item_list = poppler_page_find_text(POPPLER_PAGE(self->obj), text);
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_RECTANGLE);
g_list_free(item_list);
return ret;
}
%%
override poppler_page_get_size noargs
static PyObject *
_wrap_poppler_page_get_size(PyGObject *self)
{
double width;
double height;
poppler_page_get_size(POPPLER_PAGE(self->obj), &width, &height);
return Py_BuildValue("dd", width, height);
}
%%
override poppler_font_info_scan kwargs
static PyObject *
_wrap_poppler_font_info_scan(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "n_pages", NULL };
int n_pages;
PopplerFontsIter *fonts_iter;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i",
kwlist,
&n_pages)) {
return NULL;
}
poppler_font_info_scan (POPPLER_FONT_INFO(self->obj), n_pages, &fonts_iter);
return pyg_boxed_new(POPPLER_TYPE_FONTS_ITER, fonts_iter, TRUE, TRUE);
}
%%
override poppler_page_get_thumbnail_size noargs
static PyObject *
_wrap_poppler_page_get_thumbnail_size(PyGObject *self)
{
int width, height;
poppler_page_get_thumbnail_size (POPPLER_PAGE(self->obj), &width, &height);
return Py_BuildValue("ii", width, height);
}
%%
override poppler_page_get_link_mapping noargs
static PyObject *
_wrap_poppler_page_get_link_mapping(PyGObject *self)
{
GList *item_list;
PyObject *ret;
item_list = poppler_page_get_link_mapping(POPPLER_PAGE(self->obj));
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_LINK_MAPPING);
poppler_page_free_link_mapping(item_list);
return ret;
}
%%
override poppler_page_get_image_mapping noargs
static PyObject *
_wrap_poppler_page_get_image_mapping(PyGObject *self)
{
GList *item_list;
PyObject *ret;
item_list = poppler_page_get_image_mapping(POPPLER_PAGE(self->obj));
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_IMAGE_MAPPING);
poppler_page_free_image_mapping(item_list);
return ret;
}
%%
override poppler_page_get_form_field_mapping noargs
static PyObject *
_wrap_poppler_page_get_form_field_mapping(PyGObject *self)
{
GList *item_list;
PyObject *ret;
item_list = poppler_page_get_form_field_mapping(POPPLER_PAGE(self->obj));
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_FORM_FIELD_MAPPING);
poppler_page_free_form_field_mapping(item_list);
return ret;
}
%%
override poppler_page_get_annot_mapping noargs
static PyObject *
_wrap_poppler_page_get_annot_mapping(PyGObject *self)
{
GList *item_list;
PyObject *ret;
item_list = poppler_page_get_annot_mapping(POPPLER_PAGE(self->obj));
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_ANNOT_MAPPING);
poppler_page_free_annot_mapping(item_list);
return ret;
}
%%
override poppler_page_get_selection_region kwargs
static PyObject *
_wrap_poppler_page_get_selection_region(PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "scale", "style", "selection", NULL };
double scale;
PopplerSelectionStyle style;
PopplerRectangle *selection;
GList *item_list;
PyObject *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"diO:Page.get_selection_region", kwlist,
&scale, &style, &selection)) {
return NULL;
}
item_list = poppler_page_get_selection_region(POPPLER_PAGE(self->obj),
scale, style, selection);
ret = _glist_to_pylist_boxed(item_list, POPPLER_TYPE_RECTANGLE);
g_list_free(item_list);
return ret;
}
%%
override-attr PopplerRectangle.x1
static int
_wrap_poppler_rectangle__set_x1(PyGBoxed *self, PyObject *value, void *closure)
{
double val;
val = PyFloat_AsDouble(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerRectangle)->x1 = val;
return 0;
}
%%
override-attr PopplerRectangle.x2
static int
_wrap_poppler_rectangle__set_x2(PyGBoxed *self, PyObject *value, void *closure)
{
double val;
val = PyFloat_AsDouble(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerRectangle)->x2 = val;
return 0;
}
%%
override-attr PopplerRectangle.y1
static int
_wrap_poppler_rectangle__set_y1(PyGBoxed *self, PyObject *value, void *closure)
{
double val;
val = PyFloat_AsDouble(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerRectangle)->y1 = val;
return 0;
}
%%
override-attr PopplerRectangle.y2
static int
_wrap_poppler_rectangle__set_y2(PyGBoxed *self, PyObject *value, void *closure)
{
double val;
val = PyFloat_AsDouble(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerRectangle)->y2 = val;
return 0;
}
%%
override-attr PopplerColor.red
static int
_wrap_poppler_color__set_red(PyGBoxed *self, PyObject *value, void *closure)
{
guint16 val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerColor)->red = val;
return 0;
}
%%
override-attr PopplerColor.green
static int
_wrap_poppler_color__set_green(PyGBoxed *self, PyObject *value, void *closure)
{
guint16 val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerColor)->green = val;
return 0;
}
%%
override-attr PopplerColor.blue
static int
_wrap_poppler_color__set_blue(PyGBoxed *self, PyObject *value, void *closure)
{
guint16 val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, PopplerColor)->blue = val;
return 0;
}
%%
override poppler_action_get_typed_action noargs
static PyObject *
_wrap_poppler_action_get_typed_action(PyGBoxed *self)
{
return _poppler_action_to_poppler_action_typed(pyg_boxed_get(self, PopplerAction));
}
%%
override-attr PopplerLinkMapping.action
static PyObject *
_wrap_poppler_link_mapping__get_action(PyGBoxed * self, void *closure)
{
PopplerLinkMapping * lm = pyg_boxed_get(self, PopplerLinkMapping);
if (lm)
{
return _poppler_action_to_poppler_action_typed(lm->action);
}
Py_INCREF(Py_None);/*TODO: Should we raise an exception in this case?*/
return Py_None;
}
%%
override poppler_index_iter_get_action noargs
static PyObject *
_wrap_poppler_index_iter_get_action(PyGBoxed *self)
{
PopplerIndexIter * it = pyg_boxed_get(self, PopplerIndexIter);
if (it)
{
return _poppler_action_to_poppler_action_typed(poppler_index_iter_get_action(it));
}
Py_INCREF(Py_None);/*TODO: Should we raise an exception in this case?*/
return Py_None;
}
%%
override poppler_page_get_thumbnail noargs
static PyObject *
_wrap_poppler_page_get_thumbnail(PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
cairo_surface_t * surface;
surface = poppler_page_get_thumbnail(POPPLER_PAGE(self->obj));
#if PYCAIRO_VERSION_HEX >= 0x1010600
return PycairoSurface_FromSurface(surface, NULL);
#else
return PycairoSurface_FromSurface(surface, NULL, NULL);
#endif
}
%%
override poppler_page_get_image kwargs
static PyObject *
_wrap_poppler_page_get_image(PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "image_id", NULL };
gint image_id;
cairo_surface_t *surface;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"i:Page.get_image", kwlist,
&image_id)) {
return NULL;
}
surface = poppler_page_get_image(POPPLER_PAGE(self->obj), image_id);
#if PYCAIRO_VERSION_HEX >= 0x1010600
return PycairoSurface_FromSurface(surface, NULL);
#else
return PycairoSurface_FromSurface(surface, NULL, NULL);
#endif
}
%%
override poppler_page_render_to_pixbuf kwargs
static PyObject *
_wrap_poppler_page_render_to_pixbuf(PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "src_x", "src_y", "src_width",
"src_height", "scale", "rotation", NULL };
int src_x, src_y, src_width, src_height, rotation;
double scale;
GdkPixbuf *pixbuf = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"iiiidi:Poppler.Page.render_to_pixbuf",
kwlist, &src_x, &src_y, &src_width,
&src_height, &scale, &rotation))
return NULL;
pyg_begin_allow_threads;
poppler_page_render_to_pixbuf(POPPLER_PAGE(self->obj), src_x, src_y,
src_width, src_height, scale,
rotation, pixbuf);
pyg_end_allow_threads;
return pygobject_new((GObject *)pixbuf);
}
%%
override poppler_page_render_to_pixbuf_for_printing kwargs
static PyObject *
_wrap_poppler_page_render_to_pixbuf_for_printing(PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "src_x", "src_y", "src_width",
"src_height", "scale", "rotation", NULL };
int src_x, src_y, src_width, src_height, rotation;
double scale;
GdkPixbuf *pixbuf = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"iiiidi:Poppler.Page.render_to_pixbuf_for_printing",
kwlist, &src_x, &src_y, &src_width,
&src_height, &scale, &rotation))
return NULL;
pyg_begin_allow_threads;
poppler_page_render_to_pixbuf_for_printing(POPPLER_PAGE(self->obj),
src_x, src_y, src_width,
src_height, scale,
rotation, pixbuf);
pyg_end_allow_threads;
return pygobject_new((GObject *)pixbuf);
}