Module: Fontisan::Ufo::Convert
- Defined in:
- lib/fontisan/ufo/convert.rb,
lib/fontisan/ufo/convert/to_otc.rb,
lib/fontisan/ufo/convert/to_otf.rb,
lib/fontisan/ufo/convert/to_ttc.rb,
lib/fontisan/ufo/convert/to_ttf.rb,
lib/fontisan/ufo/convert/to_otf2.rb,
lib/fontisan/ufo/convert/to_woff.rb,
lib/fontisan/ufo/convert/to_dfont.rb,
lib/fontisan/ufo/convert/to_woff2.rb,
lib/fontisan/ufo/convert/from_bin_data.rb,
lib/fontisan/ufo/convert/to_postscript.rb
Overview
Conversion layer between the UFO model and fontisan's BinData table layer. Two directions:
ToBinData / To{Format} .convert(ufo, output_path:) → writes file
FromBinData.convert(loaded_font) → Ufo::Font
The To* paths are thin facades over the corresponding Compile::*Compiler classes. They exist to give callers a single uniform convert API and to keep the CLI's format dispatch in one data-driven place (COMPILER_FOR_FORMAT) instead of a switch statement per CLI command.
Defined Under Namespace
Modules: FromBinData, ToDfont, ToOtc, ToOtf, ToOtf2, ToPfa, ToPfb, ToPostscript, ToTtc, ToTtf, ToWoff, ToWoff2
Constant Summary collapse
- COMPILER_FOR_FORMAT =
Single source of truth for "which compiler handles this output format?". OCP: adding a format = adding one entry here + one wrapper file. The CLI reads from this hash instead of a case statement.
{ ttf: Compile::TtfCompiler, otf: Compile::OtfCompiler, otf2: Compile::Otf2Compiler, }.freeze
- WRAPPER_FOR_FORMAT =
Wrapper modules for 2-step pipelines (UFO → compiler → tmpfile → encoder → output). These don't fit the 1-step COMPILER_FOR_FORMAT registry because they need a tmpdir + a second encoder pass. OCP: adding a 2-step format = adding one entry here + one wrapper file.
{ woff: ToWoff, woff2: ToWoff2, dfont: ToDfont, ttc: ToTtc, otc: ToOtc, pfb: ToPfb, pfa: ToPfa, }.freeze
Class Method Summary collapse
-
.convert(ufo, to:, output_path:) ⇒ String
Convert a UFO to a binary format, writing to
output_path.
Class Method Details
.convert(ufo, to:, output_path:) ⇒ String
Convert a UFO to a binary format, writing to output_path.
Routes through either COMPILER_FOR_FORMAT (1-step: ttf/otf/
otf2) or WRAPPER_FOR_FORMAT (2-step: woff/woff2). Raises
ArgumentError for unknown formats.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fontisan/ufo/convert.rb', line 66 def self.convert(ufo, to:, output_path:, **) format_key = to.to_sym if (wrapper = WRAPPER_FOR_FORMAT[format_key]) return wrapper.convert(ufo, output_path: output_path, **) end compiler = COMPILER_FOR_FORMAT[format_key] raise ArgumentError, "unknown UFO output format: #{to.inspect}" unless compiler compiler.new(ufo).compile(output_path: output_path) output_path end |