www.pudn.com > sdk_host_2520.rar > pgm_sgm.pl


#;/////////////////////////////////////////////////////////////////////////////// 
#; Copyright(C) SigmaTel, Inc. 2000-2001 
#; 
#; Filename: PGM_SGM.pl 
#; Description: Utility routines used in creating Primary and Secondary Glyph Map reosurces 
#;/////////////////////////////////////////////////////////////////////////////// 
 
use strict; 
 
my $MBC_CODE = 1; 
my $SBC_CODE = 0; 
 
 
 
sub generate_PGM_SGM_MBC_src { 
    my $script_index = shift; 
 
    return sprintf "%02x%04x\n", $MBC_CODE, $script_index; 
} 
 
 
 
#;/////////////////////////////////////////////////////////////////////////////// 
sub generate_PGM_SGM_SBC_src { 
    my $script_index = shift; 
    my $glyph_index = shift; 
 
    return sprintf "%02x%02x%02x\n", $SBC_CODE, $script_index, $glyph_index; 
} 
 
 
 
 
#;/////////////////////////////////////////////////////////////////////////////// 
sub build_PGM_src {	 # ($filename, \%map, $def_script_idx, $def_glyph_idx) 
	my $filename = shift; 
	my $map = shift; 
	my $default_script_index = shift; 
	my $default_glyph_index = shift; 
 
 
	$filename = ">" . $filename; 
    open PGM_SRC, $filename || die "Can't open output file: $filename\n"; 
 
    print PGM_SRC "\$RESOURCE_TYPE\n"; 
    print PGM_SRC "DATA\n"; 
    print PGM_SRC "\$REC_SIZE\n"; 
    print PGM_SRC 3+256, "\n"; 
    print PGM_SRC "\$DATA\n"; 
    printf PGM_SRC "%06x\n", 3*256; 
    print PGM_SRC "000002\n";		              # RSRC_TYPE_DATA 
	 
	my $i; 
    my $SGM_index = 0; 
	for ($i=0; $i<256; $i++) { 
		if (defined($map->{$i})) { 
			print PGM_SRC generate_PGM_SGM_MBC_src($SGM_index++); 
		} 
		else { 
			print PGM_SRC generate_PGM_SGM_SBC_src($default_script_index, $default_glyph_index); 
		} 
	}	 
 
	close PGM_SRC; 
} 
 
#;/////////////////////////////////////////////////////////////////////////////// 
#  This function builds an SGM_xx.src file, for a single Unicode_range. 
#  Entries point to glyphs, giving the Script index and Glyph index for each. 
#  All glyphs are in the script specified by $script_index, unless the glyph is 
#  undefined, in which case, the default script/glyph is used.  For defined glyphs, 
#  the glyph index is given by the value in %map. 
 
sub build_SGM_src {	 # ($filename, \%map, $script_index, $def_script_idx, $def_glyph_idx) 
	my $filename = shift; 
	my $map = shift; 
    my $script_index = shift; 
	my $default_script_index = shift; 
	my $default_glyph_index = shift; 
 
	$filename = ">" . $filename; 
    open SGM_SRC, $filename || die "Can't open output file: $filename\n"; 
 
    print SGM_SRC "\$RESOURCE_TYPE\n"; 
    print SGM_SRC "DATA\n"; 
    print SGM_SRC "\$REC_SIZE\n"; 
    print SGM_SRC 3+256, "\n"; 
    print SGM_SRC "\$DATA\n"; 
    printf SGM_SRC "%06x\n", 3*256; 
    print SGM_SRC "000002\n";		              # RSRC_TYPE_DATA 
	 
	my $lowByte; 
	for ($lowByte=0; $lowByte<256; $lowByte++) { 
		if (defined($map->{$lowByte})) { 
			print SGM_SRC generate_PGM_SGM_SBC_src($script_index, $map->{$lowByte}); 
		} 
		else { 
			print SGM_SRC generate_PGM_SGM_SBC_src($default_script_index,  
                                                       $default_glyph_index); 
		} 
	}	 
 
	close SGM_SRC; 
} 
 
 
1;