class HexaPDF::Layout::Line

Parent

A Line describes a line of text and can contain TextFragment objects or InlineBox objects.

The items of a line fragment are aligned along the x-axis which coincides with the text baseline. The vertical alignment is determined by the value of the valign method:

:text_top

Align the top of the box with the top of the text of the Line.

:text_bottom

Align the bottom of the box with the bottom of the text of the Line.

:baseline

Align the bottom of the box with the baseline of the Line.

:top

Align the top of the box with the top of the Line.

:bottom

Align the bottom of the box with the bottom of the Line.

:text

This is a special alignment value for text fragment objects. The text fragment is aligned on the baseline and its minimum and maximum y-coordinates are used when calculating the line’s text_y_min and text_y_max.

This value may be used by other objects if they should be handled similar to text fragments, e.g. graphical representation of characters (think: emoji fonts).

Item Requirements

Each item of a line fragment has to respond to the following methods:

x_min

The minimum x-coordinate of the item.

x_max

The maximum x-coordinate of the item.

width

The width of the item.

valign

The vertical alignment of the item (see above).

draw(canvas, x, y)

Should draw the item onto the canvas at the position (x, y).

If an item has a vertical alignment of :text, it additionally has to respond to the following methods:

y_min

The minimum y-coordinate of the item.

y_max

The maximum y-coordinate of the item.

Otherwise (i.e. a vertical alignment different from :text), the following method must be implemented:

height

The height of the item.

Attributes

items[RW]

The items: TextFragment and InlineBox objects

x_offset[RW]

An optional horizontal offset that should be taken into account when positioning the line.

This offset always describes the offset from the left side (and not, for example, the offset from the right side of another line even if those two lines are actually on the same horizontal level).

y_offset[RW]

An optional vertical offset that should be taken into account when positioning the line.

For the first line in a paragraph this describes the offset from the top of the box to the baseline of the line. For all other lines it describes the offset from the previous baseline to the baseline of this line.

Public Class Methods

new(items = [])

Creates a new Line object, adding all given items to it.

Public Instance Methods

<<(item)
Alias for: add
add(item)

Adds the given item at the end of the item list.

If both the item and the last item in the item list are TextFragment objects with the same attributes, they are combined.

Note: The cache is not cleared!

Also aliased as: <<
clear_cache → line

Clears all cached values.

This method needs to be called if the line’s items are changed!

each {|item, x, y| block }

Yields each item together with its horizontal offset from 0 and vertical offset from the baseline.

height()

The height of the line fragment.

ignore_justification!()

Specifies that this line should not be justified if line justification is used.

ignore_justification?()

Returns true if justification should be ignored for this line.

text_y_max()

The maximum y-coordinate of any TextFragment item of the line.

text_y_min()

The minimum y-coordinate of any TextFragment item of the line.

width()

The width of the line fragment.

x_max()

The maximum x-coordinate of the whole line.

x_min()

The minimum x-coordinate of the whole line.

y_max()

The maximum y-coordinate of any item of the line.

It is always greater than or equal to zero.

y_min()

The minimum y-coordinate of any item of the line.

It is always lower than or equal to zero.