Class: Arrolio::TextLayout::Line

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#alignObject (readonly)

Returns the value of attribute align.



21
22
23
# File 'lib/arrolio/text_layout/line.rb', line 21

def align
  @align
end

#max_widthObject (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_runsObject (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

#widthObject (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

Returns:

  • (Boolean)


31
32
33
# File 'lib/arrolio/text_layout/line.rb', line 31

def empty?
  @placed_runs.empty?
end

#hashObject



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

Returns:

  • (Boolean)


43
44
45
# File 'lib/arrolio/text_layout/line.rb', line 43

def justified?
  @align == :justify
end

#justify_stretchObject

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_offsetObject



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