class HexaPDF::Layout::Style::Layers


Represents layers that can be drawn under or over a box.

There are two ways to specify layers via add:

  • Directly by providing a callable object.

  • By reference to a callable object or class in the ‘style.layers_map’ configuration option. The reference name is looked up in the configuration option using HexaPDF::Configuration#constantize. If the resulting object is a callable object, it is used; otherwise it is assumed that it is a class and an object is instantiated, passing in any options given on add.

The object resolved in this way needs to respond to call(canvas, box) where canvas is the HexaPDF::Content::Canvas object on which it should be drawn and box is a box-like object (e.g. Box or TextFragment). The coordinate system is translated so that the origin is at the bottom-left corner of the box during the drawing operations.

Public Class Methods

new(layers = nil)

Creates a new Layers object popuplated with the given layers.

Public Instance Methods

add {|canvas, box| block}
add(name, **options)

Adds a new layer object.

The layer object can either be specified as a block or by reference to a configured layer object in ‘style.layers_map’. In this case name is used as the reference and the options are passed to layer object if it needs initialization.

draw(canvas, x, y, box)

Draws all layer objects onto the canvas at the position [x, y] for the given box.

each(config) { |layer| ... }

Yields all layer objects. Objects that have been specified via a reference are first resolved using the provided configuration object.


Duplicates the array holding the layers.

Calls superclass method

Returns true if there are no layers defined.