Module: Prawn::Templates
- Defined in:
- lib/prawn/templates.rb
Defined Under Namespace
Modules: ObjectStoreExtensions
Instance Method Summary collapse
- #initialize_first_page(options) ⇒ Object
- #merge_template_options(page_options, options) ⇒ Object
-
#start_new_page(options = {}) ⇒ Object
FIXME: This is going to be terribly brittle because it copy-pastes the start_new_page method.
Instance Method Details
#initialize_first_page(options) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/prawn/templates.rb', line 16 def initialize_first_page() return super unless [:template] fresh_content_streams() go_to_page(1) end |
#merge_template_options(page_options, options) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/prawn/templates.rb', line 87 def (, ) object_id = state.store.import_page( [:template], [:template_page] || 1 ) .merge!(object_id: object_id, page_template: true) end |
#start_new_page(options = {}) ⇒ Object
FIXME: This is going to be terribly brittle because it copy-pastes the start_new_page method. But at least it should only run when templates are used.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/prawn/templates.rb', line 26 def start_new_page( = {}) return super unless [:template] last_page = state.page if last_page last_page_size = last_page.size last_page_layout = last_page.layout last_page_margins = last_page.margins.dup end = { size: [:size] || last_page_size, layout: [:layout] || last_page_layout, margins: last_page_margins } if last_page if last_page.graphic_state new_graphic_state = last_page.graphic_state.dup end # erase the color space so that it gets reset on new page for fussy # pdf-readers new_graphic_state.color_space = {} if new_graphic_state [:graphic_state] = new_graphic_state end (, ) state.page = PDF::Core::Page.new(self, ) () generate_margin_box # Reset the bounding box if the new page has different size or layout if last_page && (last_page.size != state.page.size || last_page.layout != state.page.layout) @bounding_box = @margin_box end state.page.new_content_stream use_graphic_settings(true) forget_text_rendering_mode! unless [:orphan] state.insert_page(state.page, @page_number) @page_number += 1 if @background canvas do image(@background, scale: @background_scale, at: bounds.top_left) end end @y = @bounding_box.absolute_top float do state.on_page_create_action(self) end end end |