Class: Arrolio::LayoutSpec::PageTemplate

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

Overview

Page geometry template ("fo:simple-page-master" in XSL-FO). Coordinates are PDF-default user space: origin at the bottom-left of the page, y grows upward. Region y is the bottom edge of the region.

Constant Summary collapse

LETTER =
[612.0, 792.0].freeze
A4 =
[595.276, 841.89].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, page_size: LETTER, margins: 72, region_extents: {}) ⇒ PageTemplate

Returns a new instance of PageTemplate.



15
16
17
18
19
20
21
22
# File 'lib/arrolio/layout_spec/page_template.rb', line 15

def initialize(name:, page_size: LETTER, margins: 72, region_extents: {})
  @name = name.to_sym
  @page_size = resolve_page_size(page_size)
  @margins = normalise_margins(margins)
  @region_extents = default_region_extents.merge(region_extents.to_h)
  @regions = compute_regions.freeze
  freeze
end

Instance Attribute Details

#marginsObject (readonly)

Returns the value of attribute margins.



13
14
15
# File 'lib/arrolio/layout_spec/page_template.rb', line 13

def margins
  @margins
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/arrolio/layout_spec/page_template.rb', line 13

def name
  @name
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



13
14
15
# File 'lib/arrolio/layout_spec/page_template.rb', line 13

def page_size
  @page_size
end

#region_extentsObject (readonly)

Returns the value of attribute region_extents.



13
14
15
# File 'lib/arrolio/layout_spec/page_template.rb', line 13

def region_extents
  @region_extents
end

#regionsObject (readonly)

Returns the value of attribute regions.



13
14
15
# File 'lib/arrolio/layout_spec/page_template.rb', line 13

def regions
  @regions
end

Instance Method Details

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



40
41
42
43
44
45
46
# File 'lib/arrolio/layout_spec/page_template.rb', line 40

def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    page_size == other.page_size &&
    margins == other.margins &&
    region_extents == other.region_extents
end

#body_regionObject



24
25
26
# File 'lib/arrolio/layout_spec/page_template.rb', line 24

def body_region
  @regions[:body]
end

#hashObject



50
51
52
# File 'lib/arrolio/layout_spec/page_template.rb', line 50

def hash
  [self.class, name, page_size, margins, region_extents].hash
end

#heightObject



36
37
38
# File 'lib/arrolio/layout_spec/page_template.rb', line 36

def height
  @page_size[1]
end

#region(name) ⇒ Object



28
29
30
# File 'lib/arrolio/layout_spec/page_template.rb', line 28

def region(name)
  @regions[name.to_sym]
end

#widthObject



32
33
34
# File 'lib/arrolio/layout_spec/page_template.rb', line 32

def width
  @page_size[0]
end