Class: Uniword::SectionProperties

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

Overview

Represents section properties Includes page setup, headers, footers, and other section-level formatting

Constant Summary collapse

PAGE_SIZES =

Page size presets (width x height in twips)

{
  letter: [12_240, 15_840], # 8.5" x 11"
  a4: [11_906, 16_838],        # 210mm x 297mm
  a3: [16_838, 23_811],        # 297mm x 420mm
  legal: [12_240, 20_160],     # 8.5" x 14"
  tabloid: [15_840, 24_480],   # 11" x 17"
  a5: [8391, 11_906], # 148mm x 210mm
}.freeze
ORIENTATIONS =

Valid orientations

%w[portrait landscape].freeze
SECTION_TYPES =

Valid section types

%w[continuous nextPage nextColumn evenPage oddPage].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ SectionProperties

Returns a new instance of SectionProperties.



70
71
72
73
74
# File 'lib/uniword/section_properties.rb', line 70

def initialize(**attributes)
  super
  validate_orientation
  validate_section_type
end

Instance Attribute Details

#page_sizeObject

Page size preset accessor



164
165
166
# File 'lib/uniword/section_properties.rb', line 164

def page_size
  @page_size
end

Class Method Details

.a4_landscapeObject

Set A4 page size (landscape)



86
87
88
89
90
91
92
# File 'lib/uniword/section_properties.rb', line 86

def self.a4_landscape
  new(
    page_width: 16_838,  # 297mm in twips
    page_height: 11_906, # 210mm in twips
    orientation: "landscape",
  )
end

.a4_portraitObject

Set A4 page size (portrait)



77
78
79
80
81
82
83
# File 'lib/uniword/section_properties.rb', line 77

def self.a4_portrait
  new(
    page_width: 11_906,  # 210mm in twips
    page_height: 16_838, # 297mm in twips
    orientation: "portrait",
  )
end

.letter_landscapeObject

Set Letter page size (landscape)



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

def self.letter_landscape
  new(
    page_width: 15_840,  # 11in in twips
    page_height: 12_240, # 8.5in in twips
    orientation: "landscape",
  )
end

.letter_portraitObject

Set Letter page size (portrait)



95
96
97
98
99
100
101
# File 'lib/uniword/section_properties.rb', line 95

def self.letter_portrait
  new(
    page_width: 12_240,  # 8.5in in twips
    page_height: 15_840, # 11in in twips
    orientation: "portrait",
  )
end

Instance Method Details

#enable_line_numbering(start: 1, count_by: 1, restart: "newPage", distance: 360) ⇒ void

This method returns an undefined value.

Enable line numbering

Parameters:

  • start (Integer) (defaults to: 1)

    Starting line number

  • count_by (Integer) (defaults to: 1)

    Increment

  • restart (String) (defaults to: "newPage")

    When to restart (continuous, newPage, newSection)

  • distance (Integer) (defaults to: 360)

    Distance from text



153
154
155
156
157
158
159
160
161
# File 'lib/uniword/section_properties.rb', line 153

def enable_line_numbering(start: 1, count_by: 1, restart: "newPage",
distance: 360)
  self.line_numbering = LineNumbering.new(
    start: start,
    count_by: count_by,
    restart: restart,
    distance: distance,
  )
end

#set_columns(count, space: 720, separator: false) ⇒ void

This method returns an undefined value.

Set multi-column layout

Parameters:

  • count (Integer)

    Number of columns

  • space (Integer) (defaults to: 720)

    Space between columns

  • separator (Boolean) (defaults to: false)

    Show separator line



141
142
143
144
# File 'lib/uniword/section_properties.rb', line 141

def set_columns(count, space: 720, separator: false)
  self.columns = ColumnConfiguration.equal(count, space: space,
                                                  separator: separator)
end

#set_page_size(name, orientation: :portrait) ⇒ void

This method returns an undefined value.

Set page size by name

Parameters:

  • name (Symbol)

    Page size name (:letter, :a4, etc.)

  • orientation (Symbol) (defaults to: :portrait)

    Orientation (:portrait or :landscape)



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/uniword/section_properties.rb', line 117

def set_page_size(name, orientation: :portrait)
  unless PAGE_SIZES.key?(name)
    raise ArgumentError,
          "Unknown page size: #{name}. Available: #{PAGE_SIZES.keys.join(', ')}"
  end

  width, height = PAGE_SIZES[name]
  if orientation == :landscape
    self.page_width = height
    self.page_height = width
    self.orientation = "landscape"
  else
    self.page_width = width
    self.page_height = height
    self.orientation = "portrait"
  end
end