prawn 2.2.2 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) 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 +2 -0
  6. data/Rakefile +4 -26
  7. data/lib/prawn.rb +10 -3
  8. data/lib/prawn/document.rb +60 -33
  9. data/lib/prawn/document/bounding_box.rb +19 -6
  10. data/lib/prawn/document/column_box.rb +2 -0
  11. data/lib/prawn/document/internals.rb +6 -4
  12. data/lib/prawn/document/span.rb +4 -1
  13. data/lib/prawn/encoding.rb +4 -1
  14. data/lib/prawn/errors.rb +2 -0
  15. data/lib/prawn/font.rb +37 -18
  16. data/lib/prawn/font_metric_cache.rb +15 -9
  17. data/lib/prawn/{font → fonts}/afm.rb +32 -23
  18. data/lib/prawn/{font → fonts}/dfont.rb +3 -1
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/{font → fonts}/ttc.rb +3 -1
  21. data/lib/prawn/{font → fonts}/ttf.rb +73 -36
  22. data/lib/prawn/graphics.rb +31 -33
  23. data/lib/prawn/graphics/blend_mode.rb +2 -0
  24. data/lib/prawn/graphics/cap_style.rb +2 -0
  25. data/lib/prawn/graphics/color.rb +26 -19
  26. data/lib/prawn/graphics/dash.rb +3 -1
  27. data/lib/prawn/graphics/join_style.rb +3 -1
  28. data/lib/prawn/graphics/patterns.rb +63 -50
  29. data/lib/prawn/graphics/transformation.rb +7 -3
  30. data/lib/prawn/graphics/transparency.rb +2 -0
  31. data/lib/prawn/grid.rb +75 -39
  32. data/lib/prawn/image_handler.rb +2 -0
  33. data/lib/prawn/images.rb +42 -38
  34. data/lib/prawn/images/image.rb +2 -0
  35. data/lib/prawn/images/jpg.rb +6 -1
  36. data/lib/prawn/images/png.rb +11 -10
  37. data/lib/prawn/measurement_extensions.rb +2 -0
  38. data/lib/prawn/measurements.rb +5 -0
  39. data/lib/prawn/outline.rb +8 -5
  40. data/lib/prawn/repeater.rb +3 -1
  41. data/lib/prawn/security.rb +49 -44
  42. data/lib/prawn/security/arcfour.rb +2 -0
  43. data/lib/prawn/soft_mask.rb +3 -1
  44. data/lib/prawn/stamp.rb +4 -1
  45. data/lib/prawn/text.rb +32 -30
  46. data/lib/prawn/text/box.rb +13 -10
  47. data/lib/prawn/text/formatted.rb +2 -0
  48. data/lib/prawn/text/formatted/arranger.rb +50 -31
  49. data/lib/prawn/text/formatted/box.rb +43 -28
  50. data/lib/prawn/text/formatted/fragment.rb +2 -0
  51. data/lib/prawn/text/formatted/line_wrap.rb +23 -19
  52. data/lib/prawn/text/formatted/parser.rb +36 -36
  53. data/lib/prawn/text/formatted/wrap.rb +19 -13
  54. data/lib/prawn/transformation_stack.rb +5 -2
  55. data/lib/prawn/utilities.rb +2 -2
  56. data/lib/prawn/version.rb +3 -1
  57. data/lib/prawn/view.rb +15 -7
  58. data/manual/basic_concepts/adding_pages.rb +2 -0
  59. data/manual/basic_concepts/basic_concepts.rb +4 -2
  60. data/manual/basic_concepts/creation.rb +2 -0
  61. data/manual/basic_concepts/cursor.rb +2 -0
  62. data/manual/basic_concepts/measurement.rb +4 -2
  63. data/manual/basic_concepts/origin.rb +2 -0
  64. data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
  65. data/manual/basic_concepts/view.rb +2 -0
  66. data/manual/bounding_box/bounding_box.rb +4 -2
  67. data/manual/bounding_box/bounds.rb +6 -4
  68. data/manual/bounding_box/canvas.rb +5 -3
  69. data/manual/bounding_box/creation.rb +2 -0
  70. data/manual/bounding_box/indentation.rb +2 -0
  71. data/manual/bounding_box/nesting.rb +3 -1
  72. data/manual/bounding_box/russian_boxes.rb +6 -4
  73. data/manual/bounding_box/stretchy.rb +2 -0
  74. data/manual/contents.rb +2 -0
  75. data/manual/cover.rb +10 -7
  76. data/manual/document_and_page_options/background.rb +8 -2
  77. data/manual/document_and_page_options/document_and_page_options.rb +7 -5
  78. data/manual/document_and_page_options/metadata.rb +2 -0
  79. data/manual/document_and_page_options/page_margins.rb +2 -0
  80. data/manual/document_and_page_options/page_size.rb +2 -0
  81. data/manual/document_and_page_options/print_scaling.rb +4 -1
  82. data/manual/example_helper.rb +5 -2
  83. data/manual/graphics/blend_mode.rb +6 -4
  84. data/manual/graphics/circle_and_ellipse.rb +2 -0
  85. data/manual/graphics/color.rb +2 -0
  86. data/manual/graphics/common_lines.rb +3 -1
  87. data/manual/graphics/fill_and_stroke.rb +3 -1
  88. data/manual/graphics/fill_rules.rb +6 -3
  89. data/manual/graphics/gradients.rb +2 -0
  90. data/manual/graphics/graphics.rb +4 -2
  91. data/manual/graphics/helper.rb +13 -4
  92. data/manual/graphics/line_width.rb +3 -0
  93. data/manual/graphics/lines_and_curves.rb +3 -1
  94. data/manual/graphics/polygon.rb +2 -0
  95. data/manual/graphics/rectangle.rb +2 -0
  96. data/manual/graphics/rotate.rb +2 -0
  97. data/manual/graphics/scale.rb +2 -0
  98. data/manual/graphics/soft_masks.rb +2 -0
  99. data/manual/graphics/stroke_cap.rb +3 -1
  100. data/manual/graphics/stroke_dash.rb +7 -5
  101. data/manual/graphics/stroke_join.rb +3 -1
  102. data/manual/graphics/translate.rb +4 -1
  103. data/manual/graphics/transparency.rb +2 -0
  104. data/manual/how_to_read_this_manual.rb +2 -0
  105. data/manual/images/absolute_position.rb +2 -0
  106. data/manual/images/fit.rb +2 -0
  107. data/manual/images/horizontal.rb +5 -3
  108. data/manual/images/images.rb +4 -2
  109. data/manual/images/plain_image.rb +2 -0
  110. data/manual/images/scale.rb +5 -3
  111. data/manual/images/vertical.rb +9 -4
  112. data/manual/images/width_and_height.rb +5 -3
  113. data/manual/layout/boxes.rb +2 -0
  114. data/manual/layout/content.rb +4 -2
  115. data/manual/layout/layout.rb +4 -2
  116. data/manual/layout/simple_grid.rb +2 -0
  117. data/manual/outline/add_subsection_to.rb +2 -0
  118. data/manual/outline/insert_section_after.rb +2 -0
  119. data/manual/outline/outline.rb +5 -3
  120. data/manual/outline/sections_and_pages.rb +2 -0
  121. data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
  122. data/manual/repeatable_content/page_numbering.rb +2 -0
  123. data/manual/repeatable_content/repeatable_content.rb +4 -2
  124. data/manual/repeatable_content/repeater.rb +2 -0
  125. data/manual/repeatable_content/stamp.rb +2 -0
  126. data/manual/security/encryption.rb +2 -0
  127. data/manual/security/permissions.rb +6 -2
  128. data/manual/security/security.rb +5 -3
  129. data/manual/table.rb +2 -0
  130. data/manual/text/alignment.rb +4 -2
  131. data/manual/text/color.rb +2 -0
  132. data/manual/text/column_box.rb +5 -3
  133. data/manual/text/fallback_fonts.rb +4 -2
  134. data/manual/text/font.rb +2 -0
  135. data/manual/text/font_size.rb +2 -0
  136. data/manual/text/font_style.rb +7 -2
  137. data/manual/text/formatted_callbacks.rb +19 -12
  138. data/manual/text/formatted_text.rb +10 -5
  139. data/manual/text/free_flowing_text.rb +5 -3
  140. data/manual/text/inline.rb +2 -0
  141. data/manual/text/kerning_and_character_spacing.rb +6 -4
  142. data/manual/text/leading.rb +2 -0
  143. data/manual/text/line_wrapping.rb +4 -1
  144. data/manual/text/paragraph_indentation.rb +6 -5
  145. data/manual/text/positioned_text.rb +2 -0
  146. data/manual/text/registering_families.rb +4 -2
  147. data/manual/text/rendering_and_color.rb +3 -1
  148. data/manual/text/right_to_left_text.rb +8 -6
  149. data/manual/text/rotation.rb +11 -4
  150. data/manual/text/single_usage.rb +2 -0
  151. data/manual/text/text.rb +4 -3
  152. data/manual/text/text_box_excess.rb +2 -0
  153. data/manual/text/text_box_extensions.rb +3 -1
  154. data/manual/text/text_box_overflow.rb +14 -10
  155. data/manual/text/utf8.rb +3 -1
  156. data/manual/text/win_ansi_charset.rb +15 -12
  157. data/prawn.gemspec +9 -12
  158. data/spec/extensions/encoding_helpers.rb +4 -2
  159. data/spec/prawn/document/bounding_box_spec.rb +90 -86
  160. data/spec/prawn/document/column_box_spec.rb +2 -0
  161. data/spec/prawn/document/security_spec.rb +12 -9
  162. data/spec/prawn/document_annotations_spec.rb +2 -0
  163. data/spec/prawn/document_destinations_spec.rb +2 -0
  164. data/spec/prawn/document_grid_spec.rb +3 -0
  165. data/spec/prawn/document_reference_spec.rb +2 -0
  166. data/spec/prawn/document_span_spec.rb +16 -6
  167. data/spec/prawn/document_spec.rb +87 -39
  168. data/spec/prawn/font_metric_cache_spec.rb +2 -0
  169. data/spec/prawn/font_spec.rb +60 -29
  170. data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
  171. data/spec/prawn/graphics/transparency_spec.rb +2 -0
  172. data/spec/prawn/graphics_spec.rb +117 -62
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
  174. data/spec/prawn/image_handler_spec.rb +2 -0
  175. data/spec/prawn/images/jpg_spec.rb +2 -0
  176. data/spec/prawn/images/png_spec.rb +2 -0
  177. data/spec/prawn/images_spec.rb +66 -7
  178. data/spec/prawn/measurements_extensions_spec.rb +2 -0
  179. data/spec/prawn/outline_spec.rb +133 -29
  180. data/spec/prawn/repeater_spec.rb +15 -12
  181. data/spec/prawn/soft_mask_spec.rb +3 -1
  182. data/spec/prawn/stamp_spec.rb +12 -7
  183. data/spec/prawn/text/box_spec.rb +82 -85
  184. data/spec/prawn/text/formatted/arranger_spec.rb +40 -38
  185. data/spec/prawn/text/formatted/box_spec.rb +86 -62
  186. data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +10 -6
  188. data/spec/prawn/text/formatted/parser_spec.rb +32 -2
  189. data/spec/prawn/text_draw_text_spec.rb +13 -10
  190. data/spec/prawn/text_rendering_mode_spec.rb +7 -1
  191. data/spec/prawn/text_spacing_spec.rb +8 -6
  192. data/spec/prawn/text_spec.rb +18 -16
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +4 -2
  194. data/spec/prawn/transformation_stack_spec.rb +2 -0
  195. data/spec/prawn/view_spec.rb +18 -0
  196. data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
  197. data/spec/spec_helper.rb +9 -10
  198. metadata +46 -117
  199. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 56fa98e400aa9b739c52009b0967373f0fc657e9
