grub/util/unifont2pff.rb
okuji 18d9c7cd53 2003-09-25 Yoshinori K. Okuji <okuji@enbug.org>
I forgot to check in these changes for a long time. This adds
	incomplete support for VGA console, and this is still very
	buggy. Also, a lot of consideration is required for I18N,
	UNICODE, and VGA font issues. Therefore, assume that this is
	such that "better than nothing".

	* font/manager.c: New file.
	* include/pupa/font.h: Likewise.
	* include/pupa/i386/pc/vga.h: Likewise.
	* term/i386/pc/vga.c: Likewise.
	* util/unifont2pff.rb: Likewise.

	* conf/i386-pc.rmk (kernel_img_HEADERS): Added machine/vga.h.
	(pkgdata_MODULES): Added vga.mod and font.mod.
	(vga_mod_SOURCES): New variables.
	(vga_mod_CFLAGS): Likewise.
	(font_mod_SOURCES): Likewise.
	(font_mod_CFLAGS): Likewise.

	* include/pupa/err.h (PUPA_ERR_BAD_FONT): New constant.

	* include/pupa/term.h: Include pupa/err.h.
	(struct pupa_term): Added init and fini.
	Changed the argument of putchar to pupa_uint32_t.

	* include/pupa/i386/pc/console.h: Include pupa/symbol.h.
	(pupa_console_real_putchar): New prototype.
	(pupa_console_putchar): Removed.
	(pupa_console_checkkey): Exported.
	(pupa_console_getkey): Likewise.

	* kern/misc.c (pupa_vsprintf): Add support for UNICODE
	characters.

	* kern/term.c (pupa_term_set_current): Rewritten.
	(pupa_putchar): Likewise.
	(pupa_putcode): New function.

	* kern/i386/pc/startup.S (pupa_console_putchar): Renamed to ...
	(pupa_console_real_putchar): ... this.
	(pupa_vga_set_mode): New function.
	(pupa_vga_get_font): Likewise.

	* normal/command.c: Include pupa/term.h.
	(terminal_command): New function.
	(pupa_command_init): Register the command "terminal".

	* normal/menu.c (DISP_LEFT): Changed to a UNICODE value.
	(DISP_UP): Likewise.
	(DISP_RIGHT): Likewise.
	(DISP_DOWN): Likewise.
	(DISP_HLINE): Likewise.
	(DISP_VLINE): Likewise.
	(DISP_UL): Likewise.
	(DISP_UR): Likewise.
	(DISP_LL): Likewise.
	(DISP_LR): Likewise.

	* term/i386/pc/console.c (pupa_console_putchar): New function.
2003-09-25 20:15:53 +00:00

79 lines
1.7 KiB
Ruby

#! /usr/bin/ruby -w
#
# Copyright (C) 2003 Yoshinori K. Okuji <okuji@enbug.org>
#
# This unifont2pff.rb is free software; the author
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
# The magic number of the font file.
MAGIC = "PPF\x7f"
def usage(status = 0)
puts "Usage: ruby unifont2pff.rb [RANGE...] FILE"
exit(status)
end
file = ARGV.pop
ranges = []
ARGV.each do |range|
if /\A([0-9a-fA-F]+):([0-9a-fA-F]+)\z/ =~ range
ranges << [$1.hex, $2.hex]
elsif /\A([0-9a-fA-F]+)\z/ =~ range
ranges << [$1.hex, $1.hex]
else
usage(1)
end
end
def ranges.contain?(code)
if self.empty?
true
else
self.each do |r|
return true if r[0] <= code and r[1] >= code
end
false
end
end
fonts = []
IO.foreach(file) do |line|
if /^([0-9A-F]+):([0-9A-F]+)$/ =~ line
code = $1.hex
next unless ranges.contain?(code)
bitmap = $2
if bitmap.size != 32 and bitmap.size != 64
raise "invalid bitmap size: #{bitmap}"
end
fonts << [code, bitmap]
else
raise "invalid line format: #{line}"
end
end
fonts.sort! {|a,b| a[0] <=> b[0]}
# Output the result.
print MAGIC
print [fonts.size].pack('V')
offset = 8 + fonts.size * 8
fonts.each do |f|
print [f[0]].pack('V')
print [offset].pack('V')
offset += 4 + 16 * f[1].size / 32
end
fonts.each do |f|
print [f[1].size / 32].pack('V')
print f[1].scan(/../).collect {|a| a.hex}.pack('C*')
end