prawn 0.4.1 → 0.5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/lib/prawn.rb +2 -72
  2. metadata +33 -224
  3. data/COPYING +0 -340
  4. data/LICENSE +0 -56
  5. data/README +0 -40
  6. data/Rakefile +0 -79
  7. data/data/encodings/win_ansi.txt +0 -29
  8. data/data/fonts/Action Man.dfont +0 -0
  9. data/data/fonts/Activa.ttf +0 -0
  10. data/data/fonts/Chalkboard.ttf +0 -0
  11. data/data/fonts/Courier-Bold.afm +0 -342
  12. data/data/fonts/Courier-BoldOblique.afm +0 -342
  13. data/data/fonts/Courier-Oblique.afm +0 -342
  14. data/data/fonts/Courier.afm +0 -342
  15. data/data/fonts/DejaVuSans.ttf +0 -0
  16. data/data/fonts/Dustismo_Roman.ttf +0 -0
  17. data/data/fonts/Helvetica-Bold.afm +0 -2827
  18. data/data/fonts/Helvetica-BoldOblique.afm +0 -2827
  19. data/data/fonts/Helvetica-Oblique.afm +0 -3051
  20. data/data/fonts/Helvetica.afm +0 -3051
  21. data/data/fonts/MustRead.html +0 -19
  22. data/data/fonts/Symbol.afm +0 -213
  23. data/data/fonts/Times-Bold.afm +0 -2588
  24. data/data/fonts/Times-BoldItalic.afm +0 -2384
  25. data/data/fonts/Times-Italic.afm +0 -2667
  26. data/data/fonts/Times-Roman.afm +0 -2419
  27. data/data/fonts/ZapfDingbats.afm +0 -225
  28. data/data/fonts/comicsans.ttf +0 -0
  29. data/data/fonts/gkai00mp.ttf +0 -0
  30. data/data/images/arrow.png +0 -0
  31. data/data/images/arrow2.png +0 -0
  32. data/data/images/barcode_issue.png +0 -0
  33. data/data/images/dice.alpha +0 -0
  34. data/data/images/dice.dat +0 -0
  35. data/data/images/dice.png +0 -0
  36. data/data/images/fractal.jpg +0 -0
  37. data/data/images/letterhead.jpg +0 -0
  38. data/data/images/page_white_text.alpha +0 -0
  39. data/data/images/page_white_text.dat +0 -0
  40. data/data/images/page_white_text.png +0 -0
  41. data/data/images/pigs.jpg +0 -0
  42. data/data/images/rails.dat +0 -0
  43. data/data/images/rails.png +0 -0
  44. data/data/images/ruport.png +0 -0
  45. data/data/images/ruport_data.dat +0 -0
  46. data/data/images/ruport_transparent.png +0 -0
  47. data/data/images/ruport_type0.png +0 -0
  48. data/data/images/stef.jpg +0 -0
  49. data/data/images/web-links.dat +0 -1
  50. data/data/images/web-links.png +0 -0
  51. data/data/shift_jis_text.txt +0 -1
  52. data/examples/bounding_box/bounding_boxes.rb +0 -44
  53. data/examples/bounding_box/lazy_bounding_boxes.rb +0 -28
  54. data/examples/bounding_box/padded_box.rb +0 -24
  55. data/examples/bounding_box/russian_boxes.rb +0 -37
  56. data/examples/general/background.rb +0 -20
  57. data/examples/general/canvas.rb +0 -16
  58. data/examples/general/measurement_units.rb +0 -52
  59. data/examples/general/multi_page_layout.rb +0 -17
  60. data/examples/general/page_geometry.rb +0 -32
  61. data/examples/graphics/basic_images.rb +0 -27
  62. data/examples/graphics/cmyk.rb +0 -13
  63. data/examples/graphics/curves.rb +0 -12
  64. data/examples/graphics/hexagon.rb +0 -14
  65. data/examples/graphics/image_fit.rb +0 -16
  66. data/examples/graphics/image_flow.rb +0 -38
  67. data/examples/graphics/image_position.rb +0 -18
  68. data/examples/graphics/line.rb +0 -33
  69. data/examples/graphics/png_types.rb +0 -23
  70. data/examples/graphics/polygons.rb +0 -17
  71. data/examples/graphics/remote_images.rb +0 -12
  72. data/examples/graphics/ruport_style_helpers.rb +0 -20
  73. data/examples/graphics/stroke_bounds.rb +0 -23
  74. data/examples/m17n/chinese_text_wrapping.rb +0 -20
  75. data/examples/m17n/euro.rb +0 -16
  76. data/examples/m17n/sjis.rb +0 -29
  77. data/examples/m17n/utf8.rb +0 -14
  78. data/examples/m17n/win_ansi_charset.rb +0 -55
  79. data/examples/text/alignment.rb +0 -19
  80. data/examples/text/dfont.rb +0 -49
  81. data/examples/text/family_based_styling.rb +0 -25
  82. data/examples/text/flowing_text_with_header_and_footer.rb +0 -37
  83. data/examples/text/font_calculations.rb +0 -92
  84. data/examples/text/font_size.rb +0 -34
  85. data/examples/text/kerning.rb +0 -31
  86. data/examples/text/simple_text.rb +0 -18
  87. data/examples/text/simple_text_ttf.rb +0 -18
  88. data/examples/text/span.rb +0 -30
  89. data/examples/text/text_box.rb +0 -26
  90. data/examples/text/text_flow.rb +0 -68
  91. data/lib/prawn/compatibility.rb +0 -38
  92. data/lib/prawn/document.rb +0 -309
  93. data/lib/prawn/document/annotations.rb +0 -63
  94. data/lib/prawn/document/bounding_box.rb +0 -368
  95. data/lib/prawn/document/destinations.rb +0 -81
  96. data/lib/prawn/document/internals.rb +0 -126
  97. data/lib/prawn/document/page_geometry.rb +0 -79
  98. data/lib/prawn/document/span.rb +0 -55
  99. data/lib/prawn/document/text.rb +0 -185
  100. data/lib/prawn/document/text/box.rb +0 -76
  101. data/lib/prawn/document/text/wrapping.rb +0 -59
  102. data/lib/prawn/encoding.rb +0 -121
  103. data/lib/prawn/errors.rb +0 -40
  104. data/lib/prawn/font.rb +0 -277
  105. data/lib/prawn/font/afm.rb +0 -202
  106. data/lib/prawn/font/dfont.rb +0 -31
  107. data/lib/prawn/font/ttf.rb +0 -326
  108. data/lib/prawn/graphics.rb +0 -257
  109. data/lib/prawn/graphics/color.rb +0 -140
  110. data/lib/prawn/images.rb +0 -339
  111. data/lib/prawn/images/jpg.rb +0 -45
  112. data/lib/prawn/images/png.rb +0 -199
  113. data/lib/prawn/literal_string.rb +0 -14
  114. data/lib/prawn/measurement_extensions.rb +0 -46
  115. data/lib/prawn/measurements.rb +0 -71
  116. data/lib/prawn/name_tree.rb +0 -165
  117. data/lib/prawn/pdf_object.rb +0 -73
  118. data/lib/prawn/reference.rb +0 -59
  119. data/spec/annotations_spec.rb +0 -90
  120. data/spec/bounding_box_spec.rb +0 -141
  121. data/spec/destinations_spec.rb +0 -15
  122. data/spec/document_spec.rb +0 -193
  123. data/spec/font_spec.rb +0 -234
  124. data/spec/graphics_spec.rb +0 -209
  125. data/spec/images_spec.rb +0 -68
  126. data/spec/jpg_spec.rb +0 -25
  127. data/spec/measurement_units_spec.rb +0 -23
  128. data/spec/name_tree_spec.rb +0 -103
  129. data/spec/pdf_object_spec.rb +0 -112
  130. data/spec/png_spec.rb +0 -196
  131. data/spec/reference_spec.rb +0 -42
  132. data/spec/spec_helper.rb +0 -23
  133. data/spec/text_spec.rb +0 -178
  134. data/vendor/pdf-inspector/README +0 -18
  135. data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -25
  136. data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -80
  137. data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -16
  138. data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -31
  139. data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
  140. data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
  141. data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
  142. data/vendor/ttfunk/example.rb +0 -45
  143. data/vendor/ttfunk/lib/ttfunk.rb +0 -102
  144. data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
  145. data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
  146. data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
  147. data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
  148. data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
  149. data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
  150. data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
  151. data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -46
  152. data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
  153. data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
  154. data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -51
  155. data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
  156. data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
  157. data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
  158. data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
  159. data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
  160. data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
  161. data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
  162. data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
  163. data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
  164. data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
  165. data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
  166. data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
  167. data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
  168. data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
  169. data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
  170. data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
  171. data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -119
  172. data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
  173. data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
  174. data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
  175. data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
  176. data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
  177. data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
  178. data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
  179. data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
