class HexaPDF::Font::TrueTypeWrapper


This class wraps a generic TrueType font object and provides the methods needed for working with the font in a PDF context.

TrueType fonts can be represented in two ways in PDF: As a simple font with Subtype TrueType or as a composite font using a Type2 CIDFont. The wrapper only supports the composite font case because:

  • By using a composite font more than 256 characters can be encoded with one font object.

  • Fonts for vertical writing can potentially be used.

  • The PDF specification recommends using a composite font (see PDF2.0 s9.9.1 at the end).

Additionally, TrueType fonts are always embedded.



Returns the PDF object associated with the wrapper.


Returns the wrapped TrueType font object.

Public Class Methods

new(document, font, pdf_object: nil, subset: true)

Creates a new object wrapping the TrueType font for the PDF document.

The optional argument pdf_object can be used to set the PDF font object that this wrapper should be associated with. If no object is set, a suitable one is automatically created.

If subset is true, the font is subset.

Public Instance Methods


Returns true if the font contains bold glyphs.

custom_glyph(id, string)

Returns a custom Glyph object which represents the given string via the given glyph id.

This functionality can be used to associate a single glyph id with multiple, different strings for replacement glyph purposes. When used in such a way, the used glyph id is often 0 which represents the missing glyph.


Returns a glyph object for the given Unicode codepoint.

The configuration option ‘font.on_missing_glyph’ is invoked if no glyph for a given codepoint is available.


Returns an array of glyph objects representing the characters in the UTF-8 encoded string.

See decode_codepoint for details.


Encodes the glyph and returns the code string.


Returns the type of the font, i.e. :TrueType.

glyph(id, str = nil)

Returns a Glyph object for the given glyph ID.

The optional argument str should be the string representation of the glyph. Only use it if it is known,

Note: Although this method is public, it should normally not be used by application code!


Returns true if the font contains glyphs with an incline (italic or slant).


Returns the scaling factor for converting font units into PDF units.


Returns true if the wrapped TrueType font will be subset.