Example #1
0
static void
pk_glyphs_fn P2C(FILE *, f,  struct font *, fontp)
{
  register struct glyph *g;
  int hppp, vppp;

  if (debug & DBG_PK)
    Printf ("Reading PK pixel file %s\n", fontp->filename);

  /* skip comment */
  Fseek (f, (long) one (f), SEEK_CUR);

  (void) four (f);	/* skip design size */
  (void) four (f);	/* skip checksum */
  hppp = sfour (f);
  vppp = sfour (f);
  if (hppp != vppp && (debug & DBG_PK))
    Printf ("Font has non-square aspect ratio %d:%d\n", vppp, hppp);

  /* Initialize glyph array.  */
  for (g = fontp->glyph; g < fontp->glyph + 256; ++g)
    {
      g->packed_data = NULL;
      g->bitmap.bits = NULL;
      g->bitmap2.bits = NULL;
    }

  /* Read glyph directory (really a pass over the whole file).  */
  for (;;)
    {
      int bytes_left, flag_low_bits;
      unsigned int cc;

      PK_skip_specials (f, fontp);
      if (PK_flag_byte == PK_POST)
	break;
      flag_low_bits = PK_flag_byte & 0x7;
      if (flag_low_bits == 7)
	{
	  bytes_left = four (f);
	  cc = four (f);
	}
      else if (flag_low_bits > 3)
	{
	  bytes_left = ((flag_low_bits - 4) << 16) + two (f);
	  cc = one (f);
	}
      else
	{
	  bytes_left = (flag_low_bits << 8) + one (f);
	  cc = one (f);
	}
      /* Use the (randomly chosen) `x2' field for the flag byte.  */
      fontp->glyph[cc].x2 = PK_flag_byte;
      
      /* Read the bitmap data, but don't unpack it.  */
      fontp->glyph[cc].packed_data = xmalloc (bytes_left);
      Fread (fontp->glyph[cc].packed_data, bytes_left, 1, f);
    }
}
Example #2
0
void
read_PK_index(struct font *fontp, wide_bool hushcs)
{
    int hppp, vppp;
    long checksum;

    fontp->read_char = read_PK_char;
    if (debug & DBG_PK)
	Printf("Reading PK pixel file %s\n", fontp->filename);

    Fseek(fontp->file, (long)one(fontp->file), 1);	/* skip comment */

    (void)four(fontp->file);	/* skip design size */
    checksum = four(fontp->file);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
	&& !hushcs)
	    Fprintf(stderr,
		    "Checksum mismatch (dvi = %lu, pk = %lu) in font file %s\n",
		    fontp->checksum, checksum, fontp->filename);
    hppp = sfour(fontp->file);
    vppp = sfour(fontp->file);
    if (hppp != vppp && (debug & DBG_PK))
	Printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
    /*
     * Prepare glyph array.
     */
    fontp->glyph = xmalloc(256 * sizeof(struct glyph));
    bzero((char *)fontp->glyph, 256 * sizeof(struct glyph));
    /*
     * Read glyph directory (really a whole pass over the file).
     */
    for (;;) {
	int bytes_left, flag_low_bits;
	unsigned int ch;

	PK_skip_specials(fontp);
	if (PK_flag_byte == PK_POST)
	    break;
	flag_low_bits = PK_flag_byte & 0x7;
	if (flag_low_bits == 7) {
	    bytes_left = four(fontp->file);
	    ch = four(fontp->file);
	}
	else if (flag_low_bits > 3) {
	    bytes_left = ((flag_low_bits - 4) << 16) + two(fontp->file);
	    ch = one(fontp->file);
	}
	else {
	    bytes_left = (flag_low_bits << 8) + one(fontp->file);
	    ch = one(fontp->file);
	}
	fontp->glyph[ch].addr = ftell(fontp->file);
	fontp->glyph[ch].x2 = PK_flag_byte;
#ifdef linux
#ifndef SHORTSEEK
#define SHORTSEEK 2048
#endif
	/* A bug in Linux libc (as of 18oct94) makes a short read faster
	   than a short forward seek. Totally non-intuitive.  */
	if (bytes_left > 0 && bytes_left < SHORTSEEK) {
	    char *dummy = xmalloc(bytes_left);
	    Fread(dummy, 1, bytes_left, fontp->file);
	    free(dummy);
	}
	else
	    /* seek backward, or long forward */
#endif /* linux */
	    Fseek(fontp->file, (long)bytes_left, 1);
	if (debug & DBG_PK)
	    Printf("Scanning pk char %u, at %ld.\n", ch, fontp->glyph[ch].addr);
    }
}