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

Instance Attribute Summary

Attributes inherited from Object

#data, #document, #must_be_indirect

Instance Method Summary collapse

Methods inherited from Font

#font_wrapper, #font_wrapper=, #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

#<=>, #==, #cache, #cached?, #clear_cache, 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.



90
91
92
# File 'lib/hexapdf/type/font_type0.rb', line 90

def bounding_box
  descendant_font.bounding_box
end

#decode(string) ⇒ Object

Decodes the given string into an array of CIDs.



72
73
74
# File 'lib/hexapdf/type/font_type0.rb', line 72

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

#descendant_fontObject

Returns the CID font of this type 0 font.



60
61
62
63
64
# File 'lib/hexapdf/type/font_type0.rb', line 60

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

#embedded?Boolean

Returns true if the font is embedded.

Returns:



95
96
97
# File 'lib/hexapdf/type/font_type0.rb', line 95

def embedded?
  descendant_font.embedded?
end

#font_fileObject

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



100
101
102
# File 'lib/hexapdf/type/font_type0.rb', line 100

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.



78
79
80
81
# File 'lib/hexapdf/type/font_type0.rb', line 78

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.



85
86
87
# File 'lib/hexapdf/type/font_type0.rb', line 85

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:



109
110
111
# File 'lib/hexapdf/type/font_type0.rb', line 109

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.



67
68
69
# File 'lib/hexapdf/type/font_type0.rb', line 67

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