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
-
.available_fonts(document) ⇒ Object
Returns a hash of the form ‘font_name => [variants, …]’ of the configured fonts.
-
.call(document, name, variant: :none, subset: true) ⇒ Object
Returns a TrueType font wrapper for the given font by looking up the needed file in the ‘font.map’ configuration option.
Class Method Details
.available_fonts(document) ⇒ Object
Returns a hash of the form ‘font_name => [variants, …]’ of the configured fonts.
76 77 78 |
# File 'lib/hexapdf/font_loader/from_configuration.rb', line 76 def self.available_fonts(document) document.config['font.map'].transform_values(&:keys) end |
.call(document, name, variant: :none, subset: true) ⇒ Object
Returns a TrueType font wrapper for 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 wrapper 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.
This method uses the FromFile font loader behind the scenes.
65 66 67 68 69 70 71 72 73 |
# File 'lib/hexapdf/font_loader/from_configuration.rb', line 65 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 |