poppler 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,307 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /**********************************************************************
3
+
4
+ rbpoppler-annotation.c -
5
+
6
+ Copyright (C) 2008 Ruby-GNOME2 Project Team
7
+
8
+ **********************************************************************/
9
+
10
+ #include "rbpoppler-private.h"
11
+
12
+ #define SELF(self) (POPPLER_ANNOT(RVAL2GOBJ(self)))
13
+
14
+ #define TYPE2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_TYPE))
15
+ #define FLAG2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_FLAG))
16
+ #define REPLY_TYPE2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_MARKUP_REPLY_TYPE))
17
+ #define DATA_TYPE2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_EXTERNAL_DATA_TYPE))
18
+ #define TEXT_ICON2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_TEXT_ICON))
19
+ #define TEXT_STATE2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_TEXT_STATE))
20
+ #define QUADDING2RVAL(obj) (GENUM2RVAL(obj, POPPLER_TYPE_ANNOT_FREE_TEXT_QUADDING))
21
+ #define LINE2RVAL(obj) (BOXED2RVAL(obj, POPPLER_TYPE_ANNOT_CALLOUT_LINE))
22
+ #define RVAL2LINE(obj) ((PopplerAnnotCalloutLine *)RVAL2BOXED(obj, POPPLER_TYPE_ANNOT_CALLOUT_LINE))
23
+
24
+ static VALUE rb_cDate;
25
+ static ID id_new;
26
+
27
+
28
+ static VALUE
29
+ annot_get_annot_type(VALUE self)
30
+ {
31
+ return TYPE2RVAL(poppler_annot_get_annot_type(SELF(self)));
32
+ }
33
+
34
+ static VALUE
35
+ annot_get_contents(VALUE self)
36
+ {
37
+ return CSTR2RVAL_FREE(poppler_annot_get_contents(SELF(self)));
38
+ }
39
+
40
+ static VALUE
41
+ annot_get_name(VALUE self)
42
+ {
43
+ return CSTR2RVAL_FREE(poppler_annot_get_name(SELF(self)));
44
+ }
45
+
46
+ static VALUE
47
+ annot_get_modified(VALUE self)
48
+ {
49
+ return CSTR2RVAL_FREE(poppler_annot_get_modified(SELF(self)));
50
+ }
51
+
52
+ static VALUE
53
+ annot_get_flags(VALUE self)
54
+ {
55
+ return FLAG2RVAL(poppler_annot_get_flags(SELF(self)));
56
+ }
57
+
58
+ static VALUE
59
+ annot_get_color(VALUE self)
60
+ {
61
+ return POPPLER_COLOR2RVAL_FREE(poppler_annot_get_color(SELF(self)));
62
+ }
63
+
64
+ /* PopplerAnnotMarkup */
65
+ #undef SELF
66
+ #define SELF(self) (POPPLER_ANNOT_MARKUP(RVAL2GOBJ(self)))
67
+
68
+ static VALUE
69
+ annot_markup_get_label(VALUE self)
70
+ {
71
+ return CSTR2RVAL_FREE(poppler_annot_markup_get_label(SELF(self)));
72
+ }
73
+
74
+ static VALUE
75
+ annot_markup_get_popup_is_open(VALUE self)
76
+ {
77
+ return CBOOL2RVAL(poppler_annot_markup_get_popup_is_open(SELF(self)));
78
+ }
79
+
80
+ static VALUE
81
+ annot_markup_get_opacity(VALUE self)
82
+ {
83
+ return rb_float_new(poppler_annot_markup_get_opacity(SELF(self)));
84
+ }
85
+
86
+ static VALUE
87
+ annot_markup_get_date(VALUE self)
88
+ {
89
+ GDate *date;
90
+ VALUE rb_date;
91
+
92
+ date = poppler_annot_markup_get_date(SELF(self));
93
+ rb_date = rb_funcall(rb_cDate, id_new, 3,
94
+ UINT2NUM(g_date_get_year(date)),
95
+ UINT2NUM(g_date_get_month(date)),
96
+ UINT2NUM(g_date_get_day(date)));
97
+ g_date_free(date);
98
+ return rb_date;
99
+ }
100
+
101
+ static VALUE
102
+ annot_markup_get_subject(VALUE self)
103
+ {
104
+ return CSTR2RVAL_FREE(poppler_annot_markup_get_subject(SELF(self)));
105
+ }
106
+
107
+ static VALUE
108
+ annot_markup_get_reply_to(VALUE self)
109
+ {
110
+ return REPLY_TYPE2RVAL(poppler_annot_markup_get_reply_to(SELF(self)));
111
+ }
112
+
113
+ static VALUE
114
+ annot_markup_get_external_data(VALUE self)
115
+ {
116
+ return DATA_TYPE2RVAL(poppler_annot_markup_get_external_data(SELF(self)));
117
+ }
118
+
119
+ /* PopplerAnnotText */
120
+ #undef SELF
121
+ #define SELF(self) (POPPLER_ANNOT_TEXT(RVAL2GOBJ(self)))
122
+
123
+ static VALUE
124
+ annot_text_get_is_open(VALUE self)
125
+ {
126
+ return CBOOL2RVAL(poppler_annot_text_get_is_open(SELF(self)));
127
+ }
128
+
129
+ static VALUE
130
+ annot_text_get_icon(VALUE self)
131
+ {
132
+ #if POPPLER_CHECK_VERSION(0, 9, 0)
133
+ return CSTR2RVAL_FREE(poppler_annot_text_get_icon(SELF(self)));
134
+ #else
135
+ return TEXT_ICON2RVAL(poppler_annot_text_get_icon(SELF(self)));
136
+ #endif
137
+ }
138
+
139
+ static VALUE
140
+ annot_text_get_state(VALUE self)
141
+ {
142
+ return TEXT_STATE2RVAL(poppler_annot_text_get_state(SELF(self)));
143
+ }
144
+
145
+ /* PopplerAnnotFreeText */
146
+ #undef SELF
147
+ #define SELF(self) (POPPLER_ANNOT_FREE_TEXT(RVAL2GOBJ(self)))
148
+
149
+ static VALUE
150
+ annot_free_text_get_quadding(VALUE self)
151
+ {
152
+ return QUADDING2RVAL(poppler_annot_free_text_get_quadding(SELF(self)));
153
+ }
154
+
155
+ static VALUE
156
+ annot_free_text_get_callout_line(VALUE self)
157
+ {
158
+ return LINE2RVAL(poppler_annot_free_text_get_callout_line(SELF(self)));
159
+ }
160
+
161
+ /* PopplerCalloutLine */
162
+ static VALUE
163
+ annot_callout_line_initialize(VALUE self, VALUE multiline, VALUE x1, VALUE y1,
164
+ VALUE x2, VALUE y2, VALUE x3, VALUE y3)
165
+ {
166
+ PopplerAnnotCalloutLine *line;
167
+
168
+ line = poppler_annot_callout_line_new();
169
+ line->multiline = RVAL2CBOOL(multiline);
170
+ line->x1 = NUM2DBL(x1);
171
+ line->y1 = NUM2DBL(y1);
172
+ line->x2 = NUM2DBL(x2);
173
+ line->y2 = NUM2DBL(y2);
174
+ line->x3 = NUM2DBL(x3);
175
+ line->y3 = NUM2DBL(y3);
176
+
177
+ G_INITIALIZE(self, line);
178
+ return Qnil;
179
+ }
180
+
181
+ DEF_ACCESSOR(annot_callout_line, multiline, RVAL2LINE, CBOOL2RVAL, RVAL2CBOOL)
182
+ DEF_ACCESSOR(annot_callout_line, x1, RVAL2LINE, rb_float_new, NUM2DBL)
183
+ DEF_ACCESSOR(annot_callout_line, y1, RVAL2LINE, rb_float_new, NUM2DBL)
184
+ DEF_ACCESSOR(annot_callout_line, x2, RVAL2LINE, rb_float_new, NUM2DBL)
185
+ DEF_ACCESSOR(annot_callout_line, y2, RVAL2LINE, rb_float_new, NUM2DBL)
186
+ DEF_ACCESSOR(annot_callout_line, x3, RVAL2LINE, rb_float_new, NUM2DBL)
187
+ DEF_ACCESSOR(annot_callout_line, y3, RVAL2LINE, rb_float_new, NUM2DBL)
188
+
189
+ static VALUE
190
+ annot_callout_line_to_a(VALUE self)
191
+ {
192
+ PopplerAnnotCalloutLine *line;
193
+
194
+ line = RVAL2LINE(self);
195
+ return rb_ary_new3(7,
196
+ CBOOL2RVAL(line->multiline),
197
+ rb_float_new(line->x1),
198
+ rb_float_new(line->y1),
199
+ rb_float_new(line->x2),
200
+ rb_float_new(line->y2),
201
+ rb_float_new(line->x3),
202
+ rb_float_new(line->y3));
203
+ }
204
+
205
+ static VALUE
206
+ annot_callout_line_inspect(VALUE self)
207
+ {
208
+ VALUE inspected;
209
+ gchar *info;
210
+ PopplerAnnotCalloutLine *line;
211
+
212
+ line = RVAL2LINE(self);
213
+ inspected = rb_call_super(0, NULL);
214
+ rb_str_resize(inspected, RSTRING_LEN(inspected) - 1);
215
+ info = g_strdup_printf(": [%s, %g, %g, %g, %g, %g, %g]>",
216
+ line->multiline ? "true" : "false",
217
+ line->x1, line->y1,
218
+ line->x2, line->y2,
219
+ line->x3, line->y3);
220
+ rb_str_cat2(inspected, info);
221
+ g_free(info);
222
+ return inspected;
223
+ }
224
+
225
+ void
226
+ Init_poppler_annotation(VALUE mPoppler)
227
+ {
228
+ VALUE cAnnotation, cAnnotationMarkup, cAnnotationText;
229
+ VALUE cAnnotationFreeText, cAnnotationCalloutLine;
230
+
231
+ id_new = rb_intern("new");
232
+ rb_cDate = rb_const_get(rb_cObject, rb_intern("Date"));
233
+
234
+ cAnnotation = G_DEF_CLASS(POPPLER_TYPE_ANNOT, "Annotation", mPoppler);
235
+ rb_define_method(cAnnotation, "type", annot_get_annot_type, 0);
236
+ rb_define_method(cAnnotation, "contents", annot_get_contents, 0);
237
+ rb_define_method(cAnnotation, "name", annot_get_name, 0);
238
+ rb_define_method(cAnnotation, "modified", annot_get_modified, 0);
239
+ rb_define_method(cAnnotation, "flags", annot_get_flags, 0);
240
+ rb_define_method(cAnnotation, "color", annot_get_color, 0);
241
+
242
+ cAnnotationMarkup = G_DEF_CLASS(POPPLER_TYPE_ANNOT_MARKUP,
243
+ "AnnotationMarkup", mPoppler);
244
+ rb_define_method(cAnnotationMarkup, "label", annot_markup_get_label, 0);
245
+ rb_define_method(cAnnotationMarkup, "popup_is_open?",
246
+ annot_markup_get_popup_is_open, 0);
247
+ rb_define_method(cAnnotationMarkup, "opacity", annot_markup_get_opacity, 0);
248
+ rb_define_method(cAnnotationMarkup, "date", annot_markup_get_date, 0);
249
+ rb_define_method(cAnnotationMarkup, "subject", annot_markup_get_subject, 0);
250
+ rb_define_method(cAnnotationMarkup, "reply_to",
251
+ annot_markup_get_reply_to, 0);
252
+ rb_define_method(cAnnotationMarkup, "external_data",
253
+ annot_markup_get_external_data, 0);
254
+
255
+ cAnnotationText = G_DEF_CLASS(POPPLER_TYPE_ANNOT_TEXT,
256
+ "AnnotationText", mPoppler);
257
+ rb_define_method(cAnnotationText, "open?", annot_text_get_is_open, 0);
258
+ rb_define_method(cAnnotationText, "icon", annot_text_get_icon, 0);
259
+ rb_define_method(cAnnotationText, "state", annot_text_get_state, 0);
260
+
261
+ cAnnotationFreeText = G_DEF_CLASS(POPPLER_TYPE_ANNOT_FREE_TEXT,
262
+ "AnnotationFreeText", mPoppler);
263
+ rb_define_method(cAnnotationFreeText, "quadding",
264
+ annot_free_text_get_quadding, 0);
265
+ rb_define_method(cAnnotationFreeText, "callout_line",
266
+ annot_free_text_get_callout_line, 0);
267
+
268
+ cAnnotationCalloutLine = G_DEF_CLASS(POPPLER_TYPE_ANNOT_CALLOUT_LINE,
269
+ "AnnotationCalloutLine", mPoppler);
270
+ rb_define_method(cAnnotationCalloutLine, "initialize",
271
+ annot_callout_line_initialize, 7);
272
+
273
+ rb_define_method(cAnnotationCalloutLine, "multiline?",
274
+ annot_callout_line_get_multiline, 0);
275
+ rb_define_method(cAnnotationCalloutLine, "set_multiline",
276
+ annot_callout_line_set_multiline, 1);
277
+ rb_define_method(cAnnotationCalloutLine, "x1",
278
+ annot_callout_line_get_x1, 0);
279
+ rb_define_method(cAnnotationCalloutLine, "set_x1",
280
+ annot_callout_line_set_x1, 1);
281
+ rb_define_method(cAnnotationCalloutLine, "y1",
282
+ annot_callout_line_get_y1, 0);
283
+ rb_define_method(cAnnotationCalloutLine, "set_y1",
284
+ annot_callout_line_set_y1, 1);
285
+ rb_define_method(cAnnotationCalloutLine, "x2",
286
+ annot_callout_line_get_x2, 0);
287
+ rb_define_method(cAnnotationCalloutLine, "set_x2",
288
+ annot_callout_line_set_x2, 2);
289
+ rb_define_method(cAnnotationCalloutLine, "y2",
290
+ annot_callout_line_get_y2, 0);
291
+ rb_define_method(cAnnotationCalloutLine, "set_y2",
292
+ annot_callout_line_set_y2, 2);
293
+ rb_define_method(cAnnotationCalloutLine, "x3",
294
+ annot_callout_line_get_x3, 0);
295
+ rb_define_method(cAnnotationCalloutLine, "set_x3",
296
+ annot_callout_line_set_x3, 3);
297
+ rb_define_method(cAnnotationCalloutLine, "y3",
298
+ annot_callout_line_get_y3, 0);
299
+ rb_define_method(cAnnotationCalloutLine, "set_y3",
300
+ annot_callout_line_set_y3, 3);
301
+
302
+ rb_define_method(cAnnotationCalloutLine, "to_a", annot_callout_line_to_a, 0);
303
+ rb_define_method(cAnnotationCalloutLine, "inspect",
304
+ annot_callout_line_inspect, 0);
305
+
306
+ G_DEF_SETTERS(cAnnotationCalloutLine);
307
+ }
@@ -0,0 +1,116 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbpoppler-attachment.c -
5
+
6
+ $Author: ktou $
7
+ $Date: 2007/10/13 05:53:10 $
8
+
9
+ Copyright (C) 2006 Ruby-GNOME2 Project Team
10
+
11
+ **********************************************************************/
12
+
13
+ #include "rbpoppler.h"
14
+
15
+ #define SELF(self) ((PopplerAttachment *)RVAL2GOBJ(self))
16
+
17
+ static ID id_call;
18
+
19
+ static gboolean
20
+ attachment_save_func(const gchar *buf, gsize count, gpointer data,
21
+ GError **error)
22
+ {
23
+ VALUE result;
24
+ VALUE callback = (VALUE)data;
25
+
26
+ result = rb_funcall(callback, id_call, 1, rb_str_new(buf, count));
27
+ return RVAL2CBOOL(result);
28
+ }
29
+
30
+ static VALUE
31
+ attachment_save(int argc, VALUE *argv, VALUE self)
32
+ {
33
+ VALUE filename;
34
+ gboolean result;
35
+ GError *error = NULL;
36
+
37
+ rb_scan_args(argc, argv, "01", &filename);
38
+
39
+ if (NIL_P(filename)) {
40
+ if (rb_block_given_p()) {
41
+ gpointer user_data = (gpointer)rb_block_proc();
42
+ result = poppler_attachment_save_to_callback(SELF(self),
43
+ attachment_save_func,
44
+ user_data,
45
+ &error);
46
+ } else {
47
+ rb_raise(rb_eArgError, "must provide filename or block");
48
+ }
49
+ } else {
50
+ result = poppler_attachment_save(SELF(self), RVAL2CSTR(filename),
51
+ &error);
52
+ }
53
+
54
+ if (error)
55
+ RAISE_GERROR(error);
56
+
57
+ return CBOOL2RVAL(result);
58
+ }
59
+
60
+ static VALUE
61
+ attachment_get_name(VALUE self)
62
+ {
63
+ return CSTR2RVAL(SELF(self)->name);
64
+ }
65
+
66
+ static VALUE
67
+ attachment_get_description(VALUE self)
68
+ {
69
+ return CSTR2RVAL(SELF(self)->description);
70
+ }
71
+
72
+ static VALUE
73
+ attachment_get_size(VALUE self)
74
+ {
75
+ return INT2NUM(SELF(self)->size);
76
+ }
77
+
78
+ static VALUE
79
+ attachment_get_mtime(VALUE self)
80
+ {
81
+ return rb_time_new(SELF(self)->mtime, 0);
82
+ }
83
+
84
+ static VALUE
85
+ attachment_get_ctime(VALUE self)
86
+ {
87
+ return rb_time_new(SELF(self)->ctime, 0);
88
+ }
89
+
90
+ static VALUE
91
+ attachment_get_checksum(VALUE self)
92
+ {
93
+ GString *checksum;
94
+ checksum = SELF(self)->checksum;
95
+ return rb_str_new(checksum->str, checksum->len);
96
+ }
97
+
98
+ void
99
+ Init_poppler_attachment(VALUE mPoppler)
100
+ {
101
+ VALUE cAttachment;
102
+
103
+ id_call = rb_intern("call");
104
+
105
+ cAttachment = G_DEF_CLASS(POPPLER_TYPE_ATTACHMENT, "Attachment", mPoppler);
106
+
107
+ rb_define_method(cAttachment, "save", attachment_save, -1);
108
+ rb_define_method(cAttachment, "name", attachment_get_name, 0);
109
+ rb_define_method(cAttachment, "description", attachment_get_description, 0);
110
+ rb_define_method(cAttachment, "size", attachment_get_size, 0);
111
+ rb_define_method(cAttachment, "mtime", attachment_get_mtime, 0);
112
+ rb_define_method(cAttachment, "ctime", attachment_get_ctime, 0);
113
+ rb_define_method(cAttachment, "checksum", attachment_get_checksum, 0);
114
+
115
+ G_DEF_SETTERS(cAttachment);
116
+ }
@@ -0,0 +1,492 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /**********************************************************************
3
+
4
+ rbpoppler-document.c -
5
+
6
+ $Author: ktou $
7
+ $Date: 2007/10/13 05:56:39 $
8
+
9
+ Copyright (C) 2006 Ruby-GNOME2 Project Team
10
+
11
+ **********************************************************************/
12
+
13
+ #include "rbpoppler.h"
14
+
15
+ #define RVAL2DOC(obj) (POPPLER_DOCUMENT(RVAL2GOBJ(obj)))
16
+
17
+ #define IITER2RVAL(obj) (BOXED2RVAL(obj, POPPLER_TYPE_INDEX_ITER))
18
+ #define RVAL2IITER(obj) (RVAL2BOXED(obj, POPPLER_TYPE_INDEX_ITER))
19
+ #define FITER2RVAL(obj) (BOXED2RVAL(obj, POPPLER_TYPE_FONTS_ITER))
20
+ #define RVAL2FITER(obj) (RVAL2BOXED(obj, POPPLER_TYPE_FONTS_ITER))
21
+
22
+ static ID id_new, id_valid, id_pdf_data_p, id_ensure_uri;
23
+ static VALUE cIndexIter;
24
+ static VALUE cFontInfo;
25
+
26
+
27
+ static VALUE
28
+ doc_initialize(int argc, VALUE *argv, VALUE self)
29
+ {
30
+ PopplerDocument *document = NULL;
31
+ GError *error = NULL;
32
+ VALUE uri_or_data, rb_password;
33
+ const char *password;
34
+
35
+ rb_scan_args(argc, argv, "11", &uri_or_data, &rb_password);
36
+
37
+ password = NIL_P(rb_password) ? NULL : RVAL2CSTR(rb_password);
38
+
39
+ if (RVAL2CBOOL(rb_funcall(self, id_pdf_data_p, 1, uri_or_data))) {
40
+ document = poppler_document_new_from_data(RSTRING_PTR(uri_or_data),
41
+ RSTRING_LEN(uri_or_data),
42
+ password, &error);
43
+ }
44
+
45
+ if (!document && !error) {
46
+ uri_or_data = rb_funcall(self, id_ensure_uri, 1, uri_or_data);
47
+ document = poppler_document_new_from_file(RVAL2CSTR(uri_or_data),
48
+ password, &error);
49
+ }
50
+
51
+ if (error)
52
+ RAISE_GERROR(error);
53
+
54
+ G_INITIALIZE(self, document);
55
+ return Qnil;
56
+ }
57
+
58
+ static VALUE
59
+ doc_save(VALUE self, VALUE uri)
60
+ {
61
+ gboolean result;
62
+ GError *error = NULL;
63
+
64
+ uri = rb_funcall(self, id_ensure_uri, 1, uri);
65
+ result = poppler_document_save(RVAL2DOC(self), RVAL2CSTR(uri), &error);
66
+
67
+ if (error)
68
+ RAISE_GERROR(error);
69
+
70
+ return CBOOL2RVAL(result);
71
+ }
72
+
73
+ static VALUE
74
+ doc_save_a_copy(VALUE self, VALUE uri)
75
+ {
76
+ gboolean result;
77
+ GError *error = NULL;
78
+
79
+ uri = rb_funcall(self, id_ensure_uri, 1, uri);
80
+ result = poppler_document_save_a_copy(RVAL2DOC(self), RVAL2CSTR(uri),
81
+ &error);
82
+
83
+ if (error)
84
+ RAISE_GERROR(error);
85
+
86
+ return CBOOL2RVAL(result);
87
+ }
88
+
89
+ static VALUE
90
+ doc_get_n_pages(VALUE self)
91
+ {
92
+ return INT2NUM(poppler_document_get_n_pages(RVAL2DOC(self)));
93
+ }
94
+
95
+ static VALUE
96
+ doc_get_page(VALUE self, VALUE index_or_label)
97
+ {
98
+ VALUE rb_page;
99
+ PopplerPage *page;
100
+
101
+ if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_label, rb_cInteger))) {
102
+ page = poppler_document_get_page(RVAL2DOC(self),
103
+ NUM2INT(index_or_label));
104
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(index_or_label, rb_cString))) {
105
+ page = poppler_document_get_page_by_label(RVAL2DOC(self),
106
+ RVAL2CSTR(index_or_label));
107
+ } else {
108
+ VALUE inspect;
109
+ inspect = rb_inspect(index_or_label);
110
+ rb_raise(rb_eArgError, "%s must be Integer or String",
111
+ RVAL2CSTR(inspect));
112
+ }
113
+
114
+ rb_page = GOBJ2RVAL(page);
115
+ if (page)
116
+ g_object_unref(page);
117
+ return rb_page;
118
+ }
119
+
120
+ static VALUE
121
+ doc_has_attachments(VALUE self)
122
+ {
123
+ return CBOOL2RVAL(poppler_document_has_attachments(RVAL2DOC(self)));
124
+ }
125
+
126
+ static VALUE
127
+ doc_get_attachments(VALUE self)
128
+ {
129
+ return GLIST2ARYF(poppler_document_get_attachments(RVAL2DOC(self)));
130
+ }
131
+
132
+ static VALUE
133
+ doc_find_dest(VALUE self, VALUE link_name)
134
+ {
135
+ return GOBJ2RVAL(poppler_document_find_dest(RVAL2DOC(self),
136
+ RVAL2CSTR(link_name)));
137
+ }
138
+
139
+ static VALUE
140
+ doc_get_form_field(VALUE self, VALUE id)
141
+ {
142
+ return GOBJ2RVAL(poppler_document_get_form_field(RVAL2DOC(self),
143
+ NUM2INT(id)));
144
+ }
145
+
146
+ static VALUE
147
+ doc_each(VALUE self)
148
+ {
149
+ PopplerDocument *document;
150
+ int i, n_pages;
151
+
152
+ document = RVAL2DOC(self);
153
+ n_pages = poppler_document_get_n_pages(document);
154
+ for (i = 0; i < n_pages; i++) {
155
+ PopplerPage *page;
156
+ VALUE rb_page;
157
+
158
+ page = poppler_document_get_page(document, i);
159
+ rb_page = GOBJ2RVAL(page);
160
+ if (page)
161
+ g_object_unref(page);
162
+ rb_yield(rb_page);
163
+ }
164
+ return self;
165
+ }
166
+
167
+ static VALUE
168
+ doc_get_index_iter(VALUE self)
169
+ {
170
+ return rb_funcall(cIndexIter, id_new, 1, self);
171
+ }
172
+
173
+ static VALUE
174
+ doc_get_font_info(VALUE self)
175
+ {
176
+ return rb_funcall(cFontInfo, id_new, 1, self);
177
+ }
178
+
179
+
180
+
181
+ /* Interface for getting the Index of a poppler_document */
182
+ #define CHECK_IITER_IS_VALID(iter) do { \
183
+ if (!RVAL2CBOOL(index_iter_valid_p(iter))) \
184
+ return Qnil; \
185
+ } while (0)
186
+
187
+ static VALUE
188
+ index_iter_valid_p(VALUE self)
189
+ {
190
+ return rb_ivar_get(self, id_valid);
191
+ }
192
+
193
+ static VALUE
194
+ index_iter_initialize(VALUE self, VALUE document)
195
+ {
196
+ PopplerIndexIter *iter;
197
+ iter = poppler_index_iter_new(RVAL2GOBJ(document));
198
+ G_INITIALIZE(self, iter);
199
+ poppler_index_iter_free(iter);
200
+ rb_ivar_set(self, id_valid, CBOOL2RVAL(iter));
201
+ return Qnil;
202
+ }
203
+
204
+ static VALUE
205
+ index_iter_get_child(VALUE self)
206
+ {
207
+ PopplerIndexIter *child;
208
+ VALUE rb_child;
209
+
210
+ CHECK_IITER_IS_VALID(self);
211
+ child = poppler_index_iter_get_child(RVAL2IITER(self));
212
+ rb_child = IITER2RVAL(child);
213
+ poppler_index_iter_free(child);
214
+ return rb_child;
215
+ }
216
+
217
+ static VALUE
218
+ index_iter_is_open(VALUE self)
219
+ {
220
+ CHECK_IITER_IS_VALID(self);
221
+ return CBOOL2RVAL(poppler_index_iter_is_open(RVAL2IITER(self)));
222
+ }
223
+
224
+ #ifndef HAVE_TYPE_POPPLERACTIONANY
225
+ static VALUE
226
+ index_iter_get_action(VALUE self)
227
+ {
228
+ CHECK_IITER_IS_VALID(self);
229
+ return POPPLER_ACTION2RVAL(poppler_index_iter_get_action(RVAL2IITER(self)));
230
+ }
231
+ #endif
232
+
233
+ static VALUE
234
+ index_iter_next(VALUE self)
235
+ {
236
+ if (poppler_index_iter_next(RVAL2IITER(self))) {
237
+ return Qtrue;
238
+ } else {
239
+ rb_ivar_set(self, id_valid, Qfalse);
240
+ return Qfalse;
241
+ }
242
+ }
243
+
244
+ static VALUE
245
+ index_iter_each(VALUE self)
246
+ {
247
+ PopplerIndexIter *iter;
248
+
249
+ CHECK_IITER_IS_VALID(self);
250
+ iter = RVAL2IITER(self);
251
+ do {
252
+ rb_yield(self);
253
+ } while (poppler_index_iter_next(iter));
254
+ rb_ivar_set(self, id_valid, Qfalse);
255
+
256
+ return self;
257
+ }
258
+
259
+
260
+ #if POPPLER_CHECK_VERSION(0, 6, 0)
261
+
262
+ static VALUE
263
+ font_info_initialize(VALUE self, VALUE document)
264
+ {
265
+ G_INITIALIZE(self, poppler_font_info_new(RVAL2GOBJ(document)));
266
+ return Qnil;
267
+ }
268
+
269
+ static VALUE
270
+ font_info_scan(VALUE self, VALUE n_pages)
271
+ {
272
+ VALUE rb_iter = Qnil;
273
+ PopplerFontsIter *iter;
274
+
275
+ if (poppler_font_info_scan(RVAL2GOBJ(self), NUM2INT(n_pages), &iter)) {
276
+ rb_iter = FITER2RVAL(iter);
277
+ rb_ivar_set(rb_iter, id_valid, Qtrue);
278
+ poppler_fonts_iter_free(iter);
279
+ }
280
+ return rb_iter;
281
+ }
282
+ #endif
283
+
284
+
285
+ #define CHECK_FITER_IS_VALID(iter) do { \
286
+ if (!RVAL2CBOOL(fonts_iter_valid_p(iter))) \
287
+ return Qnil; \
288
+ } while (0)
289
+
290
+ static VALUE
291
+ fonts_iter_valid_p(VALUE self)
292
+ {
293
+ return rb_ivar_get(self, id_valid);
294
+ }
295
+
296
+ static VALUE
297
+ fonts_iter_get_name(VALUE self)
298
+ {
299
+ CHECK_FITER_IS_VALID(self);
300
+ return CSTR2RVAL(poppler_fonts_iter_get_name(RVAL2FITER(self)));
301
+ }
302
+
303
+ static VALUE
304
+ fonts_iter_get_full_name(VALUE self)
305
+ {
306
+ CHECK_FITER_IS_VALID(self);
307
+ return CSTR2RVAL(poppler_fonts_iter_get_full_name(RVAL2FITER(self)));
308
+ }
309
+
310
+ static VALUE
311
+ fonts_iter_get_file_name(VALUE self)
312
+ {
313
+ CHECK_FITER_IS_VALID(self);
314
+ return CSTR2RVAL(poppler_fonts_iter_get_file_name(RVAL2FITER(self)));
315
+ }
316
+
317
+ static VALUE
318
+ fonts_iter_get_font_type(VALUE self)
319
+ {
320
+ CHECK_FITER_IS_VALID(self);
321
+ return GENUM2RVAL(poppler_fonts_iter_get_font_type(RVAL2FITER(self)),
322
+ POPPLER_TYPE_FONT_TYPE);
323
+ }
324
+
325
+ static VALUE
326
+ fonts_iter_is_embedded(VALUE self)
327
+ {
328
+ CHECK_FITER_IS_VALID(self);
329
+ return CBOOL2RVAL(poppler_fonts_iter_is_embedded(RVAL2FITER(self)));
330
+ }
331
+
332
+ static VALUE
333
+ fonts_iter_is_subset(VALUE self)
334
+ {
335
+ CHECK_FITER_IS_VALID(self);
336
+ return CBOOL2RVAL(poppler_fonts_iter_is_subset(RVAL2FITER(self)));
337
+ }
338
+
339
+ static VALUE
340
+ fonts_iter_next(VALUE self)
341
+ {
342
+ if (poppler_fonts_iter_next(RVAL2FITER(self))) {
343
+ return Qtrue;
344
+ } else {
345
+ rb_ivar_set(self, id_valid, Qfalse);
346
+ return Qfalse;
347
+ }
348
+ }
349
+
350
+ static VALUE
351
+ fonts_iter_each(VALUE self)
352
+ {
353
+ PopplerFontsIter *iter;
354
+
355
+ CHECK_FITER_IS_VALID(self);
356
+ iter = RVAL2FITER(self);
357
+ do {
358
+ rb_yield(self);
359
+ } while (poppler_fonts_iter_next(iter));
360
+ rb_ivar_set(self, id_valid, Qfalse);
361
+
362
+ return self;
363
+ }
364
+
365
+
366
+ /* Export to ps */
367
+ static VALUE
368
+ ps_file_initialize(VALUE self, VALUE document, VALUE filename,
369
+ VALUE first_page, VALUE n_pages)
370
+ {
371
+ PopplerPSFile *ps_file;
372
+
373
+ ps_file = poppler_ps_file_new(RVAL2GOBJ(document), RVAL2CSTR(filename),
374
+ NUM2INT(first_page), NUM2INT(n_pages));
375
+
376
+ if (!ps_file)
377
+ rb_raise(rb_eRuntimeError, "can't create Poppler::PSFile");
378
+
379
+ G_INITIALIZE(self, ps_file);
380
+ return Qnil;
381
+ }
382
+
383
+ static VALUE
384
+ ps_file_set_paper_size(VALUE self, VALUE width, VALUE height)
385
+ {
386
+ poppler_ps_file_set_paper_size(RVAL2GOBJ(self),
387
+ NUM2DBL(width), NUM2DBL(height));
388
+ return Qnil;
389
+ }
390
+
391
+ static VALUE
392
+ ps_file_set_duplex(VALUE self, VALUE duplex)
393
+ {
394
+ poppler_ps_file_set_duplex(RVAL2GOBJ(self), RVAL2CBOOL(duplex));
395
+ return Qnil;
396
+ }
397
+
398
+ void
399
+ Init_poppler_document(VALUE mPoppler)
400
+ {
401
+ VALUE cDocument, cFontsIter, cPSFile;
402
+
403
+ id_new = rb_intern("new");
404
+ id_valid = rb_intern("valid?");
405
+ id_pdf_data_p = rb_intern("pdf_data?");
406
+ id_ensure_uri = rb_intern("ensure_uri");
407
+
408
+ cDocument = G_DEF_CLASS(POPPLER_TYPE_DOCUMENT, "Document", mPoppler);
409
+ cIndexIter = G_DEF_CLASS(POPPLER_TYPE_INDEX_ITER, "IndexIter", mPoppler);
410
+ cFontInfo = G_DEF_CLASS(POPPLER_TYPE_FONT_INFO, "FontInfo", mPoppler);
411
+ cFontsIter = G_DEF_CLASS(POPPLER_TYPE_FONTS_ITER, "FontsIter", mPoppler);
412
+ cPSFile = G_DEF_CLASS(POPPLER_TYPE_PS_FILE, "PSFile", mPoppler);
413
+
414
+ G_DEF_CLASS(POPPLER_TYPE_PAGE_LAYOUT, "PageLayout", mPoppler);
415
+ G_DEF_CLASS(POPPLER_TYPE_PAGE_MODE, "PageMode", mPoppler);
416
+ G_DEF_CLASS(POPPLER_TYPE_FONT_TYPE, "FontType", mPoppler);
417
+ G_DEF_CLASS(POPPLER_TYPE_VIEWER_PREFERENCES, "ViewerPreferences", mPoppler);
418
+ G_DEF_CLASS(POPPLER_TYPE_PERMISSIONS, "Permissions", mPoppler);
419
+
420
+ rb_include_module(cDocument, rb_mEnumerable);
421
+
422
+ rb_define_method(cDocument, "initialize", doc_initialize, -1);
423
+ rb_define_method(cDocument, "save", doc_save, 1);
424
+ rb_define_method(cDocument, "save_a_copy", doc_save_a_copy, 1);
425
+ rb_define_method(cDocument, "n_pages", doc_get_n_pages, 0);
426
+ rb_define_alias(cDocument, "size", "n_pages");
427
+ rb_define_method(cDocument, "get_page", doc_get_page, 1);
428
+ rb_define_alias(cDocument, "[]", "get_page");
429
+ rb_define_method(cDocument, "has_attachments?", doc_has_attachments, 0);
430
+ rb_define_alias(cDocument, "have_attachments?", "has_attachments?");
431
+ rb_define_method(cDocument, "attachments", doc_get_attachments, 0);
432
+ rb_define_method(cDocument, "find_dest", doc_find_dest, 1);
433
+ rb_define_alias(cDocument, "get_destination", "find_dest");
434
+
435
+ rb_define_method(cDocument, "get_form_field", doc_get_form_field, 1);
436
+
437
+ rb_define_method(cDocument, "each", doc_each, 0);
438
+ rb_define_alias(cDocument, "pages", "to_a");
439
+
440
+ rb_define_method(cDocument, "index_iter", doc_get_index_iter, 0);
441
+ rb_define_method(cDocument, "font_info", doc_get_font_info, 0);
442
+
443
+ G_DEF_SETTERS(cDocument);
444
+
445
+
446
+ /* Interface for getting the Index of a poppler_document */
447
+ rb_include_module(cIndexIter, rb_mEnumerable);
448
+
449
+ rb_define_method(cIndexIter, "initialize", index_iter_initialize, 1);
450
+ rb_define_method(cIndexIter, "child", index_iter_get_child, 0);
451
+ rb_define_method(cIndexIter, "open?", index_iter_is_open, 0);
452
+ #ifndef HAVE_TYPE_POPPLERACTIONANY
453
+ rb_define_method(cIndexIter, "action", index_iter_get_action, 0);
454
+ #endif
455
+ rb_define_method(cIndexIter, "next", index_iter_next, 0);
456
+
457
+ rb_define_method(cIndexIter, "valid?", index_iter_valid_p, 0);
458
+ rb_define_method(cIndexIter, "each", index_iter_each, 0);
459
+
460
+ G_DEF_SETTERS(cIndexIter);
461
+
462
+
463
+ #if POPPLER_CHECK_VERSION(0, 6, 0)
464
+ rb_define_method(cFontInfo, "initialize", font_info_initialize, 1);
465
+ rb_define_method(cFontInfo, "scan", font_info_scan, 1);
466
+ G_DEF_SETTERS(cFontInfo);
467
+ #endif
468
+
469
+ rb_include_module(cFontsIter, rb_mEnumerable);
470
+
471
+ rb_define_method(cFontsIter, "name", fonts_iter_get_name, 0);
472
+ rb_define_method(cFontsIter, "full_name", fonts_iter_get_full_name, 0);
473
+ #if POPPLER_CHECK_VERSION(0, 6, 0)
474
+ rb_define_method(cFontsIter, "file_name", fonts_iter_get_file_name, 0);
475
+ #endif
476
+ rb_define_method(cFontsIter, "font_type", fonts_iter_get_font_type, 0);
477
+ rb_define_method(cFontsIter, "embedded?", fonts_iter_is_embedded, 0);
478
+ rb_define_method(cFontsIter, "subset?", fonts_iter_is_subset, 0);
479
+ rb_define_method(cFontsIter, "next", fonts_iter_next, 0);
480
+
481
+ rb_define_method(cFontsIter, "valid?", fonts_iter_valid_p, 0);
482
+ rb_define_method(cFontsIter, "each", fonts_iter_each, 0);
483
+
484
+ G_DEF_SETTERS(cFontsIter);
485
+
486
+ /* Export to ps */
487
+ rb_define_method(cPSFile, "initialize", ps_file_initialize, 4);
488
+ rb_define_method(cPSFile, "set_paper_size", ps_file_set_paper_size, 2);
489
+ rb_define_method(cPSFile, "set_duplex", ps_file_set_duplex, 1);
490
+
491
+ G_DEF_SETTERS(cPSFile);
492
+ }