@@ -1,368 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # bounding_box.rb : Implements a mechanism for shifting the coordinate space
4
- #
5
- # Copyright May 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- module Prawn
10
- class Document
11
-
12
- # A bounding box serves two important purposes:
13
- # * Provide bounds for flowing text, starting at a given point
14
- # * Translate the origin (0,0) for graphics primitives, for the purposes
15
- # of simplifying coordinate math.
16
- #
17
- # When flowing text, the usage of a bounding box is simple. Text will
18
- # begin at the point specified, flowing the width of the bounding box.
19
- # After the block exits, the cursor position will be moved to
20
- # the bottom of the bounding box (y - height). If flowing text exceeds
21
- # the height of the bounding box, the text will be continued on the next
22
- # page, starting again at the top-left corner of the bounding box.
23
- #
24
- # pdf.bounding_box([100,500], :width => 100, :height => 300) do
25
- # pdf.text "This text will flow in a very narrow box starting" +
26
- # "from [100,500]. The pointer will then be moved to [100,200]" +
27
- # "and return to the margin_box"
28
- # end
29
- #
30
- # When translating coordinates, the idea is to allow the user to draw
31
- # relative to the origin, and then translate their drawing to a specified
32
- # area of the document, rather than adjust all their drawing coordinates
33
- # to match this new region.
34
- #
35
- # Take for example two triangles which share one point, drawn from the
36
- # origin:
37
- #
38
- # pdf.polygon [0,250], [0,0], [150,100]
39
- # pdf.polygon [100,0], [150,100], [200,0]
40
- #
41
- # It would be easy enough to translate these triangles to another point,
42
- # e.g [200,200]
43
- #
44
- # pdf.polygon [200,450], [200,200], [350,300]
45
- # pdf.polygon [300,200], [350,300], [400,200]
46
- #
47
- # However, each time you want to move the drawing, you'd need to alter
48
- # every point in the drawing calls, which as you might imagine, can become
49
- # tedious.
50
- #
51
- # If instead, we think of the drawing as being bounded by a box, we can
52
- # see that the image is 200 points wide by 250 points tall.
53
- #
54
- # To translate it to a new origin, we simply select a point at (x,y+height)
55
- #
56
- # Using the [200,200] example:
57
- #
58
- # pdf.bounding_box([200,450], :width => 200, :height => 250) do
59
- # pdf.polygon [0,250], [0,0], [150,100]
60
- # pdf.polygon [100,0], [150,100], [200,0]
61
- # end
62
- #
63
- # Notice that the drawing is still relative to the origin. If we want to
64
- # move this drawing around the document, we simply need to recalculate the
65
- # top-left corner of the rectangular bounding-box, and all of our graphics
66
- # calls remain unmodified.
67
- #
68
- # By default, bounding boxes are specified relative to the document's
69
- # margin_box (which is itself a bounding box). You can also nest bounding
70
- # boxes, allowing you to build components which are relative to each other
71
- #
72
- # pdf.bouding_box([200,450], :width => 200, :height => 250) do
73
- # pdf.bounding_box([50,200], :width => 50, :height => 50) do
74
- # # a 50x50 bounding box that starts 50 pixels left and 50 pixels down
75
- # # the parent bounding box.
76
- # end
77
- # end
78
- #
79
- # If you wish to position the bounding boxes at absolute coordinates rather
80
- # than relative to the margins or other bounding boxes, you can use canvas()
81
- #
82
- # pdf.canvas do
83
- # pdf.bounding_box([200,450], :width => 200, :height => 250) do
84
- # # positioned at 'real' (200,450)
85
- # end
86
- # end
87
- #
88
- # Of course, if you use canvas, you will be responsible for ensuring that
89
- # you remain within the printable area of your document.
90
- #
91
- def bounding_box(*args, &block)
92
- init_bounding_box(block) do |_|
93
- translate!(args[0])
94
- @bounding_box = BoundingBox.new(self, *args)
95
- end
96
- end
97
-
98
-
99
- # A LazyBoundingBox is simply a BoundingBox with an action tied to it to be
100
- # executed later. The lazy_bounding_box method takes the same arguments as
101
- # bounding_box, but returns a LazyBoundingBox object instead of executing
102
- # the code block directly.
103
- #
104
- # You can then call LazyBoundingBox#draw at any time (or multiple times if
105
- # you wish), and the contents of the block will then be run. This can be
106
- # useful for assembling repeating page elements or reusable components.
107
- #
108
- # file = "lazy_bounding_boxes.pdf"
109
- # Prawn::Document.generate(file, :skip_page_creation => true) do
110
- # point = [bounds.right-50, bounds.bottom + 25]
111
- # page_counter = lazy_bounding_box(point, :width => 50) do
112
- # text "Page: #{page_count}"
113
- # end
114
- #
115
- # 10.times do
116
- # start_new_page
117
- # text "Some text"
118
- # page_counter.draw
119
- # end
120
- # end
121
- #
122
- def lazy_bounding_box(*args,&block)
123
- translate!(args[0])
124
- box = LazyBoundingBox.new(self,*args)
125
- box.action(&block)
126
- return box
127
- end
128
-
129
- # A shortcut to produce a bounding box which is mapped to the document's
130
- # absolute coordinates, regardless of how things are nested or margin sizes.
131
- #
132
- # pdf.canvas do
133
- # pdf.line pdf.bounds.bottom_left, pdf.bounds.top_right
134
- # end
135
- #
136
- def canvas(&block)
137
- init_bounding_box(block, :hold_position => true) do |_|
138
- @bounding_box = BoundingBox.new(self, [0,page_dimensions[3]],
139
- :width => page_dimensions[2],
140
- :height => page_dimensions[3]
141
- )
142
- end
143
- end
144
-
145
- # A bounding box with the same dimensions of its parents, minus a margin
146
- # on all sides
147
- #
148
- def padded_box(margin, &block)
149
- bounding_box [bounds.left + margin, bounds.top - margin],
150
- :width => bounds.width - (margin * 2),
151
- :height => bounds.height - (margin * 2), &block
152
- end
153
-
154
- # A header is a LazyBoundingBox drawn relative to the margins that can be
155
- # repeated on every page of the document.
156
- #
157
- # Unless <tt>:width</tt> or <tt>:height</tt> are specified, the margin_box
158
- # width and height are used.
159
- #
160
- # header margin_box.top_left do
161
- # text "Here's My Fancy Header", :size => 25, :align => :center
162
- # stroke_horizontal_rule
163
- # end
164
- #
165
- def header(top_left,options={},&block)
166
- @header = repeating_page_element(top_left,options,&block)
167
- end
168
-
169
- # A footer is a LazyBoundingBox drawn relative to the margins that can be
170
- # repeated on every page of the document.
171
- #
172
- # Unless <tt>:width</tt> or <tt>:height</tt> are specified, the margin_box
173
- # width and height are used.
174
- #
175
- # footer [margin_box.left, margin_box.bottom + 25] do
176
- # stroke_horizontal_rule
177
- # text "And here's a sexy footer", :size => 16
178
- # end
179
- #
180
- def footer(top_left,options={},&block)
181
- @footer = repeating_page_element(top_left,options,&block)
182
- end
183
-
184
- private
185
-
186
- def init_bounding_box(user_block, options={}, &init_block)
187
- parent_box = @bounding_box
188
-
189
- init_block.call(parent_box)
190
-
191
- self.y = @bounding_box.absolute_top
192
- user_block.call
193
- self.y = @bounding_box.absolute_bottom unless options[:hold_position]
194
-
195
- @bounding_box = parent_box
196
- end
197
-
198
- def repeating_page_element(top_left,options={},&block)
199
- r = LazyBoundingBox.new(self, translate(top_left),
200
- :width => options[:width] || margin_box.width,
201
- :height => options[:height] || margin_box.height )
202
- r.action(&block)
203
- return r
204
- end
205
-
206
- class BoundingBox
207
-
208
- def initialize(parent, point, options={}) #:nodoc:
209
- @parent = parent
210
- @x, @y = point
211
- @width, @height = options[:width], options[:height]
212
- end
213
-
214
- # The translated origin (x,y-height) which describes the location
215
- # of the bottom left corner of the bounding box
216
- #
217
- def anchor
218
- [@x, @y - height]
219
- end
220
-
221
- # Relative left x-coordinate of the bounding box. (Always 0)
222
- #
223
- def left
224
- 0
225
- end
226
-
227
- # Relative right x-coordinate of the bounding box. (Equal to the box width)
228
- #
229
- def right
230
- @width
231
- end
232
-
233
- # Relative top y-coordinate of the bounding box. (Equal to the box height)
234
- #
235
- def top
236
- height
237
- end
238
-
239
- # Relative bottom y-coordinate of the bounding box (Always 0)
240
- #
241
- def bottom
242
- 0
243
- end
244
-
245
- # Relative top-left point of the bounding_box
246
- #
247
- def top_left
248
- [left,top]
249
- end
250
-
251
- # Relative top-right point of the bounding box
252
- #
253
- def top_right
254
- [right,top]
255
- end
256
-
257
- # Relative bottom-right point of the bounding box
258
- #
259
- def bottom_right
260
- [right,bottom]
261
- end
262
-
263
- # Relative bottom-left point of the bounding box
264
- #
265
- def bottom_left
266
- [left,bottom]
267
- end
268
-
269
- # Absolute left x-coordinate of the bounding box
270
- #
271
- def absolute_left
272
- @x
273
- end
274
-
275
- # Absolute right x-coordinate of the bounding box
276
- #
277
- def absolute_right
278
- @x + width
279
- end
280
-
281
- # Absolute top y-coordinate of the bounding box
282
- #
283
- def absolute_top
284
- @y
285
- end
286
-
287
- # Absolute bottom y-coordinate of the bottom box
288
- #
289
- def absolute_bottom
290
- @y - height
291
- end
292
-
293
- # Absolute top-left point of the bounding box
294
- #
295
- def absolute_top_left
296
- [absolute_left, absolute_top]
297
- end
298
-
299
- # Absolute top-right point of the bounding box
300
- #
301
- def absolute_top_right
302
- [absolute_right, absolute_top]
303
- end
304
-
305
- # Absolute bottom-left point of the bounding box
306
- #
307
- def absolute_bottom_left
308
- [absolute_left, absolute_bottom]
309
- end
310
-
311
- # Absolute bottom-left point of the bounding box
312
- #
313
- def absolute_bottom_right
314
- [absolute_right, absolute_bottom]
315
- end
316
-
317
- # Width of the bounding box
318
- #
319
- def width
320
- @width
321
- end
322
-
323
- # Height of the bounding box. If the box is 'stretchy' (unspecified
324
- # height attribute), height is calculated as the distance from the top of
325
- # the box to the current drawing position.
326
- #
327
- def height
328
- @height || absolute_top - @parent.y
329
- end
330
-
331
- # Returns +false+ when the box has a defined height, +true+ when the height
332
- # is being calculated on the fly based on the current vertical position.
333
- #
334
- def stretchy?
335
- !@height
336
- end
337
-
338
- end
339
-
340
- class LazyBoundingBox < BoundingBox
341
-
342
- # Defines the block to be executed by LazyBoundingBox#draw.
343
- # Usually, this will be used via a higher level interface.
344
- # See the documentation for Document#lazy_bounding_box, Document#header,
345
- # and Document#footer
346
- #
347
- def action(&block)
348
- @action = block
349
- end
350
-
351
- # Sets Document#bounds to use the LazyBoundingBox for its bounds,
352
- # runs the block specified by LazyBoundingBox#action,
353
- # and then restores the original bounds of the document.
354
- #
355
- def draw
356
- @parent.mask(:y) do
357
- parent_box = @parent.bounds
358
- @parent.bounds = self
359
- @parent.y = absolute_top
360
- @action.call
361
- @parent.bounds = parent_box
362
- end
363
- end
364
-
365
- end
366
-
367
- end
368
- end
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # annotations.rb : Implements destination support for PDF
4
- #
5
- # Copyright November 2008, Jamis Buck. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
- require 'prawn/name_tree'
10
-
11
- module Prawn
12
- class Document
13
- module Destinations
14
- # The maximum number of children to fit into a single node in the Dests tree.
15
- NAME_TREE_CHILDREN_LIMIT = 20 #:nodoc:
16
-
17
- # The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names).
18
- # This name tree is used to store named destinations (PDF spec 8.2.1).
19
- # (For more on name trees, see section 3.8.4 in the PDF spec.)
20
- def dests
21
- names.data[:Dests] ||= ref(Prawn::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT))
22
- end
23
-
24
- # Adds a new destination to the dests name tree (see #dests). The
25
- # +reference+ parameter will be converted into a Prawn::Reference if
26
- # it is not already one.
27
- def add_dest(name, reference)
28
- reference = ref(reference) unless reference.is_a?(Prawn::Reference)
29
- dests.data.add(name, reference)
30
- end
31
-
32
- # Return a Dest specification for a specific location (and optional zoom
33
- # level).
34
- def dest_xyz(left, top, zoom=nil, page=@current_page)
35
- [page, :XYZ, left, top, zoom]
36
- end
37
-
38
- # Return a Dest specification that will fit the given page into the
39
- # viewport.
40
- def dest_fit(page=@current_page)
41
- [page, :Fit]
42
- end
43
-
44
- # Return a Dest specification that will fit the given page horizontally
45
- # into the viewport, aligned vertically at the given top coordinate.
46
- def dest_fit_horizontally(top, page=@current_page)
47
- [page, :FitH, top]
48
- end
49
-
50
- # Return a Dest specification that will fit the given page vertically
51
- # into the viewport, aligned horizontally at the given left coordinate.
52
- def dest_fit_vertically(left, page=@current_page)
53
- [page, :FitV, left]
54
- end
55
-
56
- # Return a Dest specification that will fit the given rectangle into the
57
- # viewport, for the given page.
58
- def dest_fit_rect(left, bottom, right, top, page=@current_page)
59
- [page, :FitR, left, bottom, right, top]
60
- end
61
-
62
- # Return a Dest specfication that will fit the given page's bounding box
63
- # into the viewport.
64
- def dest_fit_bounds(page=@current_page)
65
- [page, :FitB]
66
- end
67
-
68
- # Same as #dest_fit_horizontally, but works on the page's bounding box
69
- # instead of the entire page.
70
- def dest_fit_bounds_horizontally(top, page=@current_page)
71
- [page, :FitBH, top]
72
- end
73
-
74
- # Same as #dest_fit_vertically, but works on the page's bounding box
75
- # instead of the entire page.
76
- def dest_fit_bounds_vertically(left, page=@current_page)
77
- [page, :FitBV, left]
78
- end
79
- end
80
- end
81
- end
@@ -1,126 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # internals.rb : Implements document internals for Prawn
4
- #
5
- # Copyright August 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
- module Prawn
10
- class Document
11
-
12
- # This module exposes a few low-level PDF features for those who want
13
- # to extend Prawn's core functionality. If you are not comfortable with
14
- # low level PDF functionality as defined by Adobe's specification, chances
15
- # are you won't need anything you find here.
16
- #
17
- module Internals
18
- # Creates a new Prawn::Reference and adds it to the Document's object
19
- # list. The +data+ argument is anything that Prawn::PdfObject() can convert.
20
- #
21
- # If a block is given, it will be invoked just before the object is written
22
- # out to the PDF document stream. This allows you to do deferred processing
23
- # on some references (such as fonts, which you might know all the details
24
- # about until the last page of the document is finished).
25
- def ref(data, &block)
26
- @objects.push(Prawn::Reference.new(@objects.size + 1, data, &block)).last
27
- end
28
-
29
- # Appends a raw string to the current page content.
30
- #
31
- # # Raw line drawing example:
32
- # x1,y1,x2,y2 = 100,500,300,550
33
- # pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move
34
- # pdf.add_content("%.3f %.3f l" % [ x2, y2 ]) # draw path
35
- # pdf.add_content("S") # stroke
36
- #
37
- def add_content(str)
38
- @page_content << str << "\n"
39
- end
40
-
41
- # Add a new type to the current pages ProcSet
42
- #
43
- def proc_set(*types)
44
- @current_page.data[:ProcSet] ||= ref([])
45
- @current_page.data[:ProcSet].data |= types
46
- end
47
-
48
- # The Resources dictionary for the current page
49
- #
50
- def page_resources
51
- @current_page.data[:Resources] ||= {}
52
- end
53
-
54
- # The Font dictionary for the current page
55
- #
56
- def page_fonts
57
- page_resources[:Font] ||= {}
58
- end
59
-
60
- # The XObject dictionary for the current page
61
- def page_xobjects
62
- page_resources[:XObject] ||= {}
63
- end
64
-
65
- # The Name dictionary (PDF spec 3.6.3) for this document. It is
66
- # lazily initialized, so that documents that do not need a name
67
- # dictionary do not incur the additional overhead.
68
- def names
69
- @root.data[:Names] ||= ref(:Type => :Names)
70
- end
71
-
72
- private
73
-
74
- def finish_page_content
75
- @header.draw if @header
76
- @footer.draw if @footer
77
- add_content "Q"
78
- @page_content.compress_stream if compression_enabled?
79
- @page_content.data[:Length] = @page_content.stream.size
80
- end
81
-
82
- # Write out the PDF Header, as per spec 3.4.1
83
- def render_header(output)
84
- # pdf version
85
- output << "%PDF-1.3\n"
86
-
87
- # 4 binary chars, as recommended by the spec
88
- output << "\xFF\xFF\xFF\xFF\n"
89
- end
90
-
91
- # Write out the PDF Body, as per spec 3.4.2
92
- def render_body(output)
93
- @objects.each do |ref|
94
- ref.offset = output.size
95
- output << ref.object
96
- end
97
- end
98
-
99
- # Write out the PDF Cross Reference Table, as per spec 3.4.3
100
- def render_xref(output)
101
- @xref_offset = output.size
102
- output << "xref\n"
103
- output << "0 #{@objects.size + 1}\n"
104
- output << "0000000000 65535 f \n"
105
- @objects.each do |ref|
106
- output.printf("%010d", ref.offset)
107
- output << " 00000 n \n"
108
- end
109
- end
110
-
111
- # Write out the PDF Trailer, as per spec 3.4.4
112
- def render_trailer(output)
113
- trailer_hash = {:Size => @objects.size + 1,
114
- :Root => @root,
115
- :Info => @info}
116
-
117
- output << "trailer\n"
118
- output << Prawn::PdfObject(trailer_hash) << "\n"
119
- output << "startxref\n"
120
- output << @xref_offset << "\n"
121
- output << "%%EOF"
122
- end
123
-
124
- end
125
- end
126
- end