Class: Krill::LineWrap

Inherits:
Object
  • Object
show all
Defined in:
lib/krill/line_wrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#space_countObject (readonly)

The number of spaces in the last wrapped line



11
12
13
# File 'lib/krill/line_wrap.rb', line 11

def space_count
  @space_count
end

Instance Method Details

#paragraph_finished?Boolean

Whether this line is the last line in the paragraph

Returns:

  • (Boolean)


16
17
18
# File 'lib/krill/line_wrap.rb', line 16

def paragraph_finished?
  @newline_encountered || is_next_string_newline? || @arranger.finished?
end

#tokenize(fragment) ⇒ Object



20
21
22
# File 'lib/krill/line_wrap.rb', line 20

def tokenize(fragment)
  fragment.scan(scan_pattern)
end

#widthObject

The width of the last wrapped line



6
7
8
# File 'lib/krill/line_wrap.rb', line 6

def width
  @accumulated_width || 0
end

#wrap_line(width:, arranger:, kerning: nil, disable_wrap_by_char: nil) ⇒ Object

Work in conjunction with the PDF::Formatted::Arranger defined in the :arranger option to determine what formatted text will fit within the width defined by the :width option



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/krill/line_wrap.rb', line 28

def wrap_line(width:, arranger:, kerning: nil, disable_wrap_by_char: nil)
  initialize_line(
    kerning: kerning,
    width: width,
    arranger: arranger,
    disable_wrap_by_char: disable_wrap_by_char)

  while fragment = @arranger.next_string
    @fragment_output = ""

    next if empty_line?(fragment)

    break unless apply_font_settings_and_add_fragment_to_line(fragment)
  end

  @arranger.finalize_line
  @accumulated_width = @arranger.line_width
  @space_count = @arranger.space_count
  @arranger.line
end