Class: Arrolio::TextLayout::KnuthPlass::Penalty

Inherits:
Item
  • Object
show all
Defined in:
lib/arrolio/text_layout/knuth_plass/item.rb

Overview

A penalty represents a potential break point. Width is the width of the hyphen (or 0 if no hyphen). Flagged penalties (e.g., hyphenation) incur extra cost. A penalty of Infinity means "never break here"; -Infinity means "always break".

Instance Attribute Summary collapse

Attributes inherited from Item

#width

Instance Method Summary collapse

Methods inherited from Item

#box?, #glue?

Constructor Details

#initialize(penalty:, width: 0, flagged: false, run_index: nil, char_offset: nil) ⇒ Penalty

Returns a new instance of Penalty.



61
62
63
64
65
66
67
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 61

def initialize(penalty:, width: 0, flagged: false, run_index: nil, char_offset: nil)
  super(width: width)
  @penalty = penalty.to_f
  @flagged = flagged
  @run_index = run_index
  @char_offset = char_offset
end

Instance Attribute Details

#char_offsetObject (readonly)

Returns the value of attribute char_offset.



59
60
61
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59

def char_offset
  @char_offset
end

#flaggedObject (readonly)

Returns the value of attribute flagged.



59
60
61
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59

def flagged
  @flagged
end

#penaltyObject (readonly)

Returns the value of attribute penalty.



59
60
61
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59

def penalty
  @penalty
end

#run_indexObject (readonly)

Returns the value of attribute run_index.



59
60
61
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59

def run_index
  @run_index
end

Instance Method Details

#forced_break?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 71

def forced_break?
  @penalty == -Float::INFINITY
end

#no_break?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 75

def no_break?
  @penalty == Float::INFINITY
end

#penalty?Boolean

Returns:

  • (Boolean)


69
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 69

def penalty? = true