Class: Fontisan::Woff2::SfntChecksum

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

Overview

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

Per OpenType spec ("Calculating Checksums"), checksumAdjustment must be set so 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.).

Delegates the per-table uint32 sum to Utilities::ChecksumCalculator — that is the single source of truth for the OpenType checksum algorithm. This class orchestrates the per-table layout: building the offset table + table directory bytes, zeroing head's checksumAdjustment field for its own checksum per spec, then subtracting the total from the magic.

Defined Under Namespace

Classes: Table

Instance Method Summary collapse

Constructor Details

#initialize(flavor:, tables:) ⇒ SfntChecksum

tag order

Parameters:

  • flavor (Integer)

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

  • tables (Array<Table>)

    reconstructed tables in alphabetical



30
31
32
33
# File 'lib/fontisan/woff2/sfnt_checksum.rb', line 30

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

Instance Method Details

#adjustmentInteger

Compute the head.checksumAdjustment value (uint32).

Returns:

  • (Integer)


38
39
40
# File 'lib/fontisan/woff2/sfnt_checksum.rb', line 38

def adjustment
  Utilities::ChecksumCalculator.calculate_adjustment(total_checksum)
end