home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / tex / dvivga9.arc / READGF.H < prev    next >
Text File  |  1988-05-30  |  6KB  |  179 lines

  1. /* -*-C-*- readgf.h */
  2. /*-->readgf*/
  3. /**********************************************************************/
  4. /******************************* readgf *******************************/
  5. /**********************************************************************/
  6.  
  7. int
  8. readgf()    /* return 0 on success, EOF on failure */
  9. {
  10.     UNSIGN32 checksum;
  11.     register struct char_entry *tcharptr;/* temporary char_entry pointer */
  12.     register BYTE the_byte;
  13.     register UNSIGN16 the_char;    /* loop index */
  14.  
  15.     /*
  16.     Read a GF  file postamble, extracting  character metrics and  raster
  17.     locations.  The character xoffp, yoffp,  wp, and hp values will  not
  18.     be filled in until a character raster description is actually called
  19.     for.
  20.     */
  21.  
  22.     /******************************************************************/
  23.  
  24.     /* Process the post-postamble */
  25.  
  26. #if    (OS_VAXVMS)
  27.     /* VMS binary files are stored with NUL padding to the next 512 byte
  28.     multiple.  We therefore search backwards to the last non-NULL byte
  29.     to the find real end-of-file, then move back 4 bytes from that. */
  30.     FSEEK(fontfp,0L,2);        /* seek to end-of-file */
  31.     while (FSEEK(fontfp,-1L,1) == 0)
  32.     {
  33.         the_char = (UNSIGN16)fgetc(fontfp);
  34.     if (the_char)
  35.       break;        /* exit leaving pointer PAST last non-NUL */
  36.     UNGETC((char)the_char,fontfp);
  37.     }
  38.     if (FSEEK(fontfp,-4L,1))    /* start 4 bytes before last non-NUL */
  39. #else
  40.     if (FSEEK(fontfp,-4L,2))    /* start 4 bytes from end-of-file */
  41. #endif
  42.     {
  43.     (void)warning("readgf():  FSEEK() failed--GF font file may be empty");
  44.     return(EOF);
  45.     }
  46.  
  47.     while ((the_byte = (BYTE)nosignex(fontfp,(BYTE)1)) == GFEOF)
  48.     {
  49.     if (FSEEK(fontfp,-2L,1))/* backup 2 bytes to read previous one */
  50.     {
  51.         (void)warning(
  52.         "readgf():  FSEEK() failed to find GF font file EOF trailer bytes");
  53.         return(EOF);
  54.     }
  55.     }
  56.  
  57.     if (the_byte != (BYTE)GFID)
  58.     {
  59.     (void)warning("readgf():  GF font file ID byte not found");
  60.     return(EOF);
  61.     }
  62.  
  63.     if (FSEEK(fontfp,-6L,1))    /* backup to read post_post */
  64.     {
  65.     (void)warning(
  66.         "readgf():  FSEEK() failed to find GF font file POSTPOST byte");
  67.     return(EOF);
  68.     }
  69.  
  70.     if ((BYTE)nosignex(fontfp,(BYTE)1) != (BYTE)GFPOSTPOST)
  71.     {
  72.     (void)warning("readgf():  GF font file POSTPOST byte not found");
  73.     return(EOF);
  74.     }
  75.  
  76.     if (FSEEK(fontfp,(long)nosignex(fontfp,(BYTE)4),0))
  77.     {        /* position to start of postamble */
  78.     (void)warning(
  79.         "readgf():  FSEEK() failed to find postamble in GF font file");
  80.     return(EOF);
  81.     }
  82.  
  83.     /******************************************************************/
  84.  
  85.     /* Process the postamble */
  86.  
  87.     if ((BYTE)nosignex(fontfp,(BYTE)1) != (BYTE)GFPOST)
  88.     {
  89.     (void)warning("readgf():  GF font file POST byte not found");
  90.     return(EOF);
  91.     }
  92.  
  93.     (void)nosignex(fontfp,(BYTE)4);    /* discard special pointer p[4] */
  94.  
  95.     fontptr->designsize = nosignex(fontfp,(BYTE)4);
  96.  
  97.     checksum = nosignex(fontfp,(BYTE)4);
  98.     if ((fontptr->c != 0L) && (checksum != 0L) && (fontptr->c != checksum))
  99.     {
  100.     (void)sprintf(message,
  101.     "readgf():  font [%s] has checksum = 10#%010lu [16#%08lx] [8#%011lo] \
  102. different from DVI checksum = 10#%010lu [16#%08lx] [8#%011lo].  \
  103. TeX preloaded .fmt file is probably out-of-date with respect to new fonts.",
  104.         fontptr->name, fontptr->c, fontptr->c, fontptr->c,
  105.         checksum, checksum, checksum);
  106.     (void)warning(message);
  107.     }
  108.  
  109.     fontptr->hppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  110.     fontptr->vppp = (UNSIGN32)nosignex(fontfp,(BYTE)4);
  111.     fontptr->min_m = (INT32)signex(fontfp,(BYTE)4);
  112.     fontptr->max_m = (INT32)signex(fontfp,(BYTE)4);
  113.     fontptr->min_n = (INT32)signex(fontfp,(BYTE)4);
  114.     fontptr->max_n = (INT32)signex(fontfp,(BYTE)4);
  115.  
  116.     fontptr->magnification = (UNSIGN32)( 0.5 + 5.0 * 72.27 *
  117.     (float)(fontptr->hppp) / 65536.0 );    /* from GFtoPXL Section 53 */
  118.  
  119.     /******************************************************************/
  120.  
  121.     /* Process the character locators */
  122.  
  123.     the_byte = (BYTE)GFNOOP;
  124.     while (the_byte == (BYTE)GFNOOP)
  125.     {
  126.     switch(the_byte = (BYTE)nosignex(fontfp,(BYTE)1))
  127.     {
  128.     case GFCHLOC:
  129.     case GFCHLOC0:
  130.         the_char = (UNSIGN16)nosignex(fontfp,(BYTE)1);
  131.                     /* character number MOD 256 */
  132.         if (the_char >= NPXLCHARS)
  133.         {
  134.         (void)warning(
  135.         "readgf():  GF font file character number is too big for me");
  136.         return(EOF);
  137.         }
  138.         tcharptr = &(fontptr->ch[the_char]);
  139.         if (the_byte == (BYTE)GFCHLOC)    /* long form */
  140.         {
  141.         tcharptr->dx = (INT32)signex(fontfp,(BYTE)4);
  142.         tcharptr->dy = (INT32)signex(fontfp,(BYTE)4);
  143.         }
  144.         else    /* short form */
  145.         {
  146.         tcharptr->dx = (INT32)(((UNSIGN32)nosignex(fontfp,(BYTE)1)) <<
  147.             16);
  148.         tcharptr->dy = 0L;
  149.         }
  150.         tcharptr->tfmw = (UNSIGN32)(((float)nosignex(fontfp,(BYTE)4) *
  151.         (float)fontptr->s) / (float)(1L << 20));
  152.         tcharptr->pxlw = (UNSIGN16)PIXROUND(tcharptr->dx, 1.0/65536.0);
  153.         tcharptr->fontrp = (long)signex(fontfp,(BYTE)4);
  154.  
  155.         the_byte = (BYTE)GFNOOP;    /* to force loop continuation */
  156.         break;
  157.  
  158.     case GFNOOP:
  159.         break;
  160.  
  161.     default:    /* this causes loop exit */
  162.         break;
  163.     }    /* end switch */
  164.     }    /* end while */
  165.  
  166.     for (the_char = FIRSTPXLCHAR; the_char <= LASTPXLCHAR; the_char++)
  167.     {    /* Get remaining character metrics, and ignore error returns for now. */
  168.     tcharptr = &(fontptr->ch[the_char]);
  169.     if (tcharptr->fontrp >= 0L)
  170.         (void)chargf((BYTE)the_char,(void(*)())NULL);
  171.     }
  172.  
  173. #if    (BBNBITGRAPH | HPJETPLUS | POSTSCRIPT | IMPRESS | CANON_A2)
  174.     (void)newfont();
  175. #endif
  176.  
  177.     return(0);
  178. }
  179.