Class: HexaPDF::Layout::TextLayouter::Penalty

Inherits:
Object
  • Object
show all
Defined in:
lib/hexapdf/layout/text_layouter.rb

Overview

Used for layouting. Describes a penalty item, i.e. a point where a break is allowed.

If the penalty is greater than or equal to INFINITY, a break is forbidden. If it is smaller than or equal to -INFINITY, a break is mandatory.

If a penalty contains an item and a break occurs at the penalty (taking the width of the penalty/item into account), then the penality item must be the last item of the line.

Constant Summary collapse

INFINITY =

All numbers greater than this one are deemed infinite.

1000
PARAGRAPH_BREAK =

The penalty value for a mandatory paragraph break.

- 1_000_000
LINE_BREAK =

The penalty value for a mandatory line break.

- 1_000_001
ProhibitedBreak =

Singleton object describing a Penalty for a prohibited break.

new(Penalty::INFINITY)
Standard =

Singleton object describing a standard Penalty, e.g. for hyphens.

new(50)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(penalty, width = 0, item: nil) ⇒ Penalty

Creates a new Penalty with the given penality.



174
175
176
177
178
# File 'lib/hexapdf/layout/text_layouter.rb', line 174

def initialize(penalty, width = 0, item: nil)
  @penalty = penalty
  @width = width
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

The wrapped item.



171
172
173
# File 'lib/hexapdf/layout/text_layouter.rb', line 171

def item
  @item
end

#penaltyObject (readonly)

The penalty for breaking at this point.



165
166
167
# File 'lib/hexapdf/layout/text_layouter.rb', line 165

def penalty
  @penalty
end

#widthObject (readonly)

The width assigned to this item.



168
169
170
# File 'lib/hexapdf/layout/text_layouter.rb', line 168

def width
  @width
end

Instance Method Details

#inspectObject

:nodoc:



185
186
187
# File 'lib/hexapdf/layout/text_layouter.rb', line 185

def inspect #:nodoc:
  "Penalty[#{penalty} #{width} #{@item.inspect}]"
end

#typeObject

Returns :penalty.



181
182
183
# File 'lib/hexapdf/layout/text_layouter.rb', line 181

def type
  :penalty
end