Class: HexaPDF::FontUtils
- Inherits:
-
Object
- Object
- HexaPDF::FontUtils
- Defined in:
- lib/hexapdf/font_utils.rb
Overview
This class provides utility functions for working with fonts. It is available through the HexaPDF::Document#fonts method.
Instance Method Summary collapse
-
#initialize(document) ⇒ FontUtils
constructor
Creates a new FontUtils object for the given PDF document.
-
#load(name, **options) ⇒ Object
:call-seq: fonts.load(name, **options) -> font.
Constructor Details
#initialize(document) ⇒ FontUtils
Creates a new FontUtils object for the given PDF document.
44 45 46 47 |
# File 'lib/hexapdf/font_utils.rb', line 44 def initialize(document) @document = document @loaded_fonts_cache = {} end |
Instance Method Details
#load(name, **options) ⇒ Object
:call-seq:
fonts.load(name, **options) -> font
Loads and returns the font (using the loaders specified with the configuration option ‘font_loaders’).
If a font with the same parameters has been loaded before, the cached font object is used.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hexapdf/font_utils.rb', line 56 def load(name, **) font = @loaded_fonts_cache[[name, ]] return font if font each_font_loader do |loader| font = loader.call(@document, name, **) break if font end if font @loaded_fonts_cache[[name, ]] = font else raise HexaPDF::Error, "The requested font '#{name}' couldn't be found" end end |