Class: PDF::Core::DocumentState Private
- Inherits:
-
Object
- Object
- PDF::Core::DocumentState
- Defined in:
- lib/pdf/core/document_state.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 PDF document representation mostly for keeping intermediate state while document is being constructed.
Instance Attribute Summary collapse
-
#before_render_callbacks ⇒ Array<Proc>
private
Before render callbacks.
-
#compress ⇒ Boolean
private
Whether to compress streams.
-
#encrypt ⇒ Boolean
private
Whether to encrypt document.
-
#encryption_key ⇒ String?
private
Encryption key.
-
#on_page_create_callback ⇒ Proc?
private
A block to call when a new page is created.
-
#page ⇒ PDF::Core::Page
private
Current page.
-
#pages ⇒ Array<PDF::Core::Page>
private
Document pages.
-
#skip_encoding ⇒ Object
deprecated
private
Deprecated.
Unused
-
#store ⇒ PDF::Core::ObjectStore
private
Object store.
-
#trailer ⇒ Hash
private
Document trailer dict.
-
#version ⇒ Float
private
PDF version used in this document.
Instance Method Summary collapse
-
#before_render_actions(_doc) ⇒ void
private
Executes before render callbacks.
-
#initialize(options) ⇒ DocumentState
constructor
private
A new instance of DocumentState.
-
#insert_page(page, page_number) ⇒ void
private
Insert a page at the specified position.
-
#normalize_metadata(options) ⇒ Hash
private
Adds Prawn metadata to document info.
-
#on_page_create_action(doc) ⇒ void
private
Execute page creation callback if one is defined.
-
#page_count ⇒ Integer
private
Number of pages in the document.
-
#populate_pages_from_store(document) ⇒ 0, Array<PDF::Core::Page>
private
Loads pages from object store.
-
#render_body(output) ⇒ void
private
Renders document body to the output.
Constructor Details
#initialize(options) ⇒ DocumentState
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 DocumentState.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pdf/core/document_state.rb', line 20 def initialize() () @store = if [:print_scaling] PDF::Core::ObjectStore.new( info: [:info], print_scaling: [:print_scaling], ) else PDF::Core::ObjectStore.new(info: [:info]) end @version = 1.3 @pages = [] @page = nil @trailer = .fetch(:trailer, {}) @compress = .fetch(:compress, false) @encrypt = .fetch(:encrypt, false) @encryption_key = [:encryption_key] @skip_encoding = .fetch(:skip_encoding, false) @before_render_callbacks = [] @on_page_create_callback = nil end |
Instance Attribute Details
#before_render_callbacks ⇒ Array<Proc>
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.
Before render callbacks
82 83 84 |
# File 'lib/pdf/core/document_state.rb', line 82 def before_render_callbacks @before_render_callbacks end |
#compress ⇒ 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.
Whether to compress streams
67 68 69 |
# File 'lib/pdf/core/document_state.rb', line 67 def compress @compress end |
#encrypt ⇒ 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.
Whether to encrypt document
71 72 73 |
# File 'lib/pdf/core/document_state.rb', line 71 def encrypt @encrypt end |
#encryption_key ⇒ String?
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.
Encryption key
75 76 77 |
# File 'lib/pdf/core/document_state.rb', line 75 def encryption_key @encryption_key end |
#on_page_create_callback ⇒ Proc?
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 block to call when a new page is created
86 87 88 |
# File 'lib/pdf/core/document_state.rb', line 86 def on_page_create_callback @on_page_create_callback end |
#page ⇒ PDF::Core::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.
Current page
59 60 61 |
# File 'lib/pdf/core/document_state.rb', line 59 def page @page end |
#pages ⇒ Array<PDF::Core::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.
Document pages
55 56 57 |
# File 'lib/pdf/core/document_state.rb', line 55 def pages @pages end |
#skip_encoding ⇒ Object
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.
Unused
78 79 80 |
# File 'lib/pdf/core/document_state.rb', line 78 def skip_encoding @skip_encoding end |
#store ⇒ PDF::Core::ObjectStore
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.
Object store
47 48 49 |
# File 'lib/pdf/core/document_state.rb', line 47 def store @store end |
#trailer ⇒ 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.
Document trailer dict
63 64 65 |
# File 'lib/pdf/core/document_state.rb', line 63 def trailer @trailer end |
#version ⇒ Float
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.
PDF version used in this document
51 52 53 |
# File 'lib/pdf/core/document_state.rb', line 51 def version @version end |
Instance Method Details
#before_render_actions(_doc) ⇒ 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.
Executes before render callbacks
139 140 141 |
# File 'lib/pdf/core/document_state.rb', line 139 def before_render_actions(_doc) before_render_callbacks.each { |c| c.call(self) } end |
#insert_page(page, page_number) ⇒ 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.
Insert a page at the specified position.
121 122 123 124 125 |
# File 'lib/pdf/core/document_state.rb', line 121 def insert_page(page, page_number) pages.insert(page_number, page) store.pages.data[:Kids].insert(page_number, page.dictionary) store.pages.data[:Count] += 1 end |
#normalize_metadata(options) ⇒ 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.
Adds Prawn metadata to document info
108 109 110 111 112 113 114 |
# File 'lib/pdf/core/document_state.rb', line 108 def () [:info] ||= {} [:info][:Creator] ||= 'Prawn' [:info][:Producer] ||= 'Prawn' [:info] end |
#on_page_create_action(doc) ⇒ 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.
Execute page creation callback if one is defined
131 132 133 |
# File 'lib/pdf/core/document_state.rb', line 131 def on_page_create_action(doc) on_page_create_callback[doc] if on_page_create_callback end |
#page_count ⇒ Integer
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.
Number of pages in the document
146 147 148 |
# File 'lib/pdf/core/document_state.rb', line 146 def page_count pages.length end |
#populate_pages_from_store(document) ⇒ 0, Array<PDF::Core::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.
Loads pages from object store. Only does it when there are no pages loaded and there are some pages in the store.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pdf/core/document_state.rb', line 93 def populate_pages_from_store(document) return 0 if @store.page_count <= 0 || !@pages.empty? count = (1..@store.page_count) @pages = count.map { |index| orig_dict_id = @store.object_id_for_page(index) PDF::Core::Page.new(document, object_id: orig_dict_id) } end |
#render_body(output) ⇒ 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.
Renders document body to the output
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/pdf/core/document_state.rb', line 154 def render_body(output) store.each do |ref| ref.offset = output.size output << if @encrypt ref.encrypted_object(@encryption_key) else ref.object end end end |