prawn 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Gemfile +1 -9
  5. data/Rakefile +12 -22
  6. data/lib/prawn.rb +29 -48
  7. data/lib/prawn/document.rb +148 -123
  8. data/lib/prawn/document/bounding_box.rb +33 -26
  9. data/lib/prawn/document/column_box.rb +5 -7
  10. data/lib/prawn/document/internals.rb +6 -6
  11. data/lib/prawn/document/span.rb +20 -17
  12. data/lib/prawn/encoding.rb +65 -67
  13. data/lib/prawn/errors.rb +10 -7
  14. data/lib/prawn/font.rb +78 -62
  15. data/lib/prawn/font/afm.rb +93 -66
  16. data/lib/prawn/font/dfont.rb +2 -10
  17. data/lib/prawn/font/ttc.rb +34 -0
  18. data/lib/prawn/font/ttf.rb +73 -65
  19. data/lib/prawn/font_metric_cache.rb +9 -8
  20. data/lib/prawn/graphics.rb +110 -70
  21. data/lib/prawn/graphics/blend_mode.rb +7 -8
  22. data/lib/prawn/graphics/cap_style.rb +2 -4
  23. data/lib/prawn/graphics/color.rb +23 -26
  24. data/lib/prawn/graphics/dash.rb +22 -12
  25. data/lib/prawn/graphics/join_style.rb +8 -4
  26. data/lib/prawn/graphics/patterns.rb +185 -96
  27. data/lib/prawn/graphics/transformation.rb +11 -9
  28. data/lib/prawn/graphics/transparency.rb +15 -13
  29. data/lib/prawn/grid.rb +20 -20
  30. data/lib/prawn/image_handler.rb +4 -6
  31. data/lib/prawn/images.rb +22 -15
  32. data/lib/prawn/images/image.rb +0 -1
  33. data/lib/prawn/images/jpg.rb +26 -22
  34. data/lib/prawn/images/png.rb +60 -57
  35. data/lib/prawn/measurement_extensions.rb +8 -9
  36. data/lib/prawn/measurements.rb +14 -15
  37. data/lib/prawn/outline.rb +96 -78
  38. data/lib/prawn/repeater.rb +12 -10
  39. data/lib/prawn/security.rb +66 -48
  40. data/lib/prawn/security/arcfour.rb +1 -3
  41. data/lib/prawn/soft_mask.rb +23 -25
  42. data/lib/prawn/stamp.rb +16 -12
  43. data/lib/prawn/text.rb +59 -45
  44. data/lib/prawn/text/box.rb +9 -8
  45. data/lib/prawn/text/formatted.rb +4 -6
  46. data/lib/prawn/text/formatted/arranger.rb +51 -30
  47. data/lib/prawn/text/formatted/box.rb +112 -88
  48. data/lib/prawn/text/formatted/fragment.rb +10 -15
  49. data/lib/prawn/text/formatted/line_wrap.rb +118 -61
  50. data/lib/prawn/text/formatted/parser.rb +134 -110
  51. data/lib/prawn/text/formatted/wrap.rb +42 -32
  52. data/lib/prawn/transformation_stack.rb +3 -4
  53. data/lib/prawn/utilities.rb +6 -21
  54. data/lib/prawn/version.rb +1 -3
  55. data/lib/prawn/view.rb +4 -2
  56. data/manual/basic_concepts/adding_pages.rb +4 -7
  57. data/manual/basic_concepts/basic_concepts.rb +29 -22
  58. data/manual/basic_concepts/creation.rb +8 -11
  59. data/manual/basic_concepts/cursor.rb +2 -5
  60. data/manual/basic_concepts/measurement.rb +3 -6
  61. data/manual/basic_concepts/origin.rb +3 -6
  62. data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
  63. data/manual/basic_concepts/view.rb +20 -16
  64. data/manual/bounding_box/bounding_box.rb +27 -24
  65. data/manual/bounding_box/bounds.rb +9 -12
  66. data/manual/bounding_box/canvas.rb +2 -5
  67. data/manual/bounding_box/creation.rb +4 -7
  68. data/manual/bounding_box/indentation.rb +12 -15
  69. data/manual/bounding_box/nesting.rb +22 -17
  70. data/manual/bounding_box/russian_boxes.rb +8 -9
  71. data/manual/bounding_box/stretchy.rb +10 -13
  72. data/manual/contents.rb +26 -22
  73. data/manual/cover.rb +22 -20
  74. data/manual/document_and_page_options/background.rb +9 -13
  75. data/manual/document_and_page_options/document_and_page_options.rb +23 -20
  76. data/manual/document_and_page_options/metadata.rb +16 -16
  77. data/manual/document_and_page_options/page_margins.rb +16 -20
  78. data/manual/document_and_page_options/page_size.rb +11 -12
  79. data/manual/document_and_page_options/print_scaling.rb +15 -15
  80. data/manual/example_helper.rb +2 -4
  81. data/manual/graphics/blend_mode.rb +10 -9
  82. data/manual/graphics/circle_and_ellipse.rb +2 -5
  83. data/manual/graphics/color.rb +5 -9
  84. data/manual/graphics/common_lines.rb +5 -8
  85. data/manual/graphics/fill_and_stroke.rb +2 -5
  86. data/manual/graphics/fill_rules.rb +7 -10
  87. data/manual/graphics/gradients.rb +25 -21
  88. data/manual/graphics/graphics.rb +49 -43
  89. data/manual/graphics/helper.rb +10 -9
  90. data/manual/graphics/line_width.rb +5 -7
  91. data/manual/graphics/lines_and_curves.rb +5 -8
  92. data/manual/graphics/polygon.rb +4 -8
  93. data/manual/graphics/rectangle.rb +2 -5
  94. data/manual/graphics/rotate.rb +4 -7
  95. data/manual/graphics/scale.rb +12 -15
  96. data/manual/graphics/soft_masks.rb +1 -4
  97. data/manual/graphics/stroke_cap.rb +3 -6
  98. data/manual/graphics/stroke_dash.rb +9 -12
  99. data/manual/graphics/stroke_join.rb +2 -5
  100. data/manual/graphics/translate.rb +7 -10
  101. data/manual/graphics/transparency.rb +5 -8
  102. data/manual/how_to_read_this_manual.rb +4 -6
  103. data/manual/images/absolute_position.rb +4 -7
  104. data/manual/images/fit.rb +5 -8
  105. data/manual/images/horizontal.rb +6 -9
  106. data/manual/images/images.rb +25 -23
  107. data/manual/images/plain_image.rb +3 -6
  108. data/manual/images/scale.rb +7 -10
  109. data/manual/images/vertical.rb +10 -13
  110. data/manual/images/width_and_height.rb +8 -11
  111. data/manual/layout/boxes.rb +3 -6
  112. data/manual/layout/content.rb +5 -8
  113. data/manual/layout/layout.rb +16 -16
  114. data/manual/layout/simple_grid.rb +4 -7
  115. data/manual/outline/add_subsection_to.rb +18 -21
  116. data/manual/outline/insert_section_after.rb +13 -16
  117. data/manual/outline/outline.rb +19 -17
  118. data/manual/outline/sections_and_pages.rb +15 -18
  119. data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
  120. data/manual/repeatable_content/page_numbering.rb +15 -16
  121. data/manual/repeatable_content/repeatable_content.rb +23 -19
  122. data/manual/repeatable_content/repeater.rb +12 -15
  123. data/manual/repeatable_content/stamp.rb +12 -15
  124. data/manual/security/encryption.rb +7 -10
  125. data/manual/security/permissions.rb +17 -14
  126. data/manual/security/security.rb +17 -16
  127. data/manual/table.rb +2 -4
  128. data/manual/text/alignment.rb +14 -17
  129. data/manual/text/color.rb +10 -11
  130. data/manual/text/column_box.rb +5 -8
  131. data/manual/text/fallback_fonts.rb +23 -21
  132. data/manual/text/font.rb +9 -12
  133. data/manual/text/font_size.rb +11 -14
  134. data/manual/text/font_style.rb +4 -7
  135. data/manual/text/formatted_callbacks.rb +23 -21
  136. data/manual/text/formatted_text.rb +31 -25
  137. data/manual/text/free_flowing_text.rb +18 -21
  138. data/manual/text/inline.rb +16 -19
  139. data/manual/text/kerning_and_character_spacing.rb +12 -15
  140. data/manual/text/leading.rb +5 -8
  141. data/manual/text/line_wrapping.rb +33 -17
  142. data/manual/text/paragraph_indentation.rb +11 -14
  143. data/manual/text/positioned_text.rb +13 -16
  144. data/manual/text/registering_families.rb +16 -19
  145. data/manual/text/rendering_and_color.rb +7 -10
  146. data/manual/text/right_to_left_text.rb +24 -19
  147. data/manual/text/rotation.rb +26 -23
  148. data/manual/text/single_usage.rb +6 -9
  149. data/manual/text/text.rb +56 -52
  150. data/manual/text/text_box_excess.rb +18 -17
  151. data/manual/text/text_box_extensions.rb +16 -15
  152. data/manual/text/text_box_overflow.rb +15 -18
  153. data/manual/text/utf8.rb +9 -12
  154. data/manual/text/win_ansi_charset.rb +18 -19
  155. data/prawn.gemspec +37 -27
  156. data/spec/extensions/encoding_helpers.rb +0 -2
  157. data/spec/manual_spec.rb +33 -0
  158. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  159. data/spec/prawn/document/column_box_spec.rb +73 -0
  160. data/spec/prawn/document/security_spec.rb +173 -0
  161. data/spec/prawn/document_annotations_spec.rb +74 -0
  162. data/spec/prawn/document_destinations_spec.rb +13 -0
  163. data/spec/prawn/document_grid_spec.rb +96 -0
  164. data/spec/prawn/document_reference_spec.rb +25 -0
  165. data/spec/prawn/document_span_spec.rb +34 -0
  166. data/spec/prawn/document_spec.rb +751 -0
  167. data/spec/prawn/font_metric_cache_spec.rb +52 -0
  168. data/spec/prawn/font_spec.rb +513 -0
  169. data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
  170. data/spec/prawn/graphics/transparency_spec.rb +79 -0
  171. data/spec/prawn/graphics_spec.rb +817 -0
  172. data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
  173. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
  174. data/spec/prawn/images/jpg_spec.rb +18 -0
  175. data/spec/prawn/images/png_spec.rb +281 -0
  176. data/spec/prawn/images_spec.rb +170 -0
  177. data/spec/prawn/measurements_extensions_spec.rb +22 -0
  178. data/spec/prawn/outline_spec.rb +408 -0
  179. data/spec/prawn/repeater_spec.rb +163 -0
  180. data/spec/prawn/soft_mask_spec.rb +72 -0
  181. data/spec/prawn/stamp_spec.rb +168 -0
  182. data/spec/prawn/text/box_spec.rb +1113 -0
  183. data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
  184. data/spec/prawn/text/formatted/box_spec.rb +825 -0
  185. data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
  186. data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
  187. data/spec/prawn/text/formatted/parser_spec.rb +667 -0
  188. data/spec/prawn/text_draw_text_spec.rb +147 -0
  189. data/spec/prawn/text_rendering_mode_spec.rb +42 -0
  190. data/spec/prawn/text_spacing_spec.rb +93 -0
  191. data/spec/prawn/text_spec.rb +601 -0
  192. data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
  193. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
  194. data/spec/prawn/view_spec.rb +45 -0
  195. data/spec/spec_helper.rb +16 -16
  196. metadata +96 -151
  197. metadata.gz.sig +1 -0
  198. data/data/images/16bit.alpha +0 -0
  199. data/data/images/16bit.color +0 -0
  200. data/data/images/16bit.png +0 -0
  201. data/data/images/arrow.png +0 -0
  202. data/data/images/arrow2.png +0 -0
  203. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  204. data/data/images/blend_modes_top_layer.jpg +0 -0
  205. data/data/images/dice.alpha +0 -0
  206. data/data/images/dice.color +0 -0
  207. data/data/images/dice.png +0 -0
  208. data/data/images/dice_interlaced.png +0 -0
  209. data/data/images/fractal.jpg +0 -0
  210. data/data/images/indexed_color.dat +0 -0
  211. data/data/images/indexed_color.png +0 -0
  212. data/data/images/indexed_transparency.png +0 -0
  213. data/data/images/indexed_transparency_alpha.dat +0 -0
  214. data/data/images/indexed_transparency_color.dat +0 -0
  215. data/data/images/letterhead.jpg +0 -0
  216. data/data/images/license.md +0 -8
  217. data/data/images/page_white_text.alpha +0 -0
  218. data/data/images/page_white_text.color +0 -0
  219. data/data/images/page_white_text.png +0 -0
  220. data/data/images/pigs.jpg +0 -0
  221. data/data/images/prawn.png +0 -0
  222. data/data/images/ruport.png +0 -0
  223. data/data/images/ruport_data.dat +0 -0
  224. data/data/images/ruport_transparent.png +0 -0
  225. data/data/images/ruport_type0.png +0 -0
  226. data/data/images/stef.jpg +0 -0
  227. data/data/images/tru256.bmp +0 -0
  228. data/data/images/web-links.dat +0 -1
  229. data/data/images/web-links.png +0 -0
  230. data/data/pdfs/complex_template.pdf +0 -0
  231. data/data/pdfs/contains_ttf_font.pdf +0 -0
  232. data/data/pdfs/encrypted.pdf +0 -0
  233. data/data/pdfs/form.pdf +1 -819
  234. data/data/pdfs/hexagon.pdf +0 -61
  235. data/data/pdfs/indirect_reference.pdf +0 -86
  236. data/data/pdfs/multipage_template.pdf +0 -127
  237. data/data/pdfs/nested_pages.pdf +0 -118
  238. data/data/pdfs/page_without_mediabox.pdf +0 -193
  239. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  240. data/data/pdfs/two_hexagons.pdf +0 -90
  241. data/data/pdfs/version_1_6.pdf +0 -61
  242. data/data/shift_jis_text.txt +0 -1
  243. data/spec/acceptance/png_spec.rb +0 -35
  244. data/spec/annotations_spec.rb +0 -67
  245. data/spec/blend_mode_spec.rb +0 -71
  246. data/spec/bounding_box_spec.rb +0 -501
  247. data/spec/column_box_spec.rb +0 -59
  248. data/spec/destinations_spec.rb +0 -13
  249. data/spec/document_spec.rb +0 -738
  250. data/spec/font_metric_cache_spec.rb +0 -52
  251. data/spec/font_spec.rb +0 -475
  252. data/spec/formatted_text_arranger_spec.rb +0 -452
  253. data/spec/formatted_text_box_spec.rb +0 -716
  254. data/spec/formatted_text_fragment_spec.rb +0 -299
  255. data/spec/graphics_spec.rb +0 -705
  256. data/spec/grid_spec.rb +0 -95
  257. data/spec/images_spec.rb +0 -167
  258. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  259. data/spec/jpg_spec.rb +0 -23
  260. data/spec/line_wrap_spec.rb +0 -366
  261. data/spec/measurement_units_spec.rb +0 -22
  262. data/spec/outline_spec.rb +0 -409
  263. data/spec/png_spec.rb +0 -257
  264. data/spec/reference_spec.rb +0 -25
  265. data/spec/repeater_spec.rb +0 -154
  266. data/spec/security_spec.rb +0 -151
  267. data/spec/soft_mask_spec.rb +0 -78
  268. data/spec/span_spec.rb +0 -43
  269. data/spec/stamp_spec.rb +0 -179
  270. data/spec/stroke_styles_spec.rb +0 -208
  271. data/spec/text_at_spec.rb +0 -142
  272. data/spec/text_box_spec.rb +0 -1042
  273. data/spec/text_rendering_mode_spec.rb +0 -45
  274. data/spec/text_spacing_spec.rb +0 -93
  275. data/spec/text_spec.rb +0 -543
  276. data/spec/text_with_inline_formatting_spec.rb +0 -35
  277. data/spec/transparency_spec.rb +0 -91
  278. data/spec/view_spec.rb +0 -42
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # measurement_extensions.rb: Core extensions for Prawn::Measurements
3
2
  #
