Class: Fontisan::Stitcher::FormatMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/stitcher/format_metadata.rb

Overview

Immutable metadata about a stitcher output format. Single source of truth for "given a format symbol, what compiler / collection format / file extension does it use?". Adding a new format = adding a when branch in FormatMetadata.resolve; no other site in Stitcher needs to know the mapping.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, compiler_class:, collection_format:, extension:) ⇒ FormatMetadata

Returns a new instance of FormatMetadata.

Parameters:

  • name (Symbol)

    canonical format name (:ttf, :otf, :otf2)

  • compiler_class (Class)

    the Ufo::Compile::*Compiler that compiles a Ufo::Font target into the format's binary

  • collection_format (Symbol)

    :ttc or :otc — the Collection::Builder format used when packing multiple subfonts of this format into a collection

  • extension (String)

    file extension including the dot



20
21
22
23
24
25
# File 'lib/fontisan/stitcher/format_metadata.rb', line 20

def initialize(name:, compiler_class:, collection_format:, extension:)
  @name = name
  @compiler_class = compiler_class
  @collection_format = collection_format
  @extension = extension
end

Instance Attribute Details

#collection_formatObject (readonly)

Returns the value of attribute collection_format.



11
12
13
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11

def collection_format
  @collection_format
end

#compiler_classObject (readonly)

Returns the value of attribute compiler_class.



11
12
13
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11

def compiler_class
  @compiler_class
end

#extensionObject (readonly)

Returns the value of attribute extension.



11
12
13
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11

def extension
  @extension
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/fontisan/stitcher/format_metadata.rb', line 11

def name
  @name
end

Class Method Details

.resolve(name) ⇒ FormatMetadata

Resolve a format name (Symbol or String) to its metadata. Constants are referenced inside when branches so autoload fires only for the requested format, not all of them.

Parameters:

  • name (Symbol, String)

Returns:

Raises:

  • (ArgumentError)

    if name is not a known stitcher format



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

def self.resolve(name)
  case name.to_sym
  when :ttf
    new(name: :ttf, compiler_class: Ufo::Compile::TtfCompiler,
        collection_format: :ttc, extension: ".ttf")
  when :otf
    new(name: :otf, compiler_class: Ufo::Compile::OtfCompiler,
        collection_format: :otc, extension: ".otf")
  when :otf2
    new(name: :otf2, compiler_class: Ufo::Compile::Otf2Compiler,
        collection_format: :otc, extension: ".otf")
  else
    raise ArgumentError, "unknown format: #{name.inspect}"
  end
end