Class: PDF::Core::Page Private
- Inherits:
-
Object
- Object
- PDF::Core::Page
- Defined in:
- lib/pdf/core/page.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Low-level representation of a PDF page
Constant Summary collapse
- ZERO_INDENTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A convenince constant of no indents.
{ left: 0, bottom: 0, right: 0, top: 0, }.freeze
Instance Attribute Summary collapse
-
#art_indents ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
private
Page art box indents relative to page edges.
-
#bleeds ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
private
Page bleed box indents.
-
#content ⇒ PDF::Core::Reference<Hash>
private
Current content stream.
-
#crops ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
private
Page crop box indents.
-
#dictionary ⇒ PDF::Core::Reference<Hash>
private
Current content dictionary.
-
#document ⇒ Prawn::Document
private
Owning document.
-
#margins ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
private
Page margins.
-
#stack ⇒ GraphicStateStack
private
Graphic state stack.
-
#trims ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
private
Page trim box indents.
Instance Method Summary collapse
-
#art_box ⇒ Array<Numeric>
private
A rectangle, expressed in default user space units, defining the extent of the page’s meaningful content (including potential white space) as intended by the page’s creator.
-
#bleed_box ⇒ Array<Numeric>
private
Page bleed box.
-
#crop_box ⇒ Array<Numeric>
private
A rectangle, expressed in default user space units, defining the visible region of default user space.
-
#dimensions ⇒ Array<Numeric>
private
Page dimensions.
-
#ext_gstates ⇒ Hash
private
Graphic state parameter dictionary.
-
#finalize ⇒ void
private
Finalize page.
-
#fonts ⇒ Hash
private
Fonts dictionary.
-
#graphic_state ⇒ PDF::Core::GraphicState
private
Current graphic state.
-
#in_stamp_stream? ⇒ Boolean
private
Are we drawing to a stamp right now?.
-
#initialize(document, options = {}) ⇒ Page
constructor
private
A new instance of Page.
-
#layout ⇒ :portrait, :landscape
private
Page layout.
-
#resources ⇒ Hash
private
Page resources dictionary.
-
#size ⇒ Array<Numeric>
private
Page size.
-
#stamp_stream(dictionary) { ... } ⇒ void
private
Draw to stamp.
-
#trim_box ⇒ Array<Numeric>
private
A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming.
-
#xobjects ⇒ Hash
private
External objects dictionary.
Constructor Details
#initialize(document, options = {}) ⇒ Page
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Page.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pdf/core/page.rb', line 84 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] = %i[PDF Text ImageB ImageC ImageI] end |
Instance Attribute Details
#art_indents ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page art box indents relative to page edges.
14 15 16 |
# File 'lib/pdf/core/page.rb', line 14 def art_indents @art_indents end |
#bleeds ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page bleed box indents.
19 20 21 |
# File 'lib/pdf/core/page.rb', line 19 def bleeds @bleeds end |
#content ⇒ PDF::Core::Reference<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Current content stream. Can be either the page content stream or a stamp content stream.
182 183 184 |
# File 'lib/pdf/core/page.rb', line 182 def content @stamp_stream || document.state.store[@content] end |
#crops ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page crop box indents.
24 25 26 |
# File 'lib/pdf/core/page.rb', line 24 def crops @crops end |
#dictionary ⇒ PDF::Core::Reference<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Current content dictionary. Can be either the page dictionary or a stamp dictionary.
190 191 192 193 |
# File 'lib/pdf/core/page.rb', line 190 def dictionary (defined?(@stamp_dictionary) && @stamp_dictionary) || document.state.store[@dictionary] end |
#document ⇒ Prawn::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Owning document.
39 40 41 |
# File 'lib/pdf/core/page.rb', line 39 def document @document end |
#margins ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page margins.
34 35 36 |
# File 'lib/pdf/core/page.rb', line 34 def margins @margins end |
#stack ⇒ GraphicStateStack
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Graphic state stack.
44 45 46 |
# File 'lib/pdf/core/page.rb', line 44 def stack @stack end |
#trims ⇒ Hash<[:left, :right, :top, :bottom], Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page trim box indents.
29 30 31 |
# File 'lib/pdf/core/page.rb', line 29 def trims @trims end |
Instance Method Details
#art_box ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A rectangle, expressed in default user space units, defining the extent of the page’s meaningful content (including potential white space) as intended by the page’s creator.
275 276 277 278 279 280 281 282 283 |
# File 'lib/pdf/core/page.rb', line 275 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 ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page bleed box. A rectangle, expressed in default user space units, defining the region to which the contents of the page should be clipped when output in a production environment.
290 291 292 293 294 295 296 297 298 |
# File 'lib/pdf/core/page.rb', line 290 def bleed_box left, bottom, right, top = dimensions [ left + bleeds[:left], bottom + bleeds[:bottom], right - bleeds[:right], top - bleeds[:top], ] end |
#crop_box ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A rectangle, expressed in default user space units, defining the visible region of default user space. When the page is displayed or printed, its contents are to be clipped (cropped) to this rectangle and then imposed on the output medium in some implementation-defined manner.
306 307 308 309 310 311 312 313 314 |
# File 'lib/pdf/core/page.rb', line 306 def crop_box left, bottom, right, top = dimensions [ left + crops[:left], bottom + crops[:bottom], right - crops[:right], top - crops[:top], ] end |
#dimensions ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page dimensions.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/pdf/core/page.rb', line 255 def dimensions coords = PDF::Core::PageGeometry::SIZES[size] || size coords = case layout when :portrait coords when :landscape coords.reverse else raise PDF::Core::Errors::InvalidPageLayout, 'Layout must be either :portrait or :landscape' end [0, 0].concat(coords) end |
#ext_gstates ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Graphic state parameter dictionary.
231 232 233 234 235 236 237 |
# File 'lib/pdf/core/page.rb', line 231 def ext_gstates if resources[:ExtGState] document.deref(resources[:ExtGState]) else resources[:ExtGState] = {} end end |
#finalize ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Finalize page.
242 243 244 245 246 247 248 249 250 |
# File 'lib/pdf/core/page.rb', line 242 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 ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fonts dictionary.
209 210 211 212 213 214 215 |
# File 'lib/pdf/core/page.rb', line 209 def fonts if resources[:Font] document.deref(resources[:Font]) else resources[:Font] = {} end end |
#graphic_state ⇒ PDF::Core::GraphicState
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Current graphic state.
122 123 124 |
# File 'lib/pdf/core/page.rb', line 122 def graphic_state stack.current_state end |
#in_stamp_stream? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Are we drawing to a stamp right now?
152 153 154 |
# File 'lib/pdf/core/page.rb', line 152 def in_stamp_stream? !@stamp_stream.nil? end |
#layout ⇒ :portrait, :landscape
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page layout.
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/pdf/core/page.rb', line 130 def layout return @layout if defined?(@layout) && @layout mb = dictionary.data[:MediaBox] if mb[3] > mb[2] :portrait else :landscape end end |
#resources ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page resources dictionary.
198 199 200 201 202 203 204 |
# File 'lib/pdf/core/page.rb', line 198 def resources if dictionary.data[:Resources] document.deref(dictionary.data[:Resources]) else dictionary.data[:Resources] = {} end end |
#size ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Page size.
145 146 147 |
# File 'lib/pdf/core/page.rb', line 145 def size (defined?(@size) && @size) || dimensions[2, 2] end |
#stamp_stream(dictionary) { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Draw to stamp.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/pdf/core/page.rb', line 161 def stamp_stream(dictionary) @stamp_dictionary = dictionary @stamp_stream = @stamp_dictionary.stream 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_stream = nil @stamp_dictionary = nil end |
#trim_box ⇒ Array<Numeric>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A rectangle, expressed in default user space units, defining the intended dimensions of the finished page after trimming.
320 321 322 323 324 325 326 327 328 |
# File 'lib/pdf/core/page.rb', line 320 def trim_box left, bottom, right, top = dimensions [ left + trims[:left], bottom + trims[:bottom], right - trims[:right], top - trims[:top], ] end |
#xobjects ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
External objects dictionary.
220 221 222 223 224 225 226 |
# File 'lib/pdf/core/page.rb', line 220 def xobjects if resources[:XObject] document.deref(resources[:XObject]) else resources[:XObject] = {} end end |