lib/prawn/text/formatted/wrap.rb in prawn-2.4.0 vs lib/prawn/text/formatted/wrap.rb in prawn-2.5.0
- old
+ new
@@ -1,27 +1,22 @@
# frozen_string_literal: true
-# wrap.rb: Handles text wrapping for for formatted text
-#
-# Contributed by Daniel Nelson
-#
-# This is free software. Please see the LICENSE and COPYING files for details.
-
require_relative 'line_wrap'
require_relative 'arranger'
module Prawn
module Text
- module Formatted #:nodoc:
+ module Formatted
+ # Handles text wrapping for for formatted text.
+ #
# @private
-
- module Wrap #:nodoc:
+ module Wrap
def initialize(_array, options)
@line_wrap = Prawn::Text::Formatted::LineWrap.new
@arranger = Prawn::Text::Formatted::Arranger.new(
@document,
- kerning: options[:kerning]
+ kerning: options[:kerning],
)
@disable_wrap_by_char = options[:disable_wrap_by_char]
end
# See the developer documentation for PDF::Core::Text#wrap
@@ -42,11 +37,11 @@
# <tt>@everything_printed</tt>::
# set to false until everything printed, then true
#
# Returns any formatted text that was not printed
#
- def wrap(array) #:nodoc:
+ def wrap(array)
initialize_wrap(array)
stop = false
until stop
# wrap before testing if enough height for this line because the
@@ -55,11 +50,11 @@
@line_wrap.wrap_line(
document: @document,
kerning: @kerning,
width: available_width,
arranger: @arranger,
- disable_wrap_by_char: @disable_wrap_by_char
+ disable_wrap_by_char: @disable_wrap_by_char,
)
if enough_height_for_this_line?
move_baseline_down
print_line
@@ -89,28 +84,28 @@
break
end
printed_fragments << fragment.text
fragments_this_line << fragment
end
- @arranger.fragments.replace []
+ @arranger.fragments.replace([])
accumulated_width = 0
fragments_this_line.reverse! if @direction == :rtl
fragments_this_line.each do |fragment_this_line|
fragment_this_line.default_direction = @direction
format_and_draw_fragment(
fragment_this_line,
accumulated_width,
@line_wrap.width,
- word_spacing
+ word_spacing,
)
accumulated_width += fragment_this_line.width
end
- @printed_lines << printed_fragments.map do |s|
+ @printed_lines << printed_fragments.map { |s|
s.dup.force_encoding(::Encoding::UTF_8)
- end.join
+ }.join
end
def word_spacing_for_this_line
if @align == :justify && @line_wrap.space_count.positive? &&
!@line_wrap.paragraph_finished?
@@ -159,10 +154,10 @@
@arranger.apply_color_and_font_settings(fragment) do
draw_fragment(
fragment,
accumulated_width,
line_width,
- word_spacing
+ word_spacing,
)
end
end
end
end