prawn 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -9
  6. data/Rakefile +20 -23
  7. data/lib/prawn.rb +36 -49
  8. data/lib/prawn/document.rb +180 -133
  9. data/lib/prawn/document/bounding_box.rb +41 -29
  10. data/lib/prawn/document/column_box.rb +7 -7
  11. data/lib/prawn/document/internals.rb +8 -6
  12. data/lib/prawn/document/span.rb +21 -16
  13. data/lib/prawn/encoding.rb +69 -68
  14. data/lib/prawn/errors.rb +12 -7
  15. data/lib/prawn/font.rb +102 -69
  16. data/lib/prawn/font_metric_cache.rb +14 -8
  17. data/lib/prawn/{font → fonts}/afm.rb +102 -68
  18. data/lib/prawn/{font → fonts}/dfont.rb +5 -11
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/fonts/ttc.rb +36 -0
  21. data/lib/prawn/{font → fonts}/ttf.rb +87 -68
  22. data/lib/prawn/graphics.rb +119 -81
  23. data/lib/prawn/graphics/blend_mode.rb +9 -8
  24. data/lib/prawn/graphics/cap_style.rb +3 -3
  25. data/lib/prawn/graphics/color.rb +27 -25
  26. data/lib/prawn/graphics/dash.rb +23 -11
  27. data/lib/prawn/graphics/join_style.rb +9 -3
  28. data/lib/prawn/graphics/patterns.rb +190 -96
  29. data/lib/prawn/graphics/transformation.rb +15 -9
  30. data/lib/prawn/graphics/transparency.rb +17 -13
  31. data/lib/prawn/grid.rb +48 -47
  32. data/lib/prawn/image_handler.rb +5 -5
  33. data/lib/prawn/images.rb +39 -30
  34. data/lib/prawn/images/image.rb +2 -1
  35. data/lib/prawn/images/jpg.rb +28 -22
  36. data/lib/prawn/images/png.rb +65 -62
  37. data/lib/prawn/measurement_extensions.rb +10 -9
  38. data/lib/prawn/measurements.rb +19 -15
  39. data/lib/prawn/outline.rb +97 -77
  40. data/lib/prawn/repeater.rb +14 -10
  41. data/lib/prawn/security.rb +81 -61
  42. data/lib/prawn/security/arcfour.rb +2 -2
  43. data/lib/prawn/soft_mask.rb +26 -26
  44. data/lib/prawn/stamp.rb +20 -13
  45. data/lib/prawn/text.rb +68 -52
  46. data/lib/prawn/text/box.rb +11 -8
  47. data/lib/prawn/text/formatted.rb +5 -5
  48. data/lib/prawn/text/formatted/arranger.rb +53 -32
  49. data/lib/prawn/text/formatted/box.rb +134 -100
  50. data/lib/prawn/text/formatted/fragment.rb +11 -14
  51. data/lib/prawn/text/formatted/line_wrap.rb +122 -63
  52. data/lib/prawn/text/formatted/parser.rb +139 -117
  53. data/lib/prawn/text/formatted/wrap.rb +43 -31
  54. data/lib/prawn/transformation_stack.rb +7 -5
  55. data/lib/prawn/utilities.rb +7 -22
  56. data/lib/prawn/version.rb +2 -2
  57. data/lib/prawn/view.rb +17 -7
  58. data/manual/basic_concepts/adding_pages.rb +6 -7
  59. data/manual/basic_concepts/basic_concepts.rb +31 -22
  60. data/manual/basic_concepts/creation.rb +10 -11
  61. data/manual/basic_concepts/cursor.rb +4 -5
  62. data/manual/basic_concepts/measurement.rb +6 -7
  63. data/manual/basic_concepts/origin.rb +5 -6
  64. data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
  65. data/manual/basic_concepts/view.rb +22 -16
  66. data/manual/bounding_box/bounding_box.rb +29 -24
  67. data/manual/bounding_box/bounds.rb +11 -12
  68. data/manual/bounding_box/canvas.rb +4 -5
  69. data/manual/bounding_box/creation.rb +6 -7
  70. data/manual/bounding_box/indentation.rb +14 -15
  71. data/manual/bounding_box/nesting.rb +24 -17
  72. data/manual/bounding_box/russian_boxes.rb +14 -13
  73. data/manual/bounding_box/stretchy.rb +12 -13
  74. data/manual/contents.rb +28 -22
  75. data/manual/cover.rb +33 -28
  76. data/manual/document_and_page_options/background.rb +11 -13
  77. data/manual/document_and_page_options/document_and_page_options.rb +25 -20
  78. data/manual/document_and_page_options/metadata.rb +18 -16
  79. data/manual/document_and_page_options/page_margins.rb +18 -20
  80. data/manual/document_and_page_options/page_size.rb +13 -12
  81. data/manual/document_and_page_options/print_scaling.rb +17 -15
  82. data/manual/example_helper.rb +5 -4
  83. data/manual/graphics/blend_mode.rb +12 -9
  84. data/manual/graphics/circle_and_ellipse.rb +4 -5
  85. data/manual/graphics/color.rb +7 -9
  86. data/manual/graphics/common_lines.rb +7 -8
  87. data/manual/graphics/fill_and_stroke.rb +4 -5
  88. data/manual/graphics/fill_rules.rb +9 -10
  89. data/manual/graphics/gradients.rb +27 -21
  90. data/manual/graphics/graphics.rb +48 -40
  91. data/manual/graphics/helper.rb +12 -9
  92. data/manual/graphics/line_width.rb +8 -7
  93. data/manual/graphics/lines_and_curves.rb +7 -8
  94. data/manual/graphics/polygon.rb +6 -8
  95. data/manual/graphics/rectangle.rb +4 -5
  96. data/manual/graphics/rotate.rb +6 -7
  97. data/manual/graphics/scale.rb +14 -15
  98. data/manual/graphics/soft_masks.rb +3 -4
  99. data/manual/graphics/stroke_cap.rb +6 -7
  100. data/manual/graphics/stroke_dash.rb +11 -12
  101. data/manual/graphics/stroke_join.rb +5 -6
  102. data/manual/graphics/translate.rb +9 -10
  103. data/manual/graphics/transparency.rb +7 -8
  104. data/manual/how_to_read_this_manual.rb +6 -6
  105. data/manual/images/absolute_position.rb +6 -7
  106. data/manual/images/fit.rb +7 -8
  107. data/manual/images/horizontal.rb +9 -10
  108. data/manual/images/images.rb +28 -24
  109. data/manual/images/plain_image.rb +5 -6
  110. data/manual/images/scale.rb +9 -10
  111. data/manual/images/vertical.rb +13 -14
  112. data/manual/images/width_and_height.rb +10 -11
  113. data/manual/layout/boxes.rb +5 -6
  114. data/manual/layout/content.rb +7 -8
  115. data/manual/layout/layout.rb +18 -16
  116. data/manual/layout/simple_grid.rb +6 -7
  117. data/manual/outline/add_subsection_to.rb +20 -21
  118. data/manual/outline/insert_section_after.rb +15 -16
  119. data/manual/outline/outline.rb +21 -17
  120. data/manual/outline/sections_and_pages.rb +17 -18
  121. data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
  122. data/manual/repeatable_content/page_numbering.rb +17 -16
  123. data/manual/repeatable_content/repeatable_content.rb +25 -19
  124. data/manual/repeatable_content/repeater.rb +14 -15
  125. data/manual/repeatable_content/stamp.rb +14 -15
  126. data/manual/security/encryption.rb +9 -10
  127. data/manual/security/permissions.rb +19 -14
  128. data/manual/security/security.rb +19 -16
  129. data/manual/table.rb +3 -3
  130. data/manual/text/alignment.rb +16 -17
  131. data/manual/text/color.rb +12 -11
  132. data/manual/text/column_box.rb +9 -10
  133. data/manual/text/fallback_fonts.rb +25 -21
  134. data/manual/text/font.rb +11 -12
  135. data/manual/text/font_size.rb +13 -14
  136. data/manual/text/font_style.rb +7 -8
  137. data/manual/text/formatted_callbacks.rb +25 -21
  138. data/manual/text/formatted_text.rb +33 -25
  139. data/manual/text/free_flowing_text.rb +20 -21
  140. data/manual/text/inline.rb +18 -19
  141. data/manual/text/kerning_and_character_spacing.rb +14 -15
  142. data/manual/text/leading.rb +7 -8
  143. data/manual/text/line_wrapping.rb +37 -18
  144. data/manual/text/paragraph_indentation.rb +13 -14
  145. data/manual/text/positioned_text.rb +15 -16
  146. data/manual/text/registering_families.rb +20 -21
  147. data/manual/text/rendering_and_color.rb +9 -10
  148. data/manual/text/right_to_left_text.rb +26 -19
  149. data/manual/text/rotation.rb +28 -23
  150. data/manual/text/single_usage.rb +8 -9
  151. data/manual/text/text.rb +57 -52
  152. data/manual/text/text_box_excess.rb +20 -17
  153. data/manual/text/text_box_extensions.rb +18 -15
  154. data/manual/text/text_box_overflow.rb +18 -19
  155. data/manual/text/utf8.rb +11 -12
  156. data/manual/text/win_ansi_charset.rb +21 -19
  157. data/prawn.gemspec +44 -31
  158. data/spec/extensions/encoding_helpers.rb +3 -3
  159. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  160. data/spec/prawn/document/column_box_spec.rb +75 -0
  161. data/spec/prawn/document/security_spec.rb +176 -0
  162. data/spec/prawn/document_annotations_spec.rb +76 -0
  163. data/spec/prawn/document_destinations_spec.rb +15 -0
  164. data/spec/prawn/document_grid_spec.rb +99 -0
  165. data/spec/prawn/document_reference_spec.rb +27 -0
  166. data/spec/prawn/document_span_spec.rb +36 -0
  167. data/spec/prawn/document_spec.rb +802 -0
  168. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  169. data/spec/prawn/font_spec.rb +542 -0
  170. data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
  171. data/spec/prawn/graphics/transparency_spec.rb +81 -0
  172. data/spec/prawn/graphics_spec.rb +837 -0
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
  174. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +14 -14
  175. data/spec/prawn/images/jpg_spec.rb +20 -0
  176. data/spec/prawn/images/png_spec.rb +283 -0
  177. data/spec/prawn/images_spec.rb +224 -0
  178. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  179. data/spec/prawn/outline_spec.rb +412 -0
  180. data/spec/prawn/repeater_spec.rb +165 -0
  181. data/spec/prawn/soft_mask_spec.rb +74 -0
  182. data/spec/prawn/stamp_spec.rb +172 -0
  183. data/spec/prawn/text/box_spec.rb +1112 -0
  184. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  185. data/spec/prawn/text/formatted/box_spec.rb +846 -0
  186. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
  188. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  189. data/spec/prawn/text_draw_text_spec.rb +149 -0
  190. data/spec/prawn/text_rendering_mode_spec.rb +48 -0
  191. data/spec/prawn/text_spacing_spec.rb +95 -0
  192. data/spec/prawn/text_spec.rb +603 -0
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
  194. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +22 -19
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +18 -19
  198. metadata +144 -180
  199. metadata.gz.sig +4 -0
  200. data/data/images/16bit.alpha +0 -0
  201. data/data/images/16bit.color +0 -0
  202. data/data/images/16bit.png +0 -0
  203. data/data/images/arrow.png +0 -0
  204. data/data/images/arrow2.png +0 -0
  205. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  206. data/data/images/blend_modes_top_layer.jpg +0 -0
  207. data/data/images/dice.alpha +0 -0
  208. data/data/images/dice.color +0 -0
  209. data/data/images/dice.png +0 -0
  210. data/data/images/dice_interlaced.png +0 -0
  211. data/data/images/fractal.jpg +0 -0
  212. data/data/images/indexed_color.dat +0 -0
  213. data/data/images/indexed_color.png +0 -0
  214. data/data/images/indexed_transparency.png +0 -0
  215. data/data/images/indexed_transparency_alpha.dat +0 -0
  216. data/data/images/indexed_transparency_color.dat +0 -0
  217. data/data/images/letterhead.jpg +0 -0
  218. data/data/images/license.md +0 -8
  219. data/data/images/page_white_text.alpha +0 -0
  220. data/data/images/page_white_text.color +0 -0
  221. data/data/images/page_white_text.png +0 -0
  222. data/data/images/pigs.jpg +0 -0
  223. data/data/images/prawn.png +0 -0
  224. data/data/images/ruport.png +0 -0
  225. data/data/images/ruport_data.dat +0 -0
  226. data/data/images/ruport_transparent.png +0 -0
  227. data/data/images/ruport_type0.png +0 -0
  228. data/data/images/stef.jpg +0 -0
  229. data/data/images/tru256.bmp +0 -0
  230. data/data/images/web-links.dat +0 -1
  231. data/data/images/web-links.png +0 -0
  232. data/data/pdfs/complex_template.pdf +0 -0
  233. data/data/pdfs/contains_ttf_font.pdf +0 -0
  234. data/data/pdfs/encrypted.pdf +0 -0
  235. data/data/pdfs/form.pdf +1 -819
  236. data/data/pdfs/hexagon.pdf +0 -61
  237. data/data/pdfs/indirect_reference.pdf +0 -86
  238. data/data/pdfs/multipage_template.pdf +0 -127
  239. data/data/pdfs/nested_pages.pdf +0 -118
  240. data/data/pdfs/page_without_mediabox.pdf +0 -193
  241. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  242. data/data/pdfs/two_hexagons.pdf +0 -90
  243. data/data/pdfs/version_1_6.pdf +0 -61
  244. data/data/shift_jis_text.txt +0 -1
  245. data/spec/acceptance/png_spec.rb +0 -35
  246. data/spec/annotations_spec.rb +0 -67
  247. data/spec/blend_mode_spec.rb +0 -71
  248. data/spec/bounding_box_spec.rb +0 -501
  249. data/spec/column_box_spec.rb +0 -59
  250. data/spec/destinations_spec.rb +0 -13
  251. data/spec/document_spec.rb +0 -738
  252. data/spec/font_metric_cache_spec.rb +0 -52
  253. data/spec/font_spec.rb +0 -475
  254. data/spec/formatted_text_arranger_spec.rb +0 -452
  255. data/spec/formatted_text_box_spec.rb +0 -716
  256. data/spec/formatted_text_fragment_spec.rb +0 -299
  257. data/spec/graphics_spec.rb +0 -705
  258. data/spec/grid_spec.rb +0 -95
  259. data/spec/images_spec.rb +0 -167
  260. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  261. data/spec/jpg_spec.rb +0 -23
  262. data/spec/line_wrap_spec.rb +0 -366
  263. data/spec/measurement_units_spec.rb +0 -22
  264. data/spec/outline_spec.rb +0 -409
  265. data/spec/png_spec.rb +0 -257
  266. data/spec/reference_spec.rb +0 -25
  267. data/spec/repeater_spec.rb +0 -154
  268. data/spec/security_spec.rb +0 -151
  269. data/spec/soft_mask_spec.rb +0 -78
  270. data/spec/span_spec.rb +0 -43
  271. data/spec/stamp_spec.rb +0 -179
  272. data/spec/stroke_styles_spec.rb +0 -208
  273. data/spec/text_at_spec.rb +0 -142
  274. data/spec/text_box_spec.rb +0 -1042
  275. data/spec/text_rendering_mode_spec.rb +0 -45
  276. data/spec/text_spacing_spec.rb +0 -93
  277. data/spec/text_spec.rb +0 -543
  278. data/spec/text_with_inline_formatting_spec.rb +0 -35
  279. data/spec/transparency_spec.rb +0 -91
  280. data/spec/view_spec.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e103cb901b7728d21af3dfe412f3072063a86835
