Class: HexaPDF::Font::TrueType::Table
- Inherits:
-
Object
- Object
- HexaPDF::Font::TrueType::Table
- Defined in:
- lib/hexapdf/font/true_type/table.rb,
lib/hexapdf/font/true_type/table/os2.rb,
lib/hexapdf/font/true_type/table/cmap.rb,
lib/hexapdf/font/true_type/table/glyf.rb,
lib/hexapdf/font/true_type/table/head.rb,
lib/hexapdf/font/true_type/table/hhea.rb,
lib/hexapdf/font/true_type/table/hmtx.rb,
lib/hexapdf/font/true_type/table/kern.rb,
lib/hexapdf/font/true_type/table/loca.rb,
lib/hexapdf/font/true_type/table/maxp.rb,
lib/hexapdf/font/true_type/table/name.rb,
lib/hexapdf/font/true_type/table/post.rb,
lib/hexapdf/font/true_type/table/directory.rb,
lib/hexapdf/font/true_type/table/cmap_subtable.rb
Overview
Implementation of a generic table inside a sfnt-formatted font file.
See: developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html
Defined Under Namespace
Classes: Cmap, CmapSubtable, Directory, Glyf, Head, Hhea, Hmtx, Kern, Loca, Maxp, Name, OS2, Post
Constant Summary collapse
- TIME_EPOCH =
The time Epoch used in sfnt-formatted font files.
Time.new(1904, 1, 1)
Instance Attribute Summary collapse
-
#font ⇒ Object
readonly
The TrueType font object associated with this table.
Class Method Summary collapse
-
.calculate_checksum(data) ⇒ Object
Calculates the checksum for the given data.
Instance Method Summary collapse
-
#checksum_valid? ⇒ Boolean
Returns
true
if the checksum stored in the directory entry of the table matches the tables data. -
#directory_entry ⇒ Object
Returns the directory entry for this table.
-
#initialize(font, entry) ⇒ Table
constructor
Creates a new Table object for the given font and initializes it by reading the data from the font’s associated IO stream.
-
#raw_data ⇒ Object
Returns the raw table data.
Constructor Details
#initialize(font, entry) ⇒ Table
Creates a new Table object for the given font and initializes it by reading the data from the font’s associated IO stream
See: #parse_table
81 82 83 84 85 |
# File 'lib/hexapdf/font/true_type/table.rb', line 81 def initialize(font, entry) @font = font @directory_entry = entry load_from_io end |
Instance Attribute Details
#font ⇒ Object (readonly)
The TrueType font object associated with this table.
75 76 77 |
# File 'lib/hexapdf/font/true_type/table.rb', line 75 def font @font end |
Class Method Details
.calculate_checksum(data) ⇒ Object
Calculates the checksum for the given data.
65 66 67 68 69 70 71 72 |
# File 'lib/hexapdf/font/true_type/table.rb', line 65 def self.calculate_checksum(data) checksum = 0 if (remainder_length = data.length % 4) != 0 checksum = (data[-remainder_length, remainder_length] << "\0" * (4 - remainder_length)). unpack1('N') end checksum + data.unpack('N*').inject(0) {|sum, long| sum + long } % 2**32 end |
Instance Method Details
#checksum_valid? ⇒ Boolean
Returns true
if the checksum stored in the directory entry of the table matches the tables data.
96 97 98 |
# File 'lib/hexapdf/font/true_type/table.rb', line 96 def checksum_valid? directory_entry.checksum == self.class.calculate_checksum(raw_data) end |
#directory_entry ⇒ Object
Returns the directory entry for this table.
See: Directory
90 91 92 |
# File 'lib/hexapdf/font/true_type/table.rb', line 90 def directory_entry @directory_entry end |
#raw_data ⇒ Object
Returns the raw table data.
101 102 103 |
# File 'lib/hexapdf/font/true_type/table.rb', line 101 def raw_data with_io_pos(directory_entry.offset) { io.read(directory_entry.length) } end |