prawn 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +10 -3
  7. data/lib/prawn.rb +9 -3
  8. data/lib/prawn/document.rb +40 -18
  9. data/lib/prawn/document/bounding_box.rb +9 -4
  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 +2 -0
  13. data/lib/prawn/encoding.rb +4 -1
  14. data/lib/prawn/errors.rb +2 -0
  15. data/lib/prawn/font.rb +34 -17
  16. data/lib/prawn/font_metric_cache.rb +8 -3
  17. data/lib/prawn/{font → fonts}/afm.rb +14 -7
  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 +23 -12
  22. data/lib/prawn/graphics.rb +24 -26
  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 +8 -3
  26. data/lib/prawn/graphics/dash.rb +3 -1
  27. data/lib/prawn/graphics/join_style.rb +2 -0
  28. data/lib/prawn/graphics/patterns.rb +7 -2
  29. data/lib/prawn/graphics/transformation.rb +5 -1
  30. data/lib/prawn/graphics/transparency.rb +2 -0
  31. data/lib/prawn/grid.rb +39 -38
  32. data/lib/prawn/image_handler.rb +2 -0
  33. data/lib/prawn/images.rb +21 -19
  34. data/lib/prawn/images/image.rb +2 -0
  35. data/lib/prawn/images/jpg.rb +2 -0
  36. data/lib/prawn/images/png.rb +9 -9
  37. data/lib/prawn/measurement_extensions.rb +2 -0
  38. data/lib/prawn/measurements.rb +5 -0
  39. data/lib/prawn/outline.rb +2 -0
  40. data/lib/prawn/repeater.rb +2 -0
  41. data/lib/prawn/security.rb +26 -24
  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 +14 -12
  46. data/lib/prawn/text/box.rb +3 -1
  47. data/lib/prawn/text/formatted.rb +2 -0
  48. data/lib/prawn/text/formatted/arranger.rb +12 -12
  49. data/lib/prawn/text/formatted/box.rb +23 -13
  50. data/lib/prawn/text/formatted/fragment.rb +2 -0
  51. data/lib/prawn/text/formatted/line_wrap.rb +10 -8
  52. data/lib/prawn/text/formatted/parser.rb +8 -10
  53. data/lib/prawn/text/formatted/wrap.rb +4 -2
  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 +3 -1
  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 +2 -0
  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 +2 -0
  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 +2 -0
  77. data/manual/document_and_page_options/document_and_page_options.rb +4 -2
  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 +2 -0
  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 +2 -0
  87. data/manual/graphics/fill_and_stroke.rb +2 -0
  88. data/manual/graphics/fill_rules.rb +2 -0
  89. data/manual/graphics/gradients.rb +2 -0
  90. data/manual/graphics/graphics.rb +4 -2
  91. data/manual/graphics/helper.rb +2 -0
  92. data/manual/graphics/line_width.rb +3 -0
  93. data/manual/graphics/lines_and_curves.rb +2 -0
  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 +2 -0
  101. data/manual/graphics/stroke_join.rb +3 -1
  102. data/manual/graphics/translate.rb +2 -0
  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 +3 -1
  108. data/manual/images/images.rb +4 -2
  109. data/manual/images/plain_image.rb +2 -0
  110. data/manual/images/scale.rb +2 -0
  111. data/manual/images/vertical.rb +3 -1
  112. data/manual/images/width_and_height.rb +2 -0
  113. data/manual/layout/boxes.rb +2 -0
  114. data/manual/layout/content.rb +2 -0
  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 +4 -2
  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 +2 -0
  128. data/manual/security/security.rb +4 -2
  129. data/manual/table.rb +2 -0
  130. data/manual/text/alignment.rb +2 -0
  131. data/manual/text/color.rb +2 -0
  132. data/manual/text/column_box.rb +4 -2
  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 +4 -2
  137. data/manual/text/formatted_callbacks.rb +2 -0
  138. data/manual/text/formatted_text.rb +3 -1
  139. data/manual/text/free_flowing_text.rb +2 -0
  140. data/manual/text/inline.rb +2 -0
  141. data/manual/text/kerning_and_character_spacing.rb +2 -0
  142. data/manual/text/leading.rb +2 -0
  143. data/manual/text/line_wrapping.rb +4 -1
  144. data/manual/text/paragraph_indentation.rb +2 -0
  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 +2 -0
  148. data/manual/text/right_to_left_text.rb +2 -0
  149. data/manual/text/rotation.rb +3 -1
  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 +2 -0
  154. data/manual/text/text_box_overflow.rb +3 -1
  155. data/manual/text/utf8.rb +3 -1
  156. data/manual/text/win_ansi_charset.rb +6 -3
  157. data/prawn.gemspec +14 -11
  158. data/spec/extensions/encoding_helpers.rb +4 -2
  159. data/spec/prawn/document/bounding_box_spec.rb +8 -8
  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 +2 -0
  167. data/spec/prawn/document_spec.rb +59 -14
  168. data/spec/prawn/font_metric_cache_spec.rb +2 -0
  169. data/spec/prawn/font_spec.rb +45 -16
  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 +40 -20
  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 +56 -2
  178. data/spec/prawn/measurements_extensions_spec.rb +2 -0
  179. data/spec/prawn/outline_spec.rb +6 -2
  180. data/spec/prawn/repeater_spec.rb +6 -4
  181. data/spec/prawn/soft_mask_spec.rb +2 -0
  182. data/spec/prawn/stamp_spec.rb +11 -7
  183. data/spec/prawn/text/box_spec.rb +26 -27
  184. data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
  185. data/spec/prawn/text/formatted/box_spec.rb +78 -57
  186. data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
  188. data/spec/prawn/text/formatted/parser_spec.rb +32 -2
  189. data/spec/prawn/text_draw_text_spec.rb +5 -3
  190. data/spec/prawn/text_rendering_mode_spec.rb +7 -1
  191. data/spec/prawn/text_spacing_spec.rb +6 -4
  192. data/spec/prawn/text_spec.rb +9 -7
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
  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 +86 -73
  199. metadata.gz.sig +4 -2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Implementation of the "ARCFOUR" algorithm ("alleged RC4 (tm)"). Implemented