4
- data.tar.gz: 132ff9e3bf2aeeeb1e9b574e5b84115192e576dc
2
+ SHA256:
3
+ metadata.gz: 1dd091ffaaed7c69fe8a0353317736d1f145e91f3f133a6d04ed0cffd7b5eb37
4
+ data.tar.gz: 98d1b0c973c9bf1947681ea971240fe9c351a9bcc1a74c91e7f8f677510eb11c
5
5
  SHA512:
6
- metadata.gz: 0cad684b3b096da6cdceb69e47b78c5629251687d28c8a3ab4f824fc64b842daa11e2f62122033d9b27f1cd4afe809bfad1c3cc2c150e909cae09f5480a442ec
7
- data.tar.gz: 5ea7ffa1b819a00d71897150c87afd0a7b7cc08e1afc8c4b41a425fd262f5276c961e969ea0e6e0178dde6f74ded16842076674abe39afbc5ca9bfaf513d5aab
6
+ metadata.gz: 9b75677d2586bf8a812549075cc9532bc02f78dc18b0e0db99711ad1087586f4fef6ae2f244e96a73366172410357d19e9371ac7b7eacf4a3bcbf85292ffb028
7
+ data.tar.gz: 138ac861e5016c49836a882c8beda2d2ed250e63959307ffe720624d322fd92b21ca71945e9cf58d0439851f8ebec515d13fb5f1d1660a3c9f4c996c5d04e701
Binary file
Binary file
data/GPLv2 CHANGED
@@ -1,12 +1,12 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 2, June 1991
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
3
 
