Class: Uniword::Wordprocessingml::PageSetup
- Inherits:
-
Object
- Object
- Uniword::Wordprocessingml::PageSetup
- Defined in:
- lib/uniword/wordprocessingml/page_setup.rb
Overview
Applies uniform page setup across every section of a document — Word's Layout dialog as an API.
Paper size (named presets), orientation (with dimension swap, like Word), and margins (twips, or strings with in/cm/mm suffix). Header/footer/gutter margins are left untouched.
Constant Summary collapse
- PAPER_SIZES =
Named paper sizes in twips [width, height] (portrait).
{ "letter" => [12_240, 15_840], "legal" => [12_240, 20_160], "a4" => [11_906, 16_838], "a5" => [8_391, 11_906], "executive" => [10_440, 15_120], }.freeze
- TWIPS_PER_INCH =
1440- TWIPS_PER_CM =
567- TWIPS_PER_MM =
57- ORIENTATIONS =
%w[portrait landscape].freeze
Instance Attribute Summary collapse
-
#sections_updated ⇒ Integer
readonly
Number of sections updated.
Instance Method Summary collapse
-
#apply(document) ⇒ Integer
Apply the setup to every section in the document.
-
#initialize(size: nil, orientation: nil, margins: nil, **side_margins) ⇒ PageSetup
constructor
A new instance of PageSetup.
Constructor Details
#initialize(size: nil, orientation: nil, margins: nil, **side_margins) ⇒ PageSetup
Returns a new instance of PageSetup.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/uniword/wordprocessingml/page_setup.rb', line 43 def initialize(size: nil, orientation: nil, margins: nil, **side_margins) @size = normalize_size(size) @orientation = normalize_orientation(orientation) @margins = side_margins.to_h do |side, value| [side, parse_margin(value)] end uniform = parse_margin(margins) %i[top right bottom left].each do |side| @margins[side] = uniform if @margins[side].nil? end @sections_updated = 0 end |
Instance Attribute Details
#sections_updated ⇒ Integer (readonly)
Returns number of sections updated.
34 35 36 |
# File 'lib/uniword/wordprocessingml/page_setup.rb', line 34 def sections_updated @sections_updated end |
Instance Method Details
#apply(document) ⇒ Integer
Apply the setup to every section in the document.
61 62 63 64 65 66 67 68 |
# File 'lib/uniword/wordprocessingml/page_setup.rb', line 61 def apply(document) each_section_properties(document) do |sect_pr| apply_page_size(sect_pr) if @size || @orientation apply_margins(sect_pr) @sections_updated += 1 end sections_updated end |