class HexaPDF::Font::TrueType::Font
Represents a font in the TrueType
font file format.
Constants
- DEFAULT_CONFIG
The default configuration:
- font.ttf.table_mapping
-
The default mapping from table tag as symbol to table class name.
- font.ttf.unknown_format
-
Action to take when encountering unknown subtables. Can either be :ignore which ignores them or :raise which raises an error.
Attributes
The configuration for the TrueType
font.
The IO stream associated with this file.
Public Class Methods
Creates a new TrueType
font file object for the given IO object.
The config
hash can contain configuration options.
# File lib/hexapdf/font/true_type/font.rb, line 80 def initialize(io, config: {}) @io = io @config = DEFAULT_CONFIG.merge(config) @tables = {} end
Public Instance Methods
Returns the table instance for the given tag (a symbol), or nil
if no such table exists.
# File lib/hexapdf/font/true_type/font.rb, line 87 def [](tag) return @tables[tag] if @tables.key?(tag) entry = directory.entry(tag.to_s.b) entry ? @tables[tag] = table_class(tag).new(self, entry) : nil end
Returns the ascender of the font.
# File lib/hexapdf/font/true_type/font.rb, line 144 def ascender self[:"OS/2"].typo_ascender || self[:hhea].ascent end
Returns the bounding of the font.
# File lib/hexapdf/font/true_type/font.rb, line 129 def bounding_box self[:head].bbox end
Returns the cap height of the font.
# File lib/hexapdf/font/true_type/font.rb, line 134 def cap_height self[:"OS/2"].cap_height end
Returns the descender of the font.
# File lib/hexapdf/font/true_type/font.rb, line 149 def descender self[:"OS/2"].typo_descender || self[:hhea].descent end
Returns the font directory.
# File lib/hexapdf/font/true_type/font.rb, line 95 def directory @directory ||= Table::Directory.new(self, io ? Table::Directory::SELF_ENTRY : nil) end
Returns the family name of the font.
# File lib/hexapdf/font/true_type/font.rb, line 119 def family_name self[:name][:font_family].preferred_record end
Returns a set of features this font supports.
Features that may be available are for example :kern or :liga.
# File lib/hexapdf/font/true_type/font.rb, line 102 def features @features ||= Set.new.tap do |set| set << :kern if self[:kern]&.horizontal_kerning_subtable end end
Returns the PostScript font name.
# File lib/hexapdf/font/true_type/font.rb, line 109 def font_name self[:name][:postscript_name].preferred_record end
Returns the full name of the font.
# File lib/hexapdf/font/true_type/font.rb, line 114 def full_name self[:name][:font_name].preferred_record end
Returns the italic angle of the font, in degrees counter-clockwise from the vertical.
# File lib/hexapdf/font/true_type/font.rb, line 154 def italic_angle self[:post].italic_angle.to_f end
Returns th glyph ID of the missing glyph, i.e. 0.
# File lib/hexapdf/font/true_type/font.rb, line 187 def missing_glyph_id 0 end
Returns the distance from the baseline to the top of the strikeout line.
# File lib/hexapdf/font/true_type/font.rb, line 177 def strikeout_position self[:"OS/2"].strikeout_position end
Returns the stroke width for the strikeout line.
# File lib/hexapdf/font/true_type/font.rb, line 182 def strikeout_thickness self[:"OS/2"].strikeout_size end
Returns the distance from the baseline to the top of the underline.
# File lib/hexapdf/font/true_type/font.rb, line 167 def underline_position self[:post].underline_position end
Returns the stroke width for the underline.
# File lib/hexapdf/font/true_type/font.rb, line 172 def underline_thickness self[:post].underline_thickness end
Returns the weight of the font.
# File lib/hexapdf/font/true_type/font.rb, line 124 def weight self[:"OS/2"].weight_class || 0 end
Returns the x-height of the font.
# File lib/hexapdf/font/true_type/font.rb, line 139 def x_height self[:"OS/2"].x_height end
Private Instance Methods
Returns the class that is used for handling tables of the given tag.
# File lib/hexapdf/font/true_type/font.rb, line 194 def table_class(tag) k = config['font.true_type.table_mapping'].fetch(tag, 'HexaPDF::Font::TrueType::Table') ::Object.const_get(k) end