4
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
6
  Everyone is permitted to copy and distribute verbatim copies
7
7
  of this license document, but changing it is not allowed.
8
8
 
9
- Preamble
9
+ Preamble
10
10
 
11
11
  The licenses for most software are designed to take away your
12
12
  freedom to share and change it. By contrast, the GNU General Public
@@ -15,7 +15,7 @@ software--to make sure the software is free for all its users. This
15
15
  General Public License applies to most of the Free Software
16
16
  Foundation's software and to any other program whose authors commit to
17
17
  using it. (Some other Free Software Foundation software is covered by
18
- the GNU Library General Public License instead.) You can apply it to
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
19
  your programs, too.
20
20
 
21
21
  When we speak of free software, we are referring to freedom, not
@@ -55,8 +55,8 @@ patent must be licensed for everyone's free use or not licensed at all.
55
55
 
56
56
  The precise terms and conditions for copying, distribution and
57
57
  modification follow.
58
-
59
- GNU GENERAL PUBLIC LICENSE
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
60
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
61
 
62
62
  0. This License applies to any program or other work which contains
@@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
110
110
  License. (Exception: if the Program itself is interactive but
111
111
  does not normally print such an announcement, your work based on
112
112
  the Program is not required to print an announcement.)
113
-
113
+
114
114
  These requirements apply to the modified work as a whole. If
115
115
  identifiable sections of that work are not derived from the Program,
116
116
  and can be reasonably considered independent and separate works in
@@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
168
168
  access to copy the source code from the same place counts as
169
169
  distribution of the source code, even though third parties are not
170
170
  compelled to copy the source along with the object code.
171
-
171
+
172
172
  4. You may not copy, modify, sublicense, or distribute the Program
173
173
  except as expressly provided under this License. Any attempt
174
174
  otherwise to copy, modify, sublicense or distribute the Program is
@@ -225,7 +225,7 @@ impose that choice.
225
225
 
226
226
  This section is intended to make thoroughly clear what is believed to
227
227
  be a consequence of the rest of this License.
228
-
228
+
229
229
  8. If the distribution and/or use of the Program is restricted in
