Sha256: d2349555f42a1213eac1924f2f1d2e63a4b72ec3fba9aae5efe3b0ef2f77057a
Contents?: true
Size: 1.59 KB
Versions: 1
Compression:
Stored size: 1.59 KB
Contents
#!/usr/bin/env ruby require 'hershey' require 'optparse' options = {} OptionParser.new do |opts| opts.banner = "Usage: hershey [options]" opts.on("-w", "--width WIDTH", Integer, "Width of the pages") do |vars| options[:width] = vars end opts.on("-h", "--height HEIGHT", Integer, "The height per page (defaults to 8.5x11 ratio)") do |f| options[:height] = f end opts.on("-i", "--input INFILE", "The input file (required)") do |f| options[:input] = f end opts.on("-o", "--output OUTFILE", "The output file base name (required)") do |f| options[:output] = f end options[:max] = 100 opts.on("-m", "--max MAX", Integer, "Max pages") do |range| options[:max] = range end opts.on("-o", "--output OUTFILE", "The output file base name") do |f| options[:output] = f end opts.on("-f", "--font FONT", Hershey::FONTS.keys, "The font to use") do |f| options[:font] = f.downcase end opts.separator("Fonts: #{Hershey::FONTS.keys.map {|k| k.to_s}.join(', ')}") opts.on("--help", "Shows this help message") do puts opts exit end end.parse! unless options[:width].is_a?(Integer) puts "Missing number of variables for equation" puts "Call with -h or --help for help" exit(1) end options[:height] ||= (options[:width] / 8.5 * 11 / 20).ceil * 20 pages = Hershey.svgs(File.read(options[:input]), options.select{|k,_| [:width,:height,:font].include?(k)}) pages.each_with_index do |page, i| f = "#{options[:output]}_#{i}.svg" puts "#{f}: #{page.each_char.inject(0) {|m,s| s == 'L' ? m + 1 : m}} line segments." open(f, 'w') {|f| f.write(page)} end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hershey-0.0.7 | bin/hershey |