Module: Idml::TextEngine::VerticalTextLayout

Defined in:
lib/idml/text_engine/vertical_text_layout.rb

Overview

Vertical (top-to-bottom, right-to-left) glyph layout for CJK vertical writing (StoryOrientation="Vertical"). Glyphs stay UPRIGHT — CJK ideographs render correctly stacked; Latin glyphs are not rotated to the vertical axis (documented approximation). Line breaking (and therefore kinsoku shori) is reused from LineBreaker against the column height.

Defined Under Namespace

Classes: PositionedGlyph

Class Method Summary collapse

Class Method Details

.column_height(frame) ⇒ Object

The frame's usable vertical extent for one column of text.



32
33
34
# File 'lib/idml/text_engine/vertical_text_layout.rb', line 32

def self.column_height(frame)
  frame.height - (frame.inset_top || 0) - (frame.inset_bottom || 0)
end

.layout(glyphs:, frame:, leading:, size:, start_column: 0) ⇒ Object

Stacks glyphs into columns of at most the frame's text height; column 0 is the rightmost. start_column places the first column after already-used columns (multi-run frames). Returns [positioned_glyphs, next_column_index].



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/idml/text_engine/vertical_text_layout.rb', line 19

def self.layout(glyphs:, frame:, leading:, size:, start_column: 0)
  lines = TextEngine::LineBreaker.break(
    glyphs: glyphs, frame_width: column_height(frame),
  )
  positioned = []
  lines.each_with_index do |line, index|
    stack_column(positioned, line.glyphs, frame, leading, size,
                 index + start_column)
  end
  [positioned, start_column + lines.length]
end

.tatechuyoko_group(glyphs:, frame:, leading:, size:, start_column:) ⇒ Object

Positions a tate-chu-yoko group (e.g. the digits "12" kept horizontal inside vertical text): glyphs share one baseline at the top of the given column slot and advance left-to- right, centered in the slot. Returns [positioned_glyphs, next_column_index]; nil when the group is wider than the column height (caller falls back to stacked layout).



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/idml/text_engine/vertical_text_layout.rb', line 58

def self.tatechuyoko_group(glyphs:, frame:, leading:, size:,
                           start_column:)
  total = glyphs.sum(&:width)
  return nil if total > column_height(frame)

  right = frame.x + frame.width - (frame.inset_right || 0)
  slot_center = right - ((start_column + 0.5) * leading)
  x = slot_center - (total / 2.0)
  baseline_y = frame.y + frame.height - (frame.inset_top || 0) - size
  positioned = glyphs.map do |glyph|
    glyph_position = PositionedGlyph.new(
      codepoint: glyph.codepoint, x: x, y: baseline_y,
    )
    x += glyph.width
    glyph_position
  end
  [positioned, start_column + 1]
end