Class: Arrolio::Flowables::RotatedText

Inherits:
Arrolio::Flowable show all
Defined in:
lib/arrolio/flowables/rotated_text.rb

Overview

Text rendered at a fixed rotation around its baseline. Used for cover layouts where vertical text runs along the page edge (some flavors put the docidentifier + edition rotated 90° on the left margin).

angle is in degrees, clockwise from horizontal. Common values: 90 (text reads top-to-bottom), 270 (bottom-to-top).

The flowable consumes zero vertical flow space (it's absolutely positioned via PositionedBlock or similar) so siblings continue normally.

Instance Attribute Summary collapse

Attributes inherited from Arrolio::Flowable

#style

Instance Method Summary collapse

Methods inherited from Arrolio::Flowable

#do_split, #keep_together?, #keep_with_next?, #min_keep_height, #page_break_after?, #page_break_before?, #space_after, #space_before, #split, #splittable?

Constructor Details

#initialize(text, style: Style::Definition.new, angle: 90) ⇒ RotatedText

Returns a new instance of RotatedText.



19
20
21
22
23
# File 'lib/arrolio/flowables/rotated_text.rb', line 19

def initialize(text, style: Style::Definition.new, angle: 90)
  super(style: style)
  @text = text.to_s
  @angle = angle.to_f
end

Instance Attribute Details

#angleObject (readonly)

Returns the value of attribute angle.



17
18
19
# File 'lib/arrolio/flowables/rotated_text.rb', line 17

def angle
  @angle
end

#textObject (readonly)

Returns the value of attribute text.



17
18
19
# File 'lib/arrolio/flowables/rotated_text.rb', line 17

def text
  @text
end

Instance Method Details

#emit(x, y, width, _context = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/arrolio/flowables/rotated_text.rb', line 31

def emit(x, y, width, _context = nil)
  line_h = height(width)
  measurer = GlyphMeasurer.new(font_name: @style.font_name)
  text_w = measurer.width_of_string(@text, font_size: @style.font_size)

  box = Output::PlacedBox.new(
    x: x, y: y - line_h,
    width: text_w, height: line_h,
    kind: :rotated_text,
    data: {
      text: @text,
      angle: @angle,
      line_height: line_h,
      style: @style
    }
  )
  [[box], 0.0]
end

#height(_width, _context = nil) ⇒ Object



25
26
27
28
29
# File 'lib/arrolio/flowables/rotated_text.rb', line 25

def height(_width, _context = nil)
  GlyphMeasurer.new(font_name: @style.font_name)
               .line_height(font_size: @style.font_size,
                            line_spacing: @style.line_spacing)
end