pdflib_mini 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +160 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/pdflib_mini.rb +38 -0
  13. data/lib/pdflib_mini/handle.rb +4 -0
  14. data/lib/pdflib_mini/handle/action.rb +10 -0
  15. data/lib/pdflib_mini/handle/asset.rb +10 -0
  16. data/lib/pdflib_mini/handle/base.rb +16 -0
  17. data/lib/pdflib_mini/handle/bookmark.rb +10 -0
  18. data/lib/pdflib_mini/handle/color.rb +10 -0
  19. data/lib/pdflib_mini/handle/data3d.rb +10 -0
  20. data/lib/pdflib_mini/handle/data3d_view.rb +10 -0
  21. data/lib/pdflib_mini/handle/folder.rb +22 -0
  22. data/lib/pdflib_mini/handle/font.rb +42 -0
  23. data/lib/pdflib_mini/handle/graphics.rb +39 -0
  24. data/lib/pdflib_mini/handle/graphics_state.rb +16 -0
  25. data/lib/pdflib_mini/handle/image.rb +39 -0
  26. data/lib/pdflib_mini/handle/item.rb +22 -0
  27. data/lib/pdflib_mini/handle/layer.rb +17 -0
  28. data/lib/pdflib_mini/handle/path.rb +45 -0
  29. data/lib/pdflib_mini/handle/pattern.rb +16 -0
  30. data/lib/pdflib_mini/handle/pdf.rb +6 -0
  31. data/lib/pdflib_mini/handle/pdf/document.rb +51 -0
  32. data/lib/pdflib_mini/handle/pdf/page.rb +72 -0
  33. data/lib/pdflib_mini/handle/profile.rb +10 -0
  34. data/lib/pdflib_mini/handle/shading.rb +16 -0
  35. data/lib/pdflib_mini/handle/table_cell.rb +39 -0
  36. data/lib/pdflib_mini/handle/template.rb +16 -0
  37. data/lib/pdflib_mini/handle/textflow.rb +42 -0
  38. data/lib/pdflib_mini/handle/textline.rb +33 -0
  39. data/lib/pdflib_mini/info.rb +237 -0
  40. data/lib/pdflib_mini/info_reader.rb +54 -0
  41. data/lib/pdflib_mini/pdflib.rb +457 -0
  42. data/lib/pdflib_mini/version.rb +3 -0
  43. data/pdflib_mini.gemspec +28 -0
  44. metadata +142 -0
