Class: HexaPDF::Type::FontType0

Inherits:
Font show all
Defined in:
lib/hexapdf/type/font_type0.rb

Overview

Represents a composite PDF font.

Composites fonts wrap a descendant CIDFont and use CIDs to identify glyphs. A CID can be encoded in one or more bytes and an associated CMap specifies how this encoding is done. Composite fonts also allow for vertical writing mode and support TrueType as well as OpenType fonts.

See: PDF1.7 s9.7

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 Font

#must_be_indirect?

Methods inherited from Dictionary

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

Methods inherited from Object

#<=>, #==, deep_copy, #deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #must_be_indirect?, #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.



87
88
89
# File 'lib/hexapdf/type/font_type0.rb', line 87

def bounding_box
  descendant_font.bounding_box
end

#decode(string) ⇒ Object

Decodes the given string into an array of CIDs.



69
70
71
# File 'lib/hexapdf/type/font_type0.rb', line 69

def decode(string)
  cmap.read_codes(string)
end

#descendant_fontObject

Returns the CID font of this type 0 font.



57
58
59
60
61
# File 'lib/hexapdf/type/font_type0.rb', line 57

def descendant_font
  document.cache(@data, :descendant_font) do
    document.wrap(document.deref(self[:DescendantFonts][0]))
  end
end

#embedded?Boolean

Returns true if the font is embedded.

Returns:



92
93
94
# File 'lib/hexapdf/type/font_type0.rb', line 92

def embedded?
  descendant_font.embedded?
end

#font_fileObject

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



97
98
99
# File 'lib/hexapdf/type/font_type0.rb', line 97

def font_file
  descendant_font.font_file
end

#to_utf8(code) ⇒ Object

Returns the UTF-8 string for the given code, or calls the configuration option ‘font.on_missing_unicode_mapping’ if no mapping was found.



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

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

#width(code) ⇒ Object

Returns the unscaled width of the given CID in glyph units, or 0 if the width for the code point is missing.



82
83
84
# File 'lib/hexapdf/type/font_type0.rb', line 82

def width(code)
  descendant_font.width(cmap.to_cid(code))
end

#word_spacing_applicable?Boolean

Returns whether word spacing is applicable when using this font.

Note that the return value is cached when accessed the first time.

See: PDF1.7 s9.3.3

Returns:



106
107
108
# File 'lib/hexapdf/type/font_type0.rb', line 106

def word_spacing_applicable?
  @word_spacing_applicable ||= ((cmap.read_codes("\x20") && true) rescue false)
end

#writing_modeObject

Returns the writing mode which is either :horizontal or :vertical.



64
65
66
# File 'lib/hexapdf/type/font_type0.rb', line 64

def writing_mode
  cmap.wmode == 0 ? :horizontal : :vertical
end