Class: Arrolio::TextLayout::Line
- Inherits:
-
Object
- Object
- Arrolio::TextLayout::Line
- Defined in:
- lib/arrolio/text_layout/line.rb
Overview
One laid-out line: a list of PlacedRun tuples plus the line's content width, target width, and alignment.
Defined Under Namespace
Classes: PlacedRun
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#max_width ⇒ Object
readonly
Returns the value of attribute max_width.
-
#placed_runs ⇒ Object
readonly
Returns the value of attribute placed_runs.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(placed_runs, width:, max_width:, align: :left) ⇒ Line
constructor
A new instance of Line.
- #justified? ⇒ Boolean
-
#justify_stretch ⇒ Object
Negative when the line is overfull (TeX shrink): the renderer compresses inter-word gaps.
- #x_offset ⇒ Object
Constructor Details
#initialize(placed_runs, width:, max_width:, align: :left) ⇒ Line
Returns a new instance of Line.
23 24 25 26 27 28 29 |
# File 'lib/arrolio/text_layout/line.rb', line 23 def initialize(placed_runs, width:, max_width:, align: :left) @placed_runs = placed_runs.freeze @width = width.to_f @max_width = max_width.to_f @align = align freeze end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
21 22 23 |
# File 'lib/arrolio/text_layout/line.rb', line 21 def align @align end |
#max_width ⇒ Object (readonly)
Returns the value of attribute max_width.
21 22 23 |
# File 'lib/arrolio/text_layout/line.rb', line 21 def max_width @max_width end |
#placed_runs ⇒ Object (readonly)
Returns the value of attribute placed_runs.
21 22 23 |
# File 'lib/arrolio/text_layout/line.rb', line 21 def placed_runs @placed_runs end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
21 22 23 |
# File 'lib/arrolio/text_layout/line.rb', line 21 def width @width end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
59 60 61 62 63 64 65 |
# File 'lib/arrolio/text_layout/line.rb', line 59 def ==(other) other.is_a?(self.class) && placed_runs == other.placed_runs && width == other.width && max_width == other.max_width && align == other.align end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/arrolio/text_layout/line.rb', line 31 def empty? @placed_runs.empty? end |
#hash ⇒ Object
69 70 71 |
# File 'lib/arrolio/text_layout/line.rb', line 69 def hash [self.class, placed_runs, width, max_width, align].hash end |
#justified? ⇒ Boolean
43 44 45 |
# File 'lib/arrolio/text_layout/line.rb', line 43 def justified? @align == :justify end |
#justify_stretch ⇒ Object
Negative when the line is overfull (TeX shrink): the renderer compresses inter-word gaps. Clamping at zero made compressed lines draw at natural width, past the measure.
50 51 52 53 54 55 56 57 |
# File 'lib/arrolio/text_layout/line.rb', line 50 def justify_stretch return 0.0 unless justified? gaps = word_gap_count return 0.0 if gaps.zero? (@max_width - @width) / gaps.to_f end |
#x_offset ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/arrolio/text_layout/line.rb', line 35 def x_offset case @align when :center then ((@max_width - @width) / 2.0) when :right then (@max_width - @width) else 0.0 end end |