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.
Source Code
84 | def initialize(document, options = {}) |
85 | @document = document |
86 | @margins = options[:margins] || { |
87 | left: 36, |
88 | right: 36, |
89 | top: 36, |
90 | bottom: 36, |
91 | }
|
92 | @crops = options[:crops] || ZERO_INDENTS |
93 | @bleeds = options[:bleeds] || ZERO_INDENTS |
94 | @trims = options[:trims] || ZERO_INDENTS |
95 | @art_indents = options[:art_indents] || ZERO_INDENTS |
96 | @stack = GraphicStateStack.new(options[:graphic_state]) |
97 | @size = options[:size] || 'LETTER' |
98 | @layout = options[:layout] || :portrait |
99 | |
100 | @stamp_stream = nil |
101 | @stamp_dictionary = nil |
102 | |
103 | @content = document.ref({}) |
104 | content << 'q' << "\n" |
105 | @dictionary = document.ref( |
106 | Type: :Page, |
107 | Parent: document.state.store.pages, |
108 | MediaBox: dimensions, |
109 | CropBox: crop_box, |
110 | BleedBox: bleed_box, |
111 | TrimBox: trim_box, |
112 | ArtBox: art_box, |
113 | Contents: content, |
114 | )
|
115 | |
116 | resources[:ProcSet] = %i[PDF Text ImageB ImageC ImageI] |
117 | 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.
Source Code
14 | def art_indents |
15 | @art_indents
|
16 | 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.
Source Code
19 | def bleeds |
20 | @bleeds
|
21 | 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.
Source Code
182 | def content |
183 | @stamp_stream || document.state.store[@content] |
184 | 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.
Source Code
24 | def crops |
25 | @crops
|
26 | 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.
Source Code
190 | def dictionary |
191 | (defined?(@stamp_dictionary) && @stamp_dictionary) || |
192 | document.state.store[@dictionary] |
193 | 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.
Source Code
39 | def document |
40 | @document
|
41 | 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.
Source Code
34 | def margins |
35 | @margins
|
36 | 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.
Source Code
44 | def stack |
45 | @stack
|
46 | 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.
Source Code
29 | def trims |
30 | @trims
|
31 | 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.
Source Code
275 | def art_box |
276 | left, bottom, right, top = dimensions |
277 | [
|
278 | left + art_indents[:left], |
279 | bottom + art_indents[:bottom], |
280 | right - art_indents[:right], |
281 | top - art_indents[:top], |
282 | ]
|
283 | 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.
Source Code
290 | def bleed_box |
291 | left, bottom, right, top = dimensions |
292 | [
|
293 | left + bleeds[:left], |
294 | bottom + bleeds[:bottom], |
295 | right - bleeds[:right], |
296 | top - bleeds[:top], |
297 | ]
|
298 | 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.
Source Code
306 | def crop_box |
307 | left, bottom, right, top = dimensions |
308 | [
|
309 | left + crops[:left], |
310 | bottom + crops[:bottom], |
311 | right - crops[:right], |
312 | top - crops[:top], |
313 | ]
|
314 | 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.
Source Code
255 | def dimensions |
256 | coords = PDF::Core::PageGeometry::SIZES[size] || size |
257 | coords = |
258 | case layout |
259 | when :portrait |
260 | coords
|
261 | when :landscape |
262 | coords.reverse |
263 | else
|
264 | raise PDF::Core::Errors::InvalidPageLayout, |
265 | 'Layout must be either :portrait or :landscape'
|
266 | end
|
267 | [0, 0].concat(coords) |
268 | 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.
Source Code
231 | def ext_gstates |
232 | if resources[:ExtGState] |
233 | document.deref(resources[:ExtGState]) |
234 | else
|
235 | resources[:ExtGState] = {} |
236 | end
|
237 | 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.
Source Code
242 | def finalize |
243 | if dictionary.data[:Contents].is_a?(Array) |
244 | dictionary.data[:Contents].each do |stream| |
245 | stream.stream.compress! if document.compression_enabled? |
246 | end
|
247 | elsif document.compression_enabled? |
248 | content.stream.compress! |
249 | end
|
250 | 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.
Source Code
209 | def fonts |
210 | if resources[:Font] |
211 | document.deref(resources[:Font]) |
212 | else
|
213 | resources[:Font] = {} |
214 | end
|
215 | 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.
Source Code
122 | def graphic_state |
123 | stack.current_state |
124 | 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?
Source Code
152 | def in_stamp_stream? |
153 | !@stamp_stream.nil? |
154 | 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.
Source Code
130 | def layout |
131 | return @layout if defined?(@layout) && @layout |
132 | |
133 | mb = dictionary.data[:MediaBox] |
134 | if mb[3] > mb[2] |
135 | :portrait
|
136 | else
|
137 | :landscape
|
138 | end
|
139 | 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.
Source Code
198 | def resources |
199 | if dictionary.data[:Resources] |
200 | document.deref(dictionary.data[:Resources]) |
201 | else
|
202 | dictionary.data[:Resources] = {} |
203 | end
|
204 | 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.
Source Code
145 | def size |
146 | (defined?(@size) && @size) || dimensions[2, 2] |
147 | 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.
Source Code
161 | def stamp_stream(dictionary) |
162 | @stamp_dictionary = dictionary |
163 | @stamp_stream = @stamp_dictionary.stream |
164 | graphic_stack_size = stack.stack.size |
165 | |
166 | document.save_graphics_state |
167 | document.__send__(:freeze_stamp_graphics) |
168 | yield if block_given? |
169 | |
170 | until graphic_stack_size == stack.stack.size |
171 | document.restore_graphics_state |
172 | end
|
173 | |
174 | @stamp_stream = nil |
175 | @stamp_dictionary = nil |
176 | 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.
Source Code
320 | def trim_box |
321 | left, bottom, right, top = dimensions |
322 | [
|
323 | left + trims[:left], |
324 | bottom + trims[:bottom], |
325 | right - trims[:right], |
326 | top - trims[:top], |
327 | ]
|
328 | 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.
Source Code
220 | def xobjects |
221 | if resources[:XObject] |
222 | document.deref(resources[:XObject]) |
223 | else
|
224 | resources[:XObject] = {} |
225 | end
|
226 | end
|