Sha256: a1c2f7652b14ccef13e3b5ec723512f76f840b947a7d9c75d592b7ecd3606fec
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require 'tempfile' module Fontana class Fontforge def self.convert(input_ext, input_string, output_ext) input_file = create_input_file(input_ext, input_string) output_file = setup_output_file output_ext run_conversion_command(input_file, output_file, output_ext.split('.').last) return_string = readback_output_file(output_file) cleanup(input_file) cleanup(output_file) return_string end def self.information(font_path) run_information_command(font_path).strip end private def self.cleanup(tempfile) tempfile.unlink end def self.create_input_file(ext, content, filename = 'fontana-fontforge-input') tempfile = Tempfile.new([filename, ext]) tempfile.binmode tempfile.write content tempfile.close tempfile end def self.setup_output_file(extension, filename = 'fontana-fontforge-output') tempfile = Tempfile.new([filename, extension]) tempfile.close tempfile end def self.readback_output_file(output_file) output = nil File.open(output_file.path, 'rb') { |file| output = file.read } output end def self.run_conversion_command(input_file, output_file, ext) puts "fontforge -script #{File.join(File.dirname(__FILE__), 'fontforge', "2#{ext}.pe")} #{input_file.path} #{output_file.path}" puts `fontforge -script #{File.join(File.dirname(__FILE__), 'fontforge', "2#{ext}.pe")} #{input_file.path} #{output_file.path}` end def self.run_information_command(input_file_path) puts "fontforge -script #{File.join(File.dirname(__FILE__), 'fontforge', "info.pe")} '#{input_file_path}'" `fontforge -script #{File.join(File.dirname(__FILE__), 'fontforge', "info.pe")} '#{input_file_path}'` end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fontana-0.0.1.rc1 | lib/fontana/fontforge.rb |