Class: Fontisan::Validation::Woff2Validator

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

Overview

Woff2Validator is the main orchestrator for WOFF2 font validation

This class coordinates WOFF2-specific validation checks (header, tables) and produces a comprehensive ValidationReport. It is designed to validate WOFF2 encoding quality and spec compliance.

Single Responsibility: Orchestration of WOFF2 validation workflow

Examples:

Validating a WOFF2 font

validator = Woff2Validator.new(level: :standard)
report = validator.validate(woff2_font, font_path)
puts report.text_summary

Validating WOFF2 encoding result

woff2_font = Woff2Font.from_file("output.woff2")
validator = Woff2Validator.new
report = validator.validate(woff2_font, "output.woff2")
puts "Valid: #{report.valid}"

Constant Summary collapse

LEVELS =

Validation levels

%i[strict standard lenient].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level: :standard, rules_path: nil) ⇒ Woff2Validator

Initialize WOFF2 validator

Parameters:

  • level (Symbol) (defaults to: :standard)

    Validation level (:strict, :standard, :lenient)

  • rules_path (String, nil) (defaults to: nil)

    Path to custom rules file



36
37
38
39
40
41
42
43
# File 'lib/fontisan/validation/woff2_validator.rb', line 36

def initialize(level: :standard, rules_path: nil)
  @level = level
  validate_level!

  @rules = load_rules(rules_path)
  @header_validator = Woff2HeaderValidator.new(@rules)
  @table_validator = Woff2TableValidator.new(@rules)
end

Instance Attribute Details

#levelSymbol (readonly)

Get the current validation level

Returns:

  • (Symbol)

    The validation level



97
98
99
# File 'lib/fontisan/validation/woff2_validator.rb', line 97

def level
  @level
end

Instance Method Details

#validate(woff2_font, font_path) ⇒ Models::ValidationReport

Validate a WOFF2 font

Parameters:

  • woff2_font (Woff2Font)

    The WOFF2 font to validate

  • font_path (String)

    Path to the font file

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fontisan/validation/woff2_validator.rb', line 50

def validate(woff2_font, font_path)
  report = Models::ValidationReport.new(
    font_path: font_path,
    valid: true,
  )

  begin
    # Run all validation checks
    all_issues = []

    # 1. Header validation
    all_issues.concat(@header_validator.validate(woff2_font))

    # 2. Table validation
    all_issues.concat(@table_validator.validate(woff2_font))

    # 3. WOFF2-specific checks
    all_issues.concat(check_woff2_specific(woff2_font))

    # Add issues to report
    all_issues.each do |issue|
      case issue[:severity]
      when "error"
        report.add_error(issue[:category], issue[:message],
                         issue[:location])
      when "warning"
        report.add_warning(issue[:category], issue[:message],
                           issue[:location])
      when "info"
        report.add_info(issue[:category], issue[:message],
                        issue[:location])
      end
    end

    # Determine overall validity based on level
    report.valid = determine_validity(report)
  rescue StandardError => e
    report.add_error("woff2_validation", "WOFF2 validation failed: #{e.message}", nil)
    report.valid = false
  end

  report
end