Class: Uniword::TextFrame

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/text_frame.rb

Overview

Represents a text frame for positioned text

Text frames allow precise positioning of paragraphs on the page, commonly used for sidebars, pull quotes, and floating text boxes.

Examples:

Absolute positioned frame

frame = TextFrame.new(
  width: 4000,
  height: 1000,
  x: 1000,
  y: 3000,
  h_anchor: 'margin',
  v_anchor: 'margin'
)

Aligned frame

frame = TextFrame.new(
  width: 4000,
  h_alignment: 'right',
  v_alignment: 'top',
  h_anchor: 'page',
  v_anchor: 'page'
)

Constant Summary collapse

ANCHOR_TYPES =

Anchor types

%w[margin page text column character].freeze
H_ALIGNMENTS =

Alignment options

%w[left center right inside outside].freeze
V_ALIGNMENTS =
%w[top center bottom inside outside].freeze
SIZE_RULES =

Size rules

%w[auto atLeast exact].freeze
WRAP_TYPES =

Wrap types

%w[around none through tight].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ TextFrame

Returns a new instance of TextFrame.



69
70
71
72
73
74
75
# File 'lib/uniword/text_frame.rb', line 69

def initialize(**attributes)
  super
  validate_anchors
  validate_alignments
  validate_rules
  validate_wrap
end

Instance Attribute Details

#h_alignmentString

Horizontal alignment

Returns:

  • (String)

    the current value of h_alignment



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def h_alignment
  @h_alignment
end

#h_anchorString

Horizontal anchor point

Returns:

  • (String)

    the current value of h_anchor



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def h_anchor
  @h_anchor
end

#h_ruleString

Width rule (auto, atLeast, exact)

Returns:

  • (String)

    the current value of h_rule



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def h_rule
  @h_rule
end

#heightInteger

Frame height in twips

Returns:

  • (Integer)

    the current value of height



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def height
  @height
end

#lock_anchorBoolean

Lock anchor position

Returns:

  • (Boolean)

    the current value of lock_anchor



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def lock_anchor
  @lock_anchor
end

#v_alignmentString

Vertical alignment

Returns:

  • (String)

    the current value of v_alignment



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def v_alignment
  @v_alignment
end

#v_anchorString

Vertical anchor point

Returns:

  • (String)

    the current value of v_anchor



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def v_anchor
  @v_anchor
end

#w_ruleString

Height rule (auto, atLeast, exact)

Returns:

  • (String)

    the current value of w_rule



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def w_rule
  @w_rule
end

#widthInteger

Frame width in twips

Returns:

  • (Integer)

    the current value of width



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def width
  @width
end

#wrapString

Text wrapping style

Returns:

  • (String)

    the current value of wrap



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def wrap
  @wrap
end

#xInteger

Horizontal position in twips

Returns:

  • (Integer)

    the current value of x



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def x
  @x
end

#yInteger

Vertical position in twips

Returns:

  • (Integer)

    the current value of y



42
43
44
# File 'lib/uniword/text_frame.rb', line 42

def y
  @y
end

Class Method Details

.absolute(width:, height:, x:, y:) ⇒ TextFrame

Create absolutely positioned frame

Parameters:

  • width (Integer)

    Frame width

  • height (Integer)

    Frame height

  • x (Integer)

    Horizontal position

  • y (Integer)

    Vertical position

  • options (Hash)

    Additional options

Returns:



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/uniword/text_frame.rb', line 85

def self.absolute(width:, height:, x:, y:, **)
  new(
    width: width,
    height: height,
    x: x,
    y: y,
    h_rule: "exact",
    w_rule: "exact",
    **
  )
end

.aligned(width:, h_alignment:, v_alignment:) ⇒ TextFrame

Create aligned frame

Parameters:

  • width (Integer)

    Frame width

  • h_alignment (String)

    Horizontal alignment

  • v_alignment (String)

    Vertical alignment

  • options (Hash)

    Additional options

Returns:



104
105
106
107
108
109
110
111
112
# File 'lib/uniword/text_frame.rb', line 104

def self.aligned(width:, h_alignment:, v_alignment:, **)
  new(
    width: width,
    h_alignment: h_alignment,
    v_alignment: v_alignment,
    h_rule: "exact",
    **
  )
end

Instance Method Details

#absolute_position?Boolean

Check if frame uses absolute positioning

Returns:

  • (Boolean)

    true if has x,y coordinates



117
118
119
# File 'lib/uniword/text_frame.rb', line 117

def absolute_position?
  !x.nil? && !y.nil?
end

#aligned_position?Boolean

Check if frame uses alignment positioning

Returns:

  • (Boolean)

    true if has alignments



124
125
126
# File 'lib/uniword/text_frame.rb', line 124

def aligned_position?
  !h_alignment.nil? || !v_alignment.nil?
end