1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 56 57 58 59 60 61 62 63 64 65 66 67
|
# frozen_string_literal: true
# internals.rb : Implements document internals for Prawn
#
# Copyright August 2008, Gregory Brown. All Rights Reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
require 'forwardable'
module Prawn
class Document
# This module exposes a few low-level PDF features for those who want
# to extend Prawn's core functionality. If you are not comfortable with
# low level PDF functionality as defined by Adobe's specification, chances
# are you won't need anything you find here.
#
# @private
module Internals
extend Forwardable
# These methods are not officially part of Prawn's public API,
# but they are used in documentation and possibly in extensions.
# Perhaps they will become part of the extension API?
# Anyway, for now it's not clear what we should do w. them.
delegate %i[
graphic_state
on_page_create
] => :renderer
def save_graphics_state(state = nil, &block)
save_transformation_stack
renderer.save_graphics_state(state, &block)
end
def restore_graphics_state
restore_transformation_stack
renderer.restore_graphics_state
end
# FIXME: This is a circular reference, because in theory Prawn should
# be passing instances of renderer to PDF::Core::Page, but it's
# passing Prawn::Document objects instead.
#
# A proper design would probably not require Prawn to directly instantiate
# PDF::Core::Page objects at all!
delegate [:compression_enabled?] => :renderer
# FIXME: More circular references in PDF::Core::Page.
delegate %i[ref ref! deref] => :renderer
# FIXME: Another circular reference, because we mix in a module from
# PDF::Core to provide destinations, which in theory should not
# rely on a Prawn::Document object but is currently wired up that way.
delegate [:names] => :renderer
# FIXME: Circular reference because we mix PDF::Core::Text into
# Prawn::Document. PDF::Core::Text should either be split up or
# moved in its entirety back up into Prawn.
delegate [:add_content] => :renderer
def renderer
@renderer ||= PDF::Core::Renderer.new(state)
end
end
end
end
|