4
- data.tar.gz: 33ec56d682263af565d208b38a4a11e99db61b16
2
+ SHA256:
3
+ metadata.gz: d64c2da1e4be48e40f4fa6fa4de35e04c75debf0119e8c59b3fba9d944c112db
4
+ data.tar.gz: 393bbdd1a5df657d5c6190d4bd10ecd7353522e714b2f60c8d9c5f70e5bc1ce9
5
5
  SHA512:
6
- metadata.gz: 04a3e22e55410e60240d203d74fbb43d20daa129c3e3e5d6334abab38d619e3e69c57e37c9522a2360176de3126723e3fb96e92ba3b2225bfac593e4ef4403a9
7
- data.tar.gz: 0a498d73aca1141f7b5b0e3fed25d5b94ddd27ffee63bafd16ad0634860024fd49280697aed0df1253e53f15207dd6f13006eb9e87b7f9ddcac10077872cdf04
6
+ metadata.gz: c4980639ca24796d577be790ed0f6fa85c985f1a6eb147e4c5db1df261c5d50afe8a466f06b65588b71a897e22e8d2b7b01daceed1714f6164124057154d2d28
7
+ data.tar.gz: e0fd560d4a80f2827736d599266bcb2e2fe19abedcde639520fba8bd19a2f12fe2cf0e8a60a91b87dbac4336d25c680f94b2341e5f9ce3d6d24f2e65f24e24a3
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,23 +1,9 @@
1
- require 'bundler'
2
- Bundler.setup
1
+ # frozen_string_literal: true
3
2
 
