class HexaPDF::Font::TrueType::Table
Implementation of a generic table inside a sfnt-formatted font file.
See: developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html
Constants
- TIME_EPOCH
The time Epoch used in sfnt-formatted font files.
Attributes
The TrueType
font object associated with this table.
Public Class Methods
Calculates the checksum for the given data.
# File lib/hexapdf/font/true_type/table.rb, line 64 def self.calculate_checksum(data) data.unpack('N*').inject(0) {|sum, long| sum + long } % 2**32 end
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
# File lib/hexapdf/font/true_type/table.rb, line 75 def initialize(font, entry) @font = font @directory_entry = entry load_from_io end
Public Instance Methods
Returns true
if the checksum stored in the directory entry of the table matches the tables data.
# File lib/hexapdf/font/true_type/table.rb, line 90 def checksum_valid? directory_entry.checksum == self.class.calculate_checksum(raw_data) end
Returns the directory entry for this table.
See: Directory
# File lib/hexapdf/font/true_type/table.rb, line 84 def directory_entry @directory_entry end
Returns the raw table data.
# File lib/hexapdf/font/true_type/table.rb, line 95 def raw_data with_io_pos(directory_entry.offset) { io.read(directory_entry.length) } end
Private Instance Methods
The IO stream of the associated font object.
# File lib/hexapdf/font/true_type/table.rb, line 102 def io @font.io end
Loads the data for this table from the IO stream of the associated font object into this object.
See parse_table
for more information.
# File lib/hexapdf/font/true_type/table.rb, line 110 def load_from_io with_io_pos(directory_entry.offset) { parse_table } end
Parses the table with the IO position already at the correct offset.
This method does the actual work of parsing a table entry and must be implemented by subclasses.
See: load_from_io
# File lib/hexapdf/font/true_type/table.rb, line 120 def parse_table # noop for unsupported tables end
Reads a 16.16-bit signed fixed-point integer and returns a Rational as result.
# File lib/hexapdf/font/true_type/table.rb, line 141 def read_fixed Rational(io.read(4).unpack1('i>'), 65536) end
Reads count
bytes from the current position of the font's associated IO stream, unpacks them using the provided format specifier and returns the result.
# File lib/hexapdf/font/true_type/table.rb, line 136 def read_formatted(count, format) io.read(count).unpack(format) end
Sets the IO cursor to the given position while yielding to the block and returns the block's return value.
# File lib/hexapdf/font/true_type/table.rb, line 126 def with_io_pos(pos) old_pos = io.pos io.pos = pos yield ensure io.pos = old_pos end