Class: Fontisan::Woff2::Woff2Header

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/fontisan/woff2/header.rb

Overview

WOFF2 Header structure

[‘Woff2::Header`](lib/fontisan/woff2/header.rb) represents the main header of a WOFF2 file according to W3C WOFF2 specification.

The header is more compact than WOFF, using 48 bytes.

Structure (all big-endian):

  • uint32: signature (0x774F4632 ‘wOF2’)

  • uint32: flavor (0x00010000 for TTF, 0x4F54544F for CFF)

  • uint32: file_length (total WOFF2 file size)

  • uint16: numTables (number of font tables)

  • uint16: reserved (must be 0)

  • uint32: totalSfntSize (uncompressed font size)

  • uint32: totalCompressedSize (size of compressed data block)

  • uint16: majorVersion (major version of WOFF file)

  • uint16: minorVersion (minor version of WOFF file)

  • uint32: metaOffset (offset to metadata, 0 if none)

  • uint32: metaLength (compressed metadata length)

  • uint32: metaOrigLength (uncompressed metadata length)

  • uint32: privOffset (offset to private data, 0 if none)

  • uint32: privLength (length of private data)

Reference: www.w3.org/TR/WOFF2/#woff20Header

Examples:

Create a header

header = Woff2::Header.new
header.signature = 0x774F4632
header.flavor = 0x00010000
header.num_tables = 10

Constant Summary collapse

SIGNATURE =

WOFF2 signature constant

0x774F4632

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.header_sizeInteger

Get header size in bytes

Returns:

  • (Integer)

    Header size (always 48 bytes)



96
97
98
# File 'lib/fontisan/woff2/header.rb', line 96

def self.header_size
  48
end

Instance Method Details

#cff?Boolean

Check if font is CFF flavored

Returns:

  • (Boolean)

    True if CFF/OpenType



75
76
77
# File 'lib/fontisan/woff2/header.rb', line 75

def cff?
  flavor == 0x4F54544F # 'OTTO'
end

#has_metadata?Boolean

Check if metadata is present

Returns:

  • (Boolean)

    True if metadata exists



82
83
84
# File 'lib/fontisan/woff2/header.rb', line 82

def has_metadata?
  meta_offset.positive? && meta_length.positive?
end

#has_private_data?Boolean

Check if private data is present

Returns:

  • (Boolean)

    True if private data exists



89
90
91
# File 'lib/fontisan/woff2/header.rb', line 89

def has_private_data?
  priv_offset.positive? && priv_length.positive?
end

#truetype?Boolean

Check if font is TrueType flavored

Returns:

  • (Boolean)

    True if TrueType



68
69
70
# File 'lib/fontisan/woff2/header.rb', line 68

def truetype?
  [0x00010000, 0x74727565].include?(flavor) # 'true'
end

#valid_signature?Boolean

Check if signature is valid

Returns:

  • (Boolean)

    True if signature is valid



61
62
63
# File 'lib/fontisan/woff2/header.rb', line 61

def valid_signature?
  signature == SIGNATURE
end