class HexaPDF::Layout::Box

Parent

The base class for all layout boxes.

HexaPDF uses the following box model:

  • Each box can specify a width and height. Padding and border are inside, the margin outside of this rectangle.

  • The content_width and content_height accessors can be used to get the width and height of the content box without padding and the border.

  • If width or height is set to zero, they are determined automatically during layouting.

Attributes

height[R]

The height of the box, including padding and/or borders.

style[R]

The style to be applied.

Only the following properties are used:

width[R]

The width of the box, including padding and/or borders.

Public Class Methods

create(width: 0, height: 0, content_box: false, **style, &block)

Creates a new Box object, using the provided block as drawing block (see ::new). Any additional keyword arguments are used for creating the box's Style object.

If content_box is true, the width and height are taken to mean the content width and height and the style's padding and border are removed from them appropriately.

new(width: 0, height: 0, style: Style.new) {|canv, box| block} → box

Creates a new Box object with the given width and height that uses the provided block when it is asked to draw itself on a canvas (see draw).

Since the final location of the box is not known beforehand, the drawing operations inside the block should draw inside the rectangle (0, 0, #content_width, #content_height) - note that the width and height of the box may not be known beforehand.

Public Instance Methods

content_height()

The height of the content box, i.e. without padding and/or borders.

content_width()

The width of the content box, i.e. without padding and/or borders.

draw(canvas, x, y)

Draws the content of the box onto the canvas at the position (x, y).

The coordinate system is translated so that the origin is at the bottom left corner of the **content box** during the drawing operations.

The block specified when creating the box is invoked with the canvas and the box as arguments. Subclasses can specify an on-demand drawing method by setting the +@draw_block+ instance variable to nil or a valid block. This is useful to avoid unnecessary set-up operations when the block does nothing.

empty?()

Returns true if no drawing operations are performed.

fit(available_width, available_height, frame)

Fits the box into the Frame and returns true if fitting was successful.

The default implementation uses the whole available space for width and height if they were initially set to 0. Otherwise the specified dimensions are used.