230
230
  certain countries either by patents or by copyrighted interfaces, the
231
231
  original copyright holder who places the Program under this License
@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
255
255
  of preserving the free status of all derivatives of our free software and
256
256
  of promoting the sharing and reuse of software generally.
257
257
 
258
- NO WARRANTY
258
+ NO WARRANTY
259
259
 
260
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
261
  FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
277
  PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
278
  POSSIBILITY OF SUCH DAMAGES.
279
279
 
280
- END OF TERMS AND CONDITIONS
281
-
282
- How to Apply These Terms to Your New Programs
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
283
 
284
284
  If you develop a new program, and you want it to be of the greatest
285
285
  possible use to the public, the best way to achieve this is to make it
@@ -303,17 +303,16 @@ the "copyright" line and a pointer to where the full notice is found.
303
303
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
304
  GNU General Public License for more details.
305
305
 
306
- You should have received a copy of the GNU General Public License
307
- along with this program; if not, write to the Free Software
308
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
-
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
310
309
 
311
310
  Also add information on how to contact you by electronic and paper mail.
312
311
 
313
312
  If the program is interactive, make it output a short notice like this
314
313
  when it starts in an interactive mode:
315
314
 
316
- Gnomovision version 69, Copyright (C) year name of author
315
+ Gnomovision version 69, Copyright (C) year name of author
317
316
  Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
317
  This is free software, and you are welcome to redistribute it
