Class: Idml::TextEngine::Justifier
- Inherits:
-
Object
- Object
- Idml::TextEngine::Justifier
- Defined in:
- lib/idml/text_engine/justifier.rb
Overview
Distributes slack space within a line per the paragraph's alignment. Adjusts x_offset and optionally scales inter-word spaces for justified text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(frame_width, alignment) ⇒ Justifier
constructor
A new instance of Justifier.
- #justify(line) ⇒ Object
Constructor Details
#initialize(frame_width, alignment) ⇒ Justifier
Returns a new instance of Justifier.
13 14 15 16 |
# File 'lib/idml/text_engine/justifier.rb', line 13 def initialize(frame_width, alignment) @frame_width = frame_width @alignment = alignment end |
Class Method Details
.justify(line:, frame_width:, alignment: :left) ⇒ Object
9 10 11 |
# File 'lib/idml/text_engine/justifier.rb', line 9 def self.justify(line:, frame_width:, alignment: :left) new(frame_width, alignment).justify(line) end |
Instance Method Details
#justify(line) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/idml/text_engine/justifier.rb', line 18 def justify(line) case @alignment when :left, :start then line.x_offset = 0 when :center, :middle line.x_offset = (@frame_width - line.width) / 2 when :right, :end line.x_offset = @frame_width - line.width when :justified then justify_line(line) end line end |