Class: HexaPDF::Type::Font
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::Font
- 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
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. -
#embedded? ⇒ Boolean
Returns
true
if the font is embedded. -
#font_file ⇒ Object
Returns the embeeded font file object or
nil
if the font is not embedded. -
#font_wrapper ⇒ Object
Retrieves the font wrapper that is needed when this font is used for text output.
-
#font_wrapper=(font) ⇒ Object
Sets the font wrapper.
-
#glyph_scaling_factor ⇒ Object
Returns the glyph scaling factor for transforming from glyph space to text space.
-
#must_be_indirect? ⇒ Boolean
Font objects must always be indirect.
-
#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.
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, #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.
82 83 84 85 86 87 88 |
# File 'lib/hexapdf/type/font.rb', line 82 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.
91 92 93 94 |
# File 'lib/hexapdf/type/font.rb', line 91 def dict = self[:FontDescriptor] dict && (dict[:FontFile] || dict[:FontFile2] || dict[:FontFile3]) end |
#font_file ⇒ Object
Returns the embeeded font file object or nil
if the font is not embedded.
97 98 99 |
# File 'lib/hexapdf/type/font.rb', line 97 def font_file end |
#font_wrapper ⇒ Object
Retrieves the font wrapper that is needed when this font is used for text output. Returns nil
if this font can’t be used for text output.
Note: For internal use only!
See: HexaPDF::Font
59 60 61 |
# File 'lib/hexapdf/type/font.rb', line 59 def font_wrapper @font_wrapper ||= nil end |
#font_wrapper=(font) ⇒ Object
Sets the font wrapper.
See: #font_wrapper
66 67 68 |
# File 'lib/hexapdf/type/font.rb', line 66 def font_wrapper=(font) @font_wrapper = font end |
#glyph_scaling_factor ⇒ Object
Returns the glyph scaling factor for transforming from glyph space to text space.
102 103 104 |
# File 'lib/hexapdf/type/font.rb', line 102 def glyph_scaling_factor 0.001 end |
#must_be_indirect? ⇒ Boolean
Font objects must always be indirect.
71 72 73 |
# File 'lib/hexapdf/type/font.rb', line 71 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.
77 78 79 |
# File 'lib/hexapdf/type/font.rb', line 77 def to_utf8(code) to_unicode_cmap&.to_unicode(code) || missing_unicode_mapping(code) end |