prawn 0.15.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/COPYING +2 -2
  2. data/LICENSE +1 -1
  3. data/README.md +96 -0
  4. data/Rakefile +27 -30
  5. data/data/fonts/Action Man.dfont +0 -0
  6. data/data/fonts/Activa.ttf +0 -0
  7. data/data/fonts/Chalkboard.ttf +0 -0
  8. data/data/fonts/DejaVuSans.ttf +0 -0
  9. data/data/fonts/Dustismo_Roman.ttf +0 -0
  10. data/data/fonts/comicsans.ttf +0 -0
  11. data/data/fonts/gkai00mp.ttf +0 -0
  12. data/data/images/16bit.alpha +0 -0
  13. data/data/images/16bit.dat +0 -0
  14. data/data/images/dice.alpha +0 -0
  15. data/data/images/dice.dat +0 -0
  16. data/data/images/page_white_text.alpha +0 -0
  17. data/data/images/page_white_text.dat +0 -0
  18. data/data/images/rails.dat +0 -0
  19. data/data/images/rails.png +0 -0
  20. data/data/pdfs/nested_pages.pdf +13 -13
  21. data/lib/prawn.rb +21 -85
  22. data/lib/prawn/compatibility.rb +51 -0
  23. data/lib/prawn/core.rb +85 -0
  24. data/lib/prawn/core/annotations.rb +61 -0
  25. data/lib/prawn/core/byte_string.rb +9 -0
  26. data/lib/prawn/core/destinations.rb +90 -0
  27. data/lib/prawn/core/document_state.rb +78 -0
  28. data/lib/prawn/core/literal_string.rb +16 -0
  29. data/lib/prawn/core/name_tree.rb +177 -0
  30. data/lib/prawn/core/object_store.rb +264 -0
  31. data/lib/prawn/core/page.rb +215 -0
  32. data/lib/prawn/core/pdf_object.rb +108 -0
  33. data/lib/prawn/core/reference.rb +115 -0
  34. data/lib/prawn/core/text.rb +268 -0
  35. data/lib/prawn/core/text/formatted/arranger.rb +294 -0
  36. data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
  37. data/lib/prawn/core/text/formatted/wrap.rb +153 -0
  38. data/lib/prawn/document.rb +122 -155
  39. data/lib/prawn/document/bounding_box.rb +7 -36
  40. data/lib/prawn/document/column_box.rb +10 -38
  41. data/lib/prawn/document/graphics_state.rb +74 -11
  42. data/lib/prawn/document/internals.rb +23 -24
  43. data/lib/prawn/document/page_geometry.rb +136 -0
  44. data/lib/prawn/document/snapshot.rb +6 -7
  45. data/lib/prawn/document/span.rb +10 -12
  46. data/lib/prawn/encoding.rb +10 -9
  47. data/lib/prawn/errors.rb +30 -15
  48. data/lib/prawn/font.rb +104 -136
  49. data/lib/prawn/font/afm.rb +44 -46
  50. data/lib/prawn/font/dfont.rb +3 -4
  51. data/lib/prawn/font/ttf.rb +50 -31
  52. data/lib/prawn/graphics.rb +57 -302
  53. data/lib/prawn/graphics/cap_style.rb +3 -4
  54. data/lib/prawn/graphics/color.rb +5 -13
  55. data/lib/prawn/graphics/dash.rb +31 -53
  56. data/lib/prawn/graphics/gradient.rb +84 -0
  57. data/lib/prawn/graphics/join_style.rb +7 -9
  58. data/lib/prawn/graphics/transformation.rb +9 -10
  59. data/lib/prawn/graphics/transparency.rb +1 -3
  60. data/lib/prawn/images.rb +59 -69
  61. data/lib/prawn/images/image.rb +22 -6
  62. data/lib/prawn/images/jpg.rb +14 -20
  63. data/lib/prawn/images/png.rb +118 -61
  64. data/lib/prawn/layout.rb +15 -10
  65. data/lib/prawn/layout/grid.rb +54 -66
  66. data/lib/prawn/measurement_extensions.rb +6 -10
  67. data/lib/prawn/measurements.rb +21 -27
  68. data/lib/prawn/outline.rb +308 -6
  69. data/lib/prawn/repeater.rb +8 -10
  70. data/lib/prawn/security.rb +33 -55
  71. data/lib/prawn/security/arcfour.rb +0 -1
  72. data/lib/prawn/stamp.rb +3 -5
  73. data/lib/prawn/table.rb +60 -188
  74. data/lib/prawn/table/cell.rb +44 -272
  75. data/lib/prawn/table/cell/image.rb +3 -2
  76. data/lib/prawn/table/cell/in_table.rb +2 -4
  77. data/lib/prawn/table/cell/subtable.rb +2 -2
  78. data/lib/prawn/table/cell/text.rb +18 -41
  79. data/lib/prawn/table/cells.rb +48 -142
  80. data/lib/prawn/text.rb +25 -32
  81. data/lib/prawn/text/box.rb +6 -12
  82. data/lib/prawn/text/formatted.rb +4 -5
  83. data/lib/prawn/text/formatted/box.rb +59 -96
  84. data/lib/prawn/text/formatted/fragment.rb +23 -34
  85. data/lib/prawn/text/formatted/parser.rb +5 -15
  86. data/prawn.gemspec +13 -24
  87. data/spec/annotations_spec.rb +32 -16
  88. data/spec/bounding_box_spec.rb +17 -119
  89. data/spec/cell_spec.rb +42 -112
  90. data/spec/destinations_spec.rb +5 -5
  91. data/spec/document_spec.rb +111 -155
  92. data/spec/extensions/mocha.rb +0 -1
  93. data/spec/font_spec.rb +99 -149
  94. data/spec/formatted_text_arranger_spec.rb +43 -43
  95. data/spec/formatted_text_box_spec.rb +44 -43
  96. data/spec/formatted_text_fragment_spec.rb +8 -8
  97. data/spec/graphics_spec.rb +68 -151
  98. data/spec/grid_spec.rb +15 -26
  99. data/spec/images_spec.rb +30 -51
  100. data/spec/inline_formatted_text_parser_spec.rb +20 -69
  101. data/spec/jpg_spec.rb +4 -4
  102. data/spec/line_wrap_spec.rb +28 -28
  103. data/spec/measurement_units_spec.rb +6 -6
  104. data/spec/name_tree_spec.rb +112 -0
  105. data/spec/object_store_spec.rb +106 -17
  106. data/spec/outline_spec.rb +63 -103
  107. data/spec/pdf_object_spec.rb +170 -0
  108. data/spec/png_spec.rb +25 -25
  109. data/spec/reference_spec.rb +65 -8
  110. data/spec/repeater_spec.rb +10 -10
  111. data/spec/security_spec.rb +12 -44
  112. data/spec/snapshot_spec.rb +7 -7
  113. data/spec/span_spec.rb +15 -10
  114. data/spec/spec_helper.rb +8 -32
  115. data/spec/stamp_spec.rb +30 -29
  116. data/spec/stroke_styles_spec.rb +18 -36
  117. data/spec/table_spec.rb +111 -706
  118. data/spec/template_spec.rb +297 -0
  119. data/spec/text_at_spec.rb +33 -19
  120. data/spec/text_box_spec.rb +64 -100
  121. data/spec/text_rendering_mode_spec.rb +5 -5
  122. data/spec/text_spacing_spec.rb +4 -4
  123. data/spec/text_spec.rb +64 -84
  124. data/spec/transparency_spec.rb +5 -5
  125. metadata +290 -463
  126. checksums.yaml +0 -7
  127. data/.yardopts +0 -10
  128. data/Gemfile +0 -11
  129. data/data/images/16bit.color +0 -0
  130. data/data/images/dice.color +0 -0
  131. data/data/images/indexed_color.dat +0 -0
  132. data/data/images/indexed_color.png +0 -0
  133. data/data/images/page_white_text.color +0 -0
  134. data/lib/prawn/font_metric_cache.rb +0 -47
  135. data/lib/prawn/graphics/patterns.rb +0 -138
  136. data/lib/prawn/image_handler.rb +0 -36
  137. data/lib/prawn/soft_mask.rb +0 -96
  138. data/lib/prawn/table/cell/span_dummy.rb +0 -93
  139. data/lib/prawn/table/column_width_calculator.rb +0 -61
  140. data/lib/prawn/text/formatted/arranger.rb +0 -290
  141. data/lib/prawn/text/formatted/line_wrap.rb +0 -266
  142. data/lib/prawn/text/formatted/wrap.rb +0 -150
  143. data/lib/prawn/utilities.rb +0 -46
  144. data/manual/basic_concepts/adding_pages.rb +0 -27
  145. data/manual/basic_concepts/basic_concepts.rb +0 -34
  146. data/manual/basic_concepts/creation.rb +0 -39
  147. data/manual/basic_concepts/cursor.rb +0 -33
  148. data/manual/basic_concepts/measurement.rb +0 -25
  149. data/manual/basic_concepts/origin.rb +0 -38
  150. data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
  151. data/manual/bounding_box/bounding_box.rb +0 -39
  152. data/manual/bounding_box/bounds.rb +0 -49
  153. data/manual/bounding_box/canvas.rb +0 -24
  154. data/manual/bounding_box/creation.rb +0 -23
  155. data/manual/bounding_box/indentation.rb +0 -46
  156. data/manual/bounding_box/nesting.rb +0 -45
  157. data/manual/bounding_box/russian_boxes.rb +0 -40
  158. data/manual/bounding_box/stretchy.rb +0 -31
  159. data/manual/document_and_page_options/background.rb +0 -27
  160. data/manual/document_and_page_options/document_and_page_options.rb +0 -32
  161. data/manual/document_and_page_options/metadata.rb +0 -23
  162. data/manual/document_and_page_options/page_margins.rb +0 -38
  163. data/manual/document_and_page_options/page_size.rb +0 -34
  164. data/manual/document_and_page_options/print_scaling.rb +0 -20
  165. data/manual/example_file.rb +0 -111
  166. data/manual/example_helper.rb +0 -411
  167. data/manual/example_package.rb +0 -53
  168. data/manual/example_section.rb +0 -46
  169. data/manual/graphics/circle_and_ellipse.rb +0 -22
  170. data/manual/graphics/color.rb +0 -24
  171. data/manual/graphics/common_lines.rb +0 -30
  172. data/manual/graphics/fill_and_stroke.rb +0 -42
  173. data/manual/graphics/fill_rules.rb +0 -37
  174. data/manual/graphics/gradients.rb +0 -37
  175. data/manual/graphics/graphics.rb +0 -58
  176. data/manual/graphics/helper.rb +0 -24
  177. data/manual/graphics/line_width.rb +0 -35
  178. data/manual/graphics/lines_and_curves.rb +0 -41
  179. data/manual/graphics/polygon.rb +0 -29
  180. data/manual/graphics/rectangle.rb +0 -21
  181. data/manual/graphics/rotate.rb +0 -28
  182. data/manual/graphics/scale.rb +0 -41
  183. data/manual/graphics/soft_masks.rb +0 -46
  184. data/manual/graphics/stroke_cap.rb +0 -31
  185. data/manual/graphics/stroke_dash.rb +0 -48
  186. data/manual/graphics/stroke_join.rb +0 -30
  187. data/manual/graphics/translate.rb +0 -29
  188. data/manual/graphics/transparency.rb +0 -35
  189. data/manual/images/absolute_position.rb +0 -23
  190. data/manual/images/fit.rb +0 -21
  191. data/manual/images/horizontal.rb +0 -25
  192. data/manual/images/images.rb +0 -40
  193. data/manual/images/plain_image.rb +0 -18
  194. data/manual/images/scale.rb +0 -22
  195. data/manual/images/vertical.rb +0 -28
  196. data/manual/images/width_and_height.rb +0 -25
  197. data/manual/layout/boxes.rb +0 -27
  198. data/manual/layout/content.rb +0 -25
  199. data/manual/layout/layout.rb +0 -28
  200. data/manual/layout/simple_grid.rb +0 -23
  201. data/manual/manual/cover.rb +0 -36
  202. data/manual/manual/foreword.rb +0 -85
  203. data/manual/manual/how_to_read_this_manual.rb +0 -41
  204. data/manual/manual/manual.rb +0 -34
  205. data/manual/outline/add_subsection_to.rb +0 -61
  206. data/manual/outline/insert_section_after.rb +0 -47
  207. data/manual/outline/outline.rb +0 -32
  208. data/manual/outline/sections_and_pages.rb +0 -67
  209. data/manual/repeatable_content/page_numbering.rb +0 -54
  210. data/manual/repeatable_content/repeatable_content.rb +0 -31
  211. data/manual/repeatable_content/repeater.rb +0 -55
  212. data/manual/repeatable_content/stamp.rb +0 -41
  213. data/manual/security/encryption.rb +0 -31
  214. data/manual/security/permissions.rb +0 -38
  215. data/manual/security/security.rb +0 -28
  216. data/manual/syntax_highlight.rb +0 -52
  217. data/manual/table/basic_block.rb +0 -53
  218. data/manual/table/before_rendering_page.rb +0 -26
  219. data/manual/table/cell_border_lines.rb +0 -24
  220. data/manual/table/cell_borders_and_bg.rb +0 -31
  221. data/manual/table/cell_dimensions.rb +0 -30
  222. data/manual/table/cell_text.rb +0 -38
  223. data/manual/table/column_widths.rb +0 -30
  224. data/manual/table/content_and_subtables.rb +0 -39
  225. data/manual/table/creation.rb +0 -27
  226. data/manual/table/filtering.rb +0 -36
  227. data/manual/table/flow_and_header.rb +0 -17
  228. data/manual/table/image_cells.rb +0 -33
  229. data/manual/table/position.rb +0 -29
  230. data/manual/table/row_colors.rb +0 -20
  231. data/manual/table/span.rb +0 -30
  232. data/manual/table/style.rb +0 -22
  233. data/manual/table/table.rb +0 -52
  234. data/manual/table/width.rb +0 -27
  235. data/manual/text/alignment.rb +0 -44
  236. data/manual/text/color.rb +0 -24
  237. data/manual/text/column_box.rb +0 -32
  238. data/manual/text/fallback_fonts.rb +0 -37
  239. data/manual/text/font.rb +0 -41
  240. data/manual/text/font_size.rb +0 -45
  241. data/manual/text/font_style.rb +0 -23
  242. data/manual/text/formatted_callbacks.rb +0 -60
  243. data/manual/text/formatted_text.rb +0 -54
  244. data/manual/text/free_flowing_text.rb +0 -51
  245. data/manual/text/group.rb +0 -31
  246. data/manual/text/inline.rb +0 -43
  247. data/manual/text/kerning_and_character_spacing.rb +0 -39
  248. data/manual/text/leading.rb +0 -25
  249. data/manual/text/line_wrapping.rb +0 -41
  250. data/manual/text/paragraph_indentation.rb +0 -26
  251. data/manual/text/positioned_text.rb +0 -38
  252. data/manual/text/registering_families.rb +0 -48
  253. data/manual/text/rendering_and_color.rb +0 -37
  254. data/manual/text/right_to_left_text.rb +0 -43
  255. data/manual/text/rotation.rb +0 -43
  256. data/manual/text/single_usage.rb +0 -37
  257. data/manual/text/text.rb +0 -75
  258. data/manual/text/text_box_excess.rb +0 -32
  259. data/manual/text/text_box_extensions.rb +0 -45
  260. data/manual/text/text_box_overflow.rb +0 -44
  261. data/manual/text/utf8.rb +0 -28
  262. data/manual/text/win_ansi_charset.rb +0 -59
  263. data/spec/acceptance/png.rb +0 -23
  264. data/spec/column_box_spec.rb +0 -65
  265. data/spec/extensions/encoding_helpers.rb +0 -9
  266. data/spec/font_metric_cache_spec.rb +0 -52
  267. data/spec/image_handler_spec.rb +0 -54
  268. data/spec/soft_mask_spec.rb +0 -117
  269. data/spec/table/span_dummy_spec.rb +0 -17
