prawn 2.0.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) 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 +37 -49
  8. data/lib/prawn/document.rb +181 -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 +18 -8
  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 +115 -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 +120 -80
  23. data/lib/prawn/graphics/blend_mode.rb +65 -0
  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 +197 -67
  29. data/lib/prawn/graphics/transformation.rb +17 -8
  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 +107 -66
  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 +78 -49
  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 +121 -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 +44 -0
  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 +52 -0
  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 -39
  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 +4 -5
  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 +45 -33
  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/prawn/image_handler_spec.rb +53 -0
  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/prawn/transformation_stack_spec.rb +66 -0
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +19 -23
  198. metadata +145 -185
  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/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/letterhead.jpg +0 -0
  213. data/data/images/license.md +0 -8
  214. data/data/images/page_white_text.alpha +0 -0
  215. data/data/images/page_white_text.color +0 -0
  216. data/data/images/page_white_text.png +0 -0
  217. data/data/images/pal_bk.png +0 -0
  218. data/data/images/pigs.jpg +0 -0
  219. data/data/images/prawn.png +0 -0
  220. data/data/images/ruport.png +0 -0
  221. data/data/images/ruport_data.dat +0 -0
  222. data/data/images/ruport_transparent.png +0 -0
  223. data/data/images/ruport_type0.png +0 -0
  224. data/data/images/stef.jpg +0 -0
  225. data/data/images/tru256.bmp +0 -0
  226. data/data/images/web-links.dat +0 -1
  227. data/data/images/web-links.png +0 -0
  228. data/data/pdfs/complex_template.pdf +0 -0
  229. data/data/pdfs/contains_ttf_font.pdf +0 -0
  230. data/data/pdfs/encrypted.pdf +0 -0
  231. data/data/pdfs/form.pdf +1 -819
  232. data/data/pdfs/hexagon.pdf +0 -61
  233. data/data/pdfs/indirect_reference.pdf +0 -86
  234. data/data/pdfs/multipage_template.pdf +0 -127
  235. data/data/pdfs/nested_pages.pdf +0 -118
  236. data/data/pdfs/page_without_mediabox.pdf +0 -193
  237. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  238. data/data/pdfs/two_hexagons.pdf +0 -90
  239. data/data/pdfs/version_1_6.pdf +0 -61
  240. data/data/shift_jis_text.txt +0 -1
  241. data/spec/acceptance/png.rb +0 -24
  242. data/spec/annotations_spec.rb +0 -67
  243. data/spec/bounding_box_spec.rb +0 -501
  244. data/spec/column_box_spec.rb +0 -59
  245. data/spec/destinations_spec.rb +0 -13
  246. data/spec/document_spec.rb +0 -742
  247. data/spec/extensions/mocha.rb +0 -45
  248. data/spec/font_metric_cache_spec.rb +0 -52
  249. data/spec/font_spec.rb +0 -475
  250. data/spec/formatted_text_arranger_spec.rb +0 -423
  251. data/spec/formatted_text_box_spec.rb +0 -716
  252. data/spec/formatted_text_fragment_spec.rb +0 -299
  253. data/spec/graphics_spec.rb +0 -666
  254. data/spec/grid_spec.rb +0 -95
  255. data/spec/image_handler_spec.rb +0 -53
  256. data/spec/images_spec.rb +0 -167
  257. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  258. data/spec/jpg_spec.rb +0 -23
  259. data/spec/line_wrap_spec.rb +0 -366
  260. data/spec/measurement_units_spec.rb +0 -22
  261. data/spec/outline_spec.rb +0 -409
  262. data/spec/png_spec.rb +0 -235
  263. data/spec/reference_spec.rb +0 -25
  264. data/spec/repeater_spec.rb +0 -154
  265. data/spec/security_spec.rb +0 -151
  266. data/spec/soft_mask_spec.rb +0 -78
  267. data/spec/span_spec.rb +0 -43
  268. data/spec/stamp_spec.rb +0 -179
  269. data/spec/stroke_styles_spec.rb +0 -208
  270. data/spec/text_at_spec.rb +0 -142
  271. data/spec/text_box_spec.rb +0 -1038
  272. data/spec/text_rendering_mode_spec.rb +0 -45
  273. data/spec/text_spacing_spec.rb +0 -93
  274. data/spec/text_spec.rb +0 -549
  275. data/spec/text_with_inline_formatting_spec.rb +0 -35
  276. data/spec/transparency_spec.rb +0 -91
  277. data/spec/view_spec.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b05cc94288d323f650bc4a44529992282d42b69f
