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
MandatoryParagraphBreak =

Singleton object describing a Penalty for a mandatory paragraph break.

new(PARAGRAPH_BREAK)
MandatoryLineBreak =

Singleton object describing a Penalty for a mandatory line break.

new(LINE_BREAK)
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.



162
163
164
165
166
# File 'lib/hexapdf/layout/text_layouter.rb', line 162

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

Instance Attribute Details

#itemObject (readonly)

The wrapped item.



159
160
161
# File 'lib/hexapdf/layout/text_layouter.rb', line 159

def item
  @item
end

#penaltyObject (readonly)

The penalty for breaking at this point.



153
154
155
# File 'lib/hexapdf/layout/text_layouter.rb', line 153

def penalty
  @penalty
end

#widthObject (readonly)

The width assigned to this item.



156
157
158
# File 'lib/hexapdf/layout/text_layouter.rb', line 156

def width
  @width
end

Instance Method Details

#typeObject

Returns :penalty.



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

def type
  :penalty
end