@@ -8,7 +8,6 @@
8
8
 
9
9
  module Prawn
10
10
  class Document
11
- # @group Stable API
12
11
 
13
12
  # :call-seq:
14
13
  # bounding_box(point, options={}, &block)
@@ -155,10 +154,10 @@ module Prawn
155
154
  # Of course, if you use canvas, you will be responsible for ensuring that
156
155
  # you remain within the printable area of your document.
157
156
  #
158
- def bounding_box(pt, *args, &block)
157
+ def bounding_box(*args, &block)
159
158
  init_bounding_box(block) do |parent_box|
160
- pt = map_to_absolute(pt)
161
- @bounding_box = BoundingBox.new(self, parent_box, pt, *args)
159
+ map_to_absolute!(args[0])
160
+ @bounding_box = BoundingBox.new(self, parent_box, *args)
162
161
  end
163
162
  end
164
163
 
@@ -189,21 +188,10 @@ module Prawn
189
188
 
190
189
  parent_box = @bounding_box
191
190
 
192
- original_ypos = y
193
-
194
191
  init_block.call(parent_box)
195
192
 
196
193
  self.y = @bounding_box.absolute_top
197
194
  user_block.call
198
-
199
- # If the user actions did not modify the y position
200
- # restore the original y position before the bounding
201
- # box was created.
202
-
203
- if y == @bounding_box.absolute_top
204
- self.y = original_ypos
205
- end
206
-
207
195
  unless options[:hold_position] || @bounding_box.stretchy?
