home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / graf / dt-hp.zip / TCH2LOAD.C < prev    next >
C/C++ Source or Header  |  1988-10-13  |  9KB  |  257 lines

  1. /* Program to format font DEAR TEACHER for downloading into a H-P LaserJet2 */
  2. /* printer                                                                  */
  3.  
  4. /* Coded in Microsoft C 5.1 by Daniel Ross, starting 3/11/88                */
  5. /* Revised 10/13/88    16:50                                                 */
  6.  
  7. /* Although not explicitly stated in any H-P manual, this code is written    */
  8. /* with the assumption that the MSB of a word is sent before the LSB.        */
  9.  
  10. #include <STDLIB.H>
  11. #include <STDIO.H>
  12. #include <STRING.H>
  13. #include <MATH.H>
  14. /* More files are included below                                             */
  15.  
  16. #define TEACHERColsPerChar         25
  17. #define TEACHERSpaceCols           21
  18. #define TEACHERRowsAboveBaseLine   27
  19. #define TEACHERDescenderRows       8
  20. #define TEACHERRowsPerChar (TEACHERRowsAboveBaseLine + TEACHERDescenderRows)
  21. #define ColsSeparatingChars        5
  22.  
  23. long   TEACHER [128] [TEACHERRowsPerChar]   =
  24.   {
  25. #include "TEACHER.C"
  26.   } ;
  27.  
  28. #define FALSE               0
  29. #define TRUE                1
  30. #define TorF                int
  31.  
  32. #define Escape              0x1B
  33.  
  34. #define FontIDNr            12
  35.  
  36. int     CurrentCharIndex ;
  37. long    CurrentCharPattern [TEACHERRowsPerChar] ;
  38. int     BlankRowsOnTop ;
  39. int     BlankRowsOnBottom ;
  40. int     BlankColsOnRight ;
  41. int     PatternWidth_Dots ;
  42. int     PatternWidth_Bytes ;
  43. int     PatternHeight ;
  44. int     TotalPatternBytes ;
  45. FILE    * FileHandle ;
  46. char    FileName []   =   "TEACHER.LOD" ;
  47.  
  48. void   CopyToCurrentCharPattern (void)
  49.   {
  50.     static int   RowIndex ;
  51.     for (RowIndex = 0 ;   RowIndex < TEACHERRowsPerChar ;   ++ RowIndex)
  52.       CurrentCharPattern [RowIndex]   =
  53.         TEACHER [CurrentCharIndex] [RowIndex];
  54.   }
  55.  
  56. void   CalcBlankRowsOnTop (void)
  57.   {
  58.     for
  59.       (
  60.         BlankRowsOnTop = 0
  61.           ;
  62.         BlankRowsOnTop < TEACHERRowsPerChar
  63.           ;
  64.         ++ BlankRowsOnTop
  65.       )
  66.       {
  67.         if (CurrentCharPattern [BlankRowsOnTop])   return ;
  68.       } ;
  69.   }
  70.  
  71. void   CalcBlankRowsOnBottom (void)
  72.   {
  73.     for
  74.       (
  75.         BlankRowsOnBottom = 0
  76.           ;
  77.         BlankRowsOnBottom < TEACHERRowsPerChar
  78.           ;
  79.         ++ BlankRowsOnBottom
  80.       )
  81.       {
  82.         if (CurrentCharPattern [(TEACHERRowsPerChar - 1) - BlankRowsOnBottom])
  83.           return ;
  84.       } ;
  85.   }
  86.  
  87. void   CalcBlankColsOnRight (void)
  88.   {
  89.     static int    RowIndex ;
  90.     static long   Mask ;
  91.     for
  92.       (
  93.         BlankColsOnRight = 0
  94.           ;
  95.         BlankColsOnRight < TEACHERColsPerChar
  96.           ;
  97.         ++ BlankColsOnRight
  98.       )
  99.       {
  100.         Mask   =   0x80000000 >> (31 - BlankColsOnRight) ;
  101.         for (RowIndex = 0 ;   RowIndex < TEACHERRowsPerChar ;   ++ RowIndex)
  102.           {
  103.             if (CurrentCharPattern [RowIndex] & Mask)   return ;
  104.           } ;
  105.       } ;
  106.   }
  107.  
  108. void   JustifyTheCurrentCharPattern (void)
  109.   {
  110.     static int   RowIndex ;
  111.     if (BlankRowsOnTop)
  112.       {
  113.         for
  114.           (
  115.             RowIndex = 0
  116.               ;
  117.             RowIndex < (TEACHERRowsPerChar - BlankRowsOnTop)
  118.               ;
  119.             ++ RowIndex
  120.           )
  121.           CurrentCharPattern [RowIndex]   =
  122.             CurrentCharPattern [RowIndex + BlankRowsOnTop] ;
  123.       } ;
  124.   }
  125.  
  126. void   CalcPatternSizeToSend (void)
  127.   {
  128.     PatternWidth_Dots     = 32 - BlankColsOnRight ;
  129.     PatternWidth_Bytes    =   (PatternWidth_Dots + 7) / 8 ;
  130.     PatternHeight         =
  131.       TEACHERRowsPerChar  - BlankRowsOnTop  - BlankRowsOnBottom ;
  132.     TotalPatternBytes     =   PatternWidth_Bytes * PatternHeight ;
  133.   }
  134.  
  135. void   Print1Byte (int TheByte)
  136.   {
  137.     fprintf (FileHandle, "%c", TheByte & 0xFF) ;
  138.   }
  139.  
  140. void   Print1Word (int TheWord)
  141.   {
  142.     Print1Byte (TheWord >> 8) ;
  143.     Print1Byte (TheWord) ;
  144.   }
  145.  
  146. void   PrintTheFontDescriptor (void)
  147.   {
  148.     Print1Word (64) ;                   /* Font descriptor size              */
  149.     Print1Word (0) ;                    /* Reserved byte & font type         */
  150.     Print1Word (0) ;                    /* Reserved word                     */
  151.     Print1Word (TEACHERRowsAboveBaseLine) ;
  152.     Print1Word (TEACHERColsPerChar) ;
  153.     Print1Word (TEACHERRowsPerChar) ;
  154.     Print1Word (1) ;                    /* Orientation & spacing             */
  155.     Print1Word (21) ;                   /* Symbol set                        */
  156.     Print1Word ((TEACHERSpaceCols + ColsSeparatingChars) * 4) ;     /* Pitch */
  157.     Print1Word (TEACHERRowsPerChar*4);  /* Height                            */
  158.     Print1Word (26 * 4) ;               /* x height                          */
  159.     Print1Word (0) ;                    /* Width type & style                */
  160.     Print1Word (0) ;                    /* Stroke weight & typeface          */
  161.     Print1Word (1) ;                    /* Reserved byte & serif style       */
  162.     Print1Word (0) ;                    /* Reserved word                     */
  163.     Print1Word (((-3)<<8) + 3) ;        /* Underline distance & height       */
  164.     Print1Word (40 * 4) ;               /* Text height                       */
  165.     Print1Word ((TEACHERColsPerChar + ColsSeparatingChars) * 4) ; /* T width */
  166.     Print1Word (0) ;                    /* Reserved word                     */
  167.     Print1Word (0) ;                    /* Reserved word                     */
  168.     Print1Word (0) ;                    /* Pitch & height extended           */
  169.     Print1Word (0) ;                    /* Reserved word                     */
  170.     Print1Word (0) ;                    /* Reserved word                     */
  171.     Print1Word (0) ;                    /* Reserved word                     */
  172.     fprintf (FileHandle, "%16s", "DearTeacher     ") ;
  173.   }
  174.  
  175. void   main (void)
  176.   {
  177.     static int      RowIndex, ByteIndex ;
  178.     static long     CurrentLong ;
  179.     if ( ! (FileHandle = fopen (FileName, "wb")))
  180.       {
  181.         printf ("\nUnable to open font file %s", FileName) ;
  182.         exit (1) ;
  183.       } ;
  184.     /* Print the command to reset the printer                                */
  185.     fprintf (FileHandle, "%cE", Escape) ;
  186.     /* Print the command to select the font                                  */
  187.     fprintf (FileHandle, "%c*c%dD", Escape, FontIDNr) ;
  188.     /* Print the command that precedes the font descriptor                   */
  189.     fprintf (FileHandle, "%c)s64W", Escape) ;
  190.     PrintTheFontDescriptor () ;
  191.     for
  192.       (
  193.         CurrentCharIndex =  '!'
  194.           ;
  195.         CurrentCharIndex != 128
  196.           ;
  197.         ++ CurrentCharIndex
  198.       )
  199.       {
  200.         /* Print the command that selects the character                      */
  201.         fprintf (FileHandle, "%c*c%dE", Escape, CurrentCharIndex) ;
  202.         CopyToCurrentCharPattern        () ;
  203.         CalcBlankRowsOnTop              () ;
  204.         CalcBlankRowsOnBottom           () ;
  205.         CalcBlankColsOnRight            () ;
  206.         JustifyTheCurrentCharPattern    () ;
  207.         CalcPatternSizeToSend           () ;
  208.         /* Print the command that precedes the character descriptor          */
  209.         fprintf
  210.           (
  211.             FileHandle
  212.               ,
  213.             "%c(s%dW"
  214.               ,
  215.             Escape
  216.               ,
  217.             16 + TotalPatternBytes
  218.           ) ;
  219.         /* Print the character descriptor                                    */
  220.         Print1Word ((4<<8) + 0) ;       /* Format & continuation             */
  221.         Print1Word ((14<<8) + 1) ;      /* Descriptor size & class           */
  222.         Print1Word (0) ;                /* Orientation & reserved byte       */
  223.         Print1Word (0) ;                /* Left offset                       */
  224.         Print1Word (TEACHERRowsAboveBaseLine - BlankRowsOnTop) ;
  225.         Print1Word (PatternWidth_Dots) ;
  226.         Print1Word (PatternHeight) ;
  227.         Print1Word ((PatternWidth_Dots + ColsSeparatingChars) * 4) ;   /* dX */
  228.         for (RowIndex = 0 ;   RowIndex != PatternHeight ;   ++ RowIndex)
  229.           {
  230.             CurrentLong   =   CurrentCharPattern [RowIndex] ;
  231.             for
  232.               (
  233.                 ByteIndex =  0
  234.                   ;
  235.                 ByteIndex != PatternWidth_Bytes
  236.                   ;
  237.                 ++ ByteIndex
  238.               )
  239.               Print1Byte ((int) (CurrentLong >> (24 - (ByteIndex * 8)))) ;
  240.           } ;
  241.       } ;
  242.     /* Print the command that makes the font permanent                       */
  243.     fprintf (FileHandle, "%c*c5F", Escape) ;
  244.     /* Print the command that makes the font to be the primary selected font */
  245.     fprintf (FileHandle, "%c(%dX", Escape, FontIDNr) ;
  246.     /* Print the command to set vertical motion index                        */
  247.     fprintf (FileHandle, "%c&l6.4C", Escape) ;
  248.     if (fclose (FileHandle))
  249.       {
  250.         printf ("\nError closing font file %s", FileName) ;
  251.         exit (1) ;
  252.       } ;
  253.     exit (0) ;
  254.   }
  255.  
  256. /* End of file                                                              */
  257.