#!/usr/local/bin/perl -- # -*- Perl -*- Force Emacs perl-mode # # Copyright 1999 Computing Research Labs, New Mexico State University # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT # OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR # THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # 19 July 1999 # Mark Leisher # # ACKNOWLEDGEMENTS # # Markus Kuhn for fixing an incorrect count of # old _XFREE86_GLYPH_RANGES properties and fixing a bug with -1 ENCODING # fields. # # # This script edits BDF fonts by adding _XFREE86_GLYPH_RANGES properties which # contain the ranges of glyphs in a font. This is done using the following # properties: # # _XFREE86_GLYPH_RANGES # _XFREE86_GLYPH_RANGES # . . . . . # _XFREE86_GLYPH_RANGES # # It is broken into chunks about 256 bytes in size to let programs like # "bdftopcf" read the file without having trouble with lines that are too # long. # while ($fname = shift) { # # First create the bitmap that represents the defined encodings. # undef(@bitmap); $oprops = 0; $top = 0; open(IN, "$fname"); while () { $oprops++ if (/^_XFREE86_GLYPH_RANGES/); if (/^ENCODING (.+)/) { $n = int($1); $top = $n if ($n > $top); $bitmap[($n >> 5)] |= (1 << ($n & 31)) unless $n < 0; } } close(IN); # # Construct a table of range strings with a maximum length of 256 # characters, not including the atom names of _XFREE86_GLYPH_RANGES_*. # undef(@ranges); $line = ''; $linelen = 0; $s = $e = -1; for ($i = 0; $i <= $top; $i++) { if (($bitmap[($i >> 5)] & (1 << ($i & 31))) != 0) { if ($s == -1) { $s = $e = $i; } elsif ($i > $e + 1) { if ($e > $s) { $range = "${s}_${e}"; $rl = length($range); if ($linelen + $rl > 256) { push(@ranges, $line); $line = ''; $linelen = 0; } $line .= $range; $linelen += $rl; } else { $range = "$s"; $rl = length($range); if ($linelen + $rl > 256) { push(@ranges, $line); $line = ''; $linelen = 0; } $line .= $range; $linelen += $rl; } $line .= " "; $s = $e = $i; } else { $e = $i; } } } if ($e > $s) { $range = "${s}_${e}"; $rl = length($range); if ($linelen + $rl > 256) { push(@ranges, $line); $line = ''; $linelen = 0; } $line .= $range; push(@ranges, $line); } elsif ($s > -1) { $range = "$s"; $rl = length($range); if ($linelen + $rl > 256) { push(@ranges, $line); $line = ''; $linelen = 0; } $line .= $range; push(@ranges, $line); } open(IN, "$fname"); open(OUT, ">$fname.out"); $oprops = 0; while () { # # Skip all existing glyph range properties. # next if (/^_XFREE86_GLYPH_RANGES/); if (/^STARTPROPERTIES (.+)/) { print OUT "STARTPROPERTIES ", (int($1) - $oprops) + $#ranges + 1, "\n"; } elsif (/^ENDPROPERTIES/) { if ($#ranges >= 0) { for ($i = 0; $i <= $#ranges; $i++) { $ranges[$i] =~ s/ $//; print OUT "_XFREE86_GLYPH_RANGES \"", $ranges[$i], "\"\n"; } } print OUT; } else { print OUT; } } close(IN); close(OUT); rename("$fname.out", $fname); } exit 0;