Module: HexaPDF::FontLoader

Defined in:
lib/hexapdf/font_loader.rb,
lib/hexapdf/font_loader/from_file.rb,
lib/hexapdf/font_loader/standard14.rb,
lib/hexapdf/font_loader/variant_from_name.rb,
lib/hexapdf/font_loader/from_configuration.rb

Overview

Overview

A *font loader* is a callable object that loads a font based on the given name and options. If the font loader doesn’t have the requested font, it has to return nil.

The returned object has to be a PDF font wrapper and not the generic font object because it needs to be usable by the PDF canvas. See below for details.

Implementation of a Font Loader

Each font loader is a (stateless) object (normally a module) that has to be callable, i.e. it has to provide the following method:

call(document, name, **options)

Should return the font wrapper customized for the given document if the font is known or else nil.

The options argument is font loader dependent. However, all font loaders should handle the following common options:

variant

The font variant that should be used (e.g. :none, :bold, :italic, :bold_italic).

Optionally, a font loader can provide a method available_fonts(document) that returns a hash where the keys are the font names and the values are the variants of all the provided fonts.

Font Wrappers

A font wrapper needs to provide the following generic interface so that it can be used correctly by HexaPDF:

dict

This method needs to return the PDF font dictionary that represents the wrapped font.

decode_utf8(str)

This method needs to convert the given string into an array of glyph objects. The glyph objects themselves have to respond to #width which should return their horizontal width.

encode(glyph)

This method takes a single glyph object, that needs to be compatible with the font wrapper, and returns an encoded string that can be decoded with the font dictionary returned by #dict.

HexaPDF contains a font wrapper implementation for the Standard 14 PDF fonts (see HexaPDF::Font::Type1Wrapper) and one for TrueType fonts (see HexaPDF::Font::TrueTypeWrapper).

Defined Under Namespace

Modules: FromConfiguration, FromFile, Standard14, VariantFromName