Class: HexaPDF::Font::TrueType::Table

Inherits:
Object
  • Object
show all
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/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

Direct Known Subclasses

Cmap, Directory, Glyf, Head, Hhea, Hmtx, Loca, Maxp, Name, OS2, Post

Defined Under Namespace

Classes: Cmap, CmapSubtable, Directory, Glyf, Head, Hhea, Hmtx, 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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font, entry = nil) ⇒ Table

Creates a new Table object for the given font and initializes it by either reading the data from the font’s associated IO stream if entry is given or by using default values.

See: #parse_table, #load_default



74
75
76
77
78
# File 'lib/hexapdf/font/true_type/table.rb', line 74

def initialize(font, entry = nil)
  @font = font
  @directory_entry = entry
  entry ? load_from_io : load_default
end

Instance Attribute Details

#fontObject (readonly)

The TrueType font object associated with this table.



68
69
70
# File 'lib/hexapdf/font/true_type/table.rb', line 68

def font
  @font
end

Class Method Details

.calculate_checksum(data) ⇒ Object

Calculates the checksum for the given data.



62
63
64
# File 'lib/hexapdf/font/true_type/table.rb', line 62

def self.calculate_checksum(data)
  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.

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
# File 'lib/hexapdf/font/true_type/table.rb', line 89

def checksum_valid?
  unless directory_entry
    raise HexaPDF::Error, "Can't verify the checksum, no directory entry available"
  end

  data = with_io_pos(directory_entry.offset) { io.read(directory_entry.length) }
  directory_entry.checksum == self.class.calculate_checksum(data)
end

#directory_entryObject

Returns the directory entry for this table.

See: Directory



83
84
85
# File 'lib/hexapdf/font/true_type/table.rb', line 83

def directory_entry
  @directory_entry
end