2
4
  # as described at:
3
5
  # http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # soft_mask.rb : Implements soft-masking
2
4
  #
3
5
  # Copyright September 2012, Alexander Mankuta. All Rights Reserved.
@@ -73,7 +75,7 @@ module Prawn
73
75
  renderer.add_content "/#{soft_mask_registry[registry_key]} gs"
74
76
  else
75
77
  masks = page.resources[:ExtGState] ||= {}
76
- id = masks.empty? ? 'GS1' : masks.keys.sort.last.succ
78
+ id = masks.empty? ? 'GS1' : masks.keys.max.succ
77
79
  masks[id] = g_state
78
80
 
79
81
  soft_mask_registry[registry_key] = id
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # stamp.rb : Implements a repeatable stamp
2
4
  #
3
5
  # Copyright October 2009, Daniel Nelson. All Rights Reserved.
@@ -105,6 +107,7 @@ module Prawn
105
107
  def create_stamp_dictionary(name)
106
108
  raise Prawn::Errors::InvalidName if name.empty?
107
109
  raise Prawn::Errors::NameTaken unless stamp_dictionary_registry[name].nil?
110
+
108
111
  # BBox origin is the lower left margin of the page, so we need
109
112
  # it to be the full dimension of the page, or else things that
110
113
  # should appear near the top or right margin are invisible
@@ -131,7 +134,7 @@ module Prawn
131
134
  # to the /Annot dictionary of the object that contains the
132
135
  # call to the stamp object.
133
136
  def update_annotation_references(annots)
134
- if annots && annots.any?
137
+ if annots&.any?
135
138
  state.page.dictionary.data[:Annots] ||= []
136
139
  state.page.dictionary.data[:Annots] |= annots
137
140
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # text.rb : Implements PDF text primitives
2
4
  #
3
5
  # Copyright May 2008, Gregory Brown. All Rights Reserved.
@@ -6,8 +8,6 @@
6
8
 
7
9
  require 'zlib'
8
10
 
9
- require 'pdf/core/text'
10
-
11
11
  require_relative 'text/formatted'
12
12
  require_relative 'text/box'
13
13
 
@@ -17,11 +17,11 @@ module Prawn
17
17
  include Prawn::Text::Formatted
18
18
 
19
19
  # No-Break Space
20
- NBSP = "\u00A0".freeze
20
+ NBSP = "\u00A0"
21
21
  # Zero Width Space (indicate word boundaries without a space)
22
- ZWSP = "\u200B".freeze
22
+ ZWSP = "\u200B"
23
23
  # Soft Hyphen (invisible, except when causing a line break)
24
- SHY = "\u00AD".freeze
24
+ SHY = "\u00AD"
25
25
 
26
26
  # @group Stable API
27
27
 
@@ -151,6 +151,7 @@ module Prawn
151
151
  #
152
152
  def text(string, options = {})
153
153
  return false if string.nil?
154
+
154
155
  # we modify the options. don't change the user's hash
155
156
  options = options.dup
156
157
 
@@ -281,7 +282,7 @@ module Prawn
281
282
  text = text.to_s.dup