4
- data.tar.gz: 71cb2515eb6667207083899502a96487807f8667
2
+ SHA256:
3
+ metadata.gz: 1dd091ffaaed7c69fe8a0353317736d1f145e91f3f133a6d04ed0cffd7b5eb37
4
+ data.tar.gz: 98d1b0c973c9bf1947681ea971240fe9c351a9bcc1a74c91e7f8f677510eb11c
5
5
  SHA512:
6
- metadata.gz: 4081995850066454b2ec29d3532ea5470812d8af92606a7e2d65d9514105242d3e4061927559e8280c180732c8223d11f37debc7423382ffeada0820dbfc8c8c
7
- data.tar.gz: f1ef9c7346cddd535db2acde3a3522bdc4a128dcd8da2eb45439278203ca982e22543de1667a0d7f6435824884f73eb8ed046f6dbf128fa9ad3d721792bc4add
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
  #
@@ -23,7 +21,7 @@ module Prawn
23
21
 
24
22
  FLOAT_PRECISION = 1.0e-9
25
23
 
26
- # Whe set to true, Prawn will verify hash options to ensure only valid keys
24
+ # When set to true, Prawn will verify hash options to ensure only valid keys
27
25
  # are used. Off by default.
28
26
  #
29
27
  # Example:
@@ -32,58 +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/document"
80
- require_relative "prawn/font"
81
- require_relative "prawn/measurements"
82
- require_relative "prawn/repeater"
83
- require_relative "prawn/outline"
84
- require_relative "prawn/grid"
85
- require_relative "prawn/view"
86
- 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'
87
75
 
88
76
  Prawn.image_handler.register(Prawn::Images::PNG)
89
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
  #
@@ -57,16 +57,19 @@ module Prawn
57
57
  include Prawn::Images
58
58
  include Prawn::Stamp
59
59
  include Prawn::SoftMask
60
+ include Prawn::TransformationStack
60
61
 
61
62
  # @group Extension API
62
63
 
63
64
  # NOTE: We probably need to rethink the options validation system, but this
64
65
  # constant temporarily allows for extensions to modify the list.
65
66
 
