module Convert

Public Class Methods

fontforge(file, from, to) click to toggle source

////////////////////////////// /// TO BASICALLY ANYTHING //// //////////////////////////////

# File lib/typefascist/convert.rb, line 28
def self.fontforge(file, from, to)
  RubyPython.start()
  fontforge = RubyPython.import('fontforge')
  font = suppress_output { fontforge.open(file) }
  file.sub! from, to
  suppress_output { fontforge.font.generate(font, file) }
  RubyPython.stop
end
forge(file, from, to) click to toggle source
# File lib/typefascist/convert.rb, line 37
def self.forge(file, from, to)
  fonts = [from, to];
  if (fonts & @@fontforge_enabled).length.eql? 2
    Announce.info "Converting from #{from} to #{to}"
    self.fontforge(file, from, to)
    Announce.success "Font converted at #{file}"
  else
    conversion = "to_#{to}"
    if(self.respond_to? :"#{conversion}")
      self.method(conversion).call(file, from)
    else
      Announce.failure "Conversion from #{from} to #{to} not supported"
    end
  end
end
suppress_output() { || ... } click to toggle source

Suppresses all output to terminal

# File lib/typefascist/convert.rb, line 58
def self.suppress_output
  begin
    original_stderr = $stderr.clone
    original_stdout = $stdout.clone
    $stderr.reopen(File.new('/dev/null', 'w'))
    $stdout.reopen(File.new('/dev/null', 'w'))
    retval = yield
  rescue Exception => e
    $stdout.reopen(original_stdout)
    $stderr.reopen(original_stderr)
    raise e
  ensure
    $stdout.reopen(original_stdout)
    $stderr.reopen(original_stderr)
  end
  retval
end
to_woff2(file, from) click to toggle source

///////////////// /// TO WOFF2 //// /////////////////

# File lib/typefascist/convert.rb, line 15
def self.to_woff2(file, from)
  fontforge(file, from, 'otf')
  Announce.info "Converting from #{from} to woff2"
  suppress_output { system "#{Pathname.pwd}/lib/convertors/sfnt_to_woff2 #{file}" }
  suppress_output { system "rm -rf #{file}" }
  file.sub! 'otf', 'woff2'
  Announce.success "Font converted at #{file}"
end