282
283
  save_font do
283
284
  process_text_options(options)
284
- font.normalize_encoding!(text)
285
+ text = font.normalize_encoding(text)
285
286
  font_size(options[:size]) { draw_text!(text, options) }
286
287
  end
287
288
  end
@@ -293,9 +294,9 @@ module Prawn
293
294
  unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
294
295
  warn "PDF's built-in fonts have very limited support for " \
295
296
  "internationalized text.\nIf you need full UTF-8 support, " \
296
- "consider using a TTF font instead.\n\nTo disable this " \
297
+ "consider using an external font instead.\n\nTo disable this " \
297
298
  "warning, add the following line to your code:\n" \
298
- "Prawn::Font::AFM.hide_m17n_warning = true\n"
299
+ "Prawn::Fonts::AFM.hide_m17n_warning = true\n"
299
300
 
300
301
  font.class.hide_m17n_warning = true
301
302
  end
@@ -409,10 +410,11 @@ module Prawn
409
410
  elsif options[:align]
410
411
  raise ArgumentError, 'The :align option does not work with draw_text'
411
412
  end
413
+
412
414
  if options[:kerning].nil?
413
415
  options[:kerning] = default_kerning?
414
416
  end
415
- valid_options = PDF::Core::Text::VALID_OPTIONS + [:at, :rotate]
417
+ valid_options = PDF::Core::Text::VALID_OPTIONS + %i[at rotate]
416
418
  Prawn.verify_options(valid_options, options)
417
419
  options
418
420
  end
@@ -438,7 +440,7 @@ module Prawn
438
440
  options.delete(:indent_paragraphs)
439
441
  end
440
442
 
441
- def move_text_position(dy)
443
+ def move_text_position(amount)
442
444
  bottom =
443
445
  if @bounding_box.stretchy?
444
446
  @margin_box.absolute_bottom
@@ -446,9 +448,9 @@ module Prawn
446
448
  @bounding_box.absolute_bottom
447
449
  end
448
450
 
449
- @bounding_box.move_past_bottom if (y - dy) < bottom
451
+ @bounding_box.move_past_bottom if (y - amount) < bottom
450
452
 
451
- self.y -= dy
453
+ self.y -= amount
452
454
  end
453
455
  end
454
456
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # text/rectangle.rb : Implements text boxes
2
4
  #
3
5
  # Copyright November 2009, Daniel Nelson. All Rights Reserved.
@@ -59,7 +61,7 @@ module Prawn
59
61
  # or right-to-left) [value of document.text_direction]
60
62
  # <tt>:fallback_fonts</tt>::
61
63
  # An array of font names. Each name must be the name of an AFM font or
62
- # the name that was used to register a family of TTF fonts (see
64
+ # the name that was used to register a family of external fonts (see
63
65
  # Prawn::Document#font_families). If present, then each glyph will be
64
66
  # rendered using the first font that includes the glyph, starting with
65
67
  # the current font and then moving through :fallback_fonts from
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'formatted/wrap'
2
4
 
3
5
  require_relative 'formatted/box'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # core/text/formatted/arranger.rb : Implements a data structure for 2-stage
2
4
  # processing of lines of formatted text
3
5
  #
@@ -5,8 +7,6 @@
5
7
  #
6
8
  # This is free software. Please see the LICENSE and COPYING files for details.
7
9
 
8
- # rubocop: disable Style/AccessorMethodName
9
-
10
10
  module Prawn
11
11
  module Text
12
12
  module Formatted #:nodoc:
@@ -57,12 +57,10 @@ module Prawn
57
57
  end
58
58
 
59
59
  @fragments.collect do |fragment|
60
- begin
61
- fragment.text.dup.encode(::Encoding::UTF_8)
62
- rescue ::Encoding::InvalidByteSequenceError,
63
- ::Encoding::UndefinedConversionError
64
- fragment.text.dup.force_encoding(::Encoding::UTF_8)
65
- end
60
+ fragment.text.dup.encode(::Encoding::UTF_8)
61
+ rescue ::Encoding::InvalidByteSequenceError,
62
+ ::Encoding::UndefinedConversionError
63
+ fragment.text.dup.force_encoding(::Encoding::UTF_8)
66
64
  end.join
67
65
  end
68
66
 
@@ -81,8 +79,8 @@ module Prawn
81
79
  @document
82
80
  )
83
81
  @fragments << fragment
84
- set_fragment_measurements(fragment)
85
- set_line_measurement_maximums(fragment)
82
+ self.fragment_measurements = fragment
83
+ self.line_measurement_maximums = fragment
86
84
  end