66
- VALID_OPTIONS = [:page_size, :page_layout, :margin, :left_margin,
67
- :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
68
- :compress, :background, :info,
69
- :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
70
73
 
71
74
  # Any module added to this array will be included into instances of
72
75
  # Prawn::Document at the per-object level. These will also be inherited by
@@ -152,15 +155,22 @@ module Prawn
152
155
  # <tt>:right_margin</tt>:: Sets the right margin in points [0.5 inch]
153
156
  # <tt>:top_margin</tt>:: Sets the top margin in points [0.5 inch]
154
157
  # <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
155
- # <tt>:skip_page_creation</tt>:: Creates a document without starting the first page [false]
156
- # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
157
- # <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]
158
164
  # <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
159
- # <tt>:info</tt>:: Generic hash allowing for custom metadata properties [nil]
160
- # <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]
161
170
  #
162
- # Setting e.g. the :margin to 100 points and the :left_margin to 50 will result in margins
163
- # 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.
164
174
  #
165
175
  # The :margin can also be an array much like CSS shorthand:
166
176
  #
@@ -171,8 +181,8 @@ module Prawn
171
181
  # # Top is 10, right is 20, bottom is 30, left is 40.
172
182
  # :margin => [10, 20, 30, 40]
173
183
  #
174
- # Additionally, :page_size can be specified as a simple two value array giving
175
- # 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.
176
186
  #
177
187
  # Usage:
178
188
  #
@@ -180,13 +190,15 @@ module Prawn
180
190
  # pdf = Prawn::Document.new
181
191
  #
182
192
  # # New document, A4 paper, landscaped
183
- # pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
193
+ # pdf = Prawn::Document.new(page_size: "A4", page_layout: :landscape)
184
194
  #
185
195
  # # New document, Custom size
186
- # pdf = Prawn::Document.new(:page_size => [200, 300])
196
+ # pdf = Prawn::Document.new(page_size: [200, 300])
187
197
  #
188
198
  # # New document, with background
189
- # pdf = Prawn::Document.new(:background => "#{Prawn::DATADIR}/images/pigs.jpg")
199
+ # pdf = Prawn::Document.new(
200
+ # background: "#{Prawn::DATADIR}/images/pigs.jpg"
201
+ # )
190
202
  #
191
203
  def initialize(options = {}, &block)
192
204
  options = options.dup
@@ -198,21 +210,22 @@ module Prawn
198
210
 
199
211
  self.class.extensions.reverse_each { |e| extend e }
200
212
  self.state = PDF::Core::DocumentState.new(options)
201
- self.state.populate_pages_from_store(self)
213
+ state.populate_pages_from_store(self)
202
214
  renderer.min_version(state.store.min_version) if state.store.min_version
203
215
 
204
216
  renderer.min_version(1.6) if options[:print_scaling] == :none
205
217
 
206
218
  @background = options[:background]
207
219
  @background_scale = options[:background_scale] || 1
208
- @font_size = 12
220
+ @font_size = 12
209
221
 
210
- @bounding_box = nil
211
- @margin_box = nil
222
+ @bounding_box = nil
223
+ @margin_box = nil
212
224
 
213
225
  @page_number = 0
214
226
 
215
- @text_formatter = options.delete(:text_formatter) || Text::Formatted::Parser
227
+ @text_formatter = options.delete(:text_formatter) ||
228
+ Text::Formatted::Parser
216
229
 
217
230
  options[:size] = options.delete(:page_size)
218
231
  options[:layout] = options.delete(:page_layout)
@@ -239,24 +252,28 @@ module Prawn
239
252
  # pdf.start_new_page(:margin => 100)
240
253
  #
241
254
  def start_new_page(options = {})
242
- if last_page = state.page
243
- last_page_size = last_page.size
244
- 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
245
259
  last_page_margins = last_page.margins.dup
246
260
  end
247
261
 
248
262
  page_options = {
249
- :size => options[:size] || last_page_size,
250
- :layout => options[:layout] || last_page_layout,
251
- :margins => last_page_margins
263
+ size: options[:size] || last_page_size,
264
+ layout: options[:layout] || last_page_layout,
265
+ margins: last_page_margins
252
266
  }
253
267
  if last_page
254
- 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
255
271
 
256
- # erase the color space so that it gets reset on new page for fussy pdf-readers
257
- 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 = {}
258
275
 
259
- page_options.merge!(:graphic_state => new_graphic_state)
276
+ page_options[:graphic_state] = new_graphic_state
260
277
  end
261
278
 
262
279
  state.page = PDF::Core::Page.new(self, page_options)
@@ -276,7 +293,11 @@ module Prawn
276
293
  state.insert_page(state.page, @page_number)
277
294
  @page_number += 1
278
295
 
279
- 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
280
301
  @y = @bounding_box.absolute_top
281
302
 
282
303
  float do
@@ -285,6 +306,26 @@ module Prawn
285
306
  end
286
307
  end
287
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
+
288
329
  # Returns the number of pages in the document
289
330
  #
290
331
  # pdf = Prawn::Document.new
@@ -301,9 +342,9 @@ module Prawn
301
342
  #
302
343
  # See Prawn::Document#number_pages for a sample usage of this capability.
303
344
  #
304
- def go_to_page(k)
305
- @page_number = k
306
- 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]
307
348
  generate_margin_box
308
349
  @y = @bounding_box.absolute_top
309
350
  end
@@ -350,13 +391,13 @@ module Prawn
350
391
  # Renders the PDF document to string.
351
392
  # Pass an open file descriptor to render to file.
352
393
  #
353
- def render(*a, &b)
394
+ def render(*arguments, &block)
354
395
  (1..page_count).each do |i|
355
396
  go_to_page i
356
397
  repeaters.each { |r| r.run(i) }
357
398
  end
358
399
 
359
- renderer.render(*a, &b)
400
+ renderer.render(*arguments, &block)
360
401
  end
361
402
 
362
403
  # Renders the PDF document to file.
@@ -364,7 +405,7 @@ module Prawn
364
405
  # pdf.render_file "foo.pdf"
365
406
  #
366
407
  def render_file(filename)
367
- File.open(filename, "wb") { |f| render(f) }
408
+ File.open(filename, 'wb') { |f| render(f) }
368
409
  end
369
410
 