4
3
  # Copyright December 2008, Florian Witteler. All Rights Reserved.
@@ -17,34 +16,34 @@ class Numeric
17
16
  # @group Experimental API
18
17
 
19
18
  def mm
20
- return mm2pt(self)
19
+ mm2pt(self)
21
20
  end
22
21
 
23
22
  def cm
24
- return cm2pt(self)
23
+ cm2pt(self)
25
24
  end
26
25
 
27
26
  def dm
28
- return dm2pt(self)
27
+ dm2pt(self)
29
28
  end
30
29
 
31
30
  def m
32
- return m2pt(self)
31
+ m2pt(self)
33
32
  end
34
33
 
35
34
  def in
36
- return in2pt(self)
35
+ in2pt(self)
37
36
  end
38
37
 
39
38
  def yd
40
- return yd2pt(self)
39
+ yd2pt(self)
41
40
  end
42
41
 
43
42
  def ft
44
- return ft2pt(self)
43
+ ft2pt(self)
45
44
  end
46
45
 
47
46
  def pt
48
- return pt2pt(self)
47
+ pt2pt(self)
49
48
  end
50
49
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # measurements.rb: Conversions from other measurements to PDF points
3
2
  #
4
3
  # Copyright December 2008, Florian Witteler. All Rights Reserved.
