Class: HexaPDF::Type::FontType0
- Inherits:
-
Font
- Object
- Object
- Dictionary
- Font
- HexaPDF::Type::FontType0
- 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: PDF2.0 s9.7, s9.7.6.1
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
-
#bounding_box ⇒ Object
Returns the bounding box of the font or
nil
if it is not found. -
#decode(string) ⇒ Object
Decodes the given string into an array of CIDs.
-
#descendant_font ⇒ Object
Returns the CID font of this type 0 font.
-
#embedded? ⇒ Boolean
Returns
true
if the font is embedded. -
#font_descriptor ⇒ Object
Returns the font descriptor of the descendant font.
-
#font_file ⇒ Object
Returns the embeeded font file object or
nil
if the font is not embedded. -
#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.
-
#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.
-
#word_spacing_applicable? ⇒ Boolean
Returns whether word spacing is applicable when using this font.
-
#writing_mode ⇒ Object
Returns the writing mode which is either :horizontal or :vertical.
Methods inherited from Font
#font_wrapper, #font_wrapper=, #glyph_scaling_factor, #must_be_indirect?
Methods inherited from Dictionary
#[], #[]=, define_field, define_type, #delete, #each, each_field, #empty?, field, #key?, #to_hash, type, #type
Methods inherited from Object
#<=>, #==, #cache, #cached?, #clear_cache, deep_copy, #deep_copy, #document?, #eql?, field, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, make_direct, #must_be_indirect?, #null?, #oid, #oid=, #type, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#bounding_box ⇒ Object
Returns the bounding box of the font or nil
if it is not found.
95 96 97 |
# File 'lib/hexapdf/type/font_type0.rb', line 95 def bounding_box descendant_font.bounding_box end |
#decode(string) ⇒ Object
Decodes the given string into an array of CIDs.
77 78 79 |
# File 'lib/hexapdf/type/font_type0.rb', line 77 def decode(string) cmap.read_codes(string) end |
#descendant_font ⇒ Object
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.
100 101 102 |
# File 'lib/hexapdf/type/font_type0.rb', line 100 def descendant_font. end |
#font_descriptor ⇒ Object
Returns the font descriptor of the descendant font.
67 68 69 |
# File 'lib/hexapdf/type/font_type0.rb', line 67 def font_descriptor descendant_font[:FontDescriptor] end |
#font_file ⇒ Object
Returns the embeeded font file object or nil
if the font is not embedded.
105 106 107 |
# File 'lib/hexapdf/type/font_type0.rb', line 105 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.
83 84 85 86 |
# File 'lib/hexapdf/type/font_type0.rb', line 83 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.
90 91 92 |
# File 'lib/hexapdf/type/font_type0.rb', line 90 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: PDF2.0 s9.3.3
114 115 116 |
# File 'lib/hexapdf/type/font_type0.rb', line 114 def word_spacing_applicable? @word_spacing_applicable ||= (cmap.read_codes("\x20") && true rescue false) end |
#writing_mode ⇒ Object
Returns the writing mode which is either :horizontal or :vertical.
72 73 74 |
# File 'lib/hexapdf/type/font_type0.rb', line 72 def writing_mode cmap.wmode == 0 ? :horizontal : :vertical end |