File: mk_char_tab.pl

package info (click to toggle)
lepton-eda 1.9.18-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,024 kB
  • sloc: ansic: 66,688; lisp: 29,508; sh: 6,792; makefile: 3,111; perl: 1,404; pascal: 1,161; lex: 887; sed: 16; cpp: 8
file content (88 lines) | stat: -rwxr-xr-x 2,736 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl
#
# This is a perl script to create a character width table from gEDA's 
#   font .sym files.
#
# MK_CHAR_TAB typical use: 
#  ./mk_char_tab.pl
#     will produce the char width table file: char_width.c
#
  for ($i = 0; $i <= 256; $i++)    # clear the width table
      {
      @width_table[$i] = 0;
      }
  while (defined($file = <../lib/sym/font/*.sym>)) # search the directory for *.sym files
        {
        open(INFO,"<$file");
        @lines = <INFO>;
        close(INFO);

        foreach $line (@lines)       # search for the F type line
              {
              @tokens = split (/\s+/,$line);  # parse the line
              $type   = @tokens[0];
	      if ($type eq "F")
	         {
                 $char_value = ord(@tokens[1]);
                 $char_width = @tokens[2];
                 $is_space = @tokens[3];  # is this the space char?
	         if ($is_space eq "1")
		    {
		    $char_value = 32;	  # if so do fix-up
		    }
                 @width_table[$char_value] = $char_width;
#                 print "$file: @tokens, $type $char_value $char_width $is_space\n";
		 }
              }
	}
#
#  Now we'll build the C file from the width table
#
  $FileToWrite = './char_width.c';
  open(C_file, ">$FileToWrite");

  print C_file "\n#define CHAR_POINTS 2\n\n";
  print C_file "const int char_width[]={\n     ";

  for ($i = 0; $i < 256; $i++)
      {
      print C_file "@width_table[$i]";	# add the char width to the table
      if ($i == 255)			# end of table?
         {
         print C_file "\n};\n" ;
	 }
      elsif (( $i % 16) == 15 )         # end of line?
         {
         print C_file ",\n     ";
	 }
      else
          {
          print C_file ",";
	  }
      }
#
#  Add in the basic string to pixs function
#
  print C_file "\n";
  print C_file "/***************************************************************/\n";
  print C_file "/* GetStringDisplayLength:		                       */\n";
  print C_file "/* inputs: string to be sized 				       */\n";
  print C_file "/*         string\'s font size to use                           */\n";
  print C_file "/* returns: length of string in gEDA points                    */\n";
  print C_file "/***************************************************************/\n";
  print C_file "int GetStringDisplayLength(char *str,int font_size)\n";
  print C_file "{ int width=0;\n";
  print C_file "  int i, len;\n";
  print C_file "  len = strlen(str);\n";
  print C_file "  for (i=0;i<len;i++)\n";
  print C_file "      width += char_width[(int)str[i]];\n";
  print C_file "  width = (font_size*width)/CHAR_POINTS;\n";
  print C_file "  return width;\n";
  print C_file "}\n";
  print C_file "\n";

  close(C_file);

#
# we're done
#