class Prawn::DisableWordBreak::LineWrap

Private Instance Methods

add_fragment_to_line(fragment) click to toggle source

Override

Calls superclass method
# File lib/prawn/disable_word_break/line_wrap.rb, line 9
def add_fragment_to_line(fragment)
  return super(fragment) if fragment == '' || fragment == "\n"

  insert_fragment_without_word_break(fragment)
end
delete_invisible_chars(fragment) click to toggle source
# File lib/prawn/disable_word_break/line_wrap.rb, line 31
def delete_invisible_chars(fragment)
  encoding = fragment.encoding

  invisible_chars = [
    soft_hyphen(encoding),
    zero_width_space(encoding)
  ].join
  fragment.delete(invisible_chars)
end
insert_fragment_without_word_break(fragment) click to toggle source
# File lib/prawn/disable_word_break/line_wrap.rb, line 15
def insert_fragment_without_word_break(fragment)
  fragment = delete_invisible_chars(fragment)
  fragment_width = @document.width_of(fragment, kerning: @kerning)

  if @accumulated_width + fragment_width <= @width
    @accumulated_width += fragment_width
    @fragment_output += fragment
    fragment_finished(fragment)
    true
  else
    end_of_the_line_reached(fragment)
    fragment_finished(fragment)
    false
  end
end