208
196
  self.y = @bounding_box.absolute_bottom
209
197
  end
@@ -220,7 +208,7 @@ module Prawn
220
208
  #
221
209
  class BoundingBox
222
210
 
223
- def initialize(document, parent, point, options={}) # @private
211
+ def initialize(document, parent, point, options={}) #:nodoc:
224
212
  unless options[:width]
225
213
  raise ArgumentError, "BoundingBox needs the :width option to be set"
226
214
  end
@@ -234,22 +222,15 @@ module Prawn
234
222
  @stretched_height = nil
235
223
  end
236
224
 
237
- # @private
238
-
239
225
  attr_reader :document, :parent
240
-
241
- # @private
242
226
  # The current indentation of the left side of the bounding box.
243
227
  attr_reader :total_left_padding
244
-
245
- # @private
246
228
  # The current indentation of the right side of the bounding box.
247
229
  attr_reader :total_right_padding
248
230
 
249
231
  # The translated origin (x,y-height) which describes the location
250
232
  # of the bottom left corner of the bounding box
251
233
  #
252
- # @private
253
234
  def anchor
254
235
  [@x, @y - height]
255
236
  end
@@ -280,7 +261,6 @@ module Prawn
280
261
  # text "indented on both sides"
281
262
  # end
282
263
  #
