class HexaPDF::Type::Font

This class is the base class for all font objects, be it simple fonts or composite fonts.
Represents a generic font object.

def bounding_box

Returns the bounding box of the font or +nil+ if it is not found.
def bounding_box
  if key?(:FontDescriptor) && self[:FontDescriptor].key?(:FontBBox)
    self[:FontDescriptor][:FontBBox].value
  else
    nil
  end
end

def embedded?

Returns +true+ if the font is embedded.
def embedded?
  dict = self[:FontDescriptor]
  dict && (dict[:FontFile] || dict[:FontFile2] || dict[:FontFile3])
end

def font_file

Returns the embeeded font file object or +nil+ if the font is not embedded.
def font_file
  embedded?
end

def font_wrapper

See: HexaPDF::Font

Note: For internal use only!

+nil+ if this font can't be used for text output.
Retrieves the font wrapper that is needed when this font is used for text output. Returns
def font_wrapper
  @font_wrapper ||= nil
end

def font_wrapper=(font)

See: #font_wrapper

Sets the font wrapper.
def font_wrapper=(font)
  @font_wrapper = font
end

def glyph_scaling_factor

Returns the glyph scaling factor for transforming from glyph space to text space.
def glyph_scaling_factor
  0.001
end

def missing_unicode_mapping(code)

Calls the configured proc for handling missing unicode mappings.
def missing_unicode_mapping(code)
  @document.config['font.on_missing_unicode_mapping'].call(code, self)
end

def must_be_indirect?

Font objects must always be indirect.
def must_be_indirect?
  true
end

def to_unicode_cmap

Parses and caches the ToUnicode CMap.
def to_unicode_cmap
  cache(:to_unicode_cmap) do
    if key?(:ToUnicode)
      HexaPDF::Font::CMap.parse(self[:ToUnicode].stream)
    else
      nil
    end
  end
end

def to_utf8(code)

'font.on_missing_unicode_mapping' if no mapping was found.
Returns the UTF-8 string for the given character code, or calls the configuration option
def to_utf8(code)
  to_unicode_cmap&.to_unicode(code) || missing_unicode_mapping(code)
end