Class: Arrolio::WritingMode

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/writing_mode.rb

Overview

Writing mode enumeration for vertical/RTL layout. Controls the inline and block progression directions used by the layout engine. The values map to XSL-FO writing-mode property values.

LR_TB — left-to-right inline, top-to-bottom block (Latin, CJK). RL_TB — right-to-left inline, top-to-bottom block (Arabic, Hebrew). TB_RL — top-to-bottom inline, right-to-left block (vertical CJK).

Constant Summary collapse

LR_TB =
:lr_tb
RL_TB =
:rl_tb
TB_RL =
:tb_rl
DEFAULT =
LR_TB
ALL =
[LR_TB, RL_TB, TB_RL].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode = DEFAULT) ⇒ WritingMode

Returns a new instance of WritingMode.



22
23
24
25
# File 'lib/arrolio/writing_mode.rb', line 22

def initialize(mode = DEFAULT)
  @mode = mode.to_sym
  freeze
end

Instance Attribute Details

#modeObject (readonly)

Returns the value of attribute mode.



20
21
22
# File 'lib/arrolio/writing_mode.rb', line 20

def mode
  @mode
end

Class Method Details

.parse(value) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/arrolio/writing_mode.rb', line 66

def self.parse(value)
  case value.to_s.downcase.tr('-', '_')
  when 'lr_tb', 'lrtb' then new(LR_TB)
  when 'rl_tb', 'rltb' then new(RL_TB)
  when 'tb_rl', 'tbrl' then new(TB_RL)
  else new(DEFAULT)
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



57
58
59
# File 'lib/arrolio/writing_mode.rb', line 57

def ==(other)
  other.is_a?(self.class) && mode == other.mode
end

#block_directionObject

Returns the block progression direction as a 2D vector.



50
51
52
53
54
55
# File 'lib/arrolio/writing_mode.rb', line 50

def block_direction
  case @mode
  when LR_TB, RL_TB then [0, -1]
  when TB_RL then [-1, 0]
  end
end

#hashObject



62
63
64
# File 'lib/arrolio/writing_mode.rb', line 62

def hash
  [self.class, mode].hash
end

#inline_directionObject

Returns the inline progression direction as a 2D vector. [1, 0] = rightward, [-1, 0] = leftward, [0, 1] = downward.



41
42
43
44
45
46
47
# File 'lib/arrolio/writing_mode.rb', line 41

def inline_direction
  case @mode
  when LR_TB then [1, 0]
  when RL_TB then [-1, 0]
  when TB_RL then [0, 1]
  end
end

#ltr?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/arrolio/writing_mode.rb', line 35

def ltr?
  @mode == LR_TB
end

#rtl?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/arrolio/writing_mode.rb', line 31

def rtl?
  @mode == RL_TB
end

#vertical?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/arrolio/writing_mode.rb', line 27

def vertical?
  @mode == TB_RL
end