5 # glyph comment colorizing
6 # (c)2004 Stepan Roh (PUBLIC DOMAIN)
7 # usage: ./colorize.pl color sfd_files+ < glyph_codes_file
8 # will create files with suffix .color
9 # color is either none, yellow, green or hexadecimal 24bit value (0xff0000 is red)
10 # glyph_codes_file should contain codes of glyphs to be colored delimited by whitespace and/or commas
11 # - glyph codes are U+nnnn (nnnn is hexadecimal)
12 # - syntax for code ranges: U+nnnn-U+nnnn (no whitespace inside)
13 # file colorize.pe is created during the execution (it is safe to remove it after)
15 # change to the fontforge binary location if it is not in the system PATH
16 $fontforge = "fontforge";
20 if ($color eq 'yellow' || $color eq 'wip') {
22 } elsif ($color eq 'green' || $color eq 'req') {
24 } elsif ($color eq 'none') {
30 sub decode_glyph_code
($) {
36 sub parse_glyph_codes_from_stdin
() {
38 my @input = split (/(?:\s|,)+/, join ('', <STDIN
>));
39 foreach $token (@input) {
40 if ($token =~ /^(.*)-(.*)$/) {
41 push (@ret, decode_glyph_code
($1), decode_glyph_code
($2));
43 push (@ret, decode_glyph_code
($token));
44 push (@ret, decode_glyph_code
($token));
51 print STDERR
"usage: $0 color sfd_files+ < glyph_codes_file\n";
55 @glyph_codes = parse_glyph_codes_from_stdin
();
56 $color = decode_color
(shift @ARGV);
60 return ($a < $b) ?
$a : $b;
63 open (PE
, '>colorize.pe') || die "Unable to open colorize.pe : $!\n";
69 for (my $i = 0; $i < @glyph_codes; $i += 16) {
70 print PE
' SelectMore(', join (',', map { '0u'.$_ } @glyph_codes[$i..min
($i+15, @glyph_codes-1)]), ")\n";
72 print PE
' SetCharColor('.$color.')
73 Save($argv[i] + ".color")
77 close (PE
) || die "Unable to close colorize.pe : $!\n";
79 system ($fontforge, '-script', 'colorize.pe', @ARGV);