4
- require 'rake'
5
- require 'rspec/core/rake_task'
6
- require 'yard'
7
- require 'rubygems/package_task'
8
- require 'rubocop/rake_task'
3
+ GEMSPEC = File.expand_path('prawn.gemspec', __dir__)
4
+ require 'prawn/dev/tasks'
9
5
 
10
- task default: [:spec, :rubocop]
11
-
12
- desc 'Run all rspec files'
13
- RSpec::Core::RakeTask.new('spec') do |c|
14
- c.rspec_opts = '-t ~unresolved'
15
- end
16
-
17
- YARD::Rake::YardocTask.new do |t|
18
- t.options = ['--output-dir', 'doc/html']
19
- end
20
- task docs: :yard
6
+ task default: %i[spec rubocop]
21
7
 
22
8
  desc "Generate the 'Prawn by Example' manual"
23
9
  task :manual do
@@ -27,12 +13,6 @@ task :manual do
27
13
  puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
28
14
  end
29
15
 
30
- spec = Gem::Specification.load 'prawn.gemspec'
31
- Gem::PackageTask.new(spec) do |pkg|
32
- pkg.need_zip = true
33
- pkg.need_tar = true
34
- end
35
-
36
16
  desc 'Run a console with Prawn loaded'
37
17
  task :console do
