TextFragment describes an optionally kerned piece of text that shares the same font, font size and other properties.
Its items are either glyph objects of the font or numeric values describing kerning information. All returned measurement values are in text space units. If the items or the style are changed, the
clear_cache has to be called. Otherwise the measurements may not be correct!
The items of a text fragment may be frozen to indicate that the fragment is potentially used multiple times.
The rectangle with the bottom left corner (
y_min) and the top right corner (
y_max) describes the minimum bounding box of the whole text fragment and is usually not equal to the box (0, 0)-(
The items (glyphs and kerning values) of the text fragment.
The style to be applied.
Only the following properties are used:
Public Class Methods
Public Instance Methods
Returns the value that should be used as hash key when only the fragment's attributes - without the items - should play a role.
Clears all cached values.
This method needs to be called if the fragment's items or attributes are changed!
Draws the text onto the canvas at the given position.
This method is the main styled text drawing facility and therefore some optimizations are done:
The text is drawn using
HexaPDF::Content;:Canvas#show_glyphs_only which means that the text matrix is not updated. Therefore the caller must not rely on it!
All text style properties mentioned in the description of
styleare set except if
ignore_text_propertiesis set to
true. Note that this only applies to style properties that directly affect text drawing, so, for example, underlays/overlays and underlining/strikeout is always done.
The caller should set
trueif the graphics state hasn't been changed. This is the case, for example, if the last thing drawn was a text fragment with the same style.
It is assumed that the text matrix is not rotated, skewed, etc. so that setting the text position can be done using the optimal method.
Creates a new
TextFragment with the same style and custom properties as this one but with the given
The maximum y-coordinate of any item.
The minimum y-coordinate of any item.
Creates a new text fragment that repeats this fragment's items and applies the necessary spacing so that the returned text fragment fills the given
If the given
width is less than the fragment's width,
self is returned.
The height of the text fragment.
It is calculated as the difference of the maximum of the
y_max values and the minimum of the
y_min values of the items. However, the text rise value is also taken into account so that the baseline is always inside the bounds. For example, if a large negative text rise value is used, the baseline will be equal to the top boundary; if a large positive value is used, it will be equal to the bottom boundary.
Returns the custom properties hash for the text fragment.
Box#properties for usage details.
Returns the text of the fragment.
Returns the vertical alignment inside a line which is always :text for text fragments.
Line for details.
The width of the text fragment.
It is the sum of the widths of its items and is calculated by using the algorithm presented in PDF2.0 s9.4.4. By using kerning values as the first and/or last items, the text contained in the fragment may spill over the left and/or right boundary.
The maximum x-coordinate of the last glyph.
The minimum x-coordinate of the first glyph.
The maximum y-coordinate, calculated using the scaled ascender of the font.
The minimum y-coordinate, calculated using the scaled descender of the font.