87
85
  end
88
86
 
@@ -166,6 +164,7 @@ module Prawn
166
164
  @document.character_spacing(character_spacing) do
167
165
  if font || font_style != :normal
168
166
  raise 'Bad font family' unless @document.font.family
167
+
169
168
  @document.font(
170
169
  font || @document.font.family, style: font_style
171
170
  ) do
@@ -179,6 +178,7 @@ module Prawn
179
178
 
180
179
  def update_last_string(printed, unprinted, normalized_soft_hyphen = nil)
181
180
  return if printed.nil?
181
+
182
182
  if printed.empty?
183
183
  @consumed.pop
184
184
  else
@@ -284,7 +284,7 @@ module Prawn
284
284
  end
285
285
  end
286
286
 
287
- def set_fragment_measurements(fragment)
287
+ def fragment_measurements=(fragment)
288
288
  apply_font_settings(fragment) do
289
289
  fragment.width = @document.width_of(
290
290
  fragment.text,
@@ -296,7 +296,7 @@ module Prawn
296
296
  end
297
297
  end
298
298
 
299
- def set_line_measurement_maximums(fragment)
299
+ def line_measurement_maximums=(fragment)
300
300
  @max_line_height = [
301
301
  defined?(@max_line_height) && @max_line_height,
302
302
  fragment.line_height
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # text/formatted/rectangle.rb : Implements text boxes with formatted text
2
4
  #
3
5
  # Copyright February 2010, Daniel Nelson. All Rights Reserved.
@@ -246,6 +248,7 @@ module Prawn
246
248
  #
247
249
  def height
248
250
  return 0 if @baseline_y.nil? || @descender.nil?
251
+
249
252
  (@baseline_y - @descender).abs
250
253
  end
251
254
 
@@ -267,6 +270,9 @@ module Prawn
267
270
  else
268
271
  @at[0] + @width - line_width
269
272
  end
273
+ else
274
+ raise ArgumentError,
275
+ 'align must be one of :left, :right, :center or :justify symbols'
270
276
  end
271
277
 
272
278
  x += accumulated_width
@@ -338,19 +344,19 @@ module Prawn
338
344
  end
339
345
 
340
346
  def valid_options
341
- PDF::Core::Text::VALID_OPTIONS + [
342
- :at,
343
- :height, :width,
344
- :align, :valign,
345
- :rotate, :rotate_around,
346
- :overflow, :min_font_size,
347
- :disable_wrap_by_char,
348
- :leading, :character_spacing,
349
- :mode, :single_line,
350
- :document,
351
- :direction,
352
- :fallback_fonts,
353
- :draw_text_callback
347
+ PDF::Core::Text::VALID_OPTIONS + %i[
348
+ at
349
+ height width
350
+ align valign
351
+ rotate rotate_around
352
+ overflow min_font_size
353
+ disable_wrap_by_char
354
+ leading character_spacing
355
+ mode single_line
356
+ document
357
+ direction
358
+ fallback_fonts
359
+ draw_text_callback
354
360
  ]
355
361
  end
356
362
 
@@ -496,6 +502,7 @@ module Prawn
496
502
  @vertical_alignment_processed
497
503
  return
498
504
  end
505
+
499
506
  @vertical_alignment_processed = true
500
507
 
501
508
  return if @vertical_align == :top
@@ -587,6 +594,7 @@ module Prawn
587
594
 
588
595
  def draw_fragment_overlay_link(fragment)
589
596
  return unless fragment.link
597
+
590
598
  box = fragment.absolute_bounding_box
591
599
  @document.link_annotation(
592
600
  box,
@@ -601,6 +609,7 @@ module Prawn
601
609
 
602
610
  def draw_fragment_overlay_anchor(fragment)
603
611
  return unless fragment.anchor
612
+
604
613
  box = fragment.absolute_bounding_box
605
614
  @document.link_annotation(
606
615
  box,
@@ -611,6 +620,7 @@ module Prawn
611
620
 
612
621
  def draw_fragment_overlay_local(fragment)
613
622
  return unless fragment.local
623
+
614
624
  box = fragment.absolute_bounding_box
615
625
  @document.link_annotation(
616
626
  box,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # text/formatted/fragment.rb : Implements information about a formatted fragment
2
4
  #
3
5
  # Copyright March 2010, Daniel Nelson. All Rights Reserved.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # core/text/formatted/line_wrap.rb : Implements individual line wrapping of
2
4
  # formatted text
3
5
  #
@@ -39,7 +41,7 @@ module Prawn
39
41
  # rubocop: disable Lint/AssignmentInCondition
40
42
  while fragment = @arranger.next_string
41
43
  # rubocop: enable Lint/AssignmentInCondition
42
- @fragment_output = ''
44
+ @fragment_output = +''
43
45
 
44
46
  fragment.lstrip! if first_fragment_on_this_line?(fragment)
45
47
  next if empty_line?(fragment)
@@ -91,11 +93,11 @@ module Prawn
91
93
  false
92
94
  else
93
95
  tokenize(fragment).each do |segment|
94
- if segment == zero_width_space(segment.encoding)
95
- segment_width = 0
96
- else
97
- segment_width = @document.width_of(segment, kerning: @kerning)
98
- end
96
+ segment_width = if segment == zero_width_space(segment.encoding)
97
+ 0
98
+ else
99
+ @document.width_of(segment, kerning: @kerning)
100
+ end
99
101
 
100
102
  if @accumulated_width + segment_width <= @width
101
103
  @accumulated_width += segment_width
@@ -242,6 +244,7 @@ module Prawn
242
244
  !fragment.strip.empty?
243
245
  raise Prawn::Errors::CannotFit
244
246
  end
247
+
245
248
  @arranger.update_last_string(
246
249
  @fragment_output,
247
250
  remaining_text,
@@ -284,8 +287,7 @@ module Prawn
284
287
  end
285
288
 
286
289
  def update_line_status_based_on_last_output
287
- if @fragment_output =~
288
- word_division_scan_pattern(@fragment_output.encoding)
290
+ if @fragment_output&.match?(word_division_scan_pattern(@fragment_output.encoding))
289
291
  @line_contains_more_than_one_word = true
290
292
  end
291
293
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # text/formatted/parser.rb : Implements a bi-directional parser between a subset
2
4
  # of html and formatted text arrays
3
5
  #
@@ -55,21 +57,17 @@ module Prawn
55
57
  array.collect do |hash|
56
58
  prefix = ''
57
59
  suffix = ''
58
- if hash[:styles]
59
- hash[:styles].each do |style|
60
- prefix += prefixes[style]
61
- suffix = suffixes[style] + suffix
62
- end
60
+ hash[:styles]&.each do |style|
61
+ prefix += prefixes[style]
62
+ suffix = suffixes[style] + suffix
63
63
  end
64
64
 
65
65
  font = hash[:font] ? " name='#{hash[:font]}'" : nil
66
66
  size = hash[:size] ? " size='#{hash[:size]}'" : nil
67
- if hash[:character_spacing]
68
- character_spacing =
67
+ character_spacing =
68
+ if hash[:character_spacing]
69
69
  " character_spacing='#{hash[:character_spacing]}'"
70
- else
71
- character_spacing = nil
72
- end
70
+ end
73
71
  if font || size || character_spacing
74
72
  prefix += "<font#{font}#{size}#{character_spacing}>"
75
73
  suffix = '</font>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # wrap.rb: Handles text wrapping for for formatted text
2
4
  #
3
5
  # Contributed by Daniel Nelson
@@ -103,12 +105,12 @@ module Prawn
103
105
  end
104
106
 
105
107
  @printed_lines << printed_fragments.map do |s|
106
- s.force_encoding(::Encoding::UTF_8)
108
+ s.dup.force_encoding(::Encoding::UTF_8)
107
109
  end.join
108
110
  end
109
111
 
110
112
  def word_spacing_for_this_line
111
- if @align == :justify && @line_wrap.space_count > 0 &&
113
+ if @align == :justify && @line_wrap.space_count.positive? &&
112
114
  !@line_wrap.paragraph_finished?
113
115
  (available_width - @line_wrap.width) / @line_wrap.space_count
114
116
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # transformation_stack.rb : Stores the transformations that have been applied to
2
4
  # the document
3
5
  #
@@ -7,7 +9,7 @@
7
9
 
8
10
  require 'matrix'
9
11
 
10
- # rubocop: disable Metrics/ParameterLists
12
+ # rubocop: disable Metrics/ParameterLists, Naming/MethodParameterName
11
13
  module Prawn
12
14
  module TransformationStack
13
15
  def add_to_transformation_stack(a, b, c, d, e, f)
@@ -21,7 +23,7 @@ module Prawn
21
23
  end
22
24
 
23
25
  def restore_transformation_stack
24
- @transformation_stack.pop if @transformation_stack
26
+ @transformation_stack&.pop
25
27
  end
26
28
 
27
29
  def current_transformation_matrix_with_translation(x = 0, y = 0)
@@ -39,3 +41,4 @@ module Prawn
39
41
  end
40
42
  end
41
43
  end
44
+ # rubocop: enable Metrics/ParameterLists, Naming/MethodParameterName