Class: Fontisan::Validation::CollectionValidator

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

Overview

CollectionValidator validates font compatibility for collection formats

Main responsibility: Enforce format-specific compatibility rules for TTC, OTC, and dfont collections according to OpenType spec and Apple standards.

Rules:

  • TTC: TrueType fonts ONLY (per OpenType spec)

  • OTC: CFF fonts required, mixed TTF+OTF allowed (Fontisan extension)

  • dfont: Any SFNT fonts (TTF, OTF, or mixed)

  • All: Web fonts (WOFF/WOFF2) are NEVER allowed in collections

Examples:

Validate TTC compatibility

validator = CollectionValidator.new
validator.validate!([font1, font2], :ttc)

Check compatibility without raising

validator = CollectionValidator.new
result = validator.compatible?([font1, font2], :otc)

Instance Method Summary collapse

Instance Method Details

#compatibility_issues(fonts, format) ⇒ Array<String>

Get compatibility issues for fonts and format

Parameters:

  • fonts (Array)

    Fonts to check

  • format (Symbol)

    Collection format

Returns:

  • (Array<String>)

    Array of issue descriptions (empty if compatible)



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fontisan/validation/collection_validator.rb', line 67

def compatibility_issues(fonts, format)
  issues = []

  return ["Font array cannot be empty"] if fonts.nil? || fonts.empty?
  return ["Invalid format: #{format}"] unless %i[ttc otc
                                                 dfont].include?(format)

  case format
  when :ttc
    issues.concat(ttc_issues(fonts))
  when :otc
    issues.concat(otc_issues(fonts))
  when :dfont
    issues.concat(dfont_issues(fonts))
  end

  issues
end

#compatible?(fonts, format) ⇒ Boolean

Check if fonts are compatible with format (without raising)

Parameters:

  • fonts (Array)

    Fonts to check

  • format (Symbol)

    Collection format

Returns:

  • (Boolean)

    true if compatible



55
56
57
58
59
60
# File 'lib/fontisan/validation/collection_validator.rb', line 55

def compatible?(fonts, format)
  validate!(fonts, format)
  true
rescue Error
  false
end

#validate!(fonts, format) ⇒ Boolean

Validate fonts are compatible with collection format

Parameters:

  • fonts (Array<TrueTypeFont, OpenTypeFont>)

    Fonts to validate

  • format (Symbol)

    Collection format (:ttc, :otc, or :dfont)

Returns:

  • (Boolean)

    true if valid

Raises:

  • (Error)

    if validation fails



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fontisan/validation/collection_validator.rb', line 32

def validate!(fonts, format)
  validate_not_empty!(fonts)
  validate_format!(format)

  case format
  when :ttc
    validate_ttc!(fonts)
  when :otc
    validate_otc!(fonts)
  when :dfont
    validate_dfont!(fonts)
  else
    raise Error, "Unknown collection format: #{format}"
  end

  true
end