3 # Copyright (C) 2003 Free Software Foundation, Inc.
5 # This unifont2pff.rb is free software; the author
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY, to the extent permitted by law; without
11 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14 # The magic number of the font file.
18 puts "Usage: ruby unifont2pff.rb [RANGE ...] FILE"
30 if /\A0x([0-9a-fA-F]+)[:-]0x([0-9a-fA-F]+)\z/ =~ range
31 ranges << [$1.hex, $2.hex]
32 elsif /\A0x([0-9a-fA-F]+)\z/ =~ range
33 ranges << [$1.hex, $1.hex]
34 elsif /\A([0-9]+)[:-]([0-9]+)\z/ =~ range
35 ranges << [$1.to_i, $2.to_i]
36 elsif /\A([0-9]+)\z/ =~ range
37 ranges << [$1.to_i, $1.to_i]
43 def ranges.contain?(code)
48 return true if r[0] <= code and r[1] >= code
55 IO.foreach(file) do |line|
56 if /^([0-9A-F]+):([0-9A-F]+)$/ =~ line
58 next unless ranges.contain?(code)
61 if bitmap.size != 32 and bitmap.size != 64
62 raise "invalid bitmap size: #{bitmap}"
65 fonts << [code, bitmap]
67 raise "invalid line format: #{line}"
71 fonts.sort! {|a,b| a[0] <=> b[0]}
75 print [fonts.size].pack('V')
77 offset = 8 + fonts.size * 8
79 print [f[0]].pack('V')
80 print [offset].pack('V')
81 offset += 4 + 16 * f[1].size / 32
85 print [f[1].size / 32].pack('V')
86 print f[1].scan(/../).collect {|a| a.hex}.pack('C*')