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

  1. /* Program to format font DEAR TEACHER to H-P LaserJet2 soft font           */
  2. /* (portrait)                                                               */
  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. int     CurrentCharIndex ;
  35. long    CurrentCharPattern [TEACHERRowsPerChar] ;
  36. int     BlankRowsOnTop ;
  37. int     BlankRowsOnBottom ;
  38. int     BlankColsOnRight ;
  39. int     PatternWidth_Dots ;
  40. int     PatternWidth_Bytes ;
  41. int     PatternHeight ;
  42. int     TotalPatternBytes ;
  43. FILE    * FileHandle ;
  44. char    FileName []   =   "TEACHER.SFP" ;
  45.  
  46. void   CopyToCurrentCharPattern (void)
  47.   {
  48.     static int   RowIndex ;
  49.     for (RowIndex = 0 ;   RowIndex < TEACHERRowsPerChar ;   ++ RowIndex)
  50.       CurrentCharPattern [RowIndex]   =
  51.         TEACHER [CurrentCharIndex] [RowIndex];
  52.   }
  53.  
  54. void   CalcBlankRowsOnTop (void)
  55.   {
  56.     for
  57.       (
  58.         BlankRowsOnTop = 0
  59.           ;
  60.         BlankRowsOnTop < TEACHERRowsPerChar
  61.           ;
  62.         ++ BlankRowsOnTop
  63.       )
  64.       {
  65.         if (CurrentCharPattern [BlankRowsOnTop])   return ;
  66.       } ;
  67.   }
  68.  
  69. void   CalcBlankRowsOnBottom (void)
  70.   {
  71.     for
  72.       (
  73.         BlankRowsOnBottom = 0
  74.           ;
  75.         BlankRowsOnBottom < TEACHERRowsPerChar
  76.           ;
  77.         ++ BlankRowsOnBottom
  78.       )
  79.       {
  80.         if (CurrentCharPattern [(TEACHERRowsPerChar - 1) - BlankRowsOnBottom])
  81.           return ;
  82.       } ;
  83.   }
  84.  
  85. void   CalcBlankColsOnRight (void)
  86.   {
  87.     static int    RowIndex ;
  88.     static long   Mask ;
  89.     for
  90.       (
  91.         BlankColsOnRight = 0
  92.           ;
  93.         BlankColsOnRight < TEACHERColsPerChar
  94.           ;
  95.         ++ BlankColsOnRight
  96.       )
  97.       {
  98.         Mask   =   0x80000000 >> (31 - BlankColsOnRight) ;
  99.         for (RowIndex = 0 ;   RowIndex < TEACHERRowsPerChar ;   ++ RowIndex)
  100.           {
  101.             if (CurrentCharPattern [RowIndex] & Mask)   return ;
  102.           } ;
  103.       } ;
  104.   }
  105.  
  106. void   JustifyTheCurrentCharPattern (void)
  107.   {
  108.     static int   RowIndex ;
  109.     if (BlankRowsOnTop)
  110.       {
  111.         for
  112.           (
  113.             RowIndex = 0
  114.               ;
  115.             RowIndex < (TEACHERRowsPerChar - BlankRowsOnTop)
  116.               ;
  117.             ++ RowIndex
  118.           )
  119.           CurrentCharPattern [RowIndex]   =
  120.             CurrentCharPattern [RowIndex + BlankRowsOnTop] ;
  121.       } ;
  122.   }
  123.  
  124. void   CalcPatternSizeToSend (void)
  125.   {
  126.     PatternWidth_Dots     = 32 - BlankColsOnRight ;
  127.     PatternWidth_Bytes    =   (PatternWidth_Dots + 7) / 8 ;
  128.     PatternHeight         =
  129.       TEACHERRowsPerChar  - BlankRowsOnTop  - BlankRowsOnBottom ;
  130.     TotalPatternBytes     =   PatternWidth_Bytes * PatternHeight ;
  131.   }
  132.  
  133. void   Print1Byte (int TheByte)
  134.   {
  135.     fprintf (FileHandle, "%c", TheByte & 0xFF) ;
  136.   }
  137.  
  138. void   Print1Word (int TheWord)
  139.   {
  140.     Print1Byte (TheWord >> 8) ;
  141.     Print1Byte (TheWord) ;
  142.   }
  143.  
  144. void   PrintTheFontDescriptor (void)
  145.   {
  146.     Print1Word (64) ;                   /* Font descriptor size              */
  147.     Print1Word (0) ;                    /* Reserved byte & font type         */
  148.     Print1Word (0) ;                    /* Reserved word                     */
  149.     Print1Word (TEACHERRowsAboveBaseLine) ;
  150.     Print1Word (TEACHERColsPerChar) ;
  151.     Print1Word (TEACHERRowsPerChar) ;
  152.     Print1Word (1) ;                    /* Orientation & spacing             */
  153.     Print1Word (21) ;                   /* Symbol set                        */
  154.     Print1Word ((TEACHERSpaceCols + ColsSeparatingChars) * 4) ;     /* Pitch */
  155.     Print1Word (TEACHERRowsPerChar*4);  /* Height                            */
  156.     Print1Word (26 * 4) ;               /* x height                          */
  157.     Print1Word (0) ;                    /* Width type & style                */
  158.     Print1Word (0) ;                    /* Stroke weight & typeface          */
  159.     Print1Word (1) ;                    /* Reserved byte & serif style       */
  160.     Print1Word (0) ;                    /* Reserved word                     */
  161.     Print1Word (((-3)<<8) + 3) ;        /* Underline distance & height       */
  162.     Print1Word (40 * 4) ;               /* Text height                       */
  163.     Print1Word ((TEACHERColsPerChar + ColsSeparatingChars) * 4) ; /* T width */
  164.     Print1Word (0) ;                    /* Reserved word                     */
  165.     Print1Word (0) ;                    /* Reserved word                     */
  166.     Print1Word (0) ;                    /* Pitch & height extended           */
  167.     Print1Word (0) ;                    /* Reserved word                     */
  168.     Print1Word (0) ;                    /* Reserved word                     */
  169.     Print1Word (0) ;                    /* Reserved word                     */
  170.     fprintf (FileHandle, "%16s", "DearTeacher     ") ;
  171.   }
  172.  
  173. void   main (void)
  174.   {
  175.     static int      RowIndex, ByteIndex ;
  176.     static long     CurrentLong ;
  177.     if ( ! (FileHandle = fopen (FileName, "wb")))
  178.       {
  179.         printf ("\nUnable to open font file %s", FileName) ;
  180.         exit (1) ;
  181.       } ;
  182.     /* Print the command that precedes the font descriptor                   */
  183.     fprintf (FileHandle, "%c)s64W", Escape) ;
  184.     PrintTheFontDescriptor () ;
  185.     for
  186.       (
  187.         CurrentCharIndex =  '!'
  188.           ;
  189.         CurrentCharIndex != 128
  190.           ;
  191.         ++ CurrentCharIndex
  192.       )
  193.       {
  194.         /* Print the command that selects the character                      */
  195.         fprintf (FileHandle, "%c*c%dE", Escape, CurrentCharIndex) ;
  196.         CopyToCurrentCharPattern        () ;
  197.         CalcBlankRowsOnTop              () ;
  198.         CalcBlankRowsOnBottom           () ;
  199.         CalcBlankColsOnRight            () ;
  200.         JustifyTheCurrentCharPattern    () ;
  201.         CalcPatternSizeToSend           () ;
  202.         /* Print the command that precedes the character descriptor          */
  203.         fprintf
  204.           (
  205.             FileHandle
  206.               ,
  207.             "%c(s%dW"
  208.               ,
  209.             Escape
  210.               ,
  211.             16 + TotalPatternBytes
  212.           ) ;
  213.         /* Print the character descriptor                                    */
  214.         Print1Word ((4<<8) + 0) ;       /* Format & continuation             */
  215.         Print1Word ((14<<8) + 1) ;      /* Descriptor size & class           */
  216.         Print1Word (0) ;                /* Orientation & reserved byte       */
  217.         Print1Word (0) ;                /* Left offset                       */
  218.         Print1Word (TEACHERRowsAboveBaseLine - BlankRowsOnTop) ;
  219.         Print1Word (PatternWidth_Dots) ;
  220.         Print1Word (PatternHeight) ;
  221.         Print1Word ((PatternWidth_Dots + ColsSeparatingChars) * 4) ;   /* dX */
  222.         for (RowIndex = 0 ;   RowIndex != PatternHeight ;   ++ RowIndex)
  223.           {
  224.             CurrentLong   =   CurrentCharPattern [RowIndex] ;
  225.             for
  226.               (
  227.                 ByteIndex =  0
  228.                   ;
  229.                 ByteIndex != PatternWidth_Bytes
  230.                   ;
  231.                 ++ ByteIndex
  232.               )
  233.               Print1Byte ((int) (CurrentLong >> (24 - (ByteIndex * 8)))) ;
  234.           } ;
  235.       } ;
  236.     if (fclose (FileHandle))
  237.       {
  238.         printf ("\nError closing font file %s", FileName) ;
  239.         exit (1) ;
  240.       } ;
  241.     exit (0) ;
  242.   }
  243.  
  244. /* End of file                                                              */
  245.