3 # This is a perl script to create a character width table from gEDA's
6 # MK_CHAR_TAB typical use:
8 # will produce the char width table file: char_width.c
10 for ($i = 0; $i <= 256; $i++) # clear the width table
14 while (defined($file = <../lib/sy
m/font/*.sym
>)) # search the directory for *.sym files
20 foreach $line (@lines) # search for the F type line
22 @tokens = split (/\s+/,$line); # parse the line
26 $char_value = ord(@tokens[1]);
27 $char_width = @tokens[2];
28 $is_space = @tokens[3]; # is this the space char?
31 $char_value = 32; # if so do fix-up
33 @width_table[$char_value] = $char_width;
34 # print "$file: @tokens, $type $char_value $char_width $is_space\n";
39 # Now we'll build the C file from the width table
41 $FileToWrite = './char_width.c';
42 open(C_file
, ">$FileToWrite");
44 print C_file
"\n#define CHAR_POINTS 2\n\n";
45 print C_file
"const int char_width[]={\n ";
47 for ($i = 0; $i < 256; $i++)
49 print C_file
"@width_table[$i]"; # add the char width to the table
50 if ($i == 255) # end of table?
52 print C_file
"\n};\n" ;
54 elsif (( $i % 16) == 15 ) # end of line?
64 # Add in the basic string to pixs function
67 print C_file
"/***************************************************************/\n";
68 print C_file
"/* GetStringDisplayLength: */\n";
69 print C_file
"/* inputs: string to be sized */\n";
70 print C_file
"/* string\'s font size to use */\n";
71 print C_file
"/* returns: length of string in gEDA points */\n";
72 print C_file
"/***************************************************************/\n";
73 print C_file
"int GetStringDisplayLength(char *str,int font_size)\n";
74 print C_file
"{ int width=0;\n";
75 print C_file
" int i, len;\n";
76 print C_file
" len = strlen(str);\n";
77 print C_file
" for (i=0;i<len;i++)\n";
78 print C_file
" width += char_width[(int)str[i]];\n";
79 print C_file
" width = (font_size*width)/CHAR_POINTS;\n";
80 print C_file
" return width;\n";