Class: Fontisan::Ufo::Cli
- Inherits:
-
Thor
- Object
- Thor
- Fontisan::Ufo::Cli
- Defined in:
- lib/fontisan/ufo/cli.rb
Overview
CLI subcommand for UFO source operations.
fontisan ufo build font.ufo --output out.ttf [--format otf]
fontisan ufo convert font.ttf font.ufo
fontisan ufo validate font.ufo
Instance Method Summary collapse
Instance Method Details
#build(ufo) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fontisan/ufo/cli.rb', line 18 def build(ufo) font = Font.open(ufo) format_sym = ([:to] || "ttf").to_s.downcase.to_sym compiler = case format_sym when :ttf then Compile::TtfCompiler when :otf then Compile::OtfCompiler else warn "unknown format: #{[:to].inspect}" exit 1 end compiler.new(font).compile(output_path: [:output]) puts "wrote #{[:output]} (#{File.size([:output])} bytes)" rescue Errno::ENOENT warn "UFO not found: #{ufo}" exit 1 end |
#convert(input, output) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fontisan/ufo/cli.rb', line 39 def convert(input, output) if ufo?(input) font = Font.open(input) format = [:to] || File.extname(output).delete(".").downcase compiler = case format.to_sym when :ttf then Compile::TtfCompiler when :otf then Compile::OtfCompiler else warn "unsupported output format: #{format.inspect}" exit 1 end compiler.new(font).compile(output_path: output) else # Binary → UFO loaded = Fontisan::FontLoader.load(input) ufo = Convert::FromBinData.convert(loaded) Writer.new(ufo).write(output) end puts "wrote #{output}" end |
#validate(ufo) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fontisan/ufo/cli.rb', line 62 def validate(ufo) font = Font.open(ufo) issues = [] issues << "no glyphs in default layer" if font.glyphs.empty? issues << "no family name" unless font.info.family_name issues << "unitsPerEm not set" unless font.info.units_per_em issues << "missing .notdef glyph" unless font.glyph(".notdef") if issues.empty? puts "OK #{ufo}" else issues.each { |i| warn "FAIL #{i}" } exit 1 end end |