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"
26
if /\A([0-9a-fA-F]+):([0-9a-fA-F]+)\z/ =~ range
27
ranges << [$1.hex, $2.hex]
28
elsif /\A([0-9a-fA-F]+)\z/ =~ range
29
ranges << [$1.hex, $1.hex]
35
def ranges.contain?(code)
40
return true if r[0] <= code and r[1] >= code
47
IO.foreach(file) do |line|
48
if /^([0-9A-F]+):([0-9A-F]+)$/ =~ line
50
next unless ranges.contain?(code)
53
if bitmap.size != 32 and bitmap.size != 64
54
raise "invalid bitmap size: #{bitmap}"
57
fonts << [code, bitmap]
59
raise "invalid line format: #{line}"
63
fonts.sort! {|a,b| a[0] <=> b[0]}
67
print [fonts.size].pack('V')
69
offset = 8 + fonts.size * 8
71
print [f[0]].pack('V')
72
print [offset].pack('V')
73
offset += 4 + 16 * f[1].size / 32
77
print [f[1].size / 32].pack('V')
78
print f[1].scan(/../).collect {|a| a.hex}.pack('C*')