Class: HexaPDF::Type::FontSimple
- Inherits:
-
Font
- Object
- Object
- Dictionary
- Font
- HexaPDF::Type::FontSimple
- Defined in:
- lib/hexapdf/type/font_simple.rb
Overview
Represents a simple PDF font.
A simple font has only single-byte character codes and only supports horizontal metrics.
See: PDF2.0 s9.6
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
-
#decode(string) ⇒ Object
Decodes the given string into an array of character codes.
-
#encoding ⇒ Object
Returns the encoding object used for this font.
-
#font_descriptor ⇒ Object
Returns the font descriptor.
-
#symbolic? ⇒ Boolean
Returns
true
if the font is a symbolic font,false
if it is not, andnil
if it is not known. -
#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.
-
#width(code) ⇒ Object
Returns the unscaled width of the given code point 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 always :horizontal for simple fonts like Type1.
Methods inherited from Font
#bounding_box, #embedded?, #font_file, #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
#decode(string) ⇒ Object
Decodes the given string into an array of character codes.
93 94 95 |
# File 'lib/hexapdf/type/font_simple.rb', line 93 def decode(string) string.bytes end |
#encoding ⇒ Object
Returns the encoding object used for this font.
Note that the encoding is cached internally when accessed the first time.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hexapdf/type/font_simple.rb', line 68 def encoding cache(:encoding) do case (val = self[:Encoding]) when Symbol encoding = HexaPDF::Font::Encoding.for_name(val) encoding = encoding_from_font if encoding.nil? encoding when HexaPDF::Dictionary encoding = val[:BaseEncoding] && HexaPDF::Font::Encoding.for_name(val[:BaseEncoding]) encoding ||= if || symbolic? encoding_from_font else HexaPDF::Font::Encoding.for_name(:StandardEncoding) end encoding = difference_encoding(encoding, val[:Differences]) if val.key?(:Differences) encoding when nil encoding_from_font else raise HexaPDF::Error, "Unknown value for font's encoding: #{self[:Encoding]}" end end end |
#font_descriptor ⇒ Object
Returns the font descriptor. May be nil
for a standard 14 font.
The font descriptor is required except for the standard 14 fonts in PDF version up to 1.7.
61 62 63 |
# File 'lib/hexapdf/type/font_simple.rb', line 61 def font_descriptor self[:FontDescriptor] end |
#symbolic? ⇒ Boolean
Returns true
if the font is a symbolic font, false
if it is not, and nil
if it is not known.
127 128 129 |
# File 'lib/hexapdf/type/font_simple.rb', line 127 def symbolic? self[:FontDescriptor]&.flagged?(:symbolic) 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.
99 100 101 102 |
# File 'lib/hexapdf/type/font_simple.rb', line 99 def to_utf8(code) to_unicode_cmap&.to_unicode(code) || (encoding.unicode(code) rescue nil) || missing_unicode_mapping(code) end |
#width(code) ⇒ Object
Returns the unscaled width of the given code point in glyph units, or 0 if the width for the code point is missing.
106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hexapdf/type/font_simple.rb', line 106 def width(code) widths = self[:Widths] first_char = self[:FirstChar] last_char = self[:LastChar] if widths && code >= first_char && code <= last_char widths[code - first_char] elsif widths && key?(:FontDescriptor) self[:FontDescriptor][:MissingWidth] else 0 end end |
#word_spacing_applicable? ⇒ Boolean
Returns whether word spacing is applicable when using this font.
Always returns true
for simple fonts.
See: PDF2.0 s9.3.3
136 137 138 |
# File 'lib/hexapdf/type/font_simple.rb', line 136 def word_spacing_applicable? true end |
#writing_mode ⇒ Object
Returns the writing mode which is always :horizontal for simple fonts like Type1.
121 122 123 |
# File 'lib/hexapdf/type/font_simple.rb', line 121 def writing_mode :horizontal end |