@@ -9,62 +8,62 @@ module Prawn
9
8
  module Measurements
10
9
  # metric conversions
11
10
  def cm2mm(cm)
12
- return cm * 10
11
+ cm * 10
13
12
  end
14
13
 
15
14
  def dm2mm(dm)
16
- return dm * 100
15
+ dm * 100
17
16
  end
18
17
 
19
18
  def m2mm(m)
20
- return m * 1000
19
+ m * 1000
21
20
  end
22
21
 
23
22
  # imperial conversions
24
23
  # from http://en.wikipedia.org/wiki/Imperial_units
25
24
  def ft2in(ft)
26
- return ft * 12
25
+ ft * 12
27
26
  end
28
27
 
29
28
  def yd2in(yd)
30
- return yd * 36
29
+ yd * 36
31
30
  end
32
31
 
33
32
  # PostscriptPoint-converisons
34
33
  def pt2pt(pt)
35
- return pt
34
+ pt
36
35
  end
37
36
 
38
37
  def in2pt(inch)
39
- return inch * 72
38
+ inch * 72
40
39
  end
41
40
 
42
41
  def ft2pt(ft)
43
- return in2pt(ft2in(ft))
42
+ in2pt(ft2in(ft))
44
43
  end
45
44
 
46
45
  def yd2pt(yd)
