File: strip_font.rb

package info (click to toggle)
tagua 1.0~alpha2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 7,178
  • sloc: cpp: 26,149; ansic: 13,039; makefile: 182; ruby: 87; sh: 39
file content (45 lines) | stat: -rwxr-xr-x 1,064 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/ruby

require 'optparse'
require 'set'

input_file = nil
output_file = nil
font_name = nil

$options = OptionParser.new do |opt|
  opt.banner = "Usage: strip_font.rb [options] luafiles"

  opt.on( '-n', '--name FONT_NAME', 'Output font name' )    do |name|         font_name = name end
  opt.on( '-i', '--input INPUT_FONT', 'Input font')         do |file|         input_file = file end
  opt.on( '-o', '--output OUTPUT_FONT', 'Font to generate') do |file|         output_file = file end
end

$options.parse!(ARGV)

lua_files = ARGV

selection = Set.new

ARGV.each do |file|
  File.open(file) do |f|
    content = f.read
    content.scan(/(["'])0x([0-9a-fA-F]{4})\1/).each do |match|
      print(match.inspect+"\n")
      selection.add "SelectMore(0u"+match[1]+");"
    end
  end
end

a = %{
  Open("#{input_file}");
#{selection.to_a.join("\n")}
  SelectInvert();
  DetachAndRemoveGlyphs();
  SetFontNames("#{font_name}", "#{font_name}", "#{font_name}");
  SetUniqueID(0);
  Generate("#{output_file}");
}

system("echo -en #{a.inspect} | fontforge -c")