Class: Fontisan::Validation::Woff2HeaderValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/validation/woff2_header_validator.rb

Overview

Woff2HeaderValidator validates the WOFF2 header structure

This validator checks the WOFF2 header for:

  • Valid signature (0x774F4632 ‘wOF2’)

  • Valid flavor (TrueType or CFF)

  • Reserved field is zero

  • File length consistency

  • Valid table count

  • Valid compressed size

  • Metadata offset/length consistency

  • Private data offset/length consistency

Single Responsibility: WOFF2 header validation

Examples:

Validating a WOFF2 header

validator = Woff2HeaderValidator.new(rules)
issues = validator.validate(woff2_font)

Constant Summary collapse

VALID_FLAVORS =

Valid WOFF2 flavors

[
  0x00010000, # TrueType
  0x74727565, # 'true' (TrueType)
  0x4F54544F, # 'OTTO' (CFF/OpenType)
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ Woff2HeaderValidator

Initialize WOFF2 header validator

Parameters:

  • rules (Hash)

    Validation rules configuration



33
34
35
36
# File 'lib/fontisan/validation/woff2_header_validator.rb', line 33

def initialize(rules)
  @rules = rules
  @woff2_config = rules["woff2_validation"] || {}
end

Instance Method Details

#validate(woff2_font) ⇒ Array<Hash>

Validate WOFF2 header

Parameters:

  • woff2_font (Woff2Font)

    The WOFF2 font to validate

Returns:

  • (Array<Hash>)

    Array of validation issues



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fontisan/validation/woff2_header_validator.rb', line 42

def validate(woff2_font)
  issues = []

  header = woff2_font.header
  return issues unless header

  # Check signature
  issues.concat(check_signature(header))

  # Check flavor
  issues.concat(check_flavor(header))

  # Check reserved field
  issues.concat(check_reserved_field(header))

  # Check table count
  issues.concat(check_table_count(header, woff2_font))

  # Check compressed size
  issues.concat(check_compressed_size(header))

  # Check metadata consistency
  issues.concat((header))

  # Check private data consistency
  issues.concat(check_private_data(header))

  issues
end