#!/bin/nawk -f # # bdf2xbm # # Convert a bdf font into a directory of bitmaps. # The bitmap files are named :.xbm # BEGIN { verbose = 1 a["0"] = "0"; a["1"] = "8"; a["2"] = "4"; a["3"] = "c"; a["4"] = "2"; a["5"] = "a"; a["6"] = "6"; a["7"] = "e"; a["8"] = "1"; a["9"] = "9"; a["a"] = "5"; a["b"] = "d"; a["c"] = "3"; a["d"] = "b"; a["e"] = "7"; a["f"] = "f"; } /^STARTFONT/ { match(FILENAME, "^[^.]*") dir = substr( FILENAME, 1, RLENGTH ) next } /^FONT[ ]/ { fontname = $2 printf( "Decoding font \"%s\" to directory \"%s\".\n", fontname, dir ) system( "mkdir " dir ) next } /^STARTCHAR/ { charname = $2; next } /^ENCODING/ { char = $3 + 0; next } /^BBX/ { width = $2 height = $3 next } /^BITMAP/ { file = sprintf( "%03o:%s.xbm", char, charname ) if( verbose ) printf("Character %3d --> \"%s\"\n", char, file ) file = dir "/" file printf("#define %s_width %d\n", charname, width ) > file printf("#define %s_height %d\n", charname, height ) > file printf("static char %s_bits[] = {\n ", charname ) > file read = 1 # OK read bitmap lines that follow n = 0 # number of chars output to the current line ( usally > 0 ) next } /^ENDCHAR/ { read = 0 printf "};\n" > file close file next } read == 1 { len = length($1) $1 = $1 "0" # in case it is an odd length for( l = 1 ; l <= len ; l+=2 ) { if ( n > 0 ) printf( "," ) > file if ( n >= 12 ) { printf("\n ") > file n = 0 } b = a[ substr( $1, l+1, 1 ) ] a[ substr( $1, l, 1 ) ] printf( " 0x%s", b ) > file n++ } }