Module: Fontisan::Ufo::Convert::ToOtc

Defined in:
lib/fontisan/ufo/convert/to_otc.rb

Overview

UFO → OpenType Collection (.otc). Two-step:

1. Compile UFO → OTF (CFF) in tmpdir.
2. Load + feed to Collection::Builder with format: :otc.

A single UFO produces a single-face collection.

Class Method Summary collapse

Class Method Details

.convert(ufo, output_path:, compiler: :otf, **_opts) ⇒ String

Returns the output_path.

Parameters:

  • ufo (Fontisan::Ufo::Font)
  • output_path (String)
  • compiler (Symbol) (defaults to: :otf)

    :otf (default, CFF1) or :otf2 (CFF2)

Returns:

  • (String)

    the output_path

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fontisan/ufo/convert/to_otc.rb', line 19

def self.convert(ufo, output_path:, compiler: :otf, **_opts)
  compiler_class = Convert::COMPILER_FOR_FORMAT[compiler.to_sym]
  raise ArgumentError, "unknown intermediate compiler: #{compiler.inspect}" unless compiler_class

  Dir.mktmpdir do |dir|
    intermediate_path = File.join(dir, "intermediate.otf")
    compiler_class.new(ufo).compile(output_path: intermediate_path)

    loaded = Fontisan::FontLoader.load(intermediate_path)
    Fontisan::Collection::Builder.new([loaded], format: :otc,
                                                optimize: true).build_to_file(output_path)
  end

  output_path
end