Prepare 1.0 alpha3 release.
[tagua/yd.git] / strip_font.rb
blob07db6cd60e6d1dce286f31693195561f5f415a52
1 #!/usr/bin/ruby
4 # Run as:
5 # ./strip_font.rb -n 'ArphicUkaiSubsetForTagua' -i /usr/share/fonts/truetype/arphic/ukai.ttf \
6 #  -o data/themes/figurines/ShogiTTF/arphic-ukai.ttf $(find data/ -ipath '*shogi*.lua')
9 require 'optparse'
10 require 'set'
12 input_file = nil
13 output_file = nil
14 font_name = nil
16 $options = OptionParser.new do |opt|
17   opt.banner = "Usage: strip_font.rb [options] luafiles"
19   opt.on( '-n', '--name FONT_NAME', 'Output font name' )    do |name|         font_name = name end
20   opt.on( '-i', '--input INPUT_FONT', 'Input font')         do |file|         input_file = file end
21   opt.on( '-o', '--output OUTPUT_FONT', 'Font to generate') do |file|         output_file = file end
22 end
24 $options.parse!(ARGV)
26 lua_files = ARGV
28 selection = Set.new
30 ARGV.each do |file|
31   File.open(file) do |f|
32     content = f.read
33     content.scan(/(["'])0x([0-9a-fA-F]{4})\1/).each do |match|
34       #print(match.inspect+"\n")
35       selection.add "SelectMore(0u"+match[1]+");"
36     end
37   end
38 end
40 a = %{
41 Open("#{input_file}");
42 #{selection.to_a.join("\n")}
43 SelectInvert();
44 DetachAndRemoveGlyphs();
45 SetFontNames("#{font_name}", "#{font_name}", "#{font_name}");
46 SetUniqueID(0);
47 Generate("#{output_file}");
50 # FIXME: find a better way to workaround this command which does not work any more
51 #system("echo -en #{a.inspect} | fontforge -c")
53 system("echo -en #{a.inspect} >ff-script.pe")
54 system("fontforge -script ff-script.pe")
55 script("rm ff-script.pe")