* finished adding hints to Tifinagh in Sans Book, room for improvements.
[dejavu.git] / dejavu-fonts / colorize.pl
blob030c961f920660a300a68eb6de612628bba83d85
1 #!/usr/bin/perl -w
3 # $Id$
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";
18 sub decode_color($) {
19 my ($color) = @_;
20 if ($color eq 'yellow' || $color eq 'wip') {
21 return "0xffff00";
22 } elsif ($color eq 'green' || $color eq 'req') {
23 return "0x00ff00";
24 } elsif ($color eq 'none') {
25 return -2;
27 return $color;
30 sub decode_glyph_code($) {
31 my ($code) = @_;
32 $code =~ s/^[Uu]\+//;
33 return $code;
36 sub parse_glyph_codes_from_stdin() {
37 my @ret = ();
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));
42 } else {
43 push (@ret, decode_glyph_code ($token));
44 push (@ret, decode_glyph_code ($token));
47 return @ret;
50 if (@ARGV < 2) {
51 print STDERR "usage: $0 color sfd_files+ < glyph_codes_file\n";
52 exit (1);
55 @glyph_codes = parse_glyph_codes_from_stdin();
56 $color = decode_color(shift @ARGV);
58 sub min($$) {
59 my ($a, $b) = @_;
60 return ($a < $b) ? $a : $b;
63 open (PE, '>colorize.pe') || die "Unable to open colorize.pe : $!\n";
64 print PE 'i = 1
65 while ( i < $argc )
66 Open($argv[i], 1)
67 SelectNone()
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")
74 i++
75 endloop
77 close (PE) || die "Unable to close colorize.pe : $!\n";
79 system ($fontforge, '-script', 'colorize.pe', @ARGV);