Skip to content

Instantly share code, notes, and snippets.

@hibariya
Last active June 12, 2018 18:23
Show Gist options
  • Save hibariya/5b59a62d9995360ccfc4f060a13ddbcf to your computer and use it in GitHub Desktop.
Save hibariya/5b59a62d9995360ccfc4f060a13ddbcf to your computer and use it in GitHub Desktop.
Convert font (bdf) file to c file
File.write 'font.c', "const UINTN[][16] = {\n" + (Array.new(31) + File.read('u_vga16.bdf').split(/\nENCODING\s+/).tap(&:shift))[32..126].map {|char| " {\n" + char.match(/BITMAP[0-9A-F\n]+ENDCHAR/)[0].scan(/\n[0-9A-F]{2}+/).map(&:strip).map {|e| r = e.each_char.map {|a| "%04d" % Integer("0x#{a}").to_s(2) }.join; " 0b#{r}" }.join(",\n") + "\n }" }.join(",\n") + "\n};"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment