generate-bitpattern-font.pl (752B)
1 #!/usr/bin/perl -w 2 3 # Generates an SVG Font where each glyph (identified on stdin by four 4 # hex characters) consists of a bit pattern representing the Unicode 5 # code point it is the glyph for. 6 7 use strict; 8 9 print <<EOF; 10 <svg xmlns="http://www.w3.org/2000/svg"> 11 <font id="BitPattern" horiz-adv-x="1000"> 12 <font-face font-family="BitPattern" units-per-em="1000" ascent="800"/> 13 EOF 14 15 while (<>) { 16 chomp; 17 next if /^\s*$/; 18 die unless /^[0-9A-Fa-f]{4}$/; 19 my $c = hex; 20 my $s = " <glyph unicode='&#x$_;' d='"; 21 for (my $i = 0; $i < 32; $i++) { 22 if ($c & (1 << $i)) { 23 my $x = 100 * (7 - ($i % 8)); 24 my $y = 100 * int($i / 8); 25 $s .= "M$x,$y v80h80v-80z "; 26 } 27 } 28 $s .= "'/>\n"; 29 print $s; 30 } 31 32 print <<EOF; 33 </font> 34 </svg> 35 EOF