283
- # @private
284
264
  def indent(left_padding, right_padding = 0, &block)
285
265
  add_left_padding(left_padding)
286
266
  add_right_padding(right_padding)
@@ -291,7 +271,6 @@ module Prawn
291
271
  end
292
272
 
293
273
  # Increase the left padding of the bounding box.
294
- # @private
295
274
  def add_left_padding(left_padding)
296
275
  @total_left_padding += left_padding
297
276
  @x += left_padding
@@ -299,7 +278,6 @@ module Prawn
299
278
  end
300
279
 
301
280
  # Decrease the left padding of the bounding box.
302
- # @private
303
281
  def subtract_left_padding(left_padding)
304
282
  @total_left_padding -= left_padding
305
283
  @x -= left_padding
@@ -307,14 +285,12 @@ module Prawn
307
285
  end
308
286
 
309
287
  # Increase the right padding of the bounding box.
310
- # @private
311
288
  def add_right_padding(right_padding)
312
289
  @total_right_padding += right_padding
313
290
  @width -= right_padding
314
291
  end
315
292
 
316
293
  # Decrease the right padding of the bounding box.
317
- # @private
318
294
  def subtract_right_padding(right_padding)
319
295
  @total_right_padding -= right_padding
320
296
  @width += right_padding
@@ -465,19 +441,15 @@ module Prawn
465
441
  end
