Class: Krill::TextBox

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formatted_text, options = {}) ⇒ TextBox

Returns a new instance of TextBox.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/krill/text_box.rb', line 9

def initialize(formatted_text, options={})
  @original_array       = formatted_text
  @text                 = nil
  @at                   = [0, 720.0] # was [ @document.bounds.left, @document.bounds.top ]
  @width                = options.fetch(:width)
  @height               = options.fetch(:height, @at[1])
  @direction            = options.fetch(:direction, :ltr)
  @align                = options.fetch(:align, @direction == :rtl ? :right : :left)
  @leading              = options.fetch(:leading, 0)
  @kerning              = options.fetch(:kerning, true)
  @disable_wrap_by_char = options[:disable_wrap_by_char]
  @line_wrap            = Krill::LineWrap.new
  @arranger             = Krill::Arranger.new(kerning: @kerning)
end

Instance Attribute Details

#ascenderObject (readonly)

The height of the ascender of the last line printed



51
52
53
# File 'lib/krill/text_box.rb', line 51

def ascender
  @ascender
end

#atObject (readonly)

The upper left corner of the text box



45
46
47
# File 'lib/krill/text_box.rb', line 45

def at
  @at
end

#descenderObject (readonly)

The height of the descender of the last line printed



54
55
56
# File 'lib/krill/text_box.rb', line 54

def descender
  @descender
end

#leadingObject (readonly)

The leading used during printing



57
58
59
# File 'lib/krill/text_box.rb', line 57

def leading
  @leading
end

#line_heightObject (readonly)

The line height of the last line printed



48
49
50
# File 'lib/krill/text_box.rb', line 48

def line_height
  @line_height
end

#printed_linesObject (readonly)

Returns the value of attribute printed_lines.



7
8
9
# File 'lib/krill/text_box.rb', line 7

def printed_lines
  @printed_lines
end

#textObject (readonly)

The text that was successfully printed (or, if dry_run was used, the text that would have been successfully printed)



30
31
32
# File 'lib/krill/text_box.rb', line 30

def text
  @text
end

Instance Method Details

#everything_printed?Boolean

True if everything printed (or, if dry_run was used, everything would have been successfully printed)

Returns:

  • (Boolean)


40
41
42
# File 'lib/krill/text_box.rb', line 40

def everything_printed?
  @everything_printed
end

#heightObject

The height actually used during the previous render



64
65
66
67
# File 'lib/krill/text_box.rb', line 64

def height
  return 0 if @baseline_y.nil? || @descender.nil?
  (@baseline_y - @descender).abs
end

#line_gapObject



59
60
61
# File 'lib/krill/text_box.rb', line 59

def line_gap
  line_height - (ascender + descender)
end

#nothing_printed?Boolean

True if nothing printed (or, if dry_run was used, nothing would have been successfully printed)

Returns:

  • (Boolean)


34
35
36
# File 'lib/krill/text_box.rb', line 34

def nothing_printed?
  @nothing_printed
end

#renderObject



24
25
26
# File 'lib/krill/text_box.rb', line 24

def render
  wrap(normalize_encoding(original_text))
end