Class: Prune::Elements::Page

Inherits:
Base
  • Object
show all
Defined in:
lib/prune/elements/page.rb

Constant Summary collapse

FONT_OPTIONS =
[
  :name,          # Font name.
  :size,          # Font size.
  :bold,          # Bold(boolean).
  :italic,        # Italic(boolean).
  :mode,          # Font color mode.
  :fill_color,    # Color inside font.
  :stroke_color,  # Color around font.
]

Instance Attribute Summary collapse

Attributes inherited from Base

#document

Instance Method Summary collapse

Methods inherited from Base

#reference, #register, #to_s

Methods included from Functions

#mm_to_pt, #pt_to_mm

Methods included from PObjects

pa, pd, ph, pl, pn, ps

Constructor Details

#initialize(document, media_box, options = {}) ⇒ Page

Initialize.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/prune/elements/page.rb', line 28

def initialize(document, media_box, options = {})
  super(document)
  # Set stream.
  @stream = Stream.new(@document)

  # Set dictionary.
  @media_box = media_box
  @content = pd(
    pn(:Type) => pn(:Page),
    pn(:Parent) => @document.pages.reference,
    pn(:MediaBox) => pa(*@media_box),
    pn(:Contents) => @stream.reference,
    pn(:Resources) => pd(
      pn(:ProcSet) => @document.proc_set.reference))

  # Set page margin by option in millimeters(default 10mm).
  %w[top left right bottom].each do |position|
    value = options["margin_#{position}".to_sym] || 10.0
    value = mm_to_pt(value)
    instance_variable_set("@margin_#{position}", value)
  end

  # Set initial position.
  @x = @margin_left
  @y = @media_box[3] - @margin_top

  # Set page default font.
  initialize_font(options)
  # Initialize page shapes.
  @shape_ids = []
  @shapes = {}
  # Register element to document.
  register
end

Instance Attribute Details

#current_fontObject

Returns the value of attribute current_font.



11
12
13
# File 'lib/prune/elements/page.rb', line 11

def current_font
  @current_font
end

#default_fontObject (readonly)

Returns the value of attribute default_font.



6
7
8
# File 'lib/prune/elements/page.rb', line 6

def default_font
  @default_font
end

#margin_bottomObject

Returns the value of attribute margin_bottom.



15
16
17
# File 'lib/prune/elements/page.rb', line 15

def margin_bottom
  @margin_bottom
end

#margin_leftObject

Returns the value of attribute margin_left.



12
13
14
# File 'lib/prune/elements/page.rb', line 12

def margin_left
  @margin_left
end

#margin_rightObject

Returns the value of attribute margin_right.



13
14
15
# File 'lib/prune/elements/page.rb', line 13

def margin_right
  @margin_right
end

#margin_topObject

Returns the value of attribute margin_top.



14
15
16
# File 'lib/prune/elements/page.rb', line 14

def margin_top
  @margin_top
end

#shape_idsObject

Returns the value of attribute shape_ids.



7
8
9
# File 'lib/prune/elements/page.rb', line 7

def shape_ids
  @shape_ids
end

#shapesObject

Returns the value of attribute shapes.



8
9
10
# File 'lib/prune/elements/page.rb', line 8

def shapes
  @shapes
end

#xObject

Returns the value of attribute x.



9
10
11
# File 'lib/prune/elements/page.rb', line 9

def x
  @x
end

#yObject

Returns the value of attribute y.



10
11
12
# File 'lib/prune/elements/page.rb', line 10

def y
  @y
end

Instance Method Details

#heightObject

Get height of the page(pt).



74
75
76
# File 'lib/prune/elements/page.rb', line 74

def height
  @media_box[3] - @margin_top - @margin_bottom
end

#set_font(key, font) ⇒ Object

Set font to use.



79
80
81
82
83
84
85
86
87
88
# File 'lib/prune/elements/page.rb', line 79

def set_font(key, font)
  # Add :Font key to content hash unless there is no key
  unless @content[pn(:Resources)].has_key?(pn(:Font))
    @content[pn(:Resources)].update(pn(:Font) => pd)
  end
  # Add font symbol to :Font hash
  unless @content[pn(:Resources)][pn(:Font)].has_key?(key)
    @content[pn(:Resources)][pn(:Font)].update(key => font.reference)
  end
end

#streamObject

Get stream object.



64
65
66
# File 'lib/prune/elements/page.rb', line 64

def stream
  @stream.stream
end

#widthObject

Get width of the page(pt).



69
70
71
# File 'lib/prune/elements/page.rb', line 69

def width
  @media_box[2] - @margin_left - @margin_right
end