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
Loads 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.
73 74 75 |
# File 'lib/hexapdf/font_loader/from_configuration.rb', line 73 def self.available_fonts(document) document.config['font.map'].transform_values(&:keys) end |
.call(document, name, variant: :none, subset: true) ⇒ 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.
subset
-
Specifies whether the font should be subset if possible.
62 63 64 65 66 67 68 69 70 |
# File 'lib/hexapdf/font_loader/from_configuration.rb', line 62 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 |