466
442
 
467
443
  # an alias for absolute_left
468
- # @private
469
444
  def left_side
470
445
  absolute_left
471
446
  end
472
447
 
473
448
  # an alias for absolute_right
474
- # @private
475
449
  def right_side
476
450
  absolute_right
477
451
  end
478
452
 
479
- # @group Extension API
480
-
481
453
  # Moves to the top of the next page of the document, starting a new page
482
454
  # if necessary.
483
455
  #
@@ -489,6 +461,9 @@ module Prawn
489
461
  end
490
462
  end
491
463
 
464
+
465
+ alias_method :update_height, :height
466
+
492
467
  # Returns +false+ when the box has a defined height, +true+ when the height
493
468
  # is being calculated on the fly based on the current vertical position.
494
469
  #
@@ -507,12 +482,9 @@ module Prawn
507
482
  end
508
483
  end
509
484
 
510
- alias_method :update_height, :height
511
-
512
485
  # Returns a deep copy of these bounds (including all parent bounds but
513
486
  # not copying the reference to the Document).
514
487
  #
515
- # @private
516
488
  def deep_copy
517
489
  copy = dup
518
490
  # Deep-copy the parent bounds
@@ -527,7 +499,6 @@ module Prawn
527
499
  # context of the given +document+. Does *not* set the bounds of the
