summaryrefslogtreecommitdiff
path: root/tools/pbf-gen.rb
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-02-17 16:35:02 -0500
committerBenji Dial <benji6283@gmail.com>2021-02-17 16:35:02 -0500
commit3a3602861226e995d95a8898668cd559c3ca1cf6 (patch)
tree0d5bc0494297a12e9ccb76b31cb365c843216735 /tools/pbf-gen.rb
parent49d76d30a55707e2bf95fd9ba03296489fac8d1d (diff)
downloadportland-os-3a3602861226e995d95a8898668cd559c3ca1cf6.tar.gz
quick bitmap font format, borrowing new default font from X
Diffstat (limited to 'tools/pbf-gen.rb')
-rw-r--r--tools/pbf-gen.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/pbf-gen.rb b/tools/pbf-gen.rb
new file mode 100644
index 0000000..f4c59c8
--- /dev/null
+++ b/tools/pbf-gen.rb
@@ -0,0 +1,66 @@
+#args: .hex file, .pbf file, hex pitch, char width, char height, hz padding, vt padding
+#converts the .hex output of gbdfed into a pbf file
+#6x9x0x0
+
+bitmaps = {}
+
+File.readlines(ARGV[0]).map do |l|
+ bitmaps[l[0..3].to_i 16] = (l[5..-2].to_i(16) + 2**80).to_s(2)[1..-1]
+end
+
+data_area_entries = {}
+
+bitmaps.each do |cp, bm|
+ lines = bm.scan /.{#{ARGV[2].to_i}}/
+ this_entry = []
+ this_byte = 0
+ byte_mask = 1
+ for y in 0..(ARGV[4].to_i() - 1) do
+ for x in 0..(ARGV[3].to_i() - 1) do
+ if lines[y][x] == '1'
+ this_byte |= byte_mask
+ end
+ byte_mask *= 2
+ if byte_mask == 256
+ byte_mask = 1
+ this_entry << this_byte
+ this_byte = 0
+ end
+ end
+ end
+ if byte_mask != 1
+ this_entry << this_byte
+ end
+ data_area_entries[cp] = this_entry
+end
+
+data_area = []
+
+def put_u32(f, n)
+ f.putc (n % 256)
+ f.putc ((n / 256) % 256)
+ f.putc ((n / 65536) % 256)
+ f.putc ((n / 16777216) % 256)
+end
+
+File.open(ARGV[1], 'wb') do |f|
+ f.putc ARGV[3].to_i
+ f.putc ARGV[4].to_i
+ f.putc ARGV[5].to_i
+ f.putc ARGV[6].to_i
+
+ for cp in 0..255 do
+ if data_area_entries.key? cp
+ put_u32(f, data_area.length)
+ for b in data_area_entries[cp] do
+ data_area << b
+ end
+ else
+ put_u32(f, 0)
+ end
+ end
+
+ for b in data_area do
+ f.putc b
+ end
+end \ No newline at end of file