www.pudn.com > sdk_host_2520.rar > build_font_lists.pl
#///////////////////////////////////////////////////////////////////////////////
# Copyright(C) SigmaTel, Inc. 2000-2001
#
# Filename: build_font_lists.pl
# Description: Look for character (glyph) bitmaps files in current directory
# and produce "lists" to drive generation of Primary Glyph
# Map (PGM) and Secondary Glyph Map (SGM) and Script files.
#
# Inputs:
# "prefix" is the first part of the character bitmaps' filenames
#
# "restrictionList*" are text files containing a list of Unicode values
# to be included in the output. Only those codes for which a character
# bitmap file is found will be included. If there is no restriction list,
# any code for which a bitmap file is found will be included. Multiple
# restriciton lists combine in an "OR" sense.
#
#
# Bitmap filenames should have the form:
# prefix_xxxx.bmp
# where "prefix" is the name specified on the command line and "xxxx"
# is a four digit hex value (leading zeros) giving the Unicode value
# for the character.
#
# Example: arial_6_0030.bmp is the "zero" character in a 6 pixel
# tall Arial typeface.
#
#
# Inputs: prefix_xxxx.bmp
#
# Outputs: PGM_list, (several) SGM_xx_list (where "xx" is the hex value of the
# upper byte of the Unicode range (i.e. xx00-xxFF))
#
# PGM_list:
# prefix
# xxxx (default glyph)
# xx 1 (xx=Unicode prefix, 1,2,3...=SGM/Script index, not all values of
# xx 2 xx need to be present)
# ...
#
# SGM_list_xx:
# xxyy 1 (xxyy=Unicode value - xx is same as in filename, yy varies with glyph),
# xxyy 2 1,2,3...=Glyph index; not all values of yy need to be present)
# ...
#
#
#///////////////////////////////////////////////////////////////////////////////
use strict;
sub build_font_lists {
my $file_prefix = shift;
my @restrictionLists = shift;
my $pPGM = shift;
my $pSGMs = shift;
my $default_char = shift;
my %restrictions;
my $restrictionsExist = 0;
my $restrictionList;
foreach $restrictionList (@restrictionLists) {
print STDERR "\n\n ^^^ RESTRICTIONS LIST FILE : $restrictionList\n\n";
open (RESTRICTION_LIST, $restrictionList) ||
die "Can't open restriction list file: $restrictionList\n";
while () {
my $Unicode = hex ($_);
$restrictions{$Unicode} = 1;
$restrictionsExist = 1;
}
close RESTRICTION_LIST;
}
# Build a list of all bitmap files, starting with "prefix"
my $file_pattern = "$file_prefix" . "_*.bmp";
my @glyph_files = glob($file_pattern);
# Loop through all glyph files and build hashes to keep track of which
# code points and which prefix ranges are defined
my $glyph_file;
my $code_point;
my $Unicode_prefix;
my $Unicode_suffix;
foreach $glyph_file (@glyph_files) {
$glyph_file =~ m/^$file_prefix\_(....)\.bmp/i;
$code_point = hex($1);
if ($restrictionsExist && (! defined $restrictions{$code_point})) {
next;
}
$Unicode_prefix = int($code_point/256);
$Unicode_suffix = $code_point & 0x00FF;
$pPGM->{$Unicode_prefix} = 1;
$pSGMs->{$Unicode_prefix}->{$Unicode_suffix} = 1;
}
my $PGM_count = 0;
my $default_script_index = -1;
my $default_glyph_index;
for (my $i=0; $i<=0xff; $i++) {
if (defined $pPGM->{$i}) {
$pPGM->{$i} = $PGM_count++; # Assign the Unicode range a
# SGM/Script index
my $SGM_count = 0;
for (my $glyph_idx=0; $glyph_idx<=0xff; $glyph_idx++) {
if (defined $pSGMs->{$i}->{$glyph_idx}) {
$pSGMs->{$i}->{$glyph_idx} = $SGM_count++; # Assign the character a
# glyph index
# Remember the deafault character's
# position
if (($i*256 + $glyph_idx) == $default_char) {
$default_script_index = $pPGM->{$i};
$default_glyph_index = $pSGMs->{$i}{$glyph_idx};
}
}
}
}
}
if ($default_script_index < 0) {
printf STDERR "ERROR: Default character not found: 0x%04x\n", $default_char;
exit -1;
}
return ($default_script_index, $default_glyph_index);
}
1;