poppler 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +369 -0
- data/README +37 -0
- data/Rakefile +72 -0
- data/extconf.rb +49 -0
- data/sample/number-pdf.rb +32 -0
- data/sample/pdf2.rb +107 -0
- data/sample/pdf2svg.rb +26 -0
- data/sample/pdf2text.rb +16 -0
- data/sample/pdfdiv.rb +36 -0
- data/src/lib/poppler.rb +108 -0
- data/src/rbpoppler-action.c +222 -0
- data/src/rbpoppler-annotation.c +307 -0
- data/src/rbpoppler-attachment.c +116 -0
- data/src/rbpoppler-document.c +492 -0
- data/src/rbpoppler-form-field.c +291 -0
- data/src/rbpoppler-page.c +773 -0
- data/src/rbpoppler-private.h +56 -0
- data/src/rbpoppler.c +90 -0
- data/src/rbpoppler.h +60 -0
- data/src/rbpopplerversion.h +24 -0
- data/test/poppler-test-utils.rb +47 -0
- data/test/run-test.rb +27 -0
- data/test/test_annotation.rb +84 -0
- data/test/test_color.rb +26 -0
- data/test/test_constants.rb +30 -0
- data/test/test_document.rb +41 -0
- data/test/test_page.rb +78 -0
- metadata +122 -0
@@ -0,0 +1,291 @@
|
|
1
|
+
/* -*- c-file-style: "ruby" -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbpoppler-form-field.c -
|
5
|
+
|
6
|
+
Copyright (C) 2008 Ruby-GNOME2 Project Team
|
7
|
+
|
8
|
+
**********************************************************************/
|
9
|
+
|
10
|
+
#include "rbpoppler-private.h"
|
11
|
+
|
12
|
+
#define RVAL2FF(obj) RVAL2POPPLER_FORM_FIELD(obj)
|
13
|
+
#define RVAL2TF(obj) RVAL2FF(obj)
|
14
|
+
#define RVAL2BF(obj) RVAL2FF(obj)
|
15
|
+
#define RVAL2CF(obj) RVAL2FF(obj)
|
16
|
+
|
17
|
+
#define FFT2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_FORM_FIELD_TYPE))
|
18
|
+
#define RVAL2FFT(obj) (RVAL2GENUM(obj, POPPLER_TYPE_FORM_FIELD_TYPE))
|
19
|
+
#define FBT2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_FORM_BUTTON_TYPE))
|
20
|
+
#define FTT2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_FORM_TEXT_TYPE))
|
21
|
+
#define FCT2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_FORM_CHOICE_TYPE))
|
22
|
+
|
23
|
+
static VALUE cUnknownField, cTextField, cButtonField;
|
24
|
+
static VALUE cChoiceField, cSignatureField;
|
25
|
+
|
26
|
+
VALUE
|
27
|
+
rb_poppler_ruby_object_from_form_field(PopplerFormField *field)
|
28
|
+
{
|
29
|
+
VALUE obj;
|
30
|
+
|
31
|
+
obj = rbgobj_ruby_object_from_instance2(field, FALSE);
|
32
|
+
if (NIL_P(obj)) {
|
33
|
+
switch (poppler_form_field_get_field_type(field)) {
|
34
|
+
case POPPLER_FORM_FIELD_UNKNOWN:
|
35
|
+
obj = rbgobj_create_object(cUnknownField);
|
36
|
+
break;
|
37
|
+
case POPPLER_FORM_FIELD_BUTTON:
|
38
|
+
obj = rbgobj_create_object(cButtonField);
|
39
|
+
break;
|
40
|
+
case POPPLER_FORM_FIELD_TEXT:
|
41
|
+
obj = rbgobj_create_object(cTextField);
|
42
|
+
break;
|
43
|
+
case POPPLER_FORM_FIELD_CHOICE:
|
44
|
+
obj = rbgobj_create_object(cChoiceField);
|
45
|
+
break;
|
46
|
+
case POPPLER_FORM_FIELD_SIGNATURE:
|
47
|
+
obj = rbgobj_create_object(cSignatureField);
|
48
|
+
break;
|
49
|
+
}
|
50
|
+
g_object_ref(field);
|
51
|
+
G_INITIALIZE(obj, (gpointer)field);
|
52
|
+
}
|
53
|
+
|
54
|
+
return obj;
|
55
|
+
}
|
56
|
+
|
57
|
+
/* FormField */
|
58
|
+
static VALUE
|
59
|
+
form_field_get_id(VALUE self)
|
60
|
+
{
|
61
|
+
return INT2NUM(poppler_form_field_get_id(RVAL2FF(self)));
|
62
|
+
}
|
63
|
+
|
64
|
+
static VALUE
|
65
|
+
form_field_get_font_size(VALUE self)
|
66
|
+
{
|
67
|
+
return rb_float_new(poppler_form_field_get_font_size(RVAL2FF(self)));
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE
|
71
|
+
form_field_is_read_only(VALUE self)
|
72
|
+
{
|
73
|
+
return CBOOL2RVAL(poppler_form_field_is_read_only(RVAL2FF(self)));
|
74
|
+
}
|
75
|
+
|
76
|
+
/* Button Field */
|
77
|
+
static VALUE
|
78
|
+
button_field_get_button_type(VALUE self)
|
79
|
+
{
|
80
|
+
return FBT2RVAL(poppler_form_field_button_get_button_type(RVAL2FF(self)));
|
81
|
+
}
|
82
|
+
|
83
|
+
static VALUE
|
84
|
+
button_field_get_state(VALUE self)
|
85
|
+
{
|
86
|
+
return CBOOL2RVAL(poppler_form_field_button_get_state(RVAL2BF(self)));
|
87
|
+
}
|
88
|
+
|
89
|
+
static VALUE
|
90
|
+
button_field_set_state(VALUE self, VALUE state)
|
91
|
+
{
|
92
|
+
poppler_form_field_button_set_state(RVAL2BF(self), RVAL2CBOOL(state));
|
93
|
+
return Qnil;
|
94
|
+
}
|
95
|
+
|
96
|
+
/* Text Field */
|
97
|
+
static VALUE
|
98
|
+
text_field_get_text_type(VALUE self)
|
99
|
+
{
|
100
|
+
return FTT2RVAL(poppler_form_field_text_get_text_type(RVAL2TF(self)));
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
text_field_get_text(VALUE self)
|
105
|
+
{
|
106
|
+
return CSTR2RVAL(poppler_form_field_text_get_text(RVAL2TF(self)));
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE
|
110
|
+
text_field_set_text(VALUE self, VALUE text)
|
111
|
+
{
|
112
|
+
poppler_form_field_text_set_text(RVAL2TF(self), RVAL2CSTR2(text));
|
113
|
+
return Qnil;
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
text_field_get_max_length(VALUE self)
|
118
|
+
{
|
119
|
+
return INT2NUM(poppler_form_field_text_get_max_len(RVAL2TF(self)));
|
120
|
+
}
|
121
|
+
|
122
|
+
static VALUE
|
123
|
+
text_field_do_spell_check(VALUE self)
|
124
|
+
{
|
125
|
+
return CBOOL2RVAL(poppler_form_field_text_do_spell_check(RVAL2TF(self)));
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
text_field_do_scroll(VALUE self)
|
130
|
+
{
|
131
|
+
return CBOOL2RVAL(poppler_form_field_text_do_scroll(RVAL2TF(self)));
|
132
|
+
}
|
133
|
+
|
134
|
+
static VALUE
|
135
|
+
text_field_is_rich_text(VALUE self)
|
136
|
+
{
|
137
|
+
return CBOOL2RVAL(poppler_form_field_text_is_rich_text(RVAL2TF(self)));
|
138
|
+
}
|
139
|
+
|
140
|
+
static VALUE
|
141
|
+
text_field_is_password(VALUE self)
|
142
|
+
{
|
143
|
+
return CBOOL2RVAL(poppler_form_field_text_is_password(RVAL2TF(self)));
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
/* Choice Field */
|
148
|
+
static VALUE
|
149
|
+
choice_field_get_choice_type(VALUE self)
|
150
|
+
{
|
151
|
+
return FCT2RVAL(poppler_form_field_choice_get_choice_type(RVAL2CF(self)));
|
152
|
+
}
|
153
|
+
|
154
|
+
static VALUE
|
155
|
+
choice_field_is_editable(VALUE self)
|
156
|
+
{
|
157
|
+
return CBOOL2RVAL(poppler_form_field_choice_is_editable(RVAL2CF(self)));
|
158
|
+
}
|
159
|
+
|
160
|
+
static VALUE
|
161
|
+
choice_field_can_select_multiple(VALUE self)
|
162
|
+
{
|
163
|
+
return CBOOL2RVAL(poppler_form_field_choice_can_select_multiple(RVAL2CF(self)));
|
164
|
+
}
|
165
|
+
|
166
|
+
static VALUE
|
167
|
+
choice_field_do_spell_check(VALUE self)
|
168
|
+
{
|
169
|
+
return CBOOL2RVAL(poppler_form_field_choice_do_spell_check(RVAL2CF(self)));
|
170
|
+
}
|
171
|
+
|
172
|
+
static VALUE
|
173
|
+
choice_field_commit_on_change(VALUE self)
|
174
|
+
{
|
175
|
+
return CBOOL2RVAL(poppler_form_field_choice_commit_on_change(RVAL2CF(self)));
|
176
|
+
}
|
177
|
+
|
178
|
+
static VALUE
|
179
|
+
choice_field_get_n_items(VALUE self)
|
180
|
+
{
|
181
|
+
return INT2NUM(poppler_form_field_choice_get_n_items(RVAL2CF(self)));
|
182
|
+
}
|
183
|
+
|
184
|
+
static VALUE
|
185
|
+
choice_field_get_item(VALUE self, VALUE index)
|
186
|
+
{
|
187
|
+
return CSTR2RVAL(poppler_form_field_choice_get_item(RVAL2CF(self),
|
188
|
+
NUM2INT(index)));
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE
|
192
|
+
choice_field_is_item_selected(VALUE self, VALUE index)
|
193
|
+
{
|
194
|
+
return CBOOL2RVAL(poppler_form_field_choice_is_item_selected(RVAL2CF(self),
|
195
|
+
NUM2INT(index)));
|
196
|
+
}
|
197
|
+
|
198
|
+
static VALUE
|
199
|
+
choice_field_select_item(VALUE self, VALUE index)
|
200
|
+
{
|
201
|
+
poppler_form_field_choice_select_item(RVAL2CF(self), NUM2INT(index));
|
202
|
+
return Qnil;
|
203
|
+
}
|
204
|
+
|
205
|
+
static VALUE
|
206
|
+
choice_field_unselect_all(VALUE self)
|
207
|
+
{
|
208
|
+
poppler_form_field_choice_unselect_all(RVAL2CF(self));
|
209
|
+
return Qnil;
|
210
|
+
}
|
211
|
+
|
212
|
+
static VALUE
|
213
|
+
choice_field_toggle_item(VALUE self, VALUE index)
|
214
|
+
{
|
215
|
+
poppler_form_field_choice_toggle_item(RVAL2CF(self), NUM2INT(index));
|
216
|
+
return Qnil;
|
217
|
+
}
|
218
|
+
|
219
|
+
static VALUE
|
220
|
+
choice_field_set_text(VALUE self, VALUE text)
|
221
|
+
{
|
222
|
+
poppler_form_field_choice_set_text(RVAL2CF(self), RVAL2CSTR2(text));
|
223
|
+
return Qnil;
|
224
|
+
}
|
225
|
+
|
226
|
+
static VALUE
|
227
|
+
choice_field_get_text(VALUE self)
|
228
|
+
{
|
229
|
+
return CSTR2RVAL(poppler_form_field_choice_get_text(RVAL2CF(self)));
|
230
|
+
}
|
231
|
+
|
232
|
+
void
|
233
|
+
Init_poppler_form_field(VALUE mPoppler)
|
234
|
+
{
|
235
|
+
VALUE cFormField;
|
236
|
+
|
237
|
+
cFormField = G_DEF_CLASS(POPPLER_TYPE_FORM_FIELD, "FormField", mPoppler);
|
238
|
+
cUnknownField = rb_define_class_under(mPoppler, "UnknownField", cFormField);
|
239
|
+
cTextField = rb_define_class_under(mPoppler, "TextField", cFormField);
|
240
|
+
cButtonField = rb_define_class_under(mPoppler, "ButtonField", cFormField);
|
241
|
+
cChoiceField = rb_define_class_under(mPoppler, "ChoiceField", cFormField);
|
242
|
+
cSignatureField = rb_define_class_under(mPoppler, "SignatureField",
|
243
|
+
cFormField);
|
244
|
+
|
245
|
+
/* FormField */
|
246
|
+
rb_define_method(cFormField, "id", form_field_get_id, 0);
|
247
|
+
rb_define_method(cFormField, "font_size", form_field_get_font_size, 0);
|
248
|
+
rb_define_method(cFormField, "read_only?", form_field_is_read_only, 0);
|
249
|
+
|
250
|
+
G_DEF_SETTERS(cFormField);
|
251
|
+
|
252
|
+
|
253
|
+
rb_define_method(cButtonField, "type", button_field_get_button_type, 0);
|
254
|
+
rb_define_method(cButtonField, "active?", button_field_get_state, 0);
|
255
|
+
rb_define_method(cButtonField, "set_active", button_field_set_state, 1);
|
256
|
+
|
257
|
+
G_DEF_SETTERS(cButtonField);
|
258
|
+
|
259
|
+
|
260
|
+
rb_define_method(cTextField, "type", text_field_get_text_type, 0);
|
261
|
+
rb_define_method(cTextField, "text", text_field_get_text, 0);
|
262
|
+
rb_define_method(cTextField, "set_text", text_field_set_text, 1);
|
263
|
+
rb_define_method(cTextField, "max_length", text_field_get_max_length, 0);
|
264
|
+
rb_define_method(cTextField, "spell_check?", text_field_do_spell_check, 0);
|
265
|
+
rb_define_method(cTextField, "scroll?", text_field_do_scroll, 0);
|
266
|
+
rb_define_method(cTextField, "rich_text?", text_field_is_rich_text, 0);
|
267
|
+
rb_define_method(cTextField, "password?", text_field_is_password, 0);
|
268
|
+
|
269
|
+
G_DEF_SETTERS(cTextField);
|
270
|
+
|
271
|
+
|
272
|
+
rb_define_method(cChoiceField, "type", choice_field_get_choice_type, 0);
|
273
|
+
rb_define_method(cChoiceField, "editable?", choice_field_is_editable, 0);
|
274
|
+
rb_define_method(cChoiceField, "select_multiple?",
|
275
|
+
choice_field_can_select_multiple, 0);
|
276
|
+
rb_define_method(cChoiceField, "spell_check?",
|
277
|
+
choice_field_do_spell_check, 0);
|
278
|
+
rb_define_method(cChoiceField, "commit_on_change?",
|
279
|
+
choice_field_commit_on_change, 0);
|
280
|
+
rb_define_method(cChoiceField, "n_items", choice_field_get_n_items, 0);
|
281
|
+
rb_define_method(cChoiceField, "[]", choice_field_get_item, 1);
|
282
|
+
rb_define_method(cChoiceField, "selected?",
|
283
|
+
choice_field_is_item_selected, 1);
|
284
|
+
rb_define_method(cChoiceField, "select", choice_field_select_item, 1);
|
285
|
+
rb_define_method(cChoiceField, "unselect_all", choice_field_unselect_all, 0);
|
286
|
+
rb_define_method(cChoiceField, "toggle", choice_field_toggle_item, 1);
|
287
|
+
rb_define_method(cChoiceField, "text", choice_field_get_text, 0);
|
288
|
+
rb_define_method(cChoiceField, "set_text", choice_field_set_text, 1);
|
289
|
+
|
290
|
+
G_DEF_SETTERS(cChoiceField);
|
291
|
+
}
|
@@ -0,0 +1,773 @@
|
|
1
|
+
/* -*- c-file-style: "ruby" -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
rbpoppler-page.c -
|
5
|
+
|
6
|
+
Copyright (C) 2006-2008 Ruby-GNOME2 Project Team
|
7
|
+
|
8
|
+
**********************************************************************/
|
9
|
+
|
10
|
+
#include "rbpoppler-private.h"
|
11
|
+
|
12
|
+
#define SELF(self) (POPPLER_PAGE(RVAL2GOBJ(self)))
|
13
|
+
|
14
|
+
#ifndef GDK_TYPE_REGION
|
15
|
+
extern GType gdk_region_get_type(void);
|
16
|
+
# define GDK_TYPE_REGION (gdk_region_get_type())
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#define GDK_REGION2RVAL(obj) (BOXED2RVAL(obj, GDK_TYPE_REGION))
|
20
|
+
#define RVAL2GDK_PIXBUF(pixbuf) (GDK_PIXBUF(RVAL2GOBJ(pixbuf)))
|
21
|
+
|
22
|
+
|
23
|
+
#define SEL_STYLE2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_SELECTION_STYLE))
|
24
|
+
#define RVAL2SEL_STYLE(obj) (RVAL2GENUM(obj, POPPLER_TYPE_SELECTION_STYLE))
|
25
|
+
|
26
|
+
#define RVAL2TRANS(obj) ((PopplerPageTransition *)RVAL2BOXED(obj, POPPLER_TYPE_PAGE_TRANSITION))
|
27
|
+
#define TRANS2RVAL(obj) (BOXED2RVAL(obj, POPPLER_TYPE_PAGE_TRANSITION))
|
28
|
+
#define RVAL2LM(obj) ((PopplerLinkMapping *)RVAL2BOXED(obj, POPPLER_TYPE_LINK_MAPPING))
|
29
|
+
#define RVAL2IM(obj) ((PopplerImageMapping *)RVAL2BOXED(obj, POPPLER_TYPE_IMAGE_MAPPING))
|
30
|
+
#define RVAL2FFM(obj) ((PopplerFormFieldMapping *)RVAL2BOXED(obj, POPPLER_TYPE_FORM_FIELD_MAPPING))
|
31
|
+
#define RVAL2AM(obj) ((PopplerAnnotMapping *)RVAL2BOXED(obj, POPPLER_TYPE_ANNOT_MAPPING))
|
32
|
+
|
33
|
+
#define TT2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_PAGE_TRANSITION_TYPE))
|
34
|
+
#define RVAL2TT(obj) (RVAL2GENUM(obj, POPPLER_TYPE_PAGE_TRANSITION_TYPE))
|
35
|
+
#define TA2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_PAGE_TRANSITION_ALIGNMENT))
|
36
|
+
#define RVAL2TA(obj) (RVAL2GENUM(obj, POPPLER_TYPE_PAGE_TRANSITION_ALIGNMENT))
|
37
|
+
#define TD2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_PAGE_TRANSITION_DIRECTION))
|
38
|
+
#define RVAL2TD(obj) (RVAL2GENUM(obj, POPPLER_TYPE_PAGE_TRANSITION_DIRECTION))
|
39
|
+
|
40
|
+
static VALUE cPSFile, cRectangle;
|
41
|
+
|
42
|
+
#ifdef POPPLER_TYPE_COLOR
|
43
|
+
VALUE rb_cPopplerColor;
|
44
|
+
|
45
|
+
PopplerColor *
|
46
|
+
rb_poppler_ruby_object_to_color(VALUE color)
|
47
|
+
{
|
48
|
+
#ifdef POPPLER_WITH_GDK
|
49
|
+
if (RTEST(rb_obj_is_kind_of(color, rb_cGdkColor))) {
|
50
|
+
GdkColor *gdk_color;
|
51
|
+
|
52
|
+
gdk_color = RVAL2GDKCOLOR(color);
|
53
|
+
color = rb_funcall(rb_cPopplerColor, rb_intern("new"),
|
54
|
+
3,
|
55
|
+
UINT2NUM(gdk_color->red),
|
56
|
+
UINT2NUM(gdk_color->green),
|
57
|
+
UINT2NUM(gdk_color->blue));
|
58
|
+
}
|
59
|
+
#endif
|
60
|
+
|
61
|
+
return RVAL2BOXED(color, POPPLER_TYPE_COLOR);
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE
|
65
|
+
rb_poppler_ruby_object_from_color_with_free(PopplerColor *color)
|
66
|
+
{
|
67
|
+
VALUE rb_color;
|
68
|
+
|
69
|
+
rb_color = POPPLER_COLOR2RVAL(color);
|
70
|
+
g_free(color);
|
71
|
+
return rb_color;
|
72
|
+
}
|
73
|
+
#endif
|
74
|
+
|
75
|
+
#ifdef POPPLER_WITH_GDK
|
76
|
+
static VALUE
|
77
|
+
page_render_to_pixbuf(VALUE self, VALUE src_x, VALUE src_y, VALUE src_width,
|
78
|
+
VALUE src_height, VALUE scale, VALUE rotation,
|
79
|
+
VALUE pixbuf)
|
80
|
+
{
|
81
|
+
poppler_page_render_to_pixbuf(SELF(self), NUM2INT(src_x),
|
82
|
+
NUM2INT(src_y), NUM2INT(src_width),
|
83
|
+
NUM2INT(src_height), NUM2DBL(scale),
|
84
|
+
NUM2INT(rotation), RVAL2GOBJ(pixbuf));
|
85
|
+
return Qnil;
|
86
|
+
}
|
87
|
+
#endif
|
88
|
+
|
89
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
90
|
+
static VALUE
|
91
|
+
page_render(VALUE self, VALUE cairo)
|
92
|
+
{
|
93
|
+
poppler_page_render(SELF(self), RVAL2CRCONTEXT(cairo));
|
94
|
+
return Qnil;
|
95
|
+
}
|
96
|
+
#endif
|
97
|
+
|
98
|
+
static VALUE
|
99
|
+
page_render_to_ps(VALUE self, VALUE ps_file)
|
100
|
+
{
|
101
|
+
poppler_page_render_to_ps(SELF(self), RVAL2GOBJ(ps_file));
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE
|
106
|
+
page_render_generic(int argc, VALUE *argv, VALUE self)
|
107
|
+
{
|
108
|
+
if (argc == 1) {
|
109
|
+
if (RVAL2CBOOL(rb_obj_is_kind_of(argv[0], cPSFile))) {
|
110
|
+
return page_render_to_ps(self, argv[0]);
|
111
|
+
} else {
|
112
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
113
|
+
return page_render(self, argv[0]);
|
114
|
+
#else
|
115
|
+
rb_raise(rb_eArgError, "cairo is not available");
|
116
|
+
#endif
|
117
|
+
}
|
118
|
+
} else if (argc == 7) {
|
119
|
+
#ifdef POPPLER_WITH_GDK
|
120
|
+
return page_render_to_pixbuf(self, argv[0], argv[1], argv[2], argv[3],
|
121
|
+
argv[4], argv[5], argv[6]);
|
122
|
+
#else
|
123
|
+
rb_raise(rb_eArgError, "GDK is not available");
|
124
|
+
#endif
|
125
|
+
} else {
|
126
|
+
rb_raise(rb_eArgError,
|
127
|
+
"wrong number of arguments (%d for 1 or 7)",
|
128
|
+
argc);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
#ifdef POPPLER_WITH_GDK
|
133
|
+
static VALUE
|
134
|
+
page_render_to_pixbuf_for_printing(VALUE self, VALUE src_x, VALUE src_y,
|
135
|
+
VALUE src_width, VALUE src_height,
|
136
|
+
VALUE scale, VALUE rotation, VALUE pixbuf)
|
137
|
+
{
|
138
|
+
poppler_page_render_to_pixbuf_for_printing(SELF(self), NUM2INT(src_x),
|
139
|
+
NUM2INT(src_y),
|
140
|
+
NUM2INT(src_width),
|
141
|
+
NUM2INT(src_height),
|
142
|
+
NUM2DBL(scale),
|
143
|
+
NUM2INT(rotation),
|
144
|
+
RVAL2GOBJ(pixbuf));
|
145
|
+
return Qnil;
|
146
|
+
}
|
147
|
+
#endif
|
148
|
+
|
149
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
150
|
+
static VALUE
|
151
|
+
page_render_for_printing(VALUE self, VALUE cairo)
|
152
|
+
{
|
153
|
+
poppler_page_render_for_printing(SELF(self), RVAL2CRCONTEXT(cairo));
|
154
|
+
return Qnil;
|
155
|
+
}
|
156
|
+
#endif
|
157
|
+
|
158
|
+
static VALUE
|
159
|
+
page_render_for_printing_generic(int argc, VALUE *argv, VALUE self)
|
160
|
+
{
|
161
|
+
if (argc == 1) {
|
162
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
163
|
+
return page_render_for_printing(self, argv[0]);
|
164
|
+
#else
|
165
|
+
rb_raise(rb_eArgError, "cairo is not available");
|
166
|
+
#endif
|
167
|
+
} else if (argc == 7) {
|
168
|
+
#ifdef POPPLER_WITH_GDK
|
169
|
+
return page_render_to_pixbuf_for_printing(self, argv[0], argv[1],
|
170
|
+
argv[2], argv[3],
|
171
|
+
argv[4], argv[5], argv[6]);
|
172
|
+
#else
|
173
|
+
rb_raise(rb_eArgError, "GDK is not available");
|
174
|
+
#endif
|
175
|
+
} else {
|
176
|
+
rb_raise(rb_eArgError,
|
177
|
+
"wrong number of arguments (%d for 1 or 7)", argc);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
182
|
+
static VALUE
|
183
|
+
page_render_selection(VALUE self, VALUE cairo,
|
184
|
+
VALUE selection, VALUE rb_old_selection,
|
185
|
+
VALUE style, VALUE glyph_color, VALUE background_color)
|
186
|
+
{
|
187
|
+
PopplerRectangle *old_selection = NULL;
|
188
|
+
|
189
|
+
if (!NIL_P(rb_old_selection))
|
190
|
+
old_selection = RVAL2POPPLER_RECT(rb_old_selection);
|
191
|
+
poppler_page_render_selection(SELF(self), RVAL2CRCONTEXT(cairo),
|
192
|
+
RVAL2POPPLER_RECT(selection),
|
193
|
+
old_selection,
|
194
|
+
RVAL2SEL_STYLE(style),
|
195
|
+
RVAL2POPPLER_COLOR(glyph_color),
|
196
|
+
RVAL2POPPLER_COLOR(background_color));
|
197
|
+
return Qnil;
|
198
|
+
}
|
199
|
+
#endif
|
200
|
+
|
201
|
+
#ifdef POPPLER_WITH_GDK
|
202
|
+
static VALUE
|
203
|
+
page_render_selection_to_pixbuf(VALUE self, VALUE scale, VALUE rotation,
|
204
|
+
VALUE pixbuf, VALUE selection,
|
205
|
+
VALUE rb_old_selection,
|
206
|
+
VALUE style,
|
207
|
+
VALUE glyph_color, VALUE background_color)
|
208
|
+
{
|
209
|
+
PopplerRectangle *old_selection = NULL;
|
210
|
+
|
211
|
+
if (!NIL_P(rb_old_selection))
|
212
|
+
old_selection = RVAL2POPPLER_RECT(rb_old_selection);
|
213
|
+
poppler_page_render_selection_to_pixbuf(SELF(self),
|
214
|
+
NUM2DBL(scale),
|
215
|
+
NUM2INT(rotation),
|
216
|
+
RVAL2GOBJ(pixbuf),
|
217
|
+
RVAL2POPPLER_RECT(selection),
|
218
|
+
old_selection,
|
219
|
+
RVAL2SEL_STYLE(style),
|
220
|
+
RVAL2GDKCOLOR(glyph_color),
|
221
|
+
RVAL2GDKCOLOR(background_color));
|
222
|
+
return Qnil;
|
223
|
+
}
|
224
|
+
#endif
|
225
|
+
|
226
|
+
static VALUE
|
227
|
+
page_render_selection_generic(int argc, VALUE *argv, VALUE self)
|
228
|
+
{
|
229
|
+
if (argc == 6) {
|
230
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
231
|
+
return page_render_selection(self, argv[0], argv[1], argv[2],
|
232
|
+
argv[3], argv[4], argv[5]);
|
233
|
+
#else
|
234
|
+
rb_raise(rb_eArgError, "cairo is not available");
|
235
|
+
#endif
|
236
|
+
} else if (argc == 8) {
|
237
|
+
#ifdef POPPLER_WITH_GDK
|
238
|
+
return page_render_selection_to_pixbuf(self, argv[0], argv[1],
|
239
|
+
argv[2], argv[3], argv[4],
|
240
|
+
argv[5], argv[6], argv[7]);
|
241
|
+
#else
|
242
|
+
rb_raise(rb_eArgError, "GDK is not available");
|
243
|
+
#endif
|
244
|
+
} else {
|
245
|
+
rb_raise(rb_eArgError,
|
246
|
+
"wrong number of arguments (%d for 5 or 8)", argc);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
static VALUE
|
251
|
+
page_get_size(VALUE self)
|
252
|
+
{
|
253
|
+
double width, height;
|
254
|
+
poppler_page_get_size(SELF(self), &width, &height);
|
255
|
+
return rb_ary_new3(2, rb_float_new(width), rb_float_new(height));
|
256
|
+
}
|
257
|
+
|
258
|
+
static VALUE
|
259
|
+
page_get_index(VALUE self)
|
260
|
+
{
|
261
|
+
return INT2NUM(poppler_page_get_index(SELF(self)));
|
262
|
+
}
|
263
|
+
|
264
|
+
static VALUE
|
265
|
+
page_get_duration(VALUE self)
|
266
|
+
{
|
267
|
+
return rb_float_new(poppler_page_get_duration(SELF(self)));
|
268
|
+
}
|
269
|
+
|
270
|
+
static VALUE
|
271
|
+
page_get_transition(VALUE self)
|
272
|
+
{
|
273
|
+
return TRANS2RVAL(poppler_page_get_transition(SELF(self)));
|
274
|
+
}
|
275
|
+
|
276
|
+
#if RB_POPPLER_CAIRO_AVAILABLE
|
277
|
+
static VALUE
|
278
|
+
page_get_thumbnail(VALUE self)
|
279
|
+
{
|
280
|
+
return CRSURFACE2RVAL(poppler_page_get_thumbnail(SELF(self)));
|
281
|
+
}
|
282
|
+
#endif
|
283
|
+
|
284
|
+
#ifdef POPPLER_WITH_GDK
|
285
|
+
static VALUE
|
286
|
+
page_get_thumbnail_pixbuf(VALUE self)
|
287
|
+
{
|
288
|
+
return GOBJ2RVAL(poppler_page_get_thumbnail_pixbuf(SELF(self)));
|
289
|
+
}
|
290
|
+
#endif
|
291
|
+
|
292
|
+
static VALUE
|
293
|
+
page_get_thumbnail_size(VALUE self)
|
294
|
+
{
|
295
|
+
int width, height;
|
296
|
+
|
297
|
+
if (poppler_page_get_thumbnail_size(SELF(self), &width, &height))
|
298
|
+
return rb_ary_new3(2, INT2NUM(width), INT2NUM(height));
|
299
|
+
else
|
300
|
+
return Qnil;
|
301
|
+
}
|
302
|
+
|
303
|
+
static VALUE
|
304
|
+
page_find_text(VALUE self, VALUE text)
|
305
|
+
{
|
306
|
+
return GLIST2ARY2F(poppler_page_find_text(SELF(self), RVAL2CSTR(text)),
|
307
|
+
POPPLER_TYPE_RECTANGLE);
|
308
|
+
}
|
309
|
+
|
310
|
+
static VALUE
|
311
|
+
page_get_text(int argc, VALUE *argv, VALUE self)
|
312
|
+
{
|
313
|
+
gchar *text;
|
314
|
+
PopplerSelectionStyle style = POPPLER_SELECTION_GLYPH;
|
315
|
+
VALUE rb_text, arg1, arg2, rb_rect;
|
316
|
+
PopplerPage *page;
|
317
|
+
|
318
|
+
rb_scan_args(argc, argv, "02", &arg1, &arg2);
|
319
|
+
|
320
|
+
page = SELF(self);
|
321
|
+
if (NIL_P(arg1)) {
|
322
|
+
rb_rect = arg2;
|
323
|
+
} else {
|
324
|
+
if (RTEST(rb_obj_is_kind_of(arg2, cRectangle))) {
|
325
|
+
rb_rect = arg2;
|
326
|
+
} else {
|
327
|
+
rb_rect = Qnil;
|
328
|
+
if (!NIL_P(arg2)) {
|
329
|
+
style = RVAL2SEL_STYLE(arg2);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
if (NIL_P(rb_rect)) {
|
335
|
+
PopplerRectangle rect;
|
336
|
+
double width, height;
|
337
|
+
|
338
|
+
rect.x1 = 0;
|
339
|
+
rect.y1 = 0;
|
340
|
+
poppler_page_get_size(page, &width, &height);
|
341
|
+
rect.x2 = width;
|
342
|
+
rect.y2 = height;
|
343
|
+
text = poppler_page_get_text(page,
|
344
|
+
style,
|
345
|
+
&rect);
|
346
|
+
} else {
|
347
|
+
text = poppler_page_get_text(page,
|
348
|
+
style,
|
349
|
+
RVAL2POPPLER_RECT(rb_rect));
|
350
|
+
}
|
351
|
+
|
352
|
+
rb_text = CSTR2RVAL(text);
|
353
|
+
g_free(text);
|
354
|
+
return rb_text;
|
355
|
+
}
|
356
|
+
|
357
|
+
static VALUE
|
358
|
+
page_get_selection_region(VALUE self, VALUE scale, VALUE style, VALUE selection)
|
359
|
+
{
|
360
|
+
return GLIST2ARY2F(poppler_page_get_selection_region(SELF(self),
|
361
|
+
NUM2DBL(scale),
|
362
|
+
RVAL2SEL_STYLE(style),
|
363
|
+
RVAL2POPPLER_RECT(selection)),
|
364
|
+
POPPLER_TYPE_RECTANGLE);
|
365
|
+
}
|
366
|
+
|
367
|
+
static VALUE
|
368
|
+
page_get_link_mapping(VALUE self)
|
369
|
+
{
|
370
|
+
return GLIST2ARY2F(poppler_page_get_link_mapping(SELF(self)),
|
371
|
+
POPPLER_TYPE_LINK_MAPPING);
|
372
|
+
}
|
373
|
+
|
374
|
+
static VALUE
|
375
|
+
page_get_image_mapping(VALUE self)
|
376
|
+
{
|
377
|
+
VALUE mappings;
|
378
|
+
GList *image_mapping, *node;
|
379
|
+
|
380
|
+
mappings = rb_ary_new();
|
381
|
+
image_mapping = poppler_page_get_image_mapping(SELF(self));
|
382
|
+
for (node = image_mapping; node; node = g_list_next(node)) {
|
383
|
+
PopplerImageMapping *image_mapping;
|
384
|
+
VALUE mapping;
|
385
|
+
|
386
|
+
image_mapping = node->data;
|
387
|
+
mapping = BOXED2RVAL(image_mapping, POPPLER_TYPE_IMAGE_MAPPING);
|
388
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
389
|
+
rb_iv_set(mapping, "@page", self);
|
390
|
+
#endif
|
391
|
+
rb_ary_push(mappings, mapping);
|
392
|
+
}
|
393
|
+
poppler_page_free_image_mapping(image_mapping);
|
394
|
+
|
395
|
+
return mappings;
|
396
|
+
}
|
397
|
+
|
398
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
399
|
+
static VALUE
|
400
|
+
_page_get_image(VALUE self, gint image_id)
|
401
|
+
{
|
402
|
+
return CRSURFACE2RVAL(poppler_page_get_image(SELF(self), image_id));
|
403
|
+
}
|
404
|
+
|
405
|
+
static VALUE
|
406
|
+
page_get_image(VALUE self, VALUE image_id)
|
407
|
+
{
|
408
|
+
return _page_get_image(self, NUM2INT(image_id));
|
409
|
+
}
|
410
|
+
#endif
|
411
|
+
|
412
|
+
static VALUE
|
413
|
+
page_get_form_field_mapping(VALUE self)
|
414
|
+
{
|
415
|
+
return GLIST2ARY2F(poppler_page_get_form_field_mapping(SELF(self)),
|
416
|
+
POPPLER_TYPE_FORM_FIELD_MAPPING);
|
417
|
+
}
|
418
|
+
|
419
|
+
static VALUE
|
420
|
+
page_get_annot_mapping(VALUE self)
|
421
|
+
{
|
422
|
+
return GLIST2ARY2F(poppler_page_get_annot_mapping(SELF(self)),
|
423
|
+
POPPLER_TYPE_ANNOT_MAPPING);
|
424
|
+
}
|
425
|
+
|
426
|
+
static VALUE
|
427
|
+
page_get_crop_box(VALUE self)
|
428
|
+
{
|
429
|
+
PopplerRectangle rect;
|
430
|
+
|
431
|
+
poppler_page_get_crop_box(SELF(self), &rect);
|
432
|
+
return POPPLER_RECT2RVAL(&rect);
|
433
|
+
}
|
434
|
+
|
435
|
+
|
436
|
+
/* A rectangle on a page, with coordinates in PDF points. */
|
437
|
+
static VALUE
|
438
|
+
rectangle_initialize(VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
|
439
|
+
{
|
440
|
+
PopplerRectangle rectangle;
|
441
|
+
|
442
|
+
rectangle.x1 = NUM2DBL(x1);
|
443
|
+
rectangle.y1 = NUM2DBL(y1);
|
444
|
+
rectangle.x2 = NUM2DBL(x2);
|
445
|
+
rectangle.y2 = NUM2DBL(y2);
|
446
|
+
|
447
|
+
G_INITIALIZE(self, &rectangle);
|
448
|
+
return Qnil;
|
449
|
+
}
|
450
|
+
|
451
|
+
DEF_ACCESSOR(rectangle, x1, RVAL2POPPLER_RECT, rb_float_new, NUM2DBL)
|
452
|
+
DEF_ACCESSOR(rectangle, y1, RVAL2POPPLER_RECT, rb_float_new, NUM2DBL)
|
453
|
+
DEF_ACCESSOR(rectangle, x2, RVAL2POPPLER_RECT, rb_float_new, NUM2DBL)
|
454
|
+
DEF_ACCESSOR(rectangle, y2, RVAL2POPPLER_RECT, rb_float_new, NUM2DBL)
|
455
|
+
|
456
|
+
static VALUE
|
457
|
+
rectangle_to_a(VALUE self)
|
458
|
+
{
|
459
|
+
PopplerRectangle *rectangle = RVAL2POPPLER_RECT(self);
|
460
|
+
return rb_ary_new3(4,
|
461
|
+
rb_float_new(rectangle->x1),
|
462
|
+
rb_float_new(rectangle->y1),
|
463
|
+
rb_float_new(rectangle->x2),
|
464
|
+
rb_float_new(rectangle->y2));
|
465
|
+
}
|
466
|
+
|
467
|
+
static VALUE
|
468
|
+
rectangle_inspect(VALUE self)
|
469
|
+
{
|
470
|
+
VALUE inspected;
|
471
|
+
gchar *points;
|
472
|
+
PopplerRectangle *rectangle;
|
473
|
+
|
474
|
+
rectangle = RVAL2POPPLER_RECT(self);
|
475
|
+
inspected = rb_call_super(0, NULL);
|
476
|
+
rb_str_resize(inspected, RSTRING_LEN(inspected) - 1);
|
477
|
+
points = g_strdup_printf(": [%g, %g, %g, %g]>",
|
478
|
+
rectangle->x1, rectangle->y1,
|
479
|
+
rectangle->x2, rectangle->y2);
|
480
|
+
rb_str_cat2(inspected, points);
|
481
|
+
g_free(points);
|
482
|
+
return inspected;
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
#ifdef POPPLER_TYPE_COLOR
|
487
|
+
/* A color in RGB */
|
488
|
+
static VALUE
|
489
|
+
color_initialize(VALUE self, VALUE red, VALUE green, VALUE blue)
|
490
|
+
{
|
491
|
+
PopplerColor color;
|
492
|
+
|
493
|
+
color.red = NUM2UINT(red);
|
494
|
+
color.green = NUM2UINT(green);
|
495
|
+
color.blue = NUM2UINT(blue);
|
496
|
+
|
497
|
+
G_INITIALIZE(self, &color);
|
498
|
+
return Qnil;
|
499
|
+
}
|
500
|
+
|
501
|
+
DEF_ACCESSOR(color, red, RVAL2POPPLER_COLOR, UINT2NUM, NUM2UINT)
|
502
|
+
DEF_ACCESSOR(color, green, RVAL2POPPLER_COLOR, UINT2NUM, NUM2UINT)
|
503
|
+
DEF_ACCESSOR(color, blue, RVAL2POPPLER_COLOR, UINT2NUM, NUM2UINT)
|
504
|
+
|
505
|
+
static VALUE
|
506
|
+
color_to_a(VALUE self)
|
507
|
+
{
|
508
|
+
PopplerColor *color;
|
509
|
+
color = RVAL2POPPLER_COLOR(self);
|
510
|
+
return rb_ary_new3(3,
|
511
|
+
UINT2NUM(color->red),
|
512
|
+
UINT2NUM(color->green),
|
513
|
+
UINT2NUM(color->blue));
|
514
|
+
}
|
515
|
+
|
516
|
+
static VALUE
|
517
|
+
color_inspect(VALUE self)
|
518
|
+
{
|
519
|
+
VALUE inspected;
|
520
|
+
gchar *rgb;
|
521
|
+
PopplerColor *color;
|
522
|
+
|
523
|
+
color = RVAL2POPPLER_COLOR(self);
|
524
|
+
inspected = rb_call_super(0, NULL);
|
525
|
+
rb_str_resize(inspected, RSTRING_LEN(inspected) - 1);
|
526
|
+
rgb = g_strdup_printf(": [%u, %u, %u]>",
|
527
|
+
color->red, color->green, color->blue);
|
528
|
+
rb_str_cat2(inspected, rgb);
|
529
|
+
g_free(rgb);
|
530
|
+
return inspected;
|
531
|
+
}
|
532
|
+
#endif
|
533
|
+
|
534
|
+
|
535
|
+
/* Mapping between areas on the current page and PopplerActions */
|
536
|
+
#define RECT_ENTITY2RVAL(rect) POPPLER_RECT2RVAL(&(rect))
|
537
|
+
#define RECT_ENTITY_SET(rect, rb_rect) rectangle_set(&(rect), rb_rect)
|
538
|
+
static void
|
539
|
+
rectangle_set(PopplerRectangle *rect, VALUE rb_rect)
|
540
|
+
{
|
541
|
+
*rect = *(RVAL2POPPLER_RECT(rb_rect));
|
542
|
+
}
|
543
|
+
|
544
|
+
DEF_ACCESSOR_WITH_SETTER(link_mapping, area,
|
545
|
+
RVAL2LM, RECT_ENTITY2RVAL, RECT_ENTITY_SET)
|
546
|
+
DEF_ACCESSOR(link_mapping, action, RVAL2LM,
|
547
|
+
POPPLER_ACTION2RVAL, RVAL2POPPLER_ACTION)
|
548
|
+
|
549
|
+
|
550
|
+
/* Page Transition */
|
551
|
+
DEF_ACCESSOR(page_trans, type, RVAL2TRANS, RVAL2TT, TT2RVAL)
|
552
|
+
DEF_ACCESSOR(page_trans, alignment, RVAL2TRANS, RVAL2TA, TA2RVAL)
|
553
|
+
DEF_ACCESSOR(page_trans, direction, RVAL2TRANS, RVAL2TD, TD2RVAL)
|
554
|
+
DEF_ACCESSOR(page_trans, duration, RVAL2TRANS, NUM2INT, INT2NUM)
|
555
|
+
DEF_ACCESSOR(page_trans, angle, RVAL2TRANS, NUM2INT, INT2NUM)
|
556
|
+
DEF_ACCESSOR(page_trans, scale, RVAL2TRANS, NUM2DBL, rb_float_new)
|
557
|
+
DEF_ACCESSOR(page_trans, rectangular, RVAL2TRANS, RVAL2CBOOL, CBOOL2RVAL)
|
558
|
+
|
559
|
+
|
560
|
+
/* Mapping between areas on the current page and images */
|
561
|
+
DEF_ACCESSOR_WITH_SETTER(image_mapping, area,
|
562
|
+
RVAL2IM, RECT_ENTITY2RVAL, RECT_ENTITY_SET)
|
563
|
+
DEF_ACCESSOR(image_mapping, image_id, RVAL2IM, INT2NUM, NUM2INT)
|
564
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
565
|
+
static VALUE
|
566
|
+
image_mapping_get_image(VALUE self)
|
567
|
+
{
|
568
|
+
return _page_get_image(rb_iv_get(self, "@page"), RVAL2IM(self)->image_id);
|
569
|
+
}
|
570
|
+
#endif
|
571
|
+
|
572
|
+
|
573
|
+
/* Mapping between areas on the current page and form fields */
|
574
|
+
DEF_ACCESSOR_WITH_SETTER(form_field_mapping, area,
|
575
|
+
RVAL2FFM, RECT_ENTITY2RVAL, RECT_ENTITY_SET)
|
576
|
+
DEF_ACCESSOR(form_field_mapping, field, RVAL2FFM,
|
577
|
+
POPPLER_FORM_FIELD2RVAL, RVAL2POPPLER_FORM_FIELD)
|
578
|
+
|
579
|
+
static VALUE
|
580
|
+
annot_mapping_initialize(int argc, VALUE *argv, VALUE self)
|
581
|
+
{
|
582
|
+
VALUE area, annotation;
|
583
|
+
PopplerAnnotMapping *mapping;
|
584
|
+
|
585
|
+
rb_scan_args(argc, argv, "02", &area, &annotation);
|
586
|
+
|
587
|
+
mapping = poppler_annot_mapping_new();
|
588
|
+
mapping->area = *RVAL2POPPLER_RECT(area);
|
589
|
+
mapping->annot = RVAL2POPPLER_ANNOT(annotation);
|
590
|
+
G_INITIALIZE(self, mapping);
|
591
|
+
|
592
|
+
return Qnil;
|
593
|
+
}
|
594
|
+
|
595
|
+
DEF_ACCESSOR_WITH_SETTER(annot_mapping, area,
|
596
|
+
RVAL2AM, RECT_ENTITY2RVAL, RECT_ENTITY_SET)
|
597
|
+
DEF_READER(annot_mapping, annotation, annot, RVAL2AM, POPPLER_ANNOT2RVAL)
|
598
|
+
|
599
|
+
static VALUE
|
600
|
+
annot_mapping_set_annotation(VALUE self, VALUE annotation)
|
601
|
+
{
|
602
|
+
PopplerAnnotMapping *mapping;
|
603
|
+
|
604
|
+
mapping = RVAL2AM(self);
|
605
|
+
if (mapping->annot)
|
606
|
+
g_object_unref(mapping->annot);
|
607
|
+
|
608
|
+
mapping->annot = RVAL2POPPLER_ANNOT(annotation);
|
609
|
+
return Qnil;
|
610
|
+
}
|
611
|
+
|
612
|
+
void
|
613
|
+
Init_poppler_page(VALUE mPoppler)
|
614
|
+
{
|
615
|
+
VALUE cPage, cLinkMapping;
|
616
|
+
VALUE cPageTransition, cImageMapping, cFormFieldMapping;
|
617
|
+
VALUE cAnnotationMapping;
|
618
|
+
|
619
|
+
cPage = G_DEF_CLASS(POPPLER_TYPE_PAGE, "Page", mPoppler);
|
620
|
+
cRectangle = G_DEF_CLASS(POPPLER_TYPE_RECTANGLE, "Rectangle", mPoppler);
|
621
|
+
#ifdef POPPLER_TYPE_COLOR
|
622
|
+
rb_cPopplerColor = G_DEF_CLASS(POPPLER_TYPE_COLOR, "Color", mPoppler);
|
623
|
+
#endif
|
624
|
+
cLinkMapping = G_DEF_CLASS(POPPLER_TYPE_LINK_MAPPING, "LinkMapping",
|
625
|
+
mPoppler);
|
626
|
+
cPageTransition = G_DEF_CLASS(POPPLER_TYPE_PAGE_TRANSITION,
|
627
|
+
"PageTransition", mPoppler);
|
628
|
+
cImageMapping = G_DEF_CLASS(POPPLER_TYPE_IMAGE_MAPPING,
|
629
|
+
"ImageMapping", mPoppler);
|
630
|
+
cFormFieldMapping = G_DEF_CLASS(POPPLER_TYPE_FORM_FIELD_MAPPING,
|
631
|
+
"FormFieldMapping", mPoppler);
|
632
|
+
cAnnotationMapping = G_DEF_CLASS(POPPLER_TYPE_ANNOT_MAPPING,
|
633
|
+
"AnnotationMapping", mPoppler);
|
634
|
+
cPSFile = rb_const_get(mPoppler, rb_intern("PSFile"));
|
635
|
+
|
636
|
+
rb_define_method(cPage, "render", page_render_generic, -1);
|
637
|
+
rb_define_method(cPage, "render_for_printing",
|
638
|
+
page_render_for_printing_generic, -1);
|
639
|
+
rb_define_method(cPage, "size", page_get_size, 0);
|
640
|
+
rb_define_method(cPage, "index", page_get_index, 0);
|
641
|
+
rb_define_method(cPage, "duration", page_get_duration, 0);
|
642
|
+
rb_define_method(cPage, "transition", page_get_transition, 0);
|
643
|
+
|
644
|
+
#if RB_POPPLER_CAIRO_AVAILABLE
|
645
|
+
rb_define_method(cPage, "thumbnail", page_get_thumbnail, 0);
|
646
|
+
#endif
|
647
|
+
#if POPPLER_WITH_GDK
|
648
|
+
rb_define_method(cPage, "thumbnail_pixbuf", page_get_thumbnail_pixbuf, 0);
|
649
|
+
#endif
|
650
|
+
rb_define_method(cPage, "thumbnail_size", page_get_thumbnail_size, 0);
|
651
|
+
rb_define_method(cPage, "find_text", page_find_text, 1);
|
652
|
+
rb_define_method(cPage, "get_text", page_get_text, -1);
|
653
|
+
rb_define_method(cPage, "get_selection_region",
|
654
|
+
page_get_selection_region, 3);
|
655
|
+
rb_define_method(cPage, "link_mapping", page_get_link_mapping, 0);
|
656
|
+
rb_define_method(cPage, "image_mapping", page_get_image_mapping, 0);
|
657
|
+
#if RB_POPPLER_CAIRO_AVAILABLE
|
658
|
+
rb_define_method(cPage, "get_image", page_get_image, 1);
|
659
|
+
#endif
|
660
|
+
|
661
|
+
rb_define_method(cPage, "form_field_mapping",
|
662
|
+
page_get_form_field_mapping, 0);
|
663
|
+
rb_define_method(cPage, "annotation_mapping",
|
664
|
+
page_get_annot_mapping, 0);
|
665
|
+
rb_define_method(cPage, "render_selection",
|
666
|
+
page_render_selection_generic, -1);
|
667
|
+
rb_define_method(cPage, "crop_box", page_get_crop_box, 0);
|
668
|
+
|
669
|
+
G_DEF_SETTERS(cPage);
|
670
|
+
|
671
|
+
/* A rectangle on a page, with coordinates in PDF points. */
|
672
|
+
rb_define_method(cRectangle, "initialize", rectangle_initialize, 4);
|
673
|
+
rb_define_method(cRectangle, "x1", rectangle_get_x1, 0);
|
674
|
+
rb_define_method(cRectangle, "y1", rectangle_get_y1, 0);
|
675
|
+
rb_define_method(cRectangle, "x2", rectangle_get_x2, 0);
|
676
|
+
rb_define_method(cRectangle, "y2", rectangle_get_y2, 0);
|
677
|
+
rb_define_method(cRectangle, "set_x1", rectangle_set_x1, 1);
|
678
|
+
rb_define_method(cRectangle, "set_y1", rectangle_set_y1, 1);
|
679
|
+
rb_define_method(cRectangle, "set_x2", rectangle_set_x2, 1);
|
680
|
+
rb_define_method(cRectangle, "set_y2", rectangle_set_y2, 1);
|
681
|
+
rb_define_method(cRectangle, "to_a", rectangle_to_a, 0);
|
682
|
+
rb_define_method(cRectangle, "inspect", rectangle_inspect, 0);
|
683
|
+
|
684
|
+
G_DEF_SETTERS(cRectangle);
|
685
|
+
|
686
|
+
#ifdef POPPLER_TYPE_COLOR
|
687
|
+
/* A color in RGB */
|
688
|
+
rb_define_method(rb_cPopplerColor, "initialize", color_initialize, 3);
|
689
|
+
rb_define_method(rb_cPopplerColor, "red", color_get_red, 0);
|
690
|
+
rb_define_method(rb_cPopplerColor, "green", color_get_green, 0);
|
691
|
+
rb_define_method(rb_cPopplerColor, "blue", color_get_blue, 0);
|
692
|
+
rb_define_method(rb_cPopplerColor, "set_red", color_set_red, 1);
|
693
|
+
rb_define_method(rb_cPopplerColor, "set_green", color_set_green, 1);
|
694
|
+
rb_define_method(rb_cPopplerColor, "set_blue", color_set_blue, 1);
|
695
|
+
rb_define_method(rb_cPopplerColor, "to_a", color_to_a, 0);
|
696
|
+
rb_define_method(rb_cPopplerColor, "inspect", color_inspect, 0);
|
697
|
+
|
698
|
+
G_DEF_SETTERS(rb_cPopplerColor);
|
699
|
+
#endif
|
700
|
+
|
701
|
+
/* Mapping between areas on the current page and PopplerActions */
|
702
|
+
rb_define_method(cLinkMapping, "area", link_mapping_get_area, 0);
|
703
|
+
rb_define_method(cLinkMapping, "action", link_mapping_get_action, 0);
|
704
|
+
|
705
|
+
rb_define_method(cLinkMapping, "set_area", link_mapping_set_area, 1);
|
706
|
+
rb_define_method(cLinkMapping, "set_action", link_mapping_set_action, 1);
|
707
|
+
|
708
|
+
G_DEF_SETTERS(cLinkMapping);
|
709
|
+
|
710
|
+
/* Page Transition */
|
711
|
+
rb_define_method(cPageTransition, "type", page_trans_get_type, 0);
|
712
|
+
rb_define_method(cPageTransition, "alignment", page_trans_get_alignment, 0);
|
713
|
+
rb_define_method(cPageTransition, "direction", page_trans_get_direction, 0);
|
714
|
+
rb_define_method(cPageTransition, "duration", page_trans_get_duration, 0);
|
715
|
+
rb_define_method(cPageTransition, "angle", page_trans_get_angle, 0);
|
716
|
+
rb_define_method(cPageTransition, "scale", page_trans_get_scale, 0);
|
717
|
+
rb_define_method(cPageTransition, "rectangular",
|
718
|
+
page_trans_get_rectangular, 0);
|
719
|
+
|
720
|
+
rb_define_method(cPageTransition, "set_type", page_trans_set_type, 1);
|
721
|
+
rb_define_method(cPageTransition, "set_alignment",
|
722
|
+
page_trans_set_alignment, 1);
|
723
|
+
rb_define_method(cPageTransition, "set_direction",
|
724
|
+
page_trans_set_direction, 1);
|
725
|
+
rb_define_method(cPageTransition, "set_duration",
|
726
|
+
page_trans_set_duration, 1);
|
727
|
+
rb_define_method(cPageTransition, "set_angle", page_trans_set_angle, 1);
|
728
|
+
rb_define_method(cPageTransition, "set_scale", page_trans_set_scale, 1);
|
729
|
+
rb_define_method(cPageTransition, "set_rectangular",
|
730
|
+
page_trans_set_rectangular, 1);
|
731
|
+
|
732
|
+
G_DEF_SETTERS(cPageTransition);
|
733
|
+
|
734
|
+
|
735
|
+
/* Mapping between areas on the current page and images */
|
736
|
+
rb_define_method(cImageMapping, "area", image_mapping_get_area, 0);
|
737
|
+
rb_define_method(cImageMapping, "image_id", image_mapping_get_image_id, 0);
|
738
|
+
#ifdef RB_POPPLER_CAIRO_AVAILABLE
|
739
|
+
rb_define_method(cImageMapping, "image", image_mapping_get_image, 0);
|
740
|
+
#endif
|
741
|
+
|
742
|
+
rb_define_method(cImageMapping, "set_area", image_mapping_set_area, 1);
|
743
|
+
rb_define_method(cImageMapping, "set_image_id",
|
744
|
+
image_mapping_set_image_id, 1);
|
745
|
+
|
746
|
+
G_DEF_SETTERS(cImageMapping);
|
747
|
+
|
748
|
+
|
749
|
+
/* Mapping between areas on the current page and form fields */
|
750
|
+
rb_define_method(cFormFieldMapping, "area", form_field_mapping_get_area, 0);
|
751
|
+
rb_define_method(cFormFieldMapping, "field", form_field_mapping_get_field,
|
752
|
+
0);
|
753
|
+
|
754
|
+
rb_define_method(cFormFieldMapping, "set_area",
|
755
|
+
form_field_mapping_set_area, 1);
|
756
|
+
rb_define_method(cFormFieldMapping, "set_field",
|
757
|
+
form_field_mapping_set_field, 1);
|
758
|
+
|
759
|
+
G_DEF_SETTERS(cFormFieldMapping);
|
760
|
+
|
761
|
+
rb_define_method(cAnnotationMapping, "initialize",
|
762
|
+
annot_mapping_initialize, -1);
|
763
|
+
|
764
|
+
rb_define_method(cAnnotationMapping, "area", annot_mapping_get_area, 0);
|
765
|
+
rb_define_method(cAnnotationMapping, "annotation",
|
766
|
+
annot_mapping_get_annotation, 0);
|
767
|
+
|
768
|
+
rb_define_method(cAnnotationMapping, "set_area", annot_mapping_set_area, 1);
|
769
|
+
rb_define_method(cAnnotationMapping, "set_annotation",
|
770
|
+
annot_mapping_set_annotation, 1);
|
771
|
+
|
772
|
+
G_DEF_SETTERS(cAnnotationMapping);
|
773
|
+
}
|