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. last_line: (the paragraph's final
line) keeps ragged right under :justified, as InDesign does.
Defined Under Namespace
Classes: SpacingLimits
Constant Summary collapse
- DEFAULT_MAX_WORD_SPACING =
133.0- DEFAULT_MAX_LETTER_SPACING =
0.0
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(frame_width, alignment, last_line, limits) ⇒ Justifier
constructor
A new instance of Justifier.
- #justify(line) ⇒ Object
Constructor Details
#initialize(frame_width, alignment, last_line, limits) ⇒ Justifier
Returns a new instance of Justifier.
24 25 26 27 28 29 |
# File 'lib/idml/text_engine/justifier.rb', line 24 def initialize(frame_width, alignment, last_line, limits) @frame_width = frame_width @alignment = alignment @last_line = last_line @limits = limits end |
Class Method Details
.justify(line:, frame_width:, alignment: :left, last_line: false, limits: nil) ⇒ Object
19 20 21 22 |
# File 'lib/idml/text_engine/justifier.rb', line 19 def self.justify(line:, frame_width:, alignment: :left, last_line: false, limits: nil) new(frame_width, alignment, last_line, limits).justify(line) end |
Instance Method Details
#justify(line) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/idml/text_engine/justifier.rb', line 31 def justify(line) case effective_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 |