38
18
  require 'irb'
@@ -43,5 +23,3 @@ task :console do
43
23
  ARGV.clear
44
24
  IRB.start
45
25
  end
46
-
47
- RuboCop::RakeTask.new
data/lib/prawn.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Welcome to Prawn, the best PDF Generation library ever.
2
4
  # This documentation covers user level functionality.
3
5
  #
@@ -28,11 +30,17 @@ module Prawn
28
30
  # Detected unknown option(s): [:tomato]
29
31
  # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
30
32
  #
31
- attr_accessor :debug # @private
33
+ # @private
34
+ attr_accessor :debug
35
+
32
36
  module_function :debug, :debug=
33
37
 
34
- def verify_options(accepted, actual) # @private
38
+ module_function
39
+
40
+ # @private
41
+ def verify_options(accepted, actual)
35
42
  return unless debug || $DEBUG
43
+
36
44
  unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
37
45
  raise Prawn::Errors::UnknownOption,
38
46
  "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
@@ -40,7 +48,6 @@ module Prawn
40
48
  end
41
49
  yield if block_given?
42
50
  end
43
- module_function :verify_options
44
51
  end
45
52
 
46
53
  require_relative 'prawn/version'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # document.rb : Implements PDF document generation for Prawn
2
4
  #
3
5
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
@@ -62,11 +64,11 @@ module Prawn
62
64
  # NOTE: We probably need to rethink the options validation system, but this
63
65
  # constant temporarily allows for extensions to modify the list.
64
66
 
65
- VALID_OPTIONS = [
66
- :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
70
72
  ].freeze
71
73
 
72
74
  # Any module added to this array will be included into instances of
@@ -96,6 +98,7 @@ module Prawn
96
98
 
97
99
  # @private
98
100
  def self.inherited(base)
101
+ super
99
102
  extensions.each { |e| base.extensions << e }
100
103
  end
101
104
 
@@ -269,7 +272,7 @@ module Prawn
269
272
 
