~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to util/unifont2pff.rb

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/ruby -w
 
2
#
 
3
# Copyright (C) 2003  Free Software Foundation, Inc.
 
4
#
 
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.
 
8
#
 
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
 
12
# PARTICULAR PURPOSE.
 
13
 
 
14
# The magic number of the font file.
 
15
MAGIC = "PPF\x7f"
 
16
 
 
17
def usage(status = 0)
 
18
  puts "Usage: ruby unifont2pff.rb [RANGE...] FILE"
 
19
  exit(status)
 
20
end
 
21
 
 
22
file = ARGV.pop
 
23
 
 
24
ranges = []
 
25
ARGV.each do |range|
 
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]
 
30
  else
 
31
    usage(1)
 
32
  end
 
33
end
 
34
 
 
35
def ranges.contain?(code)
 
36
  if self.empty?
 
37
    true
 
38
  else
 
39
    self.each do |r|
 
40
      return true if r[0] <= code and r[1] >= code
 
41
    end
 
42
    false
 
43
  end
 
44
end
 
45
 
 
46
fonts = []
 
47
IO.foreach(file) do |line|
 
48
  if /^([0-9A-F]+):([0-9A-F]+)$/ =~ line
 
49
    code = $1.hex
 
50
    next unless ranges.contain?(code)
 
51
    
 
52
    bitmap = $2
 
53
    if bitmap.size != 32 and bitmap.size != 64
 
54
      raise "invalid bitmap size: #{bitmap}"
 
55
    end
 
56
 
 
57
    fonts << [code, bitmap]
 
58
  else
 
59
    raise "invalid line format: #{line}"
 
60
  end
 
61
end
 
62
 
 
63
fonts.sort! {|a,b| a[0] <=> b[0]}
 
64
 
 
65
# Output the result.
 
66
print MAGIC
 
67
print [fonts.size].pack('V')
 
68
 
 
69
offset = 8 + fonts.size * 8
 
70
fonts.each do |f|
 
71
  print [f[0]].pack('V')
 
72
  print [offset].pack('V')
 
73
  offset += 4 + 16 * f[1].size / 32
 
74
end
 
75
 
 
76
fonts.each do |f|
 
77
  print [f[1].size / 32].pack('V')
 
78
  print f[1].scan(/../).collect {|a| a.hex}.pack('C*')
 
79
end