319
318
  under certain conditions; type `show c' for details.
@@ -336,5 +335,5 @@ necessary. Here is a sample; alter the names:
336
335
  This General Public License does not permit incorporating your program into
337
336
  proprietary programs. If your program is a subroutine library, you may
338
337
  consider it more useful to permit linking proprietary applications with the
339
- library. If this is what you want to do, use the GNU Library General
338
+ library. If this is what you want to do, use the GNU Lesser General
340
339
  Public License instead of this License.
data/Gemfile CHANGED
@@ -1,11 +1,5 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- gemspec
3
+ source 'https://rubygems.org'
4
4
 
5
- if ENV["CI"]
6
- platforms :rbx do
7
- gem "rubysl-singleton", "~> 2.0"
8
- gem "rubysl-digest", "~> 2.0"
9
- gem "rubysl-enumerator", "~> 2.0"
10
- end
11
- end
5
+ gemspec
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
- require "bundler"
2
- Bundler.setup
1
+ # frozen_string_literal: true
3
2
 
4
3
  require 'rake'
5
4
  require 'rspec/core/rake_task'
@@ -7,43 +6,33 @@ require 'yard'
7
6
  require 'rubygems/package_task'
8
7
  require 'rubocop/rake_task'
9
8
 
10
- task :default => [:spec, :rubocop]
9
+ task default: %i[spec rubocop]
11
10
 
12
- desc "Run all rspec files"
13
- RSpec::Core::RakeTask.new("spec") do |c|
14
- c.rspec_opts = "-t ~unresolved"
15
- end
16
-
17
- desc "Show library's code statistics"
18
- task :stats do
19
- require 'code_statistics/code_statistics'
20
- puts CodeStatistics::CodeStatistics.new(
21
- [
22
- ["Prawn", "lib"],
23
- ["Specs", "spec"]
24
- ]
25
- ).to_s
11
+ desc 'Run all rspec files'
12
+ RSpec::Core::RakeTask.new('spec') do |c|
13
+ c.rspec_opts = '-t ~unresolved'
26
14
  end
27
15
 
28
16
  YARD::Rake::YardocTask.new do |t|
29
17
  t.options = ['--output-dir', 'doc/html']
30
18
  end
31
- task :docs => :yard
19
+ task docs: :yard
32
20
 
33
21
  desc "Generate the 'Prawn by Example' manual"
34
22
  task :manual do
35
- puts "Building manual..."
36
- require File.expand_path(File.join(File.dirname(__FILE__), %w[manual contents]))
37
- puts "The Prawn manual is available at manual.pdf. Happy Prawning!"
23
+ puts 'Building manual...'
24
+ require File.expand_path(File.join(__dir__, %w[manual contents]))
25
+ prawn_manual_document.render_file('manual.pdf')
26
+ puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
38
27
  end
39
28
 
40
- spec = Gem::Specification.load "prawn.gemspec"
29
+ spec = Gem::Specification.load 'prawn.gemspec'
41
30
  Gem::PackageTask.new(spec) do |pkg|
42
31
  pkg.need_zip = true
43
32
  pkg.need_tar = true
44
33
  end
45
34
 
46
- desc "Run a console with Prawn loaded"
35
+ desc 'Run a console with Prawn loaded'
47
36
  task :console do
48
37
  require 'irb'
49
38
  require 'irb/completion'
@@ -55,3 +44,11 @@ task :console do
55
44
  end
56
45
 
57
46
  RuboCop::RakeTask.new
47
+
48
+ task :checksum do
49
+ require 'digest/sha2'
50
+ built_gem_path = "prawn-#{Prawn::VERSION}.gem"
51
+ checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
52
+ checksum_path = "checksums/#{built_gem_path}.sha512"
53
+ File.write(checksum_path, checksum)
54
+ end
@@ -1,19 +1,17 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # Welcome to Prawn, the best PDF Generation library ever.
4
4
  # This documentation covers user level functionality.
5
5
  #
6
- require "set"
6
+ require 'set'
7
7
 
8
8
  require 'ttfunk'
9
- require "pdf/core"
9
+ require 'pdf/core'
10
10
 
11
11
  module Prawn
12
- extend self
13
-
14
12
  file = __FILE__
15
13
  file = File.readlink(file) if File.symlink?(file)
16
- dir = File.dirname(file)
14
+ dir = File.dirname(file)
17
15
 
18
16
  # The base source directory for Prawn as installed on the system
19
17
  #
@@ -32,59 +30,48 @@ module Prawn
32
30
  # Detected unknown option(s): [:tomato]
33
31
  # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
34
32
  #
35
- attr_accessor :debug # @private
33
+ # @private
34
+ attr_accessor :debug
35
+ module_function :debug, :debug=
36
+
37
+ module_function
36
38
 
37
- def verify_options(accepted, actual) # @private
39
+ # @private
40
+ def verify_options(accepted, actual)
38
41
  return unless debug || $DEBUG
42
+
39
43
  unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
40
- fail Prawn::Errors::UnknownOption,
41
- "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
42
- "Accepted options are: #{accepted.inspect}"
44
+ raise Prawn::Errors::UnknownOption,
45
+ "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
46
+ "Accepted options are: #{accepted.inspect}"
43
47
  end
44
48
  yield if block_given?
45
49
  end
46
-
47
- module Configurable # @private
48
- def configuration(*args)
49
- @config ||= Marshal.load(Marshal.dump(default_configuration))
50
- if Hash === args[0]
51
- @config.update(args[0])
52
- elsif args.length > 1
53
- @config.values_at(*args)
54
- elsif args.length == 1
55
- @config[args[0]]
56
- else
57
- @config
58
- end
59
- end
60
-
61
- alias_method :C, :configuration
62
- end
63
50
  end
64
51
 
65
- require_relative "prawn/version"
52
+ require_relative 'prawn/version'
66
53
 
67
- require_relative "prawn/errors"
54
+ require_relative 'prawn/errors'
68
55
 
69
- require_relative "prawn/utilities"
70
- require_relative "prawn/text"
71
- require_relative "prawn/graphics"
72
- require_relative "prawn/images"
73
- require_relative "prawn/images/image"
74
- require_relative "prawn/images/jpg"
75
- require_relative "prawn/images/png"
76
- require_relative "prawn/stamp"
77
- require_relative "prawn/soft_mask"
78
- require_relative "prawn/security"
79
- require_relative "prawn/transformation_stack"
80
- require_relative "prawn/document"
81
- require_relative "prawn/font"
82
- require_relative "prawn/measurements"
83
- require_relative "prawn/repeater"
84
- require_relative "prawn/outline"
85
- require_relative "prawn/grid"
86
- require_relative "prawn/view"
87
- require_relative "prawn/image_handler"
56
+ require_relative 'prawn/utilities'
57
+ require_relative 'prawn/text'
58
+ require_relative 'prawn/graphics'
59
+ require_relative 'prawn/images'
60
+ require_relative 'prawn/images/image'
61
+ require_relative 'prawn/images/jpg'
62
+ require_relative 'prawn/images/png'
63
+ require_relative 'prawn/stamp'
64
+ require_relative 'prawn/soft_mask'
65
+ require_relative 'prawn/security'
66
+ require_relative 'prawn/transformation_stack'
67
+ require_relative 'prawn/document'
68
+ require_relative 'prawn/font'
69
+ require_relative 'prawn/measurements'
70
+ require_relative 'prawn/repeater'
71
+ require_relative 'prawn/outline'
72
+ require_relative 'prawn/grid'
73
+ require_relative 'prawn/view'
74
+ require_relative 'prawn/image_handler'
88
75
 
89
76
  Prawn.image_handler.register(Prawn::Images::PNG)
90
77
  Prawn.image_handler.register(Prawn::Images::JPG)
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # document.rb : Implements PDF document generation for Prawn
4
4
  #
@@ -6,21 +6,21 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require "stringio"
9
+ require 'stringio'
10
10
 
11
- require_relative "document/bounding_box"
12
- require_relative "document/column_box"
13
- require_relative "document/internals"
14
- require_relative "document/span"
11
+ require_relative 'document/bounding_box'
12
+ require_relative 'document/column_box'
13
+ require_relative 'document/internals'
14
+ require_relative 'document/span'
15
15
 
16
16
  module Prawn
17
17
  # The Prawn::Document class is how you start creating a PDF document.
18
18
  #
19
19
  # There are three basic ways you can instantiate PDF Documents in Prawn, they
20
- # are through assignment, implicit block or explicit block. Below is an exmple
21
- # of each type, each example does exactly the same thing, makes a PDF document
22
- # with all the defaults and puts in the default font "Hello There" and then
23
- # saves it to the current directory as "example.pdf"
20
+ # are through assignment, implicit block or explicit block. Below is an
21
+ # example of each type, each example does exactly the same thing, makes a PDF
22
+ # document with all the defaults and puts in the default font "Hello There"
23
+ # and then saves it to the current directory as "example.pdf"
24
24
  #
25
25
  # For example, assignment can be like this:
26
26
  #
@@ -42,8 +42,8 @@ module Prawn
42
42
  # pdf.text words
43
43
  # end
44
44
  #
45
- # Usually, the block forms are used when you are simply creating a PDF document
46
- # that you want to immediately save or render out.
45
+ # Usually, the block forms are used when you are simply creating a PDF
46
+ # document that you want to immediately save or render out.
47
47
  #
48
48
  # See the new and generate methods for further details on the above.
49
49
  #
@@ -64,10 +64,12 @@ module Prawn
64
64
  # NOTE: We probably need to rethink the options validation system, but this
65
65
  # constant temporarily allows for extensions to modify the list.
66
66
 
67
- VALID_OPTIONS = [:page_size, :page_layout, :margin, :left_margin,
68
- :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
69
- :compress, :background, :info,
70
- :text_formatter, :print_scaling]
67
+ VALID_OPTIONS = %i[
68
+ page_size page_layout margin left_margin
69
+ right_margin top_margin bottom_margin skip_page_creation
70
+ compress background info
71
+ text_formatter print_scaling
72
+ ].freeze
71
73
 
72
74
  # Any module added to this array will be included into instances of
73
75
  # Prawn::Document at the per-object level. These will also be inherited by
@@ -153,15 +155,22 @@ module Prawn
153
155
  # <tt>:right_margin</tt>:: Sets the right margin in points [0.5 inch]
154
156
  # <tt>:top_margin</tt>:: Sets the top margin in points [0.5 inch]
155
157
  # <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
156
- # <tt>:skip_page_creation</tt>:: Creates a document without starting the first page [false]
157
- # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
158
- # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
158
+ # <tt>:skip_page_creation</tt>:: Creates a document without starting the
159
+ # first page [false]
160
+ # <tt>:compress</tt>:: Compresses content streams before rendering them
161
+ # [false]
162
+ # <tt>:background</tt>:: An image path to be used as background on all pages
163
+ # [nil]
159
164
  # <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
160
- # <tt>:info</tt>:: Generic hash allowing for custom metadata properties [nil]
161
- # <tt>:text_formatter</tt>: The text formatter to use for <tt>:inline_format</tt>ted text [Prawn::Text::Formatted::Parser]
165
+ # <tt>:info</tt>:: Generic hash allowing for custom metadata properties
166
+ # [nil]
167
+ # <tt>:text_formatter</tt>: The text formatter to use for
168
+ # <tt>:inline_format</tt>ted text
169
+ # [Prawn::Text::Formatted::Parser]
162
170
  #
163
- # Setting e.g. the :margin to 100 points and the :left_margin to 50 will result in margins
164
- # of 100 points on every side except for the left, where it will be 50.
171
+ # Setting e.g. the :margin to 100 points and the :left_margin to 50 will
172
+ # result in margins of 100 points on every side except for the left, where
173
+ # it will be 50.
165
174
  #
166
175
  # The :margin can also be an array much like CSS shorthand:
167
176
  #
@@ -172,8 +181,8 @@ module Prawn
172
181
  # # Top is 10, right is 20, bottom is 30, left is 40.
173
182
  # :margin => [10, 20, 30, 40]
174
183
  #
175
- # Additionally, :page_size can be specified as a simple two value array giving
176
- # the width and height of the document you need in PDF Points.
184
+ # Additionally, :page_size can be specified as a simple two value array
185
+ # giving the width and height of the document you need in PDF Points.
177
186
  #
178
187
  # Usage:
179
188
  #
@@ -181,13 +190,15 @@ module Prawn
181
190
  # pdf = Prawn::Document.new
182
191
  #
183
192
  # # New document, A4 paper, landscaped
184
- # pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
193
+ # pdf = Prawn::Document.new(page_size: "A4", page_layout: :landscape)
185
194
  #
186
195
  # # New document, Custom size
187
- # pdf = Prawn::Document.new(:page_size => [200, 300])
196
+ # pdf = Prawn::Document.new(page_size: [200, 300])
188
197
  #
189
198
  # # New document, with background
190
- # pdf = Prawn::Document.new(:background => "#{Prawn::DATADIR}/images/pigs.jpg")
199
+ # pdf = Prawn::Document.new(
200
+ # background: "#{Prawn::DATADIR}/images/pigs.jpg"
201
+ # )
191
202
  #
192
203
  def initialize(options = {}, &block)
193
204
  options = options.dup
@@ -199,21 +210,22 @@ module Prawn
199
210
 
200
211
  self.class.extensions.reverse_each { |e| extend e }
201
212
  self.state = PDF::Core::DocumentState.new(options)
202
- self.state.populate_pages_from_store(self)
213
+ state.populate_pages_from_store(self)
203
214
  renderer.min_version(state.store.min_version) if state.store.min_version
204
215
 
205
216
  renderer.min_version(1.6) if options[:print_scaling] == :none
206
217
 
207
218
  @background = options[:background]
208
219
  @background_scale = options[:background_scale] || 1
209
- @font_size = 12
220
+ @font_size = 12
210
221
 
211
- @bounding_box = nil
212
- @margin_box = nil
222
+ @bounding_box = nil
223
+ @margin_box = nil
213
224
 
214
225
  @page_number = 0
215
226
 
216
- @text_formatter = options.delete(:text_formatter) || Text::Formatted::Parser
227
+ @text_formatter = options.delete(:text_formatter) ||
228
+ Text::Formatted::Parser
217
229
 
218
230
  options[:size] = options.delete(:page_size)
219
231
  options[:layout] = options.delete(:page_layout)
@@ -240,24 +252,28 @@ module Prawn
240
252
  # pdf.start_new_page(:margin => 100)
241
253
  #
242
254
  def start_new_page(options = {})
243
- if last_page = state.page
244
- last_page_size = last_page.size
245
- last_page_layout = last_page.layout
255
+ last_page = state.page
256
+ if last_page
257
+ last_page_size = last_page.size
258
+ last_page_layout = last_page.layout
246
259
  last_page_margins = last_page.margins.dup
247
260
  end
248
261
 
249
262
  page_options = {
250
- :size => options[:size] || last_page_size,
251
- :layout => options[:layout] || last_page_layout,
252
- :margins => last_page_margins
263
+ size: options[:size] || last_page_size,
264
+ layout: options[:layout] || last_page_layout,
265
+ margins: last_page_margins
253
266
  }
254
267
  if last_page
255
- new_graphic_state = last_page.graphic_state.dup if last_page.graphic_state
268
+ if last_page.graphic_state
269
+ new_graphic_state = last_page.graphic_state.dup
270
+ end
256
271
 
257
- # erase the color space so that it gets reset on new page for fussy pdf-readers
258
- new_graphic_state.color_space = {} if new_graphic_state
272
+ # erase the color space so that it gets reset on new page for fussy
273
+ # pdf-readers
274
+ new_graphic_state&.color_space = {}
259
275
 
260
- page_options.merge!(:graphic_state => new_graphic_state)
276
+ page_options[:graphic_state] = new_graphic_state
261
277
  end
262
278
 
263
279
  state.page = PDF::Core::Page.new(self, page_options)
@@ -277,7 +293,11 @@ module Prawn
277
293
  state.insert_page(state.page, @page_number)
278
294
  @page_number += 1
279
295
 
280
- canvas { image(@background, :scale => @background_scale, :at => bounds.top_left) } if @background
296
+ if @background
297
+ canvas do
298
+ image(@background, scale: @background_scale, at: bounds.top_left)
299
+ end
300
+ end
281
301
  @y = @bounding_box.absolute_top
282
302
 
283
303
  float do
@@ -286,6 +306,26 @@ module Prawn
286
306
  end
287
307
  end
288
308
 
309
+ # Remove page of the document by index
310
+ #
311
+ # pdf = Prawn::Document.new
312
+ # pdf.page_count #=> 1
313
+ # 3.times { pdf.start_new_page }
314
+ # pdf.page_count #=> 4
315
+ # pdf.delete_page(-1)
316
+ # pdf.page_count #=> 3
317
+ #
318
+ def delete_page(index)
319
+ return false if index.abs > (state.pages.count - 1)
320
+
321
+ state.pages.delete_at(index)
322
+
323
+ state.store.pages.data[:Kids].delete_at(index)
324
+ state.store.pages.data[:Count] -= 1
325
+ @page_number -= 1
326
+ true
327
+ end
328
+
289
329
  # Returns the number of pages in the document
290
330
  #
291
331
  # pdf = Prawn::Document.new
@@ -302,9 +342,9 @@ module Prawn
302
342
  #
303
343
  # See Prawn::Document#number_pages for a sample usage of this capability.
304
344
  #
305
- def go_to_page(k)
306
- @page_number = k
307
- state.page = state.pages[k - 1]
345
+ def go_to_page(page_number)
346
+ @page_number = page_number
347
+ state.page = state.pages[page_number - 1]
308
348
  generate_margin_box
309
349
  @y = @bounding_box.absolute_top
310
350
  end
@@ -351,13 +391,13 @@ module Prawn
351
391
  # Renders the PDF document to string.
352
392
  # Pass an open file descriptor to render to file.
353
393
  #
354
- def render(*a, &b)
394
+ def render(*arguments, &block)
355
395
  (1..page_count).each do |i|
356
396
  go_to_page i
357
397
  repeaters.each { |r| r.run(i) }
358
398
  end
359
399
 
360
- renderer.render(*a, &b)
400
+ renderer.render(*arguments, &block)
361
401
  end
362
402
 
363
403
  # Renders the PDF document to file.
@@ -365,7 +405,7 @@ module Prawn
365
405
  # pdf.render_file "foo.pdf"
366
406
  #
367
407
  def render_file(filename)
368
- File.open(filename, "wb") { |f| render(f) }
408
+ File.open(filename, 'wb') { |f| render(f) }
369
409
  end
370
410
 
371
411
  # The bounds method returns the current bounding box you are currently in,
@@ -374,14 +414,15 @@ module Prawn
374
414
  # block, the box defined by that call will be returned instead of the
375
415
  # document margin box.
376
416
  #
377
- # Another important point about bounding boxes is that all x and y measurements
378
- # within a bounding box code block are relative to the bottom left corner of the
379
- # bounding box.
417
+ # Another important point about bounding boxes is that all x and
418
+ # y measurements within a bounding box code block are relative to the bottom
419
+ # left corner of the bounding box.
380
420
  #
381
421
  # For example:
382
422
  #
383
423
  # Prawn::Document.new do
384
- # # In the default "margin box" of a Prawn document of 0.5in along each edge
424
+ # # In the default "margin box" of a Prawn document of 0.5in along each
425
+ # # edge
385
426
  #
386
427
  # # Draw a border around the page (the manual way)
387
428
  # stroke do
@@ -408,8 +449,8 @@ module Prawn
408
449
 
409
450
  # Sets Document#bounds to the BoundingBox provided. See above for a brief
410
451
  # description of what a bounding box is. This function is useful if you
411
- # really need to change the bounding box manually, but usually, just entering
412
- # and exiting bounding box code blocks is good enough.
452
+ # really need to change the bounding box manually, but usually, just
453
+ # entering and exiting bounding box code blocks is good enough.
413
454
  #
414
455
  def bounds=(bounding_box)
415
456
  @bounding_box = bounding_box
@@ -418,15 +459,15 @@ module Prawn
418
459
  # Moves up the document by n points relative to the current position inside
419
460
  # the current bounding box.
420
461
  #
421
- def move_up(n)
422
- self.y += n
462
+ def move_up(amount)
463
+ self.y += amount
423
464
  end
424
465
 
425
- # Moves down the document by n points relative to the current position inside
426
- # the current bounding box.
466
+ # Moves down the document by n points relative to the current position
467
+ # inside the current bounding box.
427
468
  #
428
- def move_down(n)
429
- self.y -= n
469
+ def move_down(amount)
470
+ self.y -= amount
430
471
  end
431
472
 
432
473
  # Moves down the document and then executes a block.
@@ -486,50 +527,54 @@ module Prawn
486
527
  bounds.indent(left, right, &block)
487
528
  end
488
529
 
489
- # Places a text box on specified pages for page numbering. This should be called
490
- # towards the end of document creation, after all your content is already in
491
- # place. In your template string, <page> refers to the current page, and
492
- # <total> refers to the total amount of pages in the document. Page numbering should
493
- # occur at the end of your Prawn::Document.generate block because the method iterates
494
- # through existing pages after they are created.
530
+ # Places a text box on specified pages for page numbering. This should be
531
+ # called towards the end of document creation, after all your content is
532
+ # already in place. In your template string, <page> refers to the current
533
+ # page, and <total> refers to the total amount of pages in the document.
534
+ # Page numbering should occur at the end of your Prawn::Document.generate
535
+ # block because the method iterates through existing pages after they are
536
+ # created.
495
537
  #
496
538
  # Parameters are:
497
539
  #
498
540
  # <tt>string</tt>:: Template string for page number wording.
499
541
  # Should include '<page>' and, optionally, '<total>'.
500
542
  # <tt>options</tt>:: A hash for page numbering and text box options.
501
- # <tt>:page_filter</tt>:: A filter to specify which pages to place page numbers on.
502
- # Refer to the method 'page_match?'
543
+ # <tt>:page_filter</tt>:: A filter to specify which pages to place page
544
+ # numbers on. Refer to the method 'page_match?'
503
545
  # <tt>:start_count_at</tt>:: The starting count to increment pages from.
504
- # <tt>:total_pages</tt>:: If provided, will replace <total> with the value given.
505
- # Useful to override the total number of pages when using
506
- # the start_count_at option.
546
+ # <tt>:total_pages</tt>:: If provided, will replace <total> with the
547
+ # value given. Useful to override the total
548
+ # number of pages when using the start_count_at
549
+ # option.
507
550
  # <tt>:color</tt>:: Text fill color.
508
551
  #
509
- # Please refer to Prawn::Text::text_box for additional options concerning text
510
- # formatting and placement.
511
- #
512
- # Example: Print page numbers on every page except for the first. Start counting from
513
- # five.
552
+ # Please refer to Prawn::Text::text_box for additional options
553
+ # concerning text formatting and placement.
514
554
  #
515
- # Prawn::Document.generate("page_with_numbering.pdf") do
516
- # number_pages "<page> in a total of <total>",
517
- # {:start_count_at => 5,
518
- # :page_filter => lambda{ |pg| pg != 1 },
519
- # :at => [bounds.right - 50, 0],
520
- # :align => :right,
521
- # :size => 14}
522
- # end
555
+ # Example:
556
+ # Print page numbers on every page except for the first. Start counting
557
+ # from five.
558
+ #
559
+ # Prawn::Document.generate("page_with_numbering.pdf") do
560
+ # number_pages "<page> in a total of <total>", {
561
+ # start_count_at: 5,
562
+ # page_filter: lambda { |pg| pg != 1 },
563
+ # at: [bounds.right - 50, 0],
564
+ # align: :right,
565
+ # size: 14
566
+ # }
567
+ # end
523
568
  #
524
569
  def number_pages(string, options = {})
525
570
  opts = options.dup
526
571
  start_count_at = opts.delete(:start_count_at).to_i
527
572
 
528
- if opts.key?(:page_filter)
529
- page_filter = opts.delete(:page_filter)
530
- else
531
- page_filter = :all
532
- end
573
+ page_filter = if opts.key?(:page_filter)
574
+ opts.delete(:page_filter)
575
+ else
576
+ :all
577
+ end
533
578
 
534
579
  total_pages = opts.delete(:total_pages)
535
580
  txtcolor = opts.delete(:color)
@@ -549,12 +594,14 @@ module Prawn
549
594
  end
550
595
  if page_match?(page_filter, p)
551
596
  go_to_page(p)
552
- # have to use fill_color here otherwise text reverts back to default fill color
597
+ # have to use fill_color here otherwise text reverts back to default
598
+ # fill color
553
599
  fill_color txtcolor unless txtcolor.nil?
554
600
  total_pages = total_pages.nil? ? page_count : total_pages
555
- str = string.gsub("<page>", "#{pseudopage}").gsub("<total>", "#{total_pages}")
601
+ str = string.gsub('<page>', pseudopage.to_s)
602
+ .gsub('<total>', total_pages.to_s)
556
603
  text_box str, opts
557
- start_count = true # increment page count as soon as first match found
604
+ start_count = true # increment page count as soon as first match found
558
605
  end
559
606
  pseudopage += 1 if start_count
560
607
  end
@@ -572,21 +619,21 @@ module Prawn
572
619
  # the current page or column.
573
620
  #
574
621
  # @private
575
- def group(*a, &b)
576
- fail NotImplementedError,
577
- "Document#group has been disabled because its implementation " \
578
- "lead to corrupted documents whenever a page boundary was " \
579
- "crossed. We will try to work on reimplementing it in a " \
580
- "future release"
622
+ def group(*_arguments)
623
+ raise NotImplementedError,
624
+ 'Document#group has been disabled because its implementation ' \
625
+ 'lead to corrupted documents whenever a page boundary was ' \
626
+ 'crossed. We will try to work on reimplementing it in a ' \
627
+ 'future release'
581
628
  end
582
629
 
583
630
  # @private
584
631
  def transaction
585
- fail NotImplementedError,
586
- "Document#transaction has been disabled because its implementation " \
587
- "lead to corrupted documents whenever a page boundary was " \
588
- "crossed. We will try to work on reimplementing it in a " \
589
- "future release"
632
+ raise NotImplementedError,
633
+ 'Document#transaction has been disabled because its implementation ' \
634
+ 'lead to corrupted documents whenever a page boundary was ' \
635
+ 'crossed. We will try to work on reimplementing it in a ' \
636
+ 'future release'
590
637
  end
591
638
 
592
639
  # Provides a way to execute a block of code repeatedly based on a
@@ -617,8 +664,8 @@ module Prawn
617
664
  # @private
618
665
 
619
666
  def mask(*fields)
620
- # Stores the current state of the named attributes, executes the block, and
621
- # then restores the original values after the block has executed.
667
+ # Stores the current state of the named attributes, executes the block,
668
+ # and then restores the original values after the block has executed.
622
669
  # -- I will remove the nodoc if/when this feature is a little less hacky
623
670
  stored = {}
624
671
  fields.each { |f| stored[f] = send(f) }
@@ -630,7 +677,7 @@ module Prawn
630
677
 
631
678
  def initialize_first_page(options)
632
679
  if options[:skip_page_creation]
633
- start_new_page(options.merge(:orphan => true))
680
+ start_new_page(options.merge(orphan: true))
634
681
  else
635
682
  start_new_page(options)
636
683
  end
@@ -648,11 +695,11 @@ module Prawn
648
695
 
649
696
  private
650
697
 
651
- # setting override_settings to true ensures that a new graphic state does not end up using
652
- # previous settings.
698
+ # setting override_settings to true ensures that a new graphic state does
699
+ # not end up using previous settings.
653
700
  def use_graphic_settings(override_settings = false)
654
- set_fill_color if current_fill_color != "000000" || override_settings
655
- set_stroke_color if current_stroke_color != "000000" || override_settings
701
+ set_fill_color if current_fill_color != '000000' || override_settings
702
+ set_stroke_color if current_stroke_color != '000000' || override_settings
656
703
  write_line_width if line_width != 1 || override_settings
657
704
  write_stroke_cap_style if cap_style != :butt || override_settings
658
705
  write_stroke_join_style if join_style != :miter || override_settings
@@ -661,14 +708,16 @@ module Prawn
661
708
 
662
709
  def generate_margin_box
663
710
  old_margin_box = @margin_box
664
- page = state.page
711
+ page = state.page
665
712
 
666
713
  @margin_box = BoundingBox.new(
667
714
  self,
668
- nil, # margin box has no parent
669
- [ page.margins[:left], page.dimensions[-1] - page.margins[:top] ] ,
670
- :width => page.dimensions[-2] - (page.margins[:left] + page.margins[:right]),
671
- :height => page.dimensions[-1] - (page.margins[:top] + page.margins[:bottom])
715
+ nil, # margin box has no parent
716
+ [page.margins[:left], page.dimensions[-1] - page.margins[:top]],
717
+ width: page.dimensions[-2] -
718
+ (page.margins[:left] + page.margins[:right]),
719
+ height: page.dimensions[-1] -
720
+ (page.margins[:top] + page.margins[:bottom])
672
721
  )
673
722
 
674
723
  # This check maintains indentation settings across page breaks
@@ -679,25 +728,23 @@ module Prawn
679
728
 
680
729
  # we must update bounding box if not flowing from the previous page
681
730
  #
682
- @bounding_box = @margin_box unless @bounding_box && @bounding_box.parent
731
+ @bounding_box = @margin_box unless @bounding_box&.parent
683
732
  end
684
733
 
685
734
  def apply_margin_options(options)
686
- if options[:margin]
687
- # Treat :margin as CSS shorthand with 1-4 values.
688
- margin = Array(options[:margin])
689
- positions = { 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
690
- 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0] }[margin.length]
691
-
692
- [:top, :right, :bottom, :left].zip(positions).each do |p, i|
693
- options[:"#{p}_margin"] ||= margin[i]
694
- end
695
- end
696
-
697
- [:left, :right, :top, :bottom].each do |side|
698
- if margin = options[:"#{side}_margin"]
699
- state.page.margins[side] = margin
700
- end
735
+ sides = %i[top right bottom left]
736
+ margin = Array(options[:margin])
737
+
738
+ # Treat :margin as CSS shorthand with 1-4 values.
739
+ positions = {
740
+ 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
741
+ 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0],
742
+ 0 => []
743
+ }[margin.length]
744
+
745
+ sides.zip(positions).each do |side, pos|
746
+ new_margin = options[:"#{side}_margin"] || (margin[pos] if pos)
747
+ state.page.margins[side] = new_margin if new_margin
701
748
  end
702
749
  end
703
750