# File lib/prawn/format/instructions/text.rb, line 11 def initialize(state, text, options={}) super(state) @text = text @break = options.key?(:break) ? options[:break] : text.index(/[-\xE2\x80\x94\s]/) @discardable = options.key?(:discardable) ? options[:discardable] : text.index(/\s/) @text = state.font.normalize_encoding(@text) if options.fetch(:normalize, true) end
# File lib/prawn/format/instructions/text.rb, line 24 def accumulate(list) if list.last.is_a?(Text) && list.last.state == state list.last.text << @text else list.push(dup) end return list end
# File lib/prawn/format/instructions/text.rb, line 46 def break? @break end
# File lib/prawn/format/instructions/text.rb, line 54 def compatible?(with) with.is_a?(self.class) && with.state == state end
# File lib/prawn/format/instructions/text.rb, line 50 def discardable? @discardable end
# File lib/prawn/format/instructions/text.rb, line 72 def draw(document, draw_state, options={}) @state.apply!(draw_state[:text], draw_state[:cookies]) encoded_text = @state.font.encode_text(@text, :kerning => @state.kerning?) encoded_text.each do |subset, chunk| @state.apply_font!(draw_state[:text], draw_state[:cookies], subset) draw_state[:text].show(chunk) end draw_state[:dx] += width draw_state[:dx] += draw_state[:padding] * spaces if draw_state[:padding] end
# File lib/prawn/format/instructions/text.rb, line 19 def dup self.class.new(state, @text.dup, :normalize => false, :break => @break, :discardable => @discardable) end
# File lib/prawn/format/instructions/text.rb, line 38 def height(ignore_discardable=false) if ignore_discardable && discardable? 0 else @height end end
# File lib/prawn/format/instructions/text.rb, line 34 def spaces @spaces ||= @text.scan(/ /).length end
# File lib/prawn/format/instructions/text.rb, line 68 def to_s @text end
# File lib/prawn/format/instructions/text.rb, line 58 def width(type=:all) @width ||= @state.font.compute_width_of(@text, :size => @state.font_size, :kerning => @state.kerning?) case type when :discardable then discardable? ? @width : 0 when :nondiscardable then discardable? ? 0 : @width else @width end end
Generated with the Darkfish Rdoc Generator 2.