528
500
  # document to the resulting BoundingBox, only returns it.
529
501
  #
530
- # @private
531
502
  def self.restore_deep_copy(bounds, document)
532
503
  bounds.instance_variable_set("@document", document)
533
504
  bounds
@@ -4,28 +4,22 @@
4
4
  #
5
5
  # Author Paul Ostazeski.
6
6
 
7
- require_relative "bounding_box"
8
-
7
+ require "prawn/document/bounding_box"
9
8
  module Prawn
10
9
  class Document
11
10
 
12
- # @group Experimental API
13
-
14
11
  # A column box is a bounding box with the additional property that when
15
12
  # text flows past the bottom, it will wrap first to another column on the
16
13
  # same page, and only flow to the next page when all the columns are
17
14
  # filled.
18
15
  #
19
16
  # column_box accepts the same parameters as bounding_box, as well as the
20
- # number of :columns and a :spacer (in points) between columns. If resetting
21
- # the top margin is desired on a new page (e.g. to allow for initial page
22
- # wide column titles) the option :reflow_margins => true can be set.
17
+ # number of :columns and a :spacer (in points) between columns.
23
18
  #
24
- # Defaults are :columns = 3, :spacer = font_size, and
25
- # :reflow_margins => false
19
+ # Defaults are :columns = 3 and :spacer = font_size
26
20
  #
27
21
  # Under PDF::Writer, "spacer" was known as "gutter"
28
- #
22
+ #
29
23
  def column_box(*args, &block)
30
24
  init_column_box(block) do |parent_box|
31
25
  map_to_absolute!(args[0])
@@ -46,7 +40,7 @@ module Prawn
46
40
 
47
41
  @bounding_box = parent_box
48
42
  end
49
-
43
+
50
44
  # Implements the necessary functionality to allow Document#column_box to
51
45
  # work.
52
46
  #
@@ -57,26 +51,19 @@ module Prawn
57
51
  @columns = options[:columns] || 3
58
52
  @spacer = options[:spacer] || @document.font_size
59
53
  @current_column = 0
60
- @reflow_margins = options[:reflow_margins]
61
- end
62
-
63
- # The column width, not the width of the whole box,
64
- # before left and/or right padding
65
- def bare_column_width
66
- (@width - @spacer * (@columns - 1)) / @columns
67
54
  end
68
55
 
69
- # The column width after padding.
70
- # Used to calculate how long a line of text can be.
56
+ # The column width, not the width of the whole box. Used to calculate
57
+ # how long a line of text can be.
71
58
  #
72
59
  def width
73
- bare_column_width - (@total_left_padding + @total_right_padding)
60
+ super / @columns - @spacer - @total_left_padding - @total_right_padding
74
61
  end
75
62
 
76
63
  # Column width including the spacer.
77
64
  #
78
65
  def width_of_column
79
- bare_column_width + @spacer
66
+ width + @spacer
80
67
  end
81
68
 
82
69
  # x coordinate of the left edge of the current column
@@ -85,12 +72,6 @@ module Prawn
85
72
  absolute_left + (width_of_column * @current_column)
86
73
  end
87
74
 
88
- # Relative position of the left edge of the current column
89
- #
90
- def left
91
- width_of_column * @current_column
92
- end
93
-
94
75
  # x co-orordinate of the right edge of the current column
95
76
  #
96
77
  def right_side
@@ -98,21 +79,12 @@ module Prawn
98
79
  absolute_right - (width_of_column * columns_from_right)
99
80
  end
100
81
 
101
- # Relative position of the right edge of the current column.
102
- #
103
- def right
104
- left + width
105
- end
106
-
107
82
  # Moves to the next column or starts a new page if currently positioned at
108
83
  # the rightmost column.