370
411
  # The bounds method returns the current bounding box you are currently in,
@@ -373,14 +414,15 @@ module Prawn
373
414
  # block, the box defined by that call will be returned instead of the
374
415
  # document margin box.
375
416
  #
376
- # Another important point about bounding boxes is that all x and y measurements
377
- # within a bounding box code block are relative to the bottom left corner of the
378
- # 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.
379
420
  #
380
421
  # For example:
381
422
  #
382
423
  # Prawn::Document.new do
383
- # # 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
384
426
  #
385
427
  # # Draw a border around the page (the manual way)
386
428
  # stroke do
@@ -407,8 +449,8 @@ module Prawn
407
449
 
408
450
  # Sets Document#bounds to the BoundingBox provided. See above for a brief
409
451
  # description of what a bounding box is. This function is useful if you
410
- # really need to change the bounding box manually, but usually, just entering
411
- # 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.
412
454
  #
413
455
  def bounds=(bounding_box)
414
456
  @bounding_box = bounding_box
@@ -417,15 +459,15 @@ module Prawn
417
459
  # Moves up the document by n points relative to the current position inside
418
460
  # the current bounding box.
419
461
  #
420
- def move_up(n)
421
- self.y += n
462
+ def move_up(amount)
463
+ self.y += amount
422
464
  end
423
465
 
424
- # Moves down the document by n points relative to the current position inside
425
- # the current bounding box.
466
+ # Moves down the document by n points relative to the current position
467
+ # inside the current bounding box.
426
468
  #
427
- def move_down(n)
428
- self.y -= n
469
+ def move_down(amount)
470
+ self.y -= amount
429
471
  end
430
472
 
431
473
  # Moves down the document and then executes a block.
@@ -485,50 +527,54 @@ module Prawn
485
527
  bounds.indent(left, right, &block)
486
528
  end
487
529
 
488
- # Places a text box on specified pages for page numbering. This should be called
489
- # towards the end of document creation, after all your content is already in
490
- # place. In your template string, <page> refers to the current page, and
491
- # <total> refers to the total amount of pages in the document. Page numbering should
492
- # occur at the end of your Prawn::Document.generate block because the method iterates
493
- # 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.
494
537
  #
495
538
  # Parameters are:
496
539
  #
497
540
  # <tt>string</tt>:: Template string for page number wording.
498
541
  # Should include '<page>' and, optionally, '<total>'.
499
542
  # <tt>options</tt>:: A hash for page numbering and text box options.
500
- # <tt>:page_filter</tt>:: A filter to specify which pages to place page numbers on.
501
- # 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?'
502
545
  # <tt>:start_count_at</tt>:: The starting count to increment pages from.
503
- # <tt>:total_pages</tt>:: If provided, will replace <total> with the value given.
504
- # Useful to override the total number of pages when using
505
- # 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.
506
550
  # <tt>:color</tt>:: Text fill color.
507
551
  #
508
- # Please refer to Prawn::Text::text_box for additional options concerning text
509
- # formatting and placement.
510
- #
511
- # Example: Print page numbers on every page except for the first. Start counting from
512
- # five.
552
+ # Please refer to Prawn::Text::text_box for additional options
553
+ # concerning text formatting and placement.
513
554
  #
514
- # Prawn::Document.generate("page_with_numbering.pdf") do
515
- # number_pages "<page> in a total of <total>",
516
- # {:start_count_at => 5,
517
- # :page_filter => lambda{ |pg| pg != 1 },
518
- # :at => [bounds.right - 50, 0],
519
- # :align => :right,
520
- # :size => 14}
521
- # 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
522
568
  #
523
569
  def number_pages(string, options = {})
524
570
  opts = options.dup
525
571
  start_count_at = opts.delete(:start_count_at).to_i
526
572
 
527
- if opts.key?(:page_filter)
528
- page_filter = opts.delete(:page_filter)
529
- else
530
- page_filter = :all
531
- end
573
+ page_filter = if opts.key?(:page_filter)
574
+ opts.delete(:page_filter)
575
+ else
576
+ :all
577
+ end
532
578
 
533
579
  total_pages = opts.delete(:total_pages)
534
580
  txtcolor = opts.delete(:color)
@@ -548,12 +594,14 @@ module Prawn
548
594
  end
549
595
  if page_match?(page_filter, p)