47
- return in2pt(yd2in(yd))
46
+ in2pt(yd2in(yd))
48
47
  end
49
48
 
50
49
  def mm2pt(mm)
51
- return mm * (72 / 25.4)
50
+ mm * (72 / 25.4)
52
51
  end
53
52
 
54
53
  def cm2pt(cm)
55
- return mm2pt(cm2mm(cm))
54
+ mm2pt(cm2mm(cm))
56
55
  end
57
56
 
58
57
  def dm2pt(dm)
59
- return mm2pt(dm2mm(dm))
58
+ mm2pt(dm2mm(dm))
60
59
  end
61
60
 
62
61
  def m2pt(m)
63
- return mm2pt(m2mm(m))
62
+ mm2pt(m2mm(m))
64
63
  end
65
64
 
66
65
  def pt2mm(pt)
67
- return pt * 1 / mm2pt(1) # (25.4 / 72)
66
+ pt * 1 / mm2pt(1) # (25.4 / 72)
68
67
  end
69
68
  end
70
69
  end
@@ -1,26 +1,26 @@
1
- # encoding: utf-8
2
-
3
1
  module Prawn
4
2
  class Document
5
3
  # @group Stable API
6
4
 
7
- # Lazily instantiates a Prawn::Outline object for document. This is used as point of entry
8
- # to methods to build the outline tree for a document's table of contents.
5
+ # Lazily instantiates a Prawn::Outline object for document. This is used as
6
+ # point of entry to methods to build the outline tree for a document's table
7
+ # of contents.
9
8
  def outline
