Module: HexaPDF::FontLoader::FromConfiguration
- Defined in:
- lib/hexapdf/font_loader/from_configuration.rb
Overview
This module uses the configuration option ‘font.map’ for loading a font.
Class Method Summary collapse
-
.call(document, name, variant: :none) ⇒ Object
Loads the given font by looking up the needed file in the ‘font.map’ configuration option.
Class Method Details
.call(document, name, variant: :none) ⇒ Object
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.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hexapdf/font_loader/from_configuration.rb', line 55 def self.call(document, name, variant: :none, **) file = document.config['font.map'].dig(name, variant) return nil if file.nil? unless File.file?(file) raise HexaPDF::Error, "The configured font file #{file} does not exist" end font = HexaPDF::Font::TrueType::Font.new(io: File.open(file)) HexaPDF::Font::TrueTypeWrapper.new(document, font) end |