109
- def move_past_bottom
84
+ def move_past_bottom
110
85
  @current_column = (@current_column + 1) % @columns
111
86
  @document.y = @y
112
87
  if 0 == @current_column
113
- if @reflow_margins
114
- @y = @parent.absolute_top
115
- end
116
88
  @document.start_new_page
117
89
  end
118
90
  end
@@ -8,8 +8,71 @@
8
8
  #
9
9
 
10
10
  module Prawn
11
+ class GraphicStateStack
12
+ attr_accessor :stack
13
+
14
+ def initialize(previous_state = nil)
15
+ self.stack = [GraphicState.new(previous_state)]
16
+ end
17
+
18
+ def save_graphic_state(graphic_state = nil)
19
+ stack.push(GraphicState.new(graphic_state || current_state))
20
+ end
21
+
22
+ def restore_graphic_state
23
+ if stack.empty?
24
+ raise Prawn::Errors::EmptyGraphicStateStack,
25
+ "\n You have reached the end of the graphic state stack"
26
+ end
27
+ stack.pop
28
+ end
29
+
30
+ def current_state
31
+ stack.last
32
+ end
33
+
34
+ def present?
35
+ stack.size > 0
36
+ end
37
+
38
+ def empty?
39
+ stack.empty?
40
+ end
41
+
42
+ end
43
+
44
+ class GraphicState
45
+ attr_accessor :color_space, :dash, :cap_style, :join_style, :line_width, :fill_color, :stroke_color
46
+
47
+ def initialize(previous_state = nil)
48
+ @color_space = previous_state ? previous_state.color_space.dup : {}
49
+ @fill_color = previous_state ? previous_state.fill_color : "000000"
50
+ @stroke_color = previous_state ? previous_state.stroke_color : "000000"
51
+ @dash = previous_state ? previous_state.dash : { :dash => nil, :space => nil, :phase => 0 }
52
+ @cap_style = previous_state ? previous_state.cap_style : :butt
53
+ @join_style = previous_state ? previous_state.join_style : :miter
54
+ @line_width = previous_state ? previous_state.line_width : 1
55
+ end
56
+
57
+ def dash_setting
58
+ "[#{@dash[:dash]} #{@dash[:space]}] #{@dash[:phase]} d"
59
+ end
60
+ end
61
+
62
+ module Core
63
+ class Page
64
+ module GraphicsState
65
+
66
+ def graphic_state
67
+ stack.current_state
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+
11
74
  class Document
12
- module GraphicsState # @private
75
+ module GraphicsState
13
76
 
14
77
  # Pushes the current graphics state on to the graphics state stack so we
15
78
  # can restore it when finished with a change we want to isolate (such as
@@ -30,15 +93,15 @@ module Prawn
30
93
  # text "rotated text"
31
94
  # end
32
95
  #
33
-
96
+
34
97
  def open_graphics_state
35
98
  add_content "q"
36
99
  end
37
-
100
+
38
101
  def close_graphics_state
39
102
  add_content "Q"
40
103
  end
41
-
104
+
42
105
  def save_graphics_state(graphic_state = nil)
43
106
  graphic_stack.save_graphic_state(graphic_state)
44
107
  open_graphics_state
@@ -52,22 +115,22 @@ module Prawn
52
115
  # restores the state to those values
53
116
  def restore_graphics_state
54
117
  if graphic_stack.empty?
55
- raise PDF::Core::Errors::EmptyGraphicStateStack,
56
- "\n You have reached the end of the graphic state stack"
118
+ raise Prawn::Errors::EmptyGraphicStateStack,
119
+ "\n You have reached the end of the graphic state stack"
57
120
  end
58
- close_graphics_state
121
+ close_graphics_state
59
122
  graphic_stack.restore_graphic_state
60
123
  end
61
-
124
+
62
125
  def graphic_stack
63
126
  state.page.stack
64
127
  end
65
-
128
+
66
129
  def graphic_state
67
130
  save_graphics_state unless graphic_stack.current_state
68
- graphic_stack.current_state
131
+ graphic_stack.current_state
69
132
  end
70
-
133
+
71
134
  end
72
135
  end
73
136
  end
@@ -7,26 +7,26 @@
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
9
  module Prawn