@@ -0,0 +1,16 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Template < Base
4
+ def initialize(template, p)
5
+ super(template)
6
+ @p = p
7
+ end
8
+
9
+ # 9.3 Templates
10
+ # end_template_ext(float width, float height)
11
+ def end_template_ext(*args)
12
+ @p.end_template_ext(*args)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Textflow < Base
4
+ include PdflibMini::InfoReader
5
+
6
+ INFO_KEYWORD = PdflibMini::Info::INFO_KEYWORD_TABLE_5_14
7
+
8
+ INFO_KEYWORD.each do |keyword, type|
9
+ info_reader(:info_textflow, keyword, type)
10
+ end
11
+
12
+ def initialize(textflow, p)
13
+ super(textflow)
14
+ @p = p
15
+ end
16
+
17
+ # 5.2 Multi-Line Text with Textflows
18
+ # int add_textflow(int textflow, string text, string optlist)
19
+ def add_textflow(*args)
20
+ @p.add_textflow(self, *args)
21
+ end
22
+
23
+ # 5.2 Multi-Line Text with Textflows
24
+ # string fit_textflow(int textflow, float llx, float lly, float urx, float ury, string optlist)
25
+ def fit_textflow(*args)
26
+ @p.fit_textflow(self, *args)
27
+ end
28
+
29
+ # 5.2 Multi-Line Text with Textflows
30
+ # float info_textflow(int textflow, string keyword)
31
+ def info_textflow(keyword, _)
32
+ @p.info_textflow(self, keyword)
33
+ end
34
+
35
+ # 5.2 Multi-Line Text with Textflow
36
+ # delete_textflow(int textflow)
37
+ def delete_textflow
38
+ @p.delete_textflow(self)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ module PdflibMini
2
+ module Handle
3
+ class Textline < Base
4
+ include PdflibMini::InfoReader
5
+
6
+ INFO_KEYWORD = [
7
+ PdflibMini::Info::INFO_KEYWORD_TABLE_5_5,
8
+ PdflibMini::Info::INFO_KEYWORD_TABLE_6_3,
9
+ ].reduce([], :+)
10
+
11
+ INFO_KEYWORD.each do |keyword, type|
12
+ info_reader(:info_textline, keyword, type)
13
+ end
14
+
15
+ def initialize(text, p)
16
+ super(text)
17
+ @p = p
18
+ end
19
+
20
+ # 5.1 Single-Line Text with Textlines
21
+ # fit_textline(string text, float x, float y, string optlist)
22
+ def fit_textline(*args)
23
+ @p.fit_textline(self, *args)
24
+ end
25
+
26
+ # 5.1 Single-Line Text with Textlines
27
+ # float info_textline(string text, string keyword, string optlist)
28
+ def info_textline(*args)
29
+ @p.info_textline(self, *args)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,237 @@
1
+ module PdflibMini
2
+ module Info
3
+ # 4.1 Font Handling
4
+ # Table4.5 Keywords and options for PDF_info_font()
5
+ INFO_KEYWORD_TABLE_4_5 = [
6
+ ['ascender', :raw],
7
+ ['capheight', :raw],
8
+ ['cid', :raw],
9
+ ['cidfont', :boolean],
10
+ ['code', :raw],
11
+ ['codepage', :raw], # TODO three-valued logic
12
+ ['codepagelist', :raw],
13
+ ['checkcolorspace', :boolean],
14
+ ['descender', :raw],
15
+ ['encoding', :string],
16
+ ['fallbackfont', :font],
17
+ ['familyname', :string],
18
+ ['feature', :raw], # TODO three-valued logic
19
+ ['featurelist', :string],
20
+ ['fontfile', :string],
21
+ ['fontname', :string],
22
+ ['fontstyle', :string],
23
+ ['fonttype', :string],
24
+ ['glyphid', :raw],
25
+ ['glyphname', :string],
26
+ ['hostfont', :boolean],
27
+ ['italicangle', :raw],
28
+ ['keepnative', :raw],
29
+ ['kerningpairs', :raw],
30
+ ['linegap', :raw],
31
+ ['maingid', :raw],
32
+ ['maxcode', :raw],
33
+ ['metricsfile', :string],
34
+ ['maxuvsunicode', :raw],
35
+ ['minuvsunicode', :raw],
36
+ ['monospace', :raw], # Deprecated
37
+ ['numcids', :raw],
38
+ ['numglyphs', :raw],
39
+ ['numusableglyphs', :raw],
40
+ ['numusedglyphs', :raw],
41
+ ['outlineformat', :string],
42
+ ['predefcmap', :string],
43
+ ['replacementchar', :raw],
44
+ ['selector', :raw],
45
+ ['selectorlist', :string],
46
+ ['shapingsupport', :boolean],
47
+ ['singfont', :boolean],
48
+ ['standardfont', :boolean],
49
+ ['supplement', :raw],
50
+ ['symbolfont', :boolean],
51
+ ['unicode', :raw],
52
+ ['unicodefont', :raw],
53
+ ['unmappedglyphs', :raw],
54
+ ['usedglyph', :boolean],
55
+ ['vertical', :raw],
56
+ ['weight', :raw],
57
+ ['willembed', :boolean],
58
+ ['willsubset', :boolean],
59
+ ['xheight', :raw],
60
+ ]
61
+
62
+ # 5.1 Single-Line Text with Textlines
63
+ # Table 5.5 Keywords for PDF_info_textline()
64
+ INFO_KEYWORD_TABLE_5_5 = [
65
+ ['angle', :raw],
66
+ ['ascender', :raw],
67
+ ['capheight', :raw],
68
+ ['descender', :raw],
69
+ ['endx', :raw],
70
+ ['endy', :raw],
71
+ ['pathlength', :raw],
72
+ ['perpendiculardirx', :raw],
73
+ ['perpendiculardiry', :raw],
74
+ ['replacedchars', :raw],
75
+ ['righttoleft', :raw],
76
+ ['scalex', :raw], # Deprecated, use fitscalex
77
+ ['scaley', :raw], # Deprecated, use fitscaley
78
+ ['scriptlist', :raw],
79
+ ['startx', :raw],
80
+ ['starty', :raw],
81
+ ['textwidth', :raw],
82
+ ['textheight', :raw],
83
+ ['unknownchars', :raw],
84
+ ['unmappedchars', :raw],
85
+ ['wellformed', :boolean],
86
+ ['writingdirx', :raw],
87
+ ['writingdiry', :raw],
88
+ ['xheight', :raw],
89
+ ]
90
+
91
+ # 5.2 Multi-Line Text with Textflows
92
+ # Table 5.14 Keywords for PDF_info_textflow()
93
+ INFO_KEYWORD_TABLE_5_14 = [
94
+ ['boundingbox', :raw],
95
+ ['boxlinecount', :raw],
96
+ ['firstparalinecount', :raw],
97
+ ['firstlinedist', :raw],
98
+ ['fittext', :string],
99
+ ['fontscale', :raw],
100
+ ['lastfont', :font],
101
+ ['lastfontsize', :raw],
102
+ ['lastmark', :raw],
103
+ ['lastlinedist', :raw],
104
+ ['lastparalinecount', :raw],
105
+ ['leading', :raw],
106
+ ['leftlinex', :raw],
107
+ ['leftliney', :raw],
108
+ ['maxlinelength', :raw],
109
+ ['maxliney', :raw],
110
+ ['minlinelength', :raw],
111
+ ['minliney', :raw],
112
+ ['returnreason', :string],
113
+ ['rightlinex', :raw],
114
+ ['rightliney', :raw],
115
+ ['split', :boolean],
116
+ ['textendx', :raw],
117
+ ['textendy', :raw],
118
+ ['textheight', :raw],
119
+ ['textwidth', :raw],
120
+ ['used', :raw],
121
+ ['x1', :raw],
122
+ ['y1', :raw],
123
+ ['x2', :raw],
124
+ ['y2', :raw],
125
+ ['x3', :raw],
126
+ ['y3', :raw],
127
+ ['x4', :raw],
128
+ ['y4', :raw],
129
+ ]
130
+
131
+ # 5.3 Table Formatting
132
+ # Table 5.19 Keywords for PDF_info_table()
133
+ INFO_KEYWORD_TABLE_5_19 = [
134
+ ['firstbodyrow', :raw],
135
+ ['horboxgap', :raw],
136
+ ['horshrinking', :raw],
137
+ ['lastbodyrow', :raw],
138
+ ['returnreason', :string],
139
+ ['rowcount', :raw],
140
+ ['rowsplit', :boolean],
141
+ ['tableheight', :raw],
142
+ ['tablewidth', :raw],
143
+ ['vertboxgap', :raw],
144
+ ['vertshrinking', :raw],
145
+ # xvertline
146
+ # yhorline
147
+ ]
148
+
149
+ # 6.1 Object Fitting
150
+ # Table 6.3 Common keywords for querying the results of object fitting with
151
+ # PDF_info_image(),
152
+ # PDF_info_graphics(),
153
+ # PDF_ info_path( ),
154
+ # PDF_info_pdi_page( ),
155
+ # PDF_info_table( ),
156
+ # PDF_info_textline( )
157
+ INFO_KEYWORD_TABLE_6_3 = [
158
+ ['boundingbox', :raw],
159
+ ['fitscalex', :raw],
160
+ ['fitscaley', :raw],
161
+ ['height', :raw],
162
+ ['objectheight', :raw],
163
+ ['objectwidth', :raw],
164
+ ['width', :raw],
165
+ ['x1', :raw],
166
+ ['y1', :raw],
167
+ ['x2', :raw],
168
+ ['y2', :raw],
169
+ ['x3', :raw],
170
+ ['y3', :raw],
171
+ ['x4', :raw],
172
+ ['y4', :raw],
173
+ ]
174
+
175
+ # 7.6 Path Objects
176
+ # Table 7.8 Keywords for PDF_info_path()
177
+ INFO_KEYWORD_TABLE_7_8 = [
178
+ ['bboxwidth', :raw],
179
+ ['bboxheight', :raw],
180
+ ['numpoints', :raw],
181
+ ['px', :raw],
182
+ ['py', :raw],
183
+ ]
184
+
185
+ # 9.1 Images
186
+ # Table 9.4 Keywords for PDF_info_image()
187
+ INFO_KEYWORD_TABLE_9_4 = [
188
+ ['clippingpath', :path],
189
+ ['checkcolorspace', :boolean],
190
+ ['filename', :string],
191
+ ['iccprofile', :profile],
192
+ ['imageheight', :raw],
193
+ ['imagemask', :image],
194
+ ['imagetype', :string],
195
+ ['imagewidth', :raw],
196
+ ['infomode', :boolean],
197
+ ['mirroringx', :raw],
198
+ ['mirroringy', :raw],
199
+ ['orientation', :raw],
200
+ ['resx', :raw],
201
+ ['resy', :raw],
202
+ ['strips', :raw],
203
+ ['transparent', :boolean],
204
+ ['xid', :string],
205
+ ]
206
+
207
+ # 9.2 SVG Graphics
208
+ # Table 9.8 Keywords for PDF_info_graphics()
209
+ INFO_KEYWORD_TABLE_9_8 = [
210
+ ['description', :string],
211
+ ['filename', :string],
212
+ ['fittingpossible', :boolean],
213
+ ['graphicswidth', :raw],
214
+ ['graphicsheight', :raw],
215
+ ['istemplate', :boolean],
216
+ ['metadata', :string],
217
+ ['title', :string],
218
+ ['type', :string],
219
+ ['xid', :string],
220
+ ]
221
+
222
+ # 10.2 Page Functions
223
+ # Table 10.4 Keywords for PDF_info_pdi_page()
224
+ INFO_KEYWORD_TABLE_10_4 = [
225
+ ['fittingpossible', :boolean],
226
+ ['lang', :string],
227
+ ['mirroringx', :raw],
228
+ ['mirroringy', :raw],
229
+ ['pageheight', :raw],
230
+ ['pagewidth', :raw],
231
+ ['rotate', :raw],
232
+ ['topleveltag', :string],
233
+ ['topleveltagcount', :raw],
234
+ ['xid', :string],
235
+ ]
236
+ end
237
+ end
@@ -0,0 +1,54 @@
1
+ module PdflibMini
2
+ module InfoReader
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def info_reader(method_name, keyword, default_type)
9
+ define_method(keyword) do |*args|
10
+ optlist = args.first.is_a?(String) ? args.first : ''
11
+ options = args.last.is_a?(Hash) ? args.last : {}
12
+ result = public_send(method_name, keyword, optlist)
13
+ type = options.fetch(:as, default_type)
14
+ case type
15
+ when :raw
16
+ info_result_as_raw(result)
17
+ when :boolean
18
+ info_result_as_boolean(result)
19
+ when :string
20
+ info_result_as_string(result)
21
+ else # handle
22
+ info_result_as_handle(result, type)
23
+ end
24
+ end
25
+
26
+ if default_type == :boolean
27
+ alias_method :"#{keyword}?", keyword
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def info_result_as_raw(result)
35
+ result
36
+ end
37
+
38
+ def info_result_as_boolean(result)
39
+ result.to_i == 1
40
+ end
41
+
42
+ def info_result_as_string(result)
43
+ result = result.to_i
44
+ return nil if result == -1
45
+ @p.get_string(result, '')
46
+ end
47
+
48
+ def info_result_as_handle(result, handle)
49
+ result = result.to_i
50
+ class_name = handle.to_s.capitalize
51
+ PdflibMini::Handle.const_get(class_name).create(result, @p)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,457 @@
1
+ module PdflibMini
2
+ class Pdflib < SimpleDelegator
3
+ def initialize(p)
4
+ super p
5
+ end
6
+
7
+ # 3.1 Document Functions
8
+ # int begin_document(string filename, string optlist)
9
+ # end_document(string optlist)
10
+ def begin_document(filename, begin_optlist, end_optlist = '', &block)
11
+ super(filename, begin_optlist).tap do |result|
12
+ if block_given?
13
+ block.call(result, self)
14
+ end_document(end_optlist) if result != -1
15
+ end
16
+ end
17
+ end
18
+
19
+ # 3.3 Page Functions
20
+ # begin_page_ext(float width, float height, string optlist)
21
+ # end_page_ext(string optlist)
22
+ def begin_page_ext(width, height, begin_optlist, end_optlist = '', &block)
23
+ super(width, height, begin_optlist).tap do
24
+ if block_given?
25
+ block.call(self)
26
+ end_page_ext(end_optlist)
27
+ end
28
+ end
29
+ end
30
+
31
+ # 3.4 Layers
32
+ # int define_layer(string name, string optlist)
33
+ def define_layer(*args)
34
+ Handle::Layer.create(super(*args), self)
35
+ end
36
+
37
+ # 3.4 Layers
38
+ # begin_layer(int layer)
39
+ # end_layer( )
40
+ def begin_layer(layer, &block)
41
+ super(layer).tap do
42
+ if block_given?
43
+ block.call(self)
44
+ end_layer
45
+ end
46
+ end
47
+ end
48
+
49
+ # 4.1 Font Handling
50
+ # int load_font(string fontname, string encoding, string optlist)
51
+ # close_font(int font)
52
+ def load_font(*args, &block)
53
+ Handle::Font.create(super(*args), self).tap do |font|
54
+ if block_given?
55
+ block.call(font, self)
56
+ font.close_font if font != -1
57
+ end
58
+ end
59
+ end
60
+
61
+ # 4.4 User-defined (Type 3) Fonts
62
+ # begin_font(String fontname, double a, double b, double c, double d, double e, double f, String optlist)
63
+ # end_font( )
64
+ def begin_font(*args, &block)
65
+ super(*args).tap do
66
+ if block_given?
67
+ block.call(self)
68
+ end_font
69
+ end
70
+ end
71
+ end
72
+
73
+ # 4.4 User-defined (Type 3) Fonts
74
+ # begin_glyph_ext(int uv, string optlist)
75
+ # end_glyph( )
76
+ def begin_glyph_ext(*args, &block)
77
+ super(*args).tap do
78
+ if block_given?
79
+ block.call(self)
80
+ end_glyph
81
+ end
82
+ end
83
+ end
84
+
85
+ # 5.1 Single-Line Text with Textlines
86
+ # pseudo
87
+ def create_textline(text)
88
+ Handle::Textline.create(text, self)
89
+ end
90
+
91
+ # 5.2 Multi-Line Text with Textflows
92
+ # int add_textflow(int textflow, string text, string optlist)
93
+ # delete_textflow(int textflow)
94
+ def add_textflow(*args, &block)
95
+ Handle::Textflow.create(super(*args), self).tap do |textflow|
96
+ if block_given?
97
+ block.call(textflow, self)
98
+ textflow.delete_textflow if textflow != -1
99
+ end
100
+ end
101
+ end
102
+
103
+ # 5.2 Multi-Line Text with Textflows
104
+ # int create_textflow(string text, string optlist)
105
+ # delete_textflow(int textflow)
106
+ def create_textflow(*args, &block)
107
+ Handle::Textflow.create(super(*args), self).tap do |textflow|
108
+ if block_given?
109
+ block.call(textflow, self)
110
+ textflow.delete_textflow if textflow != -1
111
+ end
112
+ end
113
+ end
114
+
115
+ # 5.3 Table Formatting
116
+ # int add_table_cell(int table, int column, int row, string text, string optlist)
117
+ # delete_table(int table, string optlist)
118
+ def add_table_cell(table, column, row, text, create_optlist, delete_optlist = '', &block)
119
+ Handle::TableCell.create(super(table, column, row, text, create_optlist), self).tap do |table_cell|
120
+ if block_given?
121
+ block.call(table_cell, self)
122
+ table_cell.delete_table(delete_optlist) if table_cell != -1
123
+ end
124
+ end
125
+ end
126
+
127
+ # 7.2 Graphics State
128
+ # int create_gstate(string optlist)
129
+ def create_gstate(*args)
130
+ Handle::GraphicsState.create(super(*args), self)
131
+ end
132
+
133
+ # 7.2 Graphics State
134
+ # save( )
135
+ # restore( )
136
+ def save(&block)
137
+ super.tap do
138
+ if block_given?
139
+ block.call(self)
140
+ restore
141
+ end
142
+ end
143
+ end
144
+
145
+ # 7.3 Coordinate System Transformations
146
+ # translate(float tx, float ty)
147
+ def translate(*args, &block)
148
+ if block_given?
149
+ save do
150
+ super(*args)
151
+ block.call
152
+ end
153
+ else
154
+ super(*args)
155
+ end
156
+ end
157
+
158
+ # 7.3 Coordinate System Transformations
159
+ # scale(float sx, float sy)
160
+ def scale(*args, &block)
161
+ if block_given?
162
+ save do
163
+ super(*args)
164
+ block.call
165
+ end
166
+ else
167
+ super(*args)
168
+ end
169
+ end
170
+
171
+ # 7.3 Coordinate System Transformations
172
+ # rotate(float phi)
173
+ def rotate(*args, &block)
174
+ if block_given?
175
+ save do
176
+ super(*args)
177
+ block.call
178
+ end
179
+ else
180
+ super(*args)
181
+ end
182
+ end
183
+
184
+ # 7.3 Coordinate System Transformations
185
+ # align(float dx, float dy)
186
+ def align(*args, &block)
187
+ if block_given?
188
+ save do
189
+ super(*args)
190
+ block.call
191
+ end
192
+ else
193
+ super(*args)
194
+ end
195
+ end
196
+
197
+ # 7.3 Coordinate System Transformations
198
+ # skew(float alpha, float beta)
199
+ def skew(*args, &block)
200
+ if block_given?
201
+ save do
202
+ super(*args)
203
+ block.call
204
+ end
205
+ else
206
+ super(*args)
207
+ end
208
+ end
209
+
210
+ # 7.3 Coordinate System Transformations
211
+ # concat(float a, float b, float c, float d, float e, float f)
212
+ def concat(*args, &block)
213
+ if block_given?
214
+ save do
215
+ super(*args)
216
+ block.call
217
+ end
218
+ else
219
+ super(*args)
220
+ end
221
+ end
222
+
223
+ # 7.3 Coordinate System Transformations
224
+ # setmatrix(float a, float b, float c, float d, float e, float f)
225
+ def setmatrix(*args, &block)
226
+ if block_given?
227
+ save do
228
+ super(*args)
229
+ block.call
230
+ end
231
+ else
232
+ super(*args)
233
+ end
234
+ end
235
+
236
+ # 7.5 Painting and Clipping
237
+ # stroke( )
238
+ def stroke(&block)
239
+ block.call if block_given?
240
+ super
241
+ end
242
+
243
+ # 7.5 Painting and Clipping
244
+ # closepath_stroke( )
245
+ def closepath_stroke(&block)
246
+ block.call if block_given?
247
+ super
248
+ end
249
+
250
+ # 7.5 Painting and Clipping
251
+ # fill( )
252
+ def fill(&block)
253
+ block.call if block_given?
254
+ super
255
+ end
256
+
257
+ # 7.5 Painting and Clipping
258
+ # fill_stroke( )
259
+ def fill_stroke(&block)
260
+ block.call if block_given?
261
+ super
262
+ end
263
+
264
+ # 7.5 Painting and Clipping
265
+ # closepath_fill_stroke( )
266
+ def closepath_fill_stroke(&block)
267
+ block.call if block_given?
268
+ super
269
+ end
270
+
271
+ # 7.5 Painting and Clipping
272
+ # clip( )
273
+ def clip(&block)
274
+ block.call if block_given?
275
+ super
276
+ end
277
+
278
+ # 7.6 Path Objects
279
+ # int add_path_point(int path, float x, float y, string type, string optlist)
280
+ # delete_path(int path)
281
+ def add_path_point(*args, &block)
282
+ Handle::Path.create(super(*args), self).tap do |path|
283
+ if block_given?
284
+ block.call(path, self)
285
+ path.delete_path if path != -1
286
+ end
287
+ end
288
+ end
289
+
290
+ # 8.1 Setting Color
291
+ # int makespotcolor(string spotname)
292
+ def makespotcolor(*args)
293
+ Handle::Color.create(super(*args), self)
294
+ end
295
+
296
+ # 8.2 ICC Profiles
297
+ # int load_iccprofile(string profilename, string optlist)
298
+ def load_iccprofile(*args)
299
+ Handle::Profile.create(super(*args), self)
300
+ end
301
+
302
+ # 8.3 Patterns and Shadings
303
+ # int begin_pattern_ext(float width, float height, string optlist)
304
+ def begin_pattern_ext(*args)
305
+ Handle::Pattern.create(super(*args), self)
306
+ end
307
+
308
+ # 8.3 Patterns and Shadings
309
+ # int shading_pattern(int shading, string optlist)
310
+ def shading_pattern(*args)
311
+ Handle::Pattern.create(super(*args), self)
312
+ end
313
+
314
+ # 8.3 Patterns and Shadings
315
+ # int shading(string shtype, float x0, float y0, float x1, float y1, float c1, float c2, float c3, float c4, string optlist)
316
+ def shading(*args)
317
+ Handle::Shading.create(super(*args), self)
318
+ end
319
+
320
+ # 9.1 Images
321
+ # int load_image(string imagetype, string filename, string optlist)
322
+ def load_image(*args)
323
+ Handle::Image.create(super(*args), self)
324
+ end
325
+
326
+ # 9.2 SVG Graphics
327
+ # int load_graphics(string type, string filename, string optlist)
328
+ def load_graphics(*args)
329
+ Handle::Graphics.create(super(*args), self)
330
+ end
331
+
332
+ # 9.3 Templates
333
+ # int begin_template_ext(float width, float height, string optlist)
334
+ # end_template_ext(float width, float height)
335
+ def begin_template_ext(*args, &block)
336
+ Handle::Template.create(super(*args), self).tap do |template|
337
+ if block_given?
338
+ block.call(self)
339
+ template.end_template_ext(0, 0) if template != -1
340
+ end
341
+ end
342
+ end
343
+
344
+ # 10.1 Document Functions
345
+ # int open_pdi_document(string filename, string optlist)
346
+ # close_pdi_document(int doc)
347
+ def open_pdi_document(*args, &block)
348
+ Handle::Pdf::Document.create(super(*args), self, args.first).tap do |doc|
349
+ if block_given?
350
+ block.call(doc, self)
351
+ doc.close_pdi_document if doc != -1
352
+ end
353
+ end
354
+ end
355
+
356
+ # 10.2 Page Functions
357
+ # int open_pdi_page(int doc, int pagenumber, string optlist)
358
+ # close_pdi_page(int page)
359
+ def open_pdi_page(*args, &block)
360
+ Handle::Pdf::Page.create(super(*args), args.first, self).tap do |page|
361
+ if block_given?
362
+ block.call(page, args.first, self)
363
+ page.close_pdi_page if page != -1
364
+ end
365
+ end
366
+ end
367
+
368
+ # 12.1 Bookmarks
369
+ # int create_bookmark(string text, string optlist)
370
+ def create_bookmark(*args)
371
+ Handle::Bookmark.create(super(*args), self)
372
+ end
373
+
374
+ # 12.2 Annotations
375
+ # create_annotation(float llx, float lly, float urx, float ury, string type, string optlist)
376
+
377
+ # 12.3 Form Fields
378
+ # create_field(float llx, float lly, float urx, float ury, string name, string type, string optlist)
379
+
380
+ # 12.3 Form Fields
381
+ # create_fieldgroup(string name, string optlist)
382
+
383
+ # 12.4 Actions
384
+ # int create_action(string type, string optlist)
385
+ def create_action(*args)
386
+ Handle::Action.create(super(*args), self)
387
+ end
388
+
389
+ # 12.5 Named Destinations
390
+ # add_nameddest(string name, string optlist)
391
+
392
+ # 12.6 PDF Packages and Portfolios
393
+ # int add_portfolio_folder(int parent, string foldername, string optlist)
394
+ def add_portfolio_folder(*args)
395
+ Handle::Folder.create(super(*args), self)
396
+ end
397
+
398
+ # pseudo
399
+ def root_portfolio_folder
400
+ Handle::Folder.new(-1, self)
401
+ end
402
+
403
+ # 13.1 3D Artwork
404
+ # int load_3ddata(string filename, string optlist)
405
+ def load_3ddata(*args)
406
+ Handle::Data3d.create(super(*args), self)
407
+ end
408
+
409
+ # 13.1 3D Artwork
410
+ # int create_3dview(string username, string optlist)
411
+ def create_3dview(*args)
412
+ Handle::Data3dView.create(super(*args), self)
413
+ end
414
+
415
+ # 13.2 Asset and Rich Media Features (Flash)
416
+ # int load_asset(string type, string filename, string optlist)
417
+ def load_asset(*args)
418
+ Handle::Asset.create(super(*args), self)
419
+ end
420
+
421
+ # 14.3 Tagged PDF
422
+ # int begin_item(string tagname, string optlist)
423
+ # end_item(int id)
424
+ def begin_item(*args, &block)
425
+ Handle::Item.create(super(*args), self).tap do |item|
426
+ if block_given?
427
+ block.call(item, self)
428
+ item.end_item if item != -1
429
+ end
430
+ end
431
+ end
432
+
433
+ # 14.4 Marked Content
434
+ # begin_mc(string tagname, string optlist)
435
+ # end_mc( )
436
+ def begin_mc(*args, &block)
437
+ super(*args).tap do
438
+ if block_given?
439
+ block.call(self)
440
+ end_mc
441
+ end
442
+ end
443
+ end
444
+
445
+ # 14.5 Document Part Hierarchy
446
+ # begin_dpart(string optlist)
447
+ # end_dpart(string optlist)
448
+ def begin_dpart(begin_optlist, end_optlist = '', &block)
449
+ super(begin_optlist).tap do
450
+ if block_given?
451
+ block.call(self)
452
+ end_dpart(end_optlist)
453
+ end
454
+ end
455
+ end
456
+ end
457
+ end