10
9
  @outline ||= Outline.new(self)
11
10
  end
12
11
  end
13
12
 
14
13
  # The Outline class organizes the outline tree items for the document.
15
- # Note that the prev and parent instance variables are adjusted while navigating
16
- # through the nested blocks. These variables along with the presence or absense
17
- # of blocks are the primary means by which the relations for the various
18
- # OutlineItems and the OutlineRoot are set. Unfortunately, the best way to
19
- # understand how this works is to follow the method calls through a real example.
14
+ # Note that the prev and parent instance variables are adjusted while
15
+ # navigating through the nested blocks. These variables along with the
16
+ # presence or absense of blocks are the primary means by which the relations
17
+ # for the various OutlineItems and the OutlineRoot are set. Unfortunately, the
18
+ # best way to understand how this works is to follow the method calls through
19
+ # a real example.
20
20
  #
21
- # Some ideas for the organization of this class were gleaned from name_tree. In
22
- # particular the way in which the OutlineItems are finally rendered into document
23
- # objects in PdfObject through a hash.
21
+ # Some ideas for the organization of this class were gleaned from name_tree.
22
+ # In particular the way in which the OutlineItems are finally rendered into
23
+ # document objects in PdfObject through a hash.
24
24
  #
25
25
  class Outline
26
26
  # @private
@@ -42,10 +42,11 @@ module Prawn
42
42
 
43
43
  # Defines/Updates an outline for the document.
44
44
  # The outline is an optional nested index that appears on the side of a PDF
45
- # document usually with direct links to pages. The outline DSL is defined by nested
46
- # blocks involving two methods: section and page; see the documentation on those methods
47
- # for their arguments and options. Note that one can also use outline#update
48
- # to add more sections to the end of the outline tree using the same syntax and scope.
45
+ # document usually with direct links to pages. The outline DSL is defined by
46
+ # nested blocks involving two methods: section and page; see the
47
+ # documentation on those methods for their arguments and options. Note that
48
+ # one can also use outline#update to add more sections to the end of the
49
+ # outline tree using the same syntax and scope.
49
50
  #
