home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / LASER / FONTLD.ZIP / WT2SPL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-06-29  |  11.7 KB  |  327 lines

  1. program wt2spl; { FontLoader Width Table to Sprint programing language. }
  2.  
  3. type
  4.     font_descriptor = record
  5.          orientation  : byte;
  6.          symbol_set   : word;
  7.          spacing      : boolean;
  8.          pitch,
  9.          height       : word;
  10.          style        : byte;
  11.          weight       : shortint;
  12.          typeface,
  13.          font_type    : byte;
  14.          baseline,
  15.          cell_width,
  16.          cell_height,
  17.          xheight      : word;
  18.          font_name    : array [0..15] of char;
  19.          end;
  20.  
  21.     char_descriptor = record
  22.          defined      : boolean;
  23.          deltax       : integer;
  24.          char_width,
  25.          char_height  : word;
  26.          left_offset,
  27.          top_offset   : integer;
  28.          end;
  29. {
  30.   Pitch, height, xheight, and deltax are all in quarter dots.  Divide by
  31.   four to obtain the value in dots.
  32. }
  33.  
  34. var font_des      : font_descriptor;
  35.     chars         : array [0..255] of char_descriptor;
  36.     font_name,
  37.     esc_code,
  38.     esc_code_cond,
  39.     in_line,
  40.     out_line,
  41.     tmp_line      : string;
  42.     tmp_str0,
  43.     tmp_str1,
  44.     tmp_str2,
  45.     tmp_str3,
  46.     tmp_str4,
  47.     tmp_str5      : string[10];
  48.  
  49.  
  50.     in_file       : text;
  51.     out_file      : text;
  52.     in_file_name,
  53.     out_file_name : string;
  54.  
  55.     error,
  56.     val_err,
  57.     i, j, k,
  58.     in_line_no,
  59.     out_line_no   : word;
  60.  
  61.     comma         : char;
  62.  
  63. const
  64.     in_io_error   =  4;
  65.     out_io_error  =  8;
  66.     ch_start_no   = 19;
  67.  
  68. procedure Display_Title;
  69.     begin
  70.     writeln;
  71.     writeln('Width Table to Sprint SPL.');
  72.     writeln;
  73.     end;
  74. procedure Display_End(var s, s1 : string);
  75.     begin
  76.     writeln(s, ' successfully translated to: ',s1);
  77.     end;
  78. procedure Display_Help;
  79.     begin
  80.     writeln('Format:  WT2SPL.EXE  InFile.WID  [OutFile]');
  81.     writeln;
  82.     writeln('Where File.WID is a width file created by FontLoader.');
  83.     writeln('If OutFile is not specified,  ".SPL" is appended to InFile.');
  84.     writeln;
  85.     end;
  86.  
  87. procedure Handle_Error(error : word; str : string);
  88.     begin
  89.     case error of
  90.          1 : begin
  91.              display_help;
  92.              writeln('ERROR=>  Need a file name to process!');
  93.              halt(error);
  94.              end;
  95.          2 : begin
  96.              Display_Help;
  97.              writeln('ERROR=>  Unable to open file:  ',str);
  98.              halt(error);
  99.              end;
  100.          4 : writeln('ERROR=>  Error reading input file:  ',str);
  101.          8 : writeln('ERROR=>  Error writing output file:  ',str);
  102.          end;
  103.      end;
  104.  
  105. procedure Trim_Ext(var s : string); { Trims the extension off a file name. }
  106.     var i, j : word;
  107.     begin
  108.     i := 0; { Get last '.' }
  109.     for j := 1 to length(s) do
  110.         begin
  111.         if s[j] = '.' then i := j
  112.         else if s[j] = '\' then i := 0;
  113.         end;
  114.     if i <> 0 then delete(s,i,4);
  115.     end;
  116.  
  117. function Typeface(typeface_num : byte) : string;
  118.     begin
  119.     case typeface_num of
  120.          0 : typeface := 'LinePtr';
  121.          1 : typeface := 'Pica';
  122.          2 : typeface := 'Elite';
  123.          3 : typeface := 'Courier';
  124.          4 : typeface := 'Helv';
  125.          5 : typeface := 'TmsRmn';
  126.          6 : typeface := 'LtrGothic';
  127.          7 : typeface := 'Script';
  128.          8 : typeface := 'Prestige';
  129.          9 : typeface := 'Caslon';
  130.         10 : typeface := 'Orator';
  131.         11 : typeface := 'Presentation';
  132.         12 : typeface := 'HelvCond';
  133.         14 : typeface := 'Futura';
  134.         15 : typeface := 'Palatino';
  135.         16 : typeface := 'Souvenir';
  136.         17 : typeface := 'Optima';
  137.         18 : typeface := 'Garamond';
  138.         19 : typeface := 'CooperBlk';
  139.         20 : typeface := 'CoronetBld';
  140.         21 : typeface := 'Broadway';
  141.         22 : typeface := 'Bauer';
  142.         23 : typeface := 'Century';
  143.         24 : typeface := 'UnivRoman';
  144.         25 : typeface := 'AvantGarde';
  145.         27 : typeface := 'Korinna';
  146.         28 : typeface := 'BitCharter';
  147.         29 : typeface := 'CloisterBlk';
  148.         30 : typeface := 'Galliard';
  149.         else typeface := 'Unknown';
  150.         end;
  151.     end;
  152.  
  153. Begin
  154.     Display_Title;
  155.     if ParamCount > 0 then in_file_name  := ParamStr(1)
  156.     else Handle_Error(1,'');
  157.     if ParamCount > 1 then out_file_name := ParamStr(2)
  158.     else
  159.         begin
  160.         out_file_name := in_file_name;
  161.         Trim_Ext(out_file_name);
  162.         if length(out_file_name) < 252 then
  163.            out_file_name := out_file_name + '.SPL';
  164.         end;
  165.  
  166.     assign(in_file, in_file_name);
  167.     {$I-}reset(in_file);{$I+}
  168.     if IOResult <> 0 then Handle_Error(2, in_file_name)
  169.     else
  170.         begin
  171.         assign(out_file, out_file_name);
  172.         {$I-}rewrite(out_file);{$I+}
  173.         if IOResult <> 0 then Handle_Error(2, out_file_name)
  174.         else
  175.             begin
  176.             error := 0;
  177.             in_line_no  := 1;
  178.             out_line_no := 1;
  179.             While (not(EOF(in_file))) and (error = 0)
  180.                   and (in_line_no < ch_start_no) do
  181.                 begin
  182.                 {$I-}Readln(in_file, in_line);{$I+}
  183.                 val_err := 0;
  184.                 if IOResult <> 0 then error := in_io_error
  185.                 else case in_line_no of
  186.                     1 :  font_name := in_line;
  187.                     2 :  Val(in_line,font_des.orientation,val_err);
  188.                     3 :  Val(in_line,font_des.symbol_set,val_err);
  189.                     4 :  if in_line = '0' then font_des.spacing := false
  190.                          else if in_line = '1' then font_des.spacing := true
  191.                          else error := in_io_error;
  192.                     5 :  Val(in_line,font_des.pitch,val_err);
  193.                     6 :  Val(in_line,font_des.height,val_err);
  194.                     7 :  Val(in_line,font_des.style,val_err);
  195.                     8 :  Val(in_line,font_des.weight,val_err);
  196.                     9 :  Val(in_line,font_des.typeface,val_err);
  197.                     10 : Val(in_line,font_des.font_type,val_err);
  198.                     11 : Val(in_line,font_des.baseline,val_err);
  199.                     12 : Val(in_line,font_des.cell_width,val_err);
  200.                     13 : Val(in_line,font_des.cell_height,val_err);
  201.                     14 : Val(in_line,font_des.xheight,val_err);
  202.                     15 : if length(in_line) < 17 then font_name := in_line
  203.                          else error := in_io_error;
  204.                     16 : esc_code := in_line;
  205.                     17 : esc_code_cond := in_line;
  206.                     end;
  207.                 if val_err <> 0 then error := in_io_error;
  208.                 inc(in_line_no);
  209.                 end; { while not eof }
  210.             { Initialize chars array. }
  211.             for i := 0 to 255 do chars[i].defined := false;
  212.             { Read characters that are defined into the array. }
  213.             While (not(EOF(in_file))) and (error = 0) do
  214.                 begin
  215.                 {$I-}Readln(in_file, tmp_str0,
  216.                      tmp_str1, tmp_str2, tmp_str3, tmp_str4, tmp_str5);{$I+}
  217.                 Val(tmp_str0, j, i); { j is the character number. }
  218.                 if i <> 0 then error := in_io_error
  219.                 else
  220.                 with chars[j] do
  221.                     begin
  222.                     defined := true;
  223.                     Val(tmp_str1, deltax, i);
  224.                     if i <> 0 then error := in_io_error;
  225.                     Val(tmp_str2, char_width,  i);
  226.                     if i <> 0 then error := in_io_error;
  227.                     Val(tmp_str3, char_height, i);
  228.                     if i <> 0 then error := in_io_error;
  229.                     Val(tmp_str4, left_offset, i);
  230.                     if i <> 0 then error := in_io_error;
  231.                     Val(tmp_str5, top_offset,  i);
  232.                     if i <> 0 then error := in_io_error;
  233.                     end;
  234.                 end;
  235.  
  236. {
  237.   To create width tables for other programs,  I recommend modifying the
  238.   following section.
  239. }
  240.  
  241.             if error = 0 then  { Write Sprint SPL file. }
  242.                begin
  243.                {$I-}
  244.                writeln(out_file,';; This file is to be inserted into HP.SPL.');
  245.                writeln(out_file);
  246.                { Write font definition with escape code. }
  247.                Str(((72 / 300) * (font_des.height / 4)):1:0, tmp_str0);
  248.                tmp_line := typeface(font_des.typeface) + tmp_str0;
  249.                write(out_file, 'font ',tmp_line, ',');
  250.                if font_des.spacing  then
  251.                    write(out_file, 'size ',font_des.cell_height)
  252.                else
  253.                    write(out_file, 'width ', (font_des.pitch div 4));
  254.                write(out_file, ',on');
  255.                delete(esc_code_cond,1,5); { Remove orientation esc code. }
  256.                for i := 1 to length(esc_code_cond) do { Write esc code. }
  257.                    begin
  258.                    if esc_code_cond[i] = #27 then
  259.                         write(out_file, '^[')
  260.                    else write(out_file, esc_code_cond[i]);
  261.                    end;
  262.                writeln(out_file, ',pst ',tmp_line);
  263.  
  264.                { Write the Sprint width table.                      }
  265.                { Sprint's uses two tables in a multi-column format. }
  266.                { I suggest making an example to look at by running  }
  267.                { WT2SPL.EXE.                                        }
  268.                writeln(out_file, 'pst ', tmp_line, ',');
  269.                comma := ',';
  270.                for i := 32 to 47 do
  271.                    begin
  272.                    for j := 0 to 5 do
  273.                        begin
  274.                        k := i + (j * 16); { k is character number. }
  275.                        if k = ord(' ') then
  276.                           write(out_file, 'SP ')
  277.                        else if k in
  278.                            [ord('\'),ord('^'),ord('~')] then
  279.                           write(out_file, '\', char(k), ' ')
  280.                        else if k <> 127 then
  281.                        write(out_file, char(k), ' ');
  282.                        if k <> 127 then
  283.                          begin
  284.                          if chars[k].defined then
  285.                               write(out_file, (chars[k].deltax div 4), ',',#9)
  286.                          else write(out_file, (font_des.pitch  div 4), ',',#9);
  287.                          end;
  288.                        end;
  289.                    writeln(out_file);
  290.                    end;
  291.                writeln(out_file);
  292.                for i := (32 + 128) to (47 + 128) do
  293.                    begin
  294.                    for j := 0 to 5 do
  295.                        begin
  296.                        k := i + (j * 16); { k is character number. }
  297.                        if k = (ord(' ') + 128) then
  298.                           write(out_file, '~SP ')
  299.                        else if (k - 128) in
  300.                            [ord('\'),ord('^')] then
  301.                           write(out_file, '~\', char(k - 128), ' ')
  302.                        else if k <> 255 then
  303.                          write(out_file, '~', char(k - 128), ' ');
  304.                        if k = (ord('o') + 128) then
  305.                            comma := ' ' else comma := ',';
  306.                        if k <> 255 then
  307.                          begin
  308.                          if chars[k].defined then
  309.                             write(out_file, (chars[k].deltax div 4), comma,#9)
  310.                          else
  311.                             write(out_file, (font_des.pitch  div 4), comma,#9);
  312.                          end;
  313.                        end;
  314.                    writeln(out_file);
  315.                    end;
  316.                {$I+}
  317.                end;
  318. {
  319.   End of section to modify.
  320. }
  321.  
  322.             if error = 0 then Display_End(in_file_name, out_file_name);
  323.             {$I-}close(out_file);{$I+}
  324.             end; { open out_file }
  325.         {$I-}close(in_file);{$I+}
  326.         end; {open in_file }
  327. End.