| Class | Prawn::Format::Instructions::Text |
| In: |
lib/prawn/format/instructions/text.rb
lib/prawn/format/instructions/text.rb |
| Parent: | Base |
| text | [R] | |
| text | [R] |
# File lib/prawn/format/instructions/text.rb, line 12
12: def initialize(state, text, options={})
13: super(state)
14: @text = text
15: @break = options.key?(:break) ? options[:break] : text.index(/[-\xE2\x80\x94\s]/)
16: @discardable = options.key?(:discardable) ? options[:discardable] : text.index(/\s/)
17: state.font.normalize_encoding(@text) if options.fetch(:normalize, true)
18: end
# File lib/prawn/format/instructions/text.rb, line 12
12: def initialize(state, text, options={})
13: super(state)
14: @text = text
15: @break = options.key?(:break) ? options[:break] : text.index(/[-\xE2\x80\x94\s]/)
16: @discardable = options.key?(:discardable) ? options[:discardable] : text.index(/\s/)
17: state.font.normalize_encoding(@text) if options.fetch(:normalize, true)
18: end
# File lib/prawn/format/instructions/text.rb, line 25
25: def accumulate(list)
26: if list.last.is_a?(Text) && list.last.state == state
27: list.last.text << @text
28: else
29: list.push(dup)
30: end
31:
32: return list
33: end
# File lib/prawn/format/instructions/text.rb, line 25
25: def accumulate(list)
26: if list.last.is_a?(Text) && list.last.state == state
27: list.last.text << @text
28: else
29: list.push(dup)
30: end
31:
32: return list
33: end
# File lib/prawn/format/instructions/text.rb, line 55
55: def compatible?(with)
56: with.is_a?(self.class) && with.state == state
57: end
# File lib/prawn/format/instructions/text.rb, line 55
55: def compatible?(with)
56: with.is_a?(self.class) && with.state == state
57: end
# File lib/prawn/format/instructions/text.rb, line 73
73: def draw(document, draw_state, options={})
74: @state.apply!(draw_state[:text], draw_state[:cookies])
75:
76: encoded_text = @state.font.encode_text(@text, :kerning => @state.kerning?)
77: encoded_text.each do |subset, chunk|
78: @state.apply_font!(draw_state[:text], draw_state[:cookies], subset)
79: draw_state[:text].show(chunk)
80: end
81: draw_state[:dx] += width
82:
83: draw_state[:dx] += draw_state[:padding] * spaces if draw_state[:padding]
84: end
# File lib/prawn/format/instructions/text.rb, line 73
73: def draw(document, draw_state, options={})
74: @state.apply!(draw_state[:text], draw_state[:cookies])
75:
76: encoded_text = @state.font.encode_text(@text, :kerning => @state.kerning?)
77: encoded_text.each do |subset, chunk|
78: @state.apply_font!(draw_state[:text], draw_state[:cookies], subset)
79: draw_state[:text].show(chunk)
80: end
81: draw_state[:dx] += width
82:
83: draw_state[:dx] += draw_state[:padding] * spaces if draw_state[:padding]
84: end
# File lib/prawn/format/instructions/text.rb, line 20
20: def dup
21: self.class.new(state, @text.dup, :normalize => false,
22: :break => @break, :discardable => @discardable)
23: end
# File lib/prawn/format/instructions/text.rb, line 20
20: def dup
21: self.class.new(state, @text.dup, :normalize => false,
22: :break => @break, :discardable => @discardable)
23: end
# File lib/prawn/format/instructions/text.rb, line 39
39: def height(ignore_discardable=false)
40: if ignore_discardable && discardable?
41: 0
42: else
43: @height
44: end
45: end
# File lib/prawn/format/instructions/text.rb, line 39
39: def height(ignore_discardable=false)
40: if ignore_discardable && discardable?
41: 0
42: else
43: @height
44: end
45: end
# File lib/prawn/format/instructions/text.rb, line 35
35: def spaces
36: @spaces ||= @text.scan(/ /).length
37: end
# File lib/prawn/format/instructions/text.rb, line 35
35: def spaces
36: @spaces ||= @text.scan(/ /).length
37: end
# File lib/prawn/format/instructions/text.rb, line 59
59: def width(type=:all)
60: @width ||= @state.font.compute_width_of(@text, :size => @state.font_size, :kerning => @state.kerning?)
61:
62: case type
63: when :discardable then discardable? ? @width : 0
64: when :nondiscardable then discardable? ? 0 : @width
65: else @width
66: end
67: end
# File lib/prawn/format/instructions/text.rb, line 59
59: def width(type=:all)
60: @width ||= @state.font.compute_width_of(@text, :size => @state.font_size, :kerning => @state.kerning?)
61:
62: case type
63: when :discardable then discardable? ? @width : 0
64: when :nondiscardable then discardable? ? 0 : @width
65: else @width
66: end
67: end