Class: Fontisan::Commands::ValidateCollectionCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/commands/validate_collection_command.rb

Overview

Validates the structural integrity of a TTC/OTC/dfont collection (TODO 74). Complements ValidateCommand, which runs profile-based checks against a single face. This command runs collection-level checks: face count, per-face glyph cap, optional cmap-union size.

Returns an integer exit code (0 = all checks passed, 1 = any check failed) suitable for use as the CLI's exit status.

The command is intentionally narrow: it does not subclass BaseCommand (which eagerly loads a single font at construction time) because the input here is a collection, not a single face. It owns its own loading via Fontisan::Collection::Reader.

Defined Under Namespace

Classes: Check

Constant Summary collapse

DEFAULT_MAX_GLYPHS =
65_535

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, expected_faces: nil, max_glyphs: DEFAULT_MAX_GLYPHS, expected_cmap_union: nil) ⇒ ValidateCollectionCommand

Returns a new instance of ValidateCollectionCommand.

Parameters:

  • input (String)

    path to a TTC/OTC/dfont

  • expected_faces (Integer, nil) (defaults to: nil)

    required face count, or nil to skip

  • max_glyphs (Integer) (defaults to: DEFAULT_MAX_GLYPHS)

    per-face glyph cap (default 65,535)

  • expected_cmap_union (Integer, nil) (defaults to: nil)

    minimum cmap-union size, or nil to skip



41
42
43
44
45
46
47
# File 'lib/fontisan/commands/validate_collection_command.rb', line 41

def initialize(input:, expected_faces: nil, max_glyphs: DEFAULT_MAX_GLYPHS,
               expected_cmap_union: nil)
  @input = input
  @expected_faces = expected_faces
  @max_glyphs = max_glyphs
  @expected_cmap_union = expected_cmap_union
end

Instance Attribute Details

#checksArray<Check> (readonly)

Returns the most recent run's checks.

Returns:

  • (Array<Check>)

    the most recent run's checks



63
64
65
# File 'lib/fontisan/commands/validate_collection_command.rb', line 63

def checks
  @checks
end

Instance Method Details

#runInteger

Returns 0 if all checks passed, 1 otherwise.

Returns:

  • (Integer)

    0 if all checks passed, 1 otherwise



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fontisan/commands/validate_collection_command.rb', line 50

def run
  reader = Collection::Reader.open(@input)
  @checks = [
    check_face_count(reader),
    check_glyph_cap(reader),
    check_cmap_union(reader),
  ].compact

  render_report(reader)
  @checks.all?(&:passed?) ? 0 : 1
end