Class: Idml::TextEngine::VerticalLayout
- Inherits:
-
Object
- Object
- Idml::TextEngine::VerticalLayout
- Defined in:
- lib/idml/text_engine/vertical_layout.rb
Overview
Positions justified lines vertically within a text frame. Applies leading, paragraph spacing, first-line indent, and left/right insets.
Defined Under Namespace
Classes: Frame
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(frame, font_size, leading, space_before, space_after, first_line_indent, left_indent) ⇒ VerticalLayout
constructor
A new instance of VerticalLayout.
- #layout(lines) ⇒ Object
Constructor Details
#initialize(frame, font_size, leading, space_before, space_after, first_line_indent, left_indent) ⇒ VerticalLayout
Returns a new instance of VerticalLayout.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/idml/text_engine/vertical_layout.rb', line 23 def initialize(frame, font_size, leading, space_before, space_after, first_line_indent, left_indent) @frame = frame @font_size = font_size @leading = leading || (font_size * 1.2) @space_before = space_before @space_after = space_after @first_line_indent = first_line_indent @left_indent = left_indent end |
Class Method Details
.layout(lines:, frame:, font_size:, leading: nil, space_before: 0, space_after: 0, first_line_indent: 0, left_indent: 0) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/idml/text_engine/vertical_layout.rb', line 16 def self.layout(lines:, frame:, font_size:, leading: nil, space_before: 0, space_after: 0, first_line_indent: 0, left_indent: 0) new(frame, font_size, leading, space_before, space_after, first_line_indent, left_indent).layout(lines) end |
Instance Method Details
#layout(lines) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/idml/text_engine/vertical_layout.rb', line 34 def layout(lines) result = [] y = top_y - @space_before lines.each_with_index do |line, idx| y -= @leading x = frame_left + (idx.zero? ? @first_line_indent : @left_indent) x += line.x_offset.to_f current_x = x line.glyphs.each do |glyph| result << PositionedGlyph.new(glyph.codepoint, current_x, y, @font_size) current_x += glyph.width end end result end |