Class: Prawn::Core::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/core/page.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Page.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/prawn/core/page.rb', line 12

def initialize(document, options={})
  @document = document
  @size     = options[:size]    ||  "LETTER" 

  @layout   = options[:layout]  || :portrait 

  @margins  = options[:margins] || { :left    => 36,
                                     :right   => 36,
                                     :top     => 36,
                                     :bottom  => 36  }

  @content    = document.ref(:Length      => 0)
  @dictionary = document.ref(:Type        => :Page,
                             :Parent      => document.store.pages,
                             :MediaBox    => dimensions,
                             :Contents    => content)

  resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI]

  @stamp_stream      = nil
  @stamp_dictionary  = nil
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def content
  @content
end

#dictionaryObject

Returns the value of attribute dictionary.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def dictionary
  @dictionary
end

#documentObject

Returns the value of attribute document.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def document
  @document
end

#layoutObject

Returns the value of attribute layout.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def layout
  @layout
end

#marginsObject

Returns the value of attribute margins.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def margins
  @margins
end

#sizeObject

Returns the value of attribute size.



35
36
37
# File 'lib/prawn/core/page.rb', line 35

def size
  @size
end

Instance Method Details

#dimensionsObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/prawn/core/page.rb', line 56

def dimensions
  coords = Prawn::Document::PageGeometry::SIZES[size] || size
  [0,0] + case(layout)
  when :portrait
    coords
  when :landscape
    coords.reverse
  else
    raise Prawn::Errors::InvalidPageLayout,
      "Layout must be either :portrait or :landscape"
  end
end

#ext_gstatesObject



89
90
91
# File 'lib/prawn/core/page.rb', line 89

def ext_gstates
  resources[:ExtGState] ||= {}
end

#fontsObject



81
82
83
# File 'lib/prawn/core/page.rb', line 81

def fonts
  resources[:Font] ||= {}
end

#in_stamp_stream?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/prawn/core/page.rb', line 37

def in_stamp_stream?
  !!@stamp_stream
end

#resourcesObject



77
78
79
# File 'lib/prawn/core/page.rb', line 77

def resources
  dictionary.data[:Resources] ||= {}
end

#stamp_stream(dictionary) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/prawn/core/page.rb', line 41

def stamp_stream(dictionary)
  @stamp_stream     = ""
  @stamp_dictionary = dictionary

  document.send(:update_colors)
  yield if block_given?
  document.send(:update_colors)

  @stamp_dictionary.data[:Length] = @stamp_stream.length + 1
  @stamp_dictionary << @stamp_stream

  @stamp_stream      = nil
  @stamp_dictionary  = nil
end

#xobjectsObject



85
86
87
# File 'lib/prawn/core/page.rb', line 85

def xobjects
  resources[:XObject] ||= {}
end