10
- class Document
11
-
10
+ class Document
11
+
12
12
  # This module exposes a few low-level PDF features for those who want
13
13
  # to extend Prawn's core functionality. If you are not comfortable with
14
14
  # low level PDF functionality as defined by Adobe's specification, chances
15
- # are you won't need anything you find here.
15
+ # are you won't need anything you find here.
16
16
  #
17
- # @private
18
- module Internals
17
+ module Internals
18
+
19
19
  # Creates a new Prawn::Reference and adds it to the Document's object
20
- # list. The +data+ argument is anything that Prawn::PdfObject() can convert.
21
- #
22
- # Returns the identifier which points to the reference in the ObjectStore
20
+ # list. The +data+ argument is anything that Prawn::PdfObject() can convert.
23
21
  #
22
+ # Returns the identifier which points to the reference in the ObjectStore
23
+ #
24
24
  def ref(data)
25
25
  ref!(data).identifier
26
- end
26
+ end
27
27
 
28
28
  # Like ref, but returns the actual reference instead of its identifier.
29
- #
29
+ #
30
30
  # While you can use this to build up nested references within the object
31
31
  # tree, it is recommended to persist only identifiers, and them provide
32
32
  # helper methods to look up the actual references in the ObjectStore
@@ -42,21 +42,21 @@ module Prawn
42
42
  # of if it's hidden behind a Prawn::Reference, wrap it in deref().
43
43
  #
44
44
  def deref(obj)
45
- obj.is_a?(PDF::Core::Reference) ? obj.data : obj
45
+ obj.is_a?(Prawn::Core::Reference) ? obj.data : obj
46
46
  end
47
47
 
48
48
  # Appends a raw string to the current page content.
49
- #
50
- # # Raw line drawing example:
49
+ #
50
+ # # Raw line drawing example:
51
51
  # x1,y1,x2,y2 = 100,500,300,550
52
- # pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move
52
+ # pdf.add_content("%.3f %.3f m" % [ x1, y1 ]) # move
53
53
  # pdf.add_content("%.3f %.3f l" % [ x2, y2 ]) # draw path
54
- # pdf.add_content("S") # stroke
54
+ # pdf.add_content("S") # stroke
55
55
  #
56
56
  def add_content(str)
57
57
  save_graphics_state if graphic_state.nil?
58
58
  state.page.content << str << "\n"
59
- end
59
+ end
60
60
 
61
61
  # The Name dictionary (PDF spec 3.6.3) for this document. It is
62
62
  # lazily initialized, so that documents that do not need a name
@@ -67,7 +67,7 @@ module Prawn
67
67
  end
68
68
 
69
69
  # Returns true if the Names dictionary is in use for this document.
70
- #
70
+ #
71
71
  def names?
72
72
  state.store.root.data[:Names]
73
73
  end
@@ -87,8 +87,8 @@ module Prawn
87
87
  state.on_page_create_callback = nil
88
88
  end
89
89
  end
90
-
91
- private
90
+
91
+ private
92
92
 
93
93
  # adds a new, empty content stream to each page. Used in templating so
94
94
  # that imported content streams can be left pristine
@@ -100,7 +100,6 @@ module Prawn
100
100
  apply_margin_options(options)
101
101
  generate_margin_box
102
102
  use_graphic_settings(options[:template])
103
- forget_text_rendering_mode!
104
103
  end
105
104
  end
106
105
 
@@ -157,18 +156,18 @@ module Prawn
157
156
  # Write out the PDF Trailer, as per spec 3.4.4
158
157
  #
159
158
  def render_trailer(output)
160
- trailer_hash = {:Size => state.store.size + 1,
159
+ trailer_hash = {:Size => state.store.size + 1,
161
160
  :Root => state.store.root,
162
161
  :Info => state.store.info}
163
162
  trailer_hash.merge!(state.trailer) if state.trailer
164
163
 
165
164
  output << "trailer\n"
166
- output << PDF::Core::PdfObject(trailer_hash) << "\n"
167
- output << "startxref\n"
165
+ output << Prawn::Core::PdfObject(trailer_hash) << "\n"
166
+ output << "startxref\n"
168
167
  output << @xref_offset << "\n"
169
168
  output << "%%EOF" << "\n"
170
169
  end
171
-
170
+
172
171
  end
173
172
  end
174
173
  end