50
51
  # The syntax is best illustrated with an example:
51
52
  #
@@ -69,28 +70,31 @@ module Prawn
69
70
  # end
70
71
  #
71
72
  def define(&block)
72
- instance_eval(&block) if block
73
+ instance_eval(&block) if block
73
74
  end
74
75
 
75
- alias :update :define
76
+ alias update define
76
77
 
77
78
  # Inserts an outline section to the outline tree (see outline#define).
78
79
  # Although you will probably choose to exclusively use outline#define so
79
- # that your outline tree is contained and easy to manage, this method
80
- # gives you the option to insert sections to the outline tree at any point
81
- # during document generation. This method allows you to add a child subsection
82
- # to any other item at any level in the outline tree.
83
- # Currently the only way to locate the place of entry is with the title for the
84
- # item. If your title names are not unique consider using define_outline.
80
+ # that your outline tree is contained and easy to manage, this method gives
81
+ # you the option to insert sections to the outline tree at any point during
82
+ # document generation. This method allows you to add a child subsection to
83
+ # any other item at any level in the outline tree. Currently the only way
84
+ # to locate the place of entry is with the title for the item. If your title
85
+ # names are not unique consider using define_outline.
85
86
  # The method takes the following arguments:
86
- # title: a string that must match an outline title to add the subsection to
87
- # position: either :first or :last(the default) where the subsection will be placed relative
88
- # to other child elements. If you need to position your subsection in between
89
- # other elements then consider using #insert_section_after
87
+ # title: a string that must match an outline title to add
88
+ # the subsection to
89
+ # position: either :first or :last (the default) where the subsection will
90
+ # be placed relative to other child elements. If you need to position
91
+ # your subsection in between other elements then consider using
92
+ # #insert_section_after
90
93
  # block: uses the same DSL syntax as outline#define, for example:
91
94
  #
92
- # Consider using this method inside of outline.update if you want to have the outline object
93
- # to be scoped as self (see #insert_section_after example).
95
+ # Consider using this method inside of outline.update if you want to have
96
+ # the outline object to be scoped as self (see #insert_section_after
97
+ # example).
94
98
  #
95
99
  # go_to_page 2
96
100
  # start_new_page
@@ -101,8 +105,10 @@ module Prawn
101
105
  #
102
106
  def add_subsection_to(title, position = :last, &block)
103
107
  @parent = items[title]
104
- fail Prawn::Errors::UnknownOutlineTitle,
105
- "\n No outline item with title: '#{title}' exists in the outline tree" unless @parent
108
+ unless @parent
109
+ raise Prawn::Errors::UnknownOutlineTitle,
110
+ "\n No outline item with title: '#{title}' exists in the outline tree"
111
+ end
106
112
  @prev = position == :first ? nil : @parent.data.last
107
113
  nxt = position == :first ? @parent.data.first : nil
108
114
  insert_section(nxt, &block)
@@ -110,12 +116,13 @@ module Prawn
110
116
 
111
117
  # Inserts an outline section to the outline tree (see outline#define).
112
118
  # Although you will probably choose to exclusively use outline#define so
113
- # that your outline tree is contained and easy to manage, this method
114
- # gives you the option to insert sections to the outline tree at any point
115
- # during document generation. Unlike outline.add_section, this method allows
116
- # you to enter a section after any other item at any level in the outline tree.
117
- # Currently the only way to locate the place of entry is with the title for the
118
- # item. If your title names are not unique consider using define_outline.
119
+ # that your outline tree is contained and easy to manage, this method gives
120
+ # you the option to insert sections to the outline tree at any point during
121
+ # document generation. Unlike outline.add_section, this method allows you to
122
+ # enter a section after any other item at any level in the outline tree.
123
+ # Currently the only way to locate the place of entry is with the title for
124
+ # the item. If your title names are not unique consider using
125
+ # define_outline.
119
126
  # The method takes the following arguments:
120
127
  # title: the title of other section or page to insert new section after
121
128
  # block: uses the same DSL syntax as outline#define, for example:
@@ -131,30 +138,36 @@ module Prawn
131
138
  #
132
139
  def insert_section_after(title, &block)
133
140
  @prev = items[title]
