⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pklib.c

📁 字体缩放显示
💻 C
📖 第 1 页 / 共 2 页
字号:
        while (*p == paint_switch && bits_left >= 8)        {          ++p;          bits_left -= 8;        }        mask = 0x80;      }    }    if (nextcount >= counts_end)      return False;    shift_count -= bits_left;    *nextcount++ = shift_count;    tallyup(shift_count);    /* check for duplicate rows */    if (rowptr != rowdup && bits_left != width)    {      byte *p1 = rowptr;      byte *q  = rowptr + bytes_wide;      int repeat_count;      while (q < bitmap_end && *p1 == *q)      {        ++p1;        ++q;      }      repeat_count = (p1 - rowptr) / bytes_wide;      if (repeat_count > 0)      {        *nextcount++ = -repeat_count;        if (repeat_count == 1)          --base;        else        {          ++base;          tallyup(repeat_count);        }        rowptr += repeat_count * bytes_wide;      }      rowdup = rowptr;    }    paint_switch = ~paint_switch;  }#ifdef  DEBUG  /*   *      Dump the bitmap   */  for (p = bitmap; p < bitmap_end; p += bytes_wide)  {    byte *p1 = p;    int j;    mask = 0x80 >> skip;    for (j = 0; j < width; ++j)    {      putchar(*p1 & mask ? '@' : '.');      if ((mask >>= 1) == 0)      {        mask = 0x80;        ++p1;      }    }    putchar('\n');  }  putchar('\n');#endif  /* Determine the best pk_dyn_f */  pk_dyn_f = 0;  cost = base += 2 * (nextcount - counts);  for (i = 1; i < 14; ++i)  {    base += deltas[i - 1];    if (base < cost)    {      pk_dyn_f = i;      cost = base;    }  }  /* last chance to bail out */  if (cost * 4 > width * height)    return False;  /* Pack the bit counts */  pk_dyn_g = 208 - 15 * pk_dyn_f;  flag |= pk_dyn_f << 4;  bitmap_end = bitmap;  *nextcount = 0;  nextcount = counts;  while (*nextcount != 0)  {    if (*nextcount > 0)      pk_put_count(*nextcount);    else      if (*nextcount == -1)        pk_put_nyb(15);      else      {        pk_put_nyb(14);        pk_put_count(-*nextcount);      }      ++nextcount;  }  if (odd)  {    pk_put_nyb(0);    ++cost;  }  if (cost != 2 * (bitmap_end - bitmap))    printf("Cost miscalculation:  expected %d, got %ld\n",             cost, (long)(2 * (bitmap_end - bitmap)));  pk_len = bitmap_end - bitmap;  return True;}static voidpk_bm_cvt(void){  byte *rowptr;  byte *p;  int  blib1;          /* bits left in byte */  int  bits_left;      /* bits left in row */  byte *q;  int  blib2;  byte nextbyte;  flag = 14 << 4;  q = bitmap;  blib2 = 8;  nextbyte = 0;  for (rowptr = bitmap; rowptr < bitmap_end; rowptr += bytes_wide)  {    p = rowptr;    blib1 = 8 - skip;    bits_left = width;    if (blib2 != 8)    {      int n;      if (blib1 < blib2)      {        nextbyte |= *p << (blib2 - blib1);        n = blib1;      }      else      {        nextbyte |= *p >> (blib1 - blib2);        n = blib2;      }      blib2 -= n;      if ((bits_left -= n) < 0)      {        blib2 -= bits_left;        continue;      }      if ((blib1 -= n) == 0)      {        blib1 = 8;        ++p;        if (blib2 > 0)        {          nextbyte |= *p >> (8 - blib2);          blib1 -= blib2;          bits_left -= blib2;          if (bits_left < 0)          {            blib2 = -bits_left;            continue;          }        }      }      *q++ = nextbyte;    }    /* fill up whole (destination) bytes */    while (bits_left >= 8)    {      nextbyte = *p++ << (8 - blib1);      *q++ = nextbyte | (*p >> blib1);      bits_left -= 8;    }    /* now do the remainder */    nextbyte = *p << (8 - blib1);    if (bits_left > blib1)      nextbyte |= p[1] >> blib1;    blib2 = 8 - bits_left;  }  if (blib2 != 8)    *q++ = nextbyte;  pk_len = q - bitmap;}static voidputshort(short w){  putc(w >> 8, pk_file);  putc(w, pk_file);}static voidputmed(long w){  putc(w >> 16, pk_file);  putc(w >> 8, pk_file);  putc(w, pk_file);}static voidputlong(long w){  putc(w >> 24, pk_file);  putc(w >> 16, pk_file);  putc(w >> 8, pk_file);  putc(w, pk_file);}charxgetc(FILE *f){  int c;  c = getc(f);  if (c == EOF)    oops("Premature end of file.");  return (byte)c;}/* *   Open and read the tfm file.  */voidTFMopen(char **filename){  FILE *tfm_file;  int  i;  int  cc;  tfm_file = search_tfm(filename);  if (tfm_file == NULL)    oops("Cannot find tfm file.");  for (i = 0; i < 12; i++)  {    int j;        j = (int)((byte)getc(tfm_file)) << 8;    tfm_lengths[i] = j | (int)((byte)xgetc(tfm_file));  }  checksum = getlong(tfm_file);  design = getlong(tfm_file);  fseek(tfm_file, 4 * (lh + 6), 0);  for (cc = bc; cc <= ec; ++cc)  {    width_index[cc] = (byte)xgetc(tfm_file);    (void)xgetc(tfm_file);    (void)xgetc(tfm_file);    (void)xgetc(tfm_file);  }  for (i = 0; i < nw; ++i)    tfm_widths[i] = getlong(tfm_file);  fclose(tfm_file);}/* *   Create pk file and write preamble. */voidPKopen(char *filename,       char *ident,       int resolution){  int ppp;  int i;  dpi = resolution;  if ((pk_file = fopen(filename, "wb")) == NULL)  {    perror(filename);    exit(1);  }  putc(PK_PRE, pk_file);  putc(PK_ID, pk_file);  i = strlen(ident);  putc(i, pk_file);  fwrite(ident, 1, i, pk_file);  putlong(design);  putlong(checksum);  ppp = dpi / 72.27 * 65536.0 + 0.5;  putlong(ppp);                         /* hppp */  putlong(ppp);                         /* vppp */}voidPKputglyph(int cc,           int llx, int lly, int urx, int ury,            int w, int h,           byte *b){  float char_width;  long dm;  long tfm_wid;  bitmap = b;  width = w;  height = h;  hoff = -llx;  voff = ury - 2; /* Don't ask me why `-2' */                  /*   Fred                */  if (width != urx - llx || height != ury - lly)    oops("Dimensions do not match:  (%d - %d) (%d - %d) <=> %d %d",           llx, lly, urx, ury, width, height);  bytes_wide = (width + 7) / 8;  bm_size = bytes_wide * height;  bitmap_end = bitmap + bm_size;  trim_bitmap();  if (height == 0 || !pk_rll_cvt())    pk_bm_cvt();  if (!width_index[cc])    return;  tfm_wid = tfm_widths[width_index[cc]];  char_width = tfm_wid / 1048576.0 * design / 1048576.0 * dpi / 72.27;  dm = (long)(char_width + 0.5) - (char_width < -0.5);  if (pk_len + 8 < 4 * 256 && tfm_wid < (1<<24) &&      dm >= 0 && dm < 256 && width < 256 && height < 256 &&      hoff >= -128 && hoff < 128 && voff >= -128 && voff < 128)  {    putc(flag | ((pk_len + 8) >> 8), pk_file);    putc(pk_len + 8, pk_file);    putc(cc, pk_file);    putmed(tfm_wid);    putc(dm, pk_file);    putc(width, pk_file);    putc(height, pk_file);    putc(hoff, pk_file);    putc(voff, pk_file);  }  else if (pk_len + 13 < 3 * 65536L && tfm_wid < (1<<24) &&           dm >= 0 && dm < 65536L && width < 65536L && height < 65536L &&           hoff >= -65536L && hoff < 65536L &&           voff >= -65536L && voff < 65536L)  {    putc(flag | 4 | ((pk_len + 13) >> 16), pk_file);    putshort(pk_len + 13);    putc(cc, pk_file);    putmed(tfm_wid);    putshort(dm);    putshort(width);    putshort(height);    putshort(hoff);    putshort(voff);  }  else  {    putc(flag | 7, pk_file);    putlong(pk_len + 28);    putlong(cc);    putlong(tfm_wid);    putlong((long)(char_width * 65536.0 + 0.5) - (char_width < -0.5));    putlong(0);    putlong(width);    putlong(height);    putlong(hoff);    putlong(voff);  }  fwrite(bitmap, 1, pk_len, pk_file);}voidPKclose(void){  putc(PK_POST, pk_file);  while (ftell(pk_file) % 4 != 0)    putc(PK_NOP, pk_file);  fclose(pk_file);}/* end */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -