Class: HexaPDF::Type::Font

Inherits:
Dictionary show all
Defined in:
lib/hexapdf/type/font.rb

Overview

Represents a generic font object.

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

Direct Known Subclasses

CIDFont, FontSimple, FontType0

Constant Summary

Constants included from DictionaryFields

DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate

Constants inherited from Object

Object::NOT_DUPLICATABLE_CLASSES

Instance Attribute Summary

Attributes inherited from Object

#data, #document, #must_be_indirect

Instance Method Summary collapse

Methods inherited from Dictionary

#[], #[]=, define_field, #delete, #each, each_field, #empty?, field, #key?, #to_hash, #type

Methods inherited from Object

#<=>, #==, #deep_copy, deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #null?, #oid, #oid=, #type, #validate, #value, #value=

Constructor Details

This class inherits a constructor from HexaPDF::Object

Instance Method Details

#bounding_boxObject

Returns the bounding box of the font or nil if it is not found.



61
62
63
64
65
66
67
# File 'lib/hexapdf/type/font.rb', line 61

def bounding_box
  if key?(:FontDescriptor) && self[:FontDescriptor].key?(:FontBBox)
    self[:FontDescriptor][:FontBBox].value
  else
    nil
  end
end

#embedded?Boolean

Returns true if the font is embedded.

Returns:



70
71
72
73
# File 'lib/hexapdf/type/font.rb', line 70

def embedded?
  dict = self[:FontDescriptor]
  dict && (dict[:FontFile] || dict[:FontFile2] || dict[:FontFile3])
end

#font_fileObject

Returns the embeeded font file object or nil if the font is not embedded.



76
77
78
# File 'lib/hexapdf/type/font.rb', line 76

def font_file
  embedded?
end

#must_be_indirect?Boolean

Font objects must always be indirect.

Returns:



50
51
52
# File 'lib/hexapdf/type/font.rb', line 50

def must_be_indirect?
  true
end

#to_utf8(code) ⇒ Object

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.



56
57
58
# File 'lib/hexapdf/type/font.rb', line 56

def to_utf8(code)
  to_unicode_cmap && to_unicode_cmap.to_unicode(code) || missing_unicode_mapping(code)
end