Module: HexaPDF::FontLoader::Standard14
- Defined in:
- lib/hexapdf/font_loader/standard14.rb
Overview
This module is used for providing the standard 14 PDF fonts.
Constant Summary collapse
- MAPPING =
Mapping of font family name and variant to font name.
{ 'Times' => { none: 'Times-Roman', bold: 'Times-Bold', italic: 'Times-Italic', bold_italic: 'Times-BoldItalic', }, 'Helvetica' => { none: 'Helvetica', bold: 'Helvetica-Bold', italic: 'Helvetica-Oblique', bold_italic: 'Helvetica-BoldOblique', }, 'Courier' => { none: 'Courier', bold: 'Courier-Bold', italic: 'Courier-Oblique', bold_italic: 'Courier-BoldOblique', }, 'Symbol' => { none: 'Symbol', }, 'ZapfDingbats' => { none: 'ZapfDingbats', }, }.freeze
Class Method Summary collapse
-
.available_fonts(_document) ⇒ Object
Returns a hash of the form ‘font_name => [variants, …]’ of the standard 14 PDF fonts.
-
.call(document, name, variant: :none, custom_encoding: false) ⇒ Object
Returns a font wrapper for the named Standard PDF font.
Class Method Details
.available_fonts(_document) ⇒ Object
Returns a hash of the form ‘font_name => [variants, …]’ of the standard 14 PDF fonts.
99 100 101 |
# File 'lib/hexapdf/font_loader/standard14.rb', line 99 def self.available_fonts(_document) MAPPING.transform_values(&:keys) end |
.call(document, name, variant: :none, custom_encoding: false) ⇒ Object
Returns a font wrapper for the named Standard PDF font.
document
-
The PDF document to associate the font wrapper with.
name
-
The name of the built-in font. One of Times, Helvetica, Courier, Symbol or ZapfDingbats.
variant
-
The font variant. Can be :none, :bold, :italic, :bold_italic for Times, Helvetica and Courier; and must be :none for Symbol and ZapfDingbats.
custom_encoding
-
For Times, Helvetica and Courier the standard encoding WinAnsiEncoding is used. If this is not wanted because access to other glyphs is needed, set this to
true
89 90 91 92 93 94 95 96 |
# File 'lib/hexapdf/font_loader/standard14.rb', line 89 def self.call(document, name, variant: :none, custom_encoding: false, **) name = MAPPING[name] && MAPPING[name][variant] return nil if name.nil? file = File.join(HexaPDF.data_dir, 'afm', "#{name}.afm") font = (@afm_font_cache ||= {})[file] ||= HexaPDF::Font::Type1::Font.from_afm(file) HexaPDF::Font::Type1Wrapper.new(document, font, custom_encoding: custom_encoding) end |