Sha256: 14a1dcfa6c0b3598f62538e1aa33eaf70aedfbcd00e4185eec1ac9617cce88ca

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

Prawn::Text::Formatted::LineWrap.prepend (Module.new do
  def add_fragment_to_line fragment
    case fragment
    when ''
      true
    when ?\n
      @newline_encountered = true
      false
    else
      if (joined_string = @arranger.preview_joined_string)
        joined_string_width = @document.width_of (tokenize joined_string)[0], kerning: @kerning
      else
        joined_string_width = 0
      end
      last_idx = (segments = tokenize fragment).length - 1
      segments.each_with_index do |segment, idx|
        if segment == (zero_width_space segment.encoding)
          segment_width = effective_segment_width = 0
        else
          segment_width = effective_segment_width = @document.width_of segment, kerning: @kerning
          effective_segment_width += joined_string_width if idx === last_idx
        end
        if @accumulated_width + effective_segment_width <= @width
          @accumulated_width += segment_width
          if segment[-1] == (shy = soft_hyphen segment.encoding)
            @accumulated_width -= (@document.width_of shy, kerning: @kerning)
          end
          @fragment_output += segment
        else
          @line_contains_more_than_one_word = false if @accumulated_width == 0 && @line_contains_more_than_one_word
          end_of_the_line_reached segment
          fragment_finished fragment
          return false
        end
      end
      fragment_finished fragment
      true
    end
  end
end)

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.3.19 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.18 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.17 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.16 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.15 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.14 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.13 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.12 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.11 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.10 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.9 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.8 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.7 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.6 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.5 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.4 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.3 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.2 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.1 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb
asciidoctor-pdf-2.3.0 lib/asciidoctor/pdf/ext/prawn/formatted_text/line_wrap.rb