class HexaPDF::Layout::Style::Layers
bottom left corner of the box during the drawing operations.
(e.g. Box or TextFragment). The coordinate system is translated so that the origin is at the
HexaPDF::Content::Canvas object on which it should be drawn and box
is a box-like object
The object resolved in this way needs to respond to #call(canvas, box) where canvas
is the
any options given on #add.
used; otherwise it is assumed that it is a class and an object is instantiated, passing in
HexaPDF::Configuration#constantize. If the resulting object is a callable object, it is
The reference name is looked up in the configuration option using
* By reference to a callable object or class in the ‘style.layers_map’ configuration option.
* Directly by providing a callable object.
There are two ways to specify layers via #add:
Represents layers that can be drawn under or over a box.
def add(name = nil, **options, &block)
object in 'style.layers_map'. In this case +name+ is used as the reference and the options
The layer object can either be specified as a block or by reference to a configured layer
Adds a new layer object.
layers.add(name, **options)
layers.add {|canvas, box| block}
:call-seq:
def add(name = nil, **options, &block) if block_given? || name.kind_of?(Proc) @layers << (block || name) elsif name @layers << [name, options] else raise ArgumentError, "Layer object name or block missing" end end
def draw(canvas, x, y, box)
def draw(canvas, x, y, box) return if none? canvas.translate(x, y) do each(canvas.context.document.config) do |layer| canvas.save_graphics_state { layer.call(canvas, box) } end end end
def each(config) #:yield: layer
resolved using the provided configuration object.
Yields all layer objects. Objects that have been specified via a reference are first
def each(config) #:yield: layer @layers.each do |obj, options| obj = config.constantize('style.layers_map', obj) unless obj.respond_to?(:call) obj = obj.new(**options) unless obj.respond_to?(:call) yield(obj) end end
def initialize(layers = nil)
def initialize(layers = nil) @layers = [] layers&.each {|name, options| add(name, **(options || {})) } end
def initialize_copy(other)
def initialize_copy(other) super @layers = @layers.dup end
def none?
def none? @layers.empty? end