Class: PDF::Core::Page
- Inherits:
-
Object
- Object
- PDF::Core::Page
- Defined in:
- lib/pdf/core/page.rb
Overview
:nodoc:
Constant Summary collapse
- ZERO_INDENTS =
{ left: 0, bottom: 0, right: 0, top: 0 }.freeze
Instance Attribute Summary collapse
-
#art_indents ⇒ Object
Returns the value of attribute art_indents.
-
#bleeds ⇒ Object
Returns the value of attribute bleeds.
- #content ⇒ Object
-
#crops ⇒ Object
Returns the value of attribute crops.
- #dictionary ⇒ Object
-
#document ⇒ Object
Returns the value of attribute document.
-
#margins ⇒ Object
Returns the value of attribute margins.
-
#stack ⇒ Object
Returns the value of attribute stack.
-
#trims ⇒ Object
Returns the value of attribute trims.
Instance Method Summary collapse
- #art_box ⇒ Object
- #bleed_box ⇒ Object
- #crop_box ⇒ Object
- #dimensions ⇒ Object
- #ext_gstates ⇒ Object
- #finalize ⇒ Object
- #fonts ⇒ Object
- #graphic_state ⇒ Object
- #in_stamp_stream? ⇒ Boolean
-
#initialize(document, options = {}) ⇒ Page
constructor
A new instance of Page.
- #layout ⇒ Object
- #resources ⇒ Object
- #size ⇒ Object
- #stamp_stream(dictionary) ⇒ Object
- #trim_box ⇒ Object
- #xobjects ⇒ Object
Constructor Details
#initialize(document, options = {}) ⇒ Page
Returns a new instance of Page.
24 25 26 27 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 |
# File 'lib/pdf/core/page.rb', line 24 def initialize(document, = {}) @document = document @margins = [:margins] || { left: 36, right: 36, top: 36, bottom: 36 } @crops = [:crops] || ZERO_INDENTS @bleeds = [:bleeds] || ZERO_INDENTS @trims = [:trims] || ZERO_INDENTS @art_indents = [:art_indents] || ZERO_INDENTS @stack = GraphicStateStack.new([:graphic_state]) @size = [:size] || 'LETTER' @layout = [:layout] || :portrait @stamp_stream = nil @stamp_dictionary = nil @content = document.ref({}) content << 'q' << "\n" @dictionary = document.ref( Type: :Page, Parent: document.state.store.pages, MediaBox: dimensions, CropBox: crop_box, BleedBox: bleed_box, TrimBox: trim_box, ArtBox: art_box, Contents: content ) resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI] end |
Instance Attribute Details
#art_indents ⇒ Object
Returns the value of attribute art_indents.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def art_indents @art_indents end |
#bleeds ⇒ Object
Returns the value of attribute bleeds.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def bleeds @bleeds end |
#content ⇒ Object
99 100 101 |
# File 'lib/pdf/core/page.rb', line 99 def content @stamp_stream || document.state.store[@content] end |
#crops ⇒ Object
Returns the value of attribute crops.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def crops @crops end |
#dictionary ⇒ Object
103 104 105 106 |
# File 'lib/pdf/core/page.rb', line 103 def dictionary defined?(@stamp_dictionary) && @stamp_dictionary || document.state.store[@dictionary] end |
#document ⇒ Object
Returns the value of attribute document.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def document @document end |
#margins ⇒ Object
Returns the value of attribute margins.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def margins @margins end |
#stack ⇒ Object
Returns the value of attribute stack.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def stack @stack end |
#trims ⇒ Object
Returns the value of attribute trims.
13 14 15 |
# File 'lib/pdf/core/page.rb', line 13 def trims @trims end |
Instance Method Details
#art_box ⇒ Object
164 165 166 167 168 169 170 171 172 |
# File 'lib/pdf/core/page.rb', line 164 def art_box left, bottom, right, top = dimensions [ left + art_indents[:left], bottom + art_indents[:bottom], right - art_indents[:right], top - art_indents[:top] ] end |
#bleed_box ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/pdf/core/page.rb', line 174 def bleed_box left, bottom, right, top = dimensions [ left + bleeds[:left], bottom + bleeds[:bottom], right - bleeds[:right], top - bleeds[:top] ] end |
#crop_box ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/pdf/core/page.rb', line 184 def crop_box left, bottom, right, top = dimensions [ left + crops[:left], bottom + crops[:bottom], right - crops[:right], top - crops[:top] ] end |
#dimensions ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/pdf/core/page.rb', line 150 def dimensions coords = PDF::Core::PageGeometry::SIZES[size] || size [0, 0] + case layout when :portrait coords when :landscape coords.reverse else raise PDF::Core::Errors::InvalidPageLayout, 'Layout must be either :portrait or :landscape' end end |
#ext_gstates ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/pdf/core/page.rb', line 132 def ext_gstates if resources[:ExtGState] document.deref(resources[:ExtGState]) else resources[:ExtGState] = {} end end |
#finalize ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/pdf/core/page.rb', line 140 def finalize if dictionary.data[:Contents].is_a?(Array) dictionary.data[:Contents].each do |stream| stream.stream.compress! if document.compression_enabled? end elsif document.compression_enabled? content.stream.compress! end end |
#fonts ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/pdf/core/page.rb', line 116 def fonts if resources[:Font] document.deref(resources[:Font]) else resources[:Font] = {} end end |
#graphic_state ⇒ Object
57 58 59 |
# File 'lib/pdf/core/page.rb', line 57 def graphic_state stack.current_state end |
#in_stamp_stream? ⇒ Boolean
76 77 78 |
# File 'lib/pdf/core/page.rb', line 76 def in_stamp_stream? !@stamp_stream.nil? end |
#layout ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pdf/core/page.rb', line 61 def layout return @layout if defined?(@layout) && @layout mb = dictionary.data[:MediaBox] if mb[3] > mb[2] :portrait else :landscape end end |
#resources ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/pdf/core/page.rb', line 108 def resources if dictionary.data[:Resources] document.deref(dictionary.data[:Resources]) else dictionary.data[:Resources] = {} end end |
#size ⇒ Object
72 73 74 |
# File 'lib/pdf/core/page.rb', line 72 def size defined?(@size) && @size || dimensions[2, 2] end |
#stamp_stream(dictionary) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pdf/core/page.rb', line 80 def stamp_stream(dictionary) @stamp_stream = '' @stamp_dictionary = dictionary graphic_stack_size = stack.stack.size document.save_graphics_state document.send(:freeze_stamp_graphics) yield if block_given? until graphic_stack_size == stack.stack.size document.restore_graphics_state end @stamp_dictionary << @stamp_stream @stamp_stream = nil @stamp_dictionary = nil end |
#trim_box ⇒ Object
194 195 196 197 198 199 200 201 202 |
# File 'lib/pdf/core/page.rb', line 194 def trim_box left, bottom, right, top = dimensions [ left + trims[:left], bottom + trims[:bottom], right - trims[:right], top - trims[:top] ] end |
#xobjects ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/pdf/core/page.rb', line 124 def xobjects if resources[:XObject] document.deref(resources[:XObject]) else resources[:XObject] = {} end end |