| Class | Prawn::Format::Line |
| In: |
lib/prawn/format/line.rb
lib/prawn/format/line.rb |
| Parent: | Object |
| instructions | [R] | |
| instructions | [R] | |
| source | [R] | |
| source | [R] |
# File lib/prawn/format/line.rb, line 10
10: def initialize(instructions, hard_break)
11: # need to remember the "source" instructions, because lines can
12: # pushed back onto the stack en masse when flowing into boxes,
13: # if a line is discovered to not fit. Thus, a line must preserve
14: # all instructions it was originally given.
15:
16: @source = instructions
17: @hard_break = hard_break
18: end
# File lib/prawn/format/line.rb, line 10
10: def initialize(instructions, hard_break)
11: # need to remember the "source" instructions, because lines can
12: # pushed back onto the stack en masse when flowing into boxes,
13: # if a line is discovered to not fit. Thus, a line must preserve
14: # all instructions it was originally given.
15:
16: @source = instructions
17: @hard_break = hard_break
18: end
distance from top of line to baseline
# File lib/prawn/format/line.rb, line 47
47: def ascent
48: instructions.map { |instruction| instruction.ascent }.max || 0
49: end
distance from top of line to baseline
# File lib/prawn/format/line.rb, line 47
47: def ascent
48: instructions.map { |instruction| instruction.ascent }.max || 0
49: end
distance from bottom of line to baseline
# File lib/prawn/format/line.rb, line 52
52: def descent
53: instructions.map { |instruction| instruction.descent }.min || 0
54: end
distance from bottom of line to baseline
# File lib/prawn/format/line.rb, line 52
52: def descent
53: instructions.map { |instruction| instruction.descent }.min || 0
54: end
# File lib/prawn/format/line.rb, line 60
60: def draw_on(document, state, options={})
61: return if instructions.empty?
62:
63: format_state = instructions.first.state
64:
65: case(options[:align])
66: when :left
67: state[:dx] = 0
68: when :center
69: state[:dx] = (state[:width] - width) / 2.0
70: when :right
71: state[:dx] = state[:width] - width
72: when :justify
73: state[:dx] = 0
74: state[:padding] = hard_break? ? 0 : (state[:width] - width) / spaces
75: state[:text].word_space(state[:padding])
76: end
77:
78: state[:dy] -= ascent
79:
80: state[:text].move_to(state[:dx], state[:dy])
81: state[:line] = self
82:
83: document.save_font do
84: instructions.each { |instruction| instruction.draw(document, state, options) }
85: state[:pending_effects].each { |effect| effect.wrap(document, state) }
86: end
87:
88: state[:dy] -= (options[:spacing] || 0) + (height - ascent)
89: end
# File lib/prawn/format/line.rb, line 60
60: def draw_on(document, state, options={})
61: return if instructions.empty?
62:
63: format_state = instructions.first.state
64:
65: case(options[:align])
66: when :left
67: state[:dx] = 0
68: when :center
69: state[:dx] = (state[:width] - width) / 2.0
70: when :right
71: state[:dx] = state[:width] - width
72: when :justify
73: state[:dx] = 0
74: state[:padding] = hard_break? ? 0 : (state[:width] - width) / spaces
75: state[:text].word_space(state[:padding])
76: end
77:
78: state[:dy] -= ascent
79:
80: state[:text].move_to(state[:dx], state[:dy])
81: state[:line] = self
82:
83: document.save_font do
84: instructions.each { |instruction| instruction.draw(document, state, options) }
85: state[:pending_effects].each { |effect| effect.wrap(document, state) }
86: end
87:
88: state[:dy] -= (options[:spacing] || 0) + (height - ascent)
89: end
# File lib/prawn/format/line.rb, line 56
56: def height(include_blank=false)
57: instructions.map { |instruction| instruction.height(include_blank) }.max
58: end
# File lib/prawn/format/line.rb, line 56
56: def height(include_blank=false)
57: instructions.map { |instruction| instruction.height(include_blank) }.max
58: end
# File lib/prawn/format/line.rb, line 20
20: def instructions
21: @instructions ||= begin
22: instructions = source.dup
23:
24: # ignore discardable items at the end of lines
25: instructions.pop while instructions.any? && instructions.last.discardable?
26:
27: consolidate(instructions)
28: end
29: end
# File lib/prawn/format/line.rb, line 20
20: def instructions
21: @instructions ||= begin
22: instructions = source.dup
23:
24: # ignore discardable items at the end of lines
25: instructions.pop while instructions.any? && instructions.last.discardable?
26:
27: consolidate(instructions)
28: end
29: end
# File lib/prawn/format/line.rb, line 31
31: def spaces
32: @spaces ||= begin
33: spaces = instructions.inject(0) { |sum, instruction| sum + instruction.spaces }
34: [1, spaces].max
35: end
36: end
# File lib/prawn/format/line.rb, line 31
31: def spaces
32: @spaces ||= begin
33: spaces = instructions.inject(0) { |sum, instruction| sum + instruction.spaces }
34: [1, spaces].max
35: end
36: end