module HexaPDF::FontLoader::FromConfiguration

This module uses the configuration option 'font.map' for loading a font.

Public Class Methods

available_fonts(document) click to toggle source

Returns a hash of the form 'font_name => [variants, …]' of the configured fonts.

# File lib/hexapdf/font_loader/from_configuration.rb, line 72
def self.available_fonts(document)
  document.config['font.map'].transform_values(&:keys)
end
call(document, name, variant: :none, subset: true) click to toggle source

Loads the given font by looking up the needed file in the 'font.map' configuration option.

The file object representing the font file is not closed and if needed must be closed by the caller once the font is not needed anymore.

document

The PDF document to associate the font object with.

name

The name of the font.

variant

The font variant. Normally one of :none, :bold, :italic, :bold_italic.

subset

Specifies whether the font should be subset if possible.

# File lib/hexapdf/font_loader/from_configuration.rb, line 61
def self.call(document, name, variant: :none, subset: true)
  file = document.config['font.map'].dig(name, variant)
  return nil if file.nil?

  unless file.kind_of?(HexaPDF::Font::TrueType::Font) || File.file?(file)
    raise HexaPDF::Error, "The configured font file #{file} is not a valid value"
  end
  FromFile.call(document, file, subset: subset)
end