Class: DocXify::Element::PageLayout

Inherits:
Base
  • Object
show all
Defined in:
lib/docxify/element/page_layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PageLayout

Returns a new instance of PageLayout.



9
10
11
12
13
14
15
16
# File 'lib/docxify/element/page_layout.rb', line 9

def initialize(options = {})
  super()
  @document = options[:document]
  @margins = @document.margins
  @width = options[:width] || @document&.width || DocXify::A4_PORTRAIT_WIDTH
  @height = options[:height] || @document&.height || DocXify::A4_PORTRAIT_HEIGHT
  @orientation = options[:orientation] || :portrait
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



7
8
9
# File 'lib/docxify/element/page_layout.rb', line 7

def height
  @height
end

#orientationObject

Returns the value of attribute orientation.



7
8
9
# File 'lib/docxify/element/page_layout.rb', line 7

def orientation
  @orientation
end

#widthObject

Returns the value of attribute width.



7
8
9
# File 'lib/docxify/element/page_layout.rb', line 7

def width
  @width
end

Instance Method Details

#bounds_heightObject



23
24
25
# File 'lib/docxify/element/page_layout.rb', line 23

def bounds_height
  @height - @margins[:top] - @margins[:bottom]
end

#bounds_widthObject

Don’t consider this part of the public API, they’re used by Document if it’s been created



19
20
21
# File 'lib/docxify/element/page_layout.rb', line 19

def bounds_width
  @width - @margins[:left] - @margins[:right]
end

#to_s(_container = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/docxify/element/page_layout.rb', line 27

def to_s(_container = nil)
  <<~XML
    <w:p>
      <w:pPr>
        <w:sectPr>
          <w:pgSz w:w="#{@width}" w:h="#{@height}" w:orient="#{@orientation}"/>
          <w:pgMar w:bottom="#{DocXify.cm2dxa @margins[:bottom]}" w:footer="708" w:gutter="0" w:header="708" w:left="#{DocXify.cm2dxa @margins[:left]}" w:right="#{DocXify.cm2dxa @margins[:right]}" w:top="#{DocXify.cm2dxa @margins[:top]}"/>
          <w:cols w:space="708"/>
          <w:docGrid w:linePitch="360"/>
        </w:sectPr>
      </w:pPr>
    </w:p>
  XML
end