134
- fail Prawn::Errors::UnknownOutlineTitle,
135
- "\n No outline item with title: '#{title}' exists in the outline tree" unless @prev
141
+ unless @prev
142
+ raise Prawn::Errors::UnknownOutlineTitle,
143
+ "\n No outline item with title: '#{title}' exists in the outline tree"
144
+ end
136
145
  @parent = @prev.data.parent
137
146
  nxt = @prev.data.next
138
147
  insert_section(nxt, &block)
139
148
  end
140
149
 
141
- # See outline#define above for documentation on how this is used in that context
150
+ # See outline#define above for documentation on how this is used in that
151
+ # context
142
152
  #
143
153
  # Adds an outine section to the outline tree.
144
154
  # Although you will probably choose to exclusively use outline#define so
145
- # that your outline tree is contained and easy to manage, this method
146
- # gives you the option to add sections to the outline tree at any point
147
- # during document generation. When not being called from within another #section block
148
- # the section will be added at the top level after the other root elements of the outline.
149
- # For more flexible placement try using outline#insert_section_after and/or
150
- # outline#add_subsection_to
155
+ # that your outline tree is contained and easy to manage, this method gives
156
+ # you the option to add sections to the outline tree at any point during
157
+ # document generation. When not being called from within another #section
158
+ # block the section will be added at the top level after the other root
159
+ # elements of the outline. For more flexible placement try using
160
+ # outline#insert_section_after and/or outline#add_subsection_to
161
+ #
151
162
  # Takes the following arguments:
152
163
  # title: the outline text that appears for the section.
153
- # options: destination - optional integer defining the page number for a destination link
154
- # to the top of the page (using a :FIT destination).
155
- # - or an array with a custom destination (see the #dest_* methods of the
156
- # PDF::Destination module)
157
- # closed - whether the section should show its nested outline elements.
164
+ # options: destination - optional integer defining the page number for
165
+ # a destination link to the top of the page (using a :FIT
166
+ # destination).
167
+ # - or an array with a custom destination (see the #dest_*
168
+ # methods of the PDF::Destination module)
169
+ # closed - whether the section should show its nested outline
170
+ # elements.
158
171
  # - defaults to false.
159
172
  # block: more nested subsections and/or page blocks
160
173
  #
@@ -167,36 +180,40 @@ module Prawn
167
180
  add_outline_item(title, options, &block)
168
181
  end
169
182
 
170
- # See Outline#define above for more documentation on how it is used in that context
183
+ # See Outline#define above for more documentation on how it is used in that
184
+ # context
171
185
  #
172
186
  # Adds a page to the outline.
173
187
  # Although you will probably choose to exclusively use outline#define so
174
188
  # that your outline tree is contained and easy to manage, this method also
175
189
  # gives you the option to add pages to the root of outline tree at any point
176
- # during document generation. Note that the page will be added at the
177
- # top level after the other root outline elements. For more flexible placement try
178
- # using outline#insert_section_after and/or outline#add_subsection_to.
190
+ # during document generation. Note that the page will be added at the top
191
+ # level after the other root outline elements. For more flexible placement
192
+ # try using outline#insert_section_after and/or outline#add_subsection_to.
179
193
  #
180
194
  # Takes the following arguments:
181
- # options:
182
- # title - REQUIRED. The outline text that appears for the page.
183
- # destination - optional integer defining the page number for a destination link
184
- # to the top of the page (using a :FIT destination).
185
- # - or an array with a custom destination (see the #dest_* methods of the
186
- # PDF::Destination module)
187
- # closed - whether the section should show its nested outline elements.
188
- # - defaults to false.
195
+ # options:
196
+ # title - REQUIRED. The outline text that appears for the page.
197
+ # destination - optional integer defining the page number for
198
+ # a destination link to the top of the page (using a :FIT
199
+ # destination).
200
+ # or an array with a custom destination (see the dest_* methods
201
+ # of the PDF::Destination module)
202
+ # closed - whether the section should show its nested outline elements.
203
+ # - defaults to false.
189
204
  # example usage:
190
205
  #
191
206
  # outline.page :title => "Very Last Page"
192
- # Note: this method is almost identical to section except that it does not accept a block
193
- # thereby defining the outline item as a leaf on the outline tree structure.
207
+ #
208
+ # Note: this method is almost identical to section except that it does not
209
+ # accept a block thereby defining the outline item as a leaf on the outline
210
+ # tree structure.
194
211
  def page(options = {})
195
212
  if options[:title]
196
213
  title = options[:title]
197
214
  else
198
- fail Prawn::Errors::RequiredOption,
199
- "\nTitle is a required option for page"
215
+ raise Prawn::Errors::RequiredOption,
216
+ "\nTitle is a required option for page"
200
217
  end