550
596
  go_to_page(p)
551
- # 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
552
599
  fill_color txtcolor unless txtcolor.nil?
553
600
  total_pages = total_pages.nil? ? page_count : total_pages
554
- str = string.gsub("<page>", "#{pseudopage}").gsub("<total>", "#{total_pages}")
601
+ str = string.gsub('<page>', pseudopage.to_s)
602
+ .gsub('<total>', total_pages.to_s)
555
603
  text_box str, opts
556
- 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
557
605
  end
558
606
  pseudopage += 1 if start_count
559
607
  end
@@ -571,21 +619,21 @@ module Prawn
571
619
  # the current page or column.
572
620
  #
573
621
  # @private
574
- def group(*a, &b)
575
- fail NotImplementedError,
576
- "Document#group has been disabled because its implementation " \
577
- "lead to corrupted documents whenever a page boundary was " \
578
- "crossed. We will try to work on reimplementing it in a " \
579
- "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'
580
628
  end
581
629
 
582
630
  # @private
583
631
  def transaction
584
- fail NotImplementedError,
585
- "Document#transaction has been disabled because its implementation " \
586
- "lead to corrupted documents whenever a page boundary was " \
587
- "crossed. We will try to work on reimplementing it in a " \
588
- "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'
589
637
  end
590
638
 
591
639
  # Provides a way to execute a block of code repeatedly based on a
@@ -616,8 +664,8 @@ module Prawn
616
664
  # @private
617
665
 
618
666
  def mask(*fields)
619
- # Stores the current state of the named attributes, executes the block, and
620
- # 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.
621
669
  # -- I will remove the nodoc if/when this feature is a little less hacky
622
670
  stored = {}
623
671
  fields.each { |f| stored[f] = send(f) }
@@ -629,7 +677,7 @@ module Prawn
629
677
 
630
678
  def initialize_first_page(options)
631
679
  if options[:skip_page_creation]
632
- start_new_page(options.merge(:orphan => true))
680
+ start_new_page(options.merge(orphan: true))
633
681
  else
634
682
  start_new_page(options)
635
683
  end
@@ -647,11 +695,11 @@ module Prawn
647
695
 
648
696
  private
649
697
 
650
- # setting override_settings to true ensures that a new graphic state does not end up using
651
- # previous settings.
698
+ # setting override_settings to true ensures that a new graphic state does
699
+ # not end up using previous settings.
652
700
  def use_graphic_settings(override_settings = false)
653
- set_fill_color if current_fill_color != "000000" || override_settings
654
- 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
655
703
  write_line_width if line_width != 1 || override_settings
656
704
  write_stroke_cap_style if cap_style != :butt || override_settings
657
705
  write_stroke_join_style if join_style != :miter || override_settings
@@ -660,14 +708,16 @@ module Prawn
660
708
 
661
709
  def generate_margin_box
662
710
  old_margin_box = @margin_box
663
- page = state.page
711
+ page = state.page
664
712
 
665
713
  @margin_box = BoundingBox.new(
666
714
  self,
667
- nil, # margin box has no parent
668
- [ page.margins[:left], page.dimensions[-1] - page.margins[:top] ] ,
669
- :width => page.dimensions[-2] - (page.margins[:left] + page.margins[:right]),
670
- :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])
671
721
  )
672
722
 
673
723
  # This check maintains indentation settings across page breaks
@@ -678,25 +728,23 @@ module Prawn
678
728
 
679
729
  # we must update bounding box if not flowing from the previous page
680
730
  #
681
- @bounding_box = @margin_box unless @bounding_box && @bounding_box.parent
731
+ @bounding_box = @margin_box unless @bounding_box&.parent
682
732
  end
683
733
 
684
734
  def apply_margin_options(options)
685
- if options[:margin]
686
- # Treat :margin as CSS shorthand with 1-4 values.
687
- margin = Array(options[:margin])
688
- positions = { 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
689
- 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0] }[margin.length]
690
-
691
- [:top, :right, :bottom, :left].zip(positions).each do |p, i|
692
- options[:"#{p}_margin"] ||= margin[i]
693
- end
694
- end
695
-
696
- [:left, :right, :top, :bottom].each do |side|
697
- if margin = options[:"#{side}_margin"]
698
- state.page.margins[side] = margin
699
- 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
700
748
  end
701
749
  end
702
750