class HexaPDF::Type::Font
Represents a generic font object.
This class is the base class for all font objects, be it simple fonts or composite fonts.
Public Instance Methods
Returns the bounding box of the font or nil
if it is not found.
# File lib/hexapdf/type/font.rb, line 81 def bounding_box if key?(:FontDescriptor) && self[:FontDescriptor].key?(:FontBBox) self[:FontDescriptor][:FontBBox].value else nil end end
Returns true
if the font is embedded.
# File lib/hexapdf/type/font.rb, line 90 def embedded? dict = self[:FontDescriptor] dict && (dict[:FontFile] || dict[:FontFile2] || dict[:FontFile3]) end
Returns the embeeded font file object or nil
if the font is not embedded.
# File lib/hexapdf/type/font.rb, line 96 def font_file embedded? end
Retrieves the font wrapper that is needed when this font is used for text output. Returns nil
if this font can't be used for text output.
Note: For internal use only!
See: HexaPDF::Font
# File lib/hexapdf/type/font.rb, line 58 def font_wrapper @font_wrapper ||= nil end
Sets the font wrapper.
See: font_wrapper
# File lib/hexapdf/type/font.rb, line 65 def font_wrapper=(font) @font_wrapper = font end
Font
objects must always be indirect.
# File lib/hexapdf/type/font.rb, line 70 def must_be_indirect? true end
Returns the UTF-8 string for the given character code, or calls the configuration option 'font.on_missing_unicode_mapping' if no mapping was found.
# File lib/hexapdf/type/font.rb, line 76 def to_utf8(code) to_unicode_cmap&.to_unicode(code) || missing_unicode_mapping(code) end
Private Instance Methods
Calls the configured proc for handling missing unicode mappings.
# File lib/hexapdf/type/font.rb, line 114 def missing_unicode_mapping(code) @document.config['font.on_missing_unicode_mapping'].call(code, self) end
Parses and caches the ToUnicode CMap.
# File lib/hexapdf/type/font.rb, line 103 def to_unicode_cmap cache(:to_unicode_cmap) do if key?(:ToUnicode) HexaPDF::Font::CMap.parse(self[:ToUnicode].stream) else nil end end end