201
218
  add_outline_item(title, options)
202
219
  end
@@ -207,15 +224,16 @@ module Prawn
207
224
  # lazily initialized, so that documents that do not have an outline
208
225
  # do not incur the additional overhead.
209
226
  def root
210
- document.state.store.root.data[:Outlines] ||= document.ref!(PDF::Core::OutlineRoot.new)
227
+ document.state.store.root.data[:Outlines] ||=
228
+ document.ref!(PDF::Core::OutlineRoot.new)
211
229
  end
212
230
 
213
231
  def add_outline_item(title, options, &block)
214
232
  outline_item = create_outline_item(title, options)
215
- set_relations(outline_item)
233
+ establish_relations(outline_item)
216
234
  increase_count
217
235
  set_variables_for_block(outline_item, block)
218
- block.call if block
236
+ yield if block
219
237
  reset_parent(outline_item)
220
238
  end
221
239
 
@@ -234,7 +252,7 @@ module Prawn
234
252
  items[title] = document.ref!(outline_item)
235
253
  end
236
254
 
237
- def set_relations(outline_item)
255
+ def establish_relations(outline_item)
238
256
  prev.data.next = outline_item if prev
239
257
  parent.data.first = outline_item unless prev
240
258
  parent.data.last = outline_item
@@ -244,11 +262,11 @@ module Prawn
244
262
  counting_parent = parent
245
263
  while counting_parent
246
264
  counting_parent.data.count += 1
247
- if counting_parent == root
248
- counting_parent = nil
249
- else
250
- counting_parent = counting_parent.data.parent
251
- end
265
+ counting_parent = if counting_parent == root
266
+ nil
267
+ else
268
+ counting_parent.data.parent
269
+ end
252
270
  end
253
271
  end
254
272
 
@@ -267,7 +285,7 @@ module Prawn
267
285
  def insert_section(nxt, &block)
268
286
  last = @parent.data.last
269
287
  if block
270
- block.call
288
+ yield
271
289
  end
272
290
  adjust_relations(nxt, last)
273
291
  reset_root_positioning
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
- #
3
1
  # repeater.rb : Implements repeated page elements.
4
2
  # Heavy inspired by repeating_element() in PDF::Wrapper
5
3
  # http://pdf-wrapper.rubyforge.org/
@@ -20,9 +18,9 @@ module Prawn
20
18
 
21
19
  # @group Experimental API
22
20
 
23
- # Provides a way to execute a block of code repeatedly based on a
24
- # page_filter. Since Stamp is used under the hood, this method is very space
25
- # efficient.
21
+ # Provides a way to execute a block of code repeatedly based on
22
+ # a page_filter. Since Stamp is used under the hood, this method is very
23
+ # space efficient.
26
24
  #
27
25
  # Available page filters are:
28
26
  # :all -- repeats on every page
@@ -32,8 +30,9 @@ module Prawn
32
30
  # some_range -- repeats on every page included in the range
33
31
  # some_lambda -- yields page number and repeats for true return values
34
32
  #
35
- # Also accepts an optional second argument for dynamic content which executes the code
36
- # in the context of the filtered pages without using a Stamp.
33
+ # Also accepts an optional second argument for dynamic content which
34
+ # executes the code in the context of the filtered pages without using
35
+ # a Stamp.
37
36
  #
38
37
  # Example:
39
38
  #
@@ -75,7 +74,10 @@ module Prawn
75
74
  # end
76
75
  #
77
76
  def repeat(page_filter, options = {}, &block)
78
- repeaters << Prawn::Repeater.new(self, page_filter, !!options[:dynamic], &block)
77
+ dynamic = options.fetch(:dynamic, false)
78
+ repeaters << Prawn::Repeater.new(
79
+ self, page_filter, dynamic, &block
80
+ )
79
81
  end
80
82
  end
81
83
 
@@ -91,10 +93,10 @@ module Prawn
91
93
  attr_reader :name
92
94
 
93
95
  def initialize(document, page_filter, dynamic = false, &block)
94
- @document = document
96
+ @document = document
95
97
  @page_filter = page_filter
96
98
  @dynamic = dynamic
97
- @stamp_name = "prawn_repeater(#{Repeater.count})"
99
+ @stamp_name = "prawn_repeater(#{Repeater.count})"
98
100
  @document.create_stamp(@stamp_name, &block) unless dynamic
99
101
  @block = block if dynamic
100
102
  @graphic_state = document.state.page.graphic_state.dup