270
273
  # erase the color space so that it gets reset on new page for fussy
271
274
  # pdf-readers
272
- new_graphic_state.color_space = {} if new_graphic_state
275
+ new_graphic_state&.color_space = {}
273
276
 
274
277
  page_options[:graphic_state] = new_graphic_state
275
278
  end
@@ -304,6 +307,26 @@ module Prawn
304
307
  end
305
308
  end
306
309
 
310
+ # Remove page of the document by index
311
+ #
312
+ # pdf = Prawn::Document.new
313
+ # pdf.page_count #=> 1
314
+ # 3.times { pdf.start_new_page }
315
+ # pdf.page_count #=> 4
316
+ # pdf.delete_page(-1)
317
+ # pdf.page_count #=> 3
318
+ #
319
+ def delete_page(index)
320
+ return false if index.abs > (state.pages.count - 1)
321
+
322
+ state.pages.delete_at(index)
323
+
324
+ state.store.pages.data[:Kids].delete_at(index)
325
+ state.store.pages.data[:Count] -= 1
326
+ @page_number -= 1
327
+ true
328
+ end
329
+
307
330
  # Returns the number of pages in the document
308
331
  #
309
332
  # pdf = Prawn::Document.new
@@ -320,9 +343,9 @@ module Prawn
320
343
  #
321
344
  # See Prawn::Document#number_pages for a sample usage of this capability.
322
345
  #
323
- def go_to_page(k)
324
- @page_number = k
325
- state.page = state.pages[k - 1]
346
+ def go_to_page(page_number)
347
+ @page_number = page_number
348
+ state.page = state.pages[page_number - 1]
326
349
  generate_margin_box
327
350
  @y = @bounding_box.absolute_top
328
351
  end
@@ -369,13 +392,13 @@ module Prawn
369
392
  # Renders the PDF document to string.
370
393
  # Pass an open file descriptor to render to file.
371
394
  #
372
- def render(*a, &b)
395
+ def render(*arguments, &block)
373
396
  (1..page_count).each do |i|
374
397
  go_to_page i
375
398
  repeaters.each { |r| r.run(i) }
376
399
  end
377
400
 
378
- renderer.render(*a, &b)
401
+ renderer.render(*arguments, &block)
379
402
  end
380
403
 
381
404
  # Renders the PDF document to file.
@@ -437,15 +460,15 @@ module Prawn
437
460
  # Moves up the document by n points relative to the current position inside
438
461
  # the current bounding box.
439
462
  #
440
- def move_up(n)
441
- self.y += n
463
+ def move_up(amount)
464
+ self.y += amount
442
465
  end
443
466
 
444
467
  # Moves down the document by n points relative to the current position
445
468
  # inside the current bounding box.
446
469
  #
447
- def move_down(n)
448
- self.y -= n
470
+ def move_down(amount)
471
+ self.y -= amount
449
472
  end
450
473
 
451
474
  # Moves down the document and then executes a block.
@@ -548,11 +571,12 @@ module Prawn
548
571
  opts = options.dup
549
572
  start_count_at = opts.delete(:start_count_at).to_i
550
573
 
551
- page_filter = if opts.key?(:page_filter)
552
- opts.delete(:page_filter)
553
- else
554
- :all
555
- end
574
+ page_filter =
575
+ if opts.key?(:page_filter)
576
+ opts.delete(:page_filter)
577
+ else
578
+ :all
579
+ end
556
580
 
557
581
  total_pages = opts.delete(:total_pages)
558
582
  txtcolor = opts.delete(:color)
@@ -563,12 +587,13 @@ module Prawn
563
587
  pseudopage = 0
564
588
  (1..page_count).each do |p|
565
589
  unless start_count
566
- pseudopage = case start_count_at
567
- when 0
568
- 1
569
- else
570
- start_count_at.to_i
571
- end
590
+ pseudopage =
591
+ case start_count_at
592
+ when 0
593
+ 1
594
+ else
595
+ start_count_at.to_i
596
+ end
572
597
  end
573
598
  if page_match?(page_filter, p)
574
599
  go_to_page(p)
@@ -597,7 +622,7 @@ module Prawn
597
622
  # the current page or column.
598
623
  #
599
624
  # @private
600
- def group(*_a)
625
+ def group(*_arguments)
601
626
  raise NotImplementedError,
602
627
  'Document#group has been disabled because its implementation ' \
603
628
  'lead to corrupted documents whenever a page boundary was ' \
@@ -646,9 +671,9 @@ module Prawn
646
671
  # and then restores the original values after the block has executed.
647
672
  # -- I will remove the nodoc if/when this feature is a little less hacky
648
673
  stored = {}
649
- fields.each { |f| stored[f] = send(f) }
674
+ fields.each { |f| stored[f] = public_send(f) }
650
675
  yield
651
- fields.each { |f| send("#{f}=", stored[f]) }
676
+ fields.each { |f| public_send("#{f}=", stored[f]) }
652
677
  end
653
678
 
654
679
  # @group Extension API
@@ -706,17 +731,19 @@ module Prawn
706
731
 
707
732
  # we must update bounding box if not flowing from the previous page
708
733
  #
709
- @bounding_box = @margin_box unless @bounding_box && @bounding_box.parent
734
+ @bounding_box = @margin_box unless @bounding_box&.parent
710
735
  end
711
736
 
712
737
  def apply_margin_options(options)
713
- sides = [:top, :right, :bottom, :left]
738
+ sides = %i[top right bottom left]
714
739
  margin = Array(options[:margin])
715
740
 
716
741
  # Treat :margin as CSS shorthand with 1-4 values.
717
742
  positions = {
718
- 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
719
- 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0],
743
+ 4 => [0, 1, 2, 3],
744
+ 3 => [0, 1, 2, 1],
745
+ 2 => [0, 1, 0, 1],
746
+ 1 => [0, 0, 0, 0],
720
747
  0 => []
721
748
  }[margin.length]
722
749
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # bounding_box.rb : Implements a mechanism for shifting the coordinate space
2
4
  #
3
5
  # Copyright May 2008, Gregory Brown. All Rights Reserved.
@@ -153,10 +155,10 @@ module Prawn
153
155
  # Of course, if you use canvas, you will be responsible for ensuring that
154
156
  # you remain within the printable area of your document.
155
157
  #
156
- def bounding_box(pt, *args, &block)
158
+ def bounding_box(point, *args, &block)
157
159
  init_bounding_box(block) do |parent_box|
158
- pt = map_to_absolute(pt)
159
- @bounding_box = BoundingBox.new(self, parent_box, pt, *args)
160
+ point = map_to_absolute(point)
161
+ @bounding_box = BoundingBox.new(self, parent_box, point, *args)
160
162
  end
161
163
  end
162
164
 
@@ -171,7 +173,9 @@ module Prawn
171
173
  init_bounding_box(block, hold_position: true) do |_|
172
174
  # Canvas bbox acts like margin_box in that its parent bounds are unset.
173
175
  @bounding_box = BoundingBox.new(
174
- self, nil, [0, page.dimensions[3]],
176
+ self,
177
+ nil,
178
+ [0, page.dimensions[3]],
175
179
  width: page.dimensions[2],
176
180
  height: page.dimensions[3]
177
181
  )
@@ -219,7 +223,14 @@ module Prawn
219
223
  # is used for.
220
224
  #
221
225
  class BoundingBox
222
- def initialize(document, parent, point, options = {}) # @private
226
+ class NoReferenceBounds < StandardError
227
+ def initialize(message = "Can't find reference bounds: my parent is unset")
228
+ super
229
+ end
230
+ end
231
+
232
+ # @private
233
+ def initialize(document, parent, point, options = {})
223
234
  unless options[:width]
224
235
  raise ArgumentError, 'BoundingBox needs the :width option to be set'
225
236
  end
@@ -457,6 +468,7 @@ module Prawn
457
468
  #
458
469
  def height
459
470
  return @height if @height
471
+
460
472
  @stretched_height = [
461
473
  (absolute_top - @document.y),
462
474
  @stretched_height.to_f
@@ -500,7 +512,8 @@ module Prawn
500
512
  #
501
513
  def reference_bounds
502
514
  if stretchy?
503
- raise "Can't find reference bounds: my parent is unset" unless @parent
515
+ raise NoReferenceBounds unless @parent
516
+
504
517
  @parent.reference_bounds
505
518
  else
506
519
  self