Class: Fontisan::Woff2::SfntChecksum

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/woff2/sfnt_checksum.rb

Overview

Computes head.checksumAdjustment for the SFNT that the WOFF2 decoder reconstructs at runtime.

Per OpenType spec, head.checksumAdjustment must be set so that the uint32-wise sum of the entire SFNT file (offset table + table directory + all tables) equals the magic 0xB1B0AFBA. Chrome's OTS validates this; a stale value from the source font causes rejection with "Failed to convert WOFF 2.0 font to SFNT" once any table has been modified (head.flags bit 11, glyf/loca transformation, etc.).

Reference: OpenType spec, "Calculating Checksums".

Defined Under Namespace

Classes: Table

Instance Method Summary collapse

Constructor Details

#initialize(flavor:, tables:) ⇒ SfntChecksum

Returns a new instance of SfntChecksum.

Parameters:

  • flavor (Integer)

    sfnt version (0x00010000 for TrueType, 0x4F54544F for CFF)

  • tables (Array<Table>)

    reconstructed tables in alphabetical tag order



26
27
28
29
# File 'lib/fontisan/woff2/sfnt_checksum.rb', line 26

def initialize(flavor:, tables:)
  @flavor = flavor
  @tables = tables
end

Instance Method Details

#adjustmentInteger

Compute the head.checksumAdjustment value (uint32).

Returns:

  • (Integer)


34
35
36
# File 'lib/fontisan/woff2/sfnt_checksum.rb', line 34

def adjustment
  (Constants::CHECKSUM_ADJUSTMENT_MAGIC - total_checksum) & 0xFFFFFFFF
end