class HexaPDF::Font::TrueTypeWrapper

Parent

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.

Attributes

pdf_object[R]

Returns the PDF object associated with the wrapper.

wrapped_font[R]

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

bold?()

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.

decode_codepoint(codepoint)

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.

decode_utf8(str)

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

See decode_codepoint for details.

encode(glyph)

Encodes the glyph and returns the code string.

font_type()

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

glyph(id, str = nil)

Returns a Glyph object for the given glyph ID and str pair.

The optional argument str should be the string representation of the glyph. It is possible that multiple strings map to the same glyph (e.g. hyphen and soft-hyphen could be represented by the same glyph).

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

italic?()

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

scaling_factor()

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

subset?()

Returns true if the wrapped TrueType font will be subset.