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

📄 texfont_pk.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#endif  int i, j;  if ((i = PK_get_nyb(fp)) == 0) {    do {      j = PK_get_nyb(fp);      ++i;    }    while (j == 0);    while (i > 0) {      j = (j << 4) | PK_get_nyb(fp);      --i;    }    return (j - 15 + ((13 - PK_dyn_f) << 4) + PK_dyn_f);  }  else {    if (i <= PK_dyn_f) return i;    if (i < 14)      return (((i - PK_dyn_f - 1) << 4) + PK_get_nyb(fp)              + PK_dyn_f + 1);    if (i == 14) PK_repeat_count = PK_packed_num(fp);    else PK_repeat_count = 1;    return PK_packed_num(fp);  }}void TeXFont_PK::PK_skip_specials(){#ifdef DEBUG_PK  kDebug(kvs::dvi) << "TeXFont_PK::PK_skip_specials() called" << endl;#endif  int i,j;  register FILE *fp = file;#ifdef DEBUG_PK  if (fp == 0)    kDebug(kvs::dvi) << "TeXFont_PK::PK_skip_specials(): file == 0" << endl;#endif  do {    PK_flag_byte = one(fp);    if (PK_flag_byte >= PK_CMD_START) {      switch (PK_flag_byte) {      case PK_X1 :      case PK_X2 :      case PK_X3 :      case PK_X4 :        i = 0;        for (j = PK_CMD_START; j <= PK_flag_byte; ++j)          i = (i << 8) | one(fp);        while (i--) (void) one(fp);        break;      case PK_Y :        (void) four(fp);      case PK_POST :      case PK_NOOP :        break;      default :        oops(i18n("Unexpected %1 in PK file %2", PK_flag_byte, parent->filename) );        break;      }    }  }  while (PK_flag_byte != PK_POST && PK_flag_byte >= PK_CMD_START);#ifdef DEBUG_PK  kDebug(kvs::dvi) << "TeXFont_PK::PK_skip_specials() ended" << endl;#endif}void TeXFont_PK::read_PK_char(unsigned int ch){#ifdef DEBUG_PK  kDebug(kvs::dvi) << "read_PK_char" << endl;#endif  int        i, j;  int        n;  int        row_bit_pos;  bool       paint_switch;  quint32*  cp;  register struct glyph *g;  register FILE *fp = file;  long       fpwidth;  quint32   word = 0;  int        word_weight, bytes_wide;  int        rows_left, h_bit, count;  g = glyphtable + ch;  PK_flag_byte = g->x2;  PK_dyn_f = PK_flag_byte >> 4;  paint_switch = ((PK_flag_byte & 8) != 0);  PK_flag_byte &= 0x7;  if (PK_flag_byte == 7)    n = 4;  else    if (PK_flag_byte > 3)      n = 2;    else      n = 1;#ifdef DEBUG_PK  kDebug(kvs::dvi) << "loading pk char " << ch << ", char type " << n << endl;#endif  if (characterBitmaps[ch] == 0)    characterBitmaps[ch] = new bitmap();  /*   * now read rest of character preamble   */  if (n != 4)    fpwidth = num(fp, 3);  else {    fpwidth = sfour(fp);    (void) four(fp);        /* horizontal escapement */  }  (void) num(fp, n);        /* vertical escapement */  {    unsigned long w, h;    w = num(fp, n);    h = num(fp, n);    if (w > 0x7fff || h > 0x7fff)      oops(i18n("The character %1 is too large in file %2", ch, parent->filename));    characterBitmaps[ch]->w = w;    characterBitmaps[ch]->h = h;  }  g->x = snum(fp, n);  g->y = snum(fp, n);  g->dvi_advance_in_units_of_design_size_by_2e20 = fpwidth;  {    /* width must be multiple of 16 bits for raster_op */    characterBitmaps[ch]->bytes_wide = ROUNDUP((int) characterBitmaps[ch]->w, 32) * 4;    register unsigned int size = characterBitmaps[ch]->bytes_wide * characterBitmaps[ch]->h;    characterBitmaps[ch]->bits = new char[size != 0 ? size : 1];  }  cp = (quint32 *) characterBitmaps[ch]->bits;  /*   * read character data into *cp   */  bytes_wide = ROUNDUP((int) characterBitmaps[ch]->w, 32) * 4;  PK_bitpos = -1;  // The routines which read the character depend on the bit  // ordering. In principle, the bit order should be detected at  // compile time and the proper routing chosen. For the moment, as  // autoconf is somewhat complicated for the author, we prefer a  // simpler -even if somewhat slower approach and detect the ordering  // at runtime. That should of course be changed in the future.  int wordSize;  bool bigEndian;  qSysInfo (&wordSize, &bigEndian);  if (bigEndian) {    // Routine for big Endian machines. Applies e.g. to Motorola and    // (Ultra-)Sparc processors.#ifdef DEBUG_PK    kDebug(kvs::dvi) << "big Endian byte ordering" << endl;#endif    if (PK_dyn_f == 14) {        /* get raster by bits */      memset(characterBitmaps[ch]->bits, 0, (int) characterBitmaps[ch]->h * bytes_wide);      for (i = 0; i < (int) characterBitmaps[ch]->h; i++) {        /* get all rows */        cp = ADD(characterBitmaps[ch]->bits, i * bytes_wide);        row_bit_pos = 32;        for (j = 0; j < (int) characterBitmaps[ch]->w; j++) {    /* get one row */          if (--PK_bitpos < 0) {            word = one(fp);            PK_bitpos = 7;          }          if (--row_bit_pos < 0) {            cp++;            row_bit_pos = 32 - 1;          }          if (word & (1 << PK_bitpos))            *cp |= 1 << row_bit_pos;        }      }    } else {                /* get packed raster */      rows_left = characterBitmaps[ch]->h;      h_bit = characterBitmaps[ch]->w;      PK_repeat_count = 0;      word_weight = 32;      word = 0;      while (rows_left > 0) {        count = PK_packed_num(fp);        while (count > 0) {          if (count < word_weight && count < h_bit) {            h_bit -= count;            word_weight -= count;            if (paint_switch)              word |= bit_masks[count] << word_weight;            count = 0;          } else            if (count >= h_bit && h_bit <= word_weight) {              if (paint_switch)                word |= bit_masks[h_bit] << (word_weight - h_bit);              *cp++ = word;              /* "output" row(s) */              for (i = PK_repeat_count * bytes_wide / 4; i > 0; --i) {                *cp = *SUB(cp, bytes_wide);                ++cp;              }              rows_left -= PK_repeat_count + 1;              PK_repeat_count = 0;              word = 0;              word_weight = 32;              count -= h_bit;              h_bit = characterBitmaps[ch]->w;            } else {              if (paint_switch)                word |= bit_masks[word_weight];              *cp++ = word;              word = 0;              count -= word_weight;              h_bit -= word_weight;              word_weight = 32;            }        }        paint_switch = 1 - paint_switch;      }      if (cp != ((quint32 *) (characterBitmaps[ch]->bits + bytes_wide * characterBitmaps[ch]->h)))        oops(i18n("Wrong number of bits stored:  char. %1, font %2", ch, parent->filename));      if (rows_left != 0 || h_bit != characterBitmaps[ch]->w)        oops(i18n("Bad pk file (%1), too many bits", parent->filename));    }    // The data in the bitmap is now in the processor's bit order,    // that is, big endian. Since XWindows needs little endian, we    // need to change the bit order now.    register unsigned char* bitmapData = (unsigned char*) characterBitmaps[ch]->bits;    register unsigned char* endOfData  = bitmapData + characterBitmaps[ch]->bytes_wide*characterBitmaps[ch]->h;    while(bitmapData < endOfData) {      *bitmapData = bitflip[*bitmapData];      bitmapData++;    }  } else {    // Routines for small Endian start here. This applies e.g. to    // Intel and Alpha processors.#ifdef DEBUG_PK    kDebug(kvs::dvi) << "small Endian byte ordering" << endl;#endif    if (PK_dyn_f == 14) {        /* get raster by bits */      memset(characterBitmaps[ch]->bits, 0, (int) characterBitmaps[ch]->h * bytes_wide);      for (i = 0; i < (int) characterBitmaps[ch]->h; i++) {        /* get all rows */        cp = ADD(characterBitmaps[ch]->bits, i * bytes_wide);        row_bit_pos = -1;        for (j = 0; j < (int) characterBitmaps[ch]->w; j++) {    /* get one row */          if (--PK_bitpos < 0) {            word = one(fp);            PK_bitpos = 7;          }          if (++row_bit_pos >= 32) {            cp++;            row_bit_pos = 0;          }          if (word & (1 << PK_bitpos))            *cp |= 1 << row_bit_pos;        }      }    } else {                /* get packed raster */      rows_left = characterBitmaps[ch]->h;      h_bit = characterBitmaps[ch]->w;      PK_repeat_count = 0;      word_weight = 32;      word = 0;      while (rows_left > 0) {        count = PK_packed_num(fp);        while (count > 0) {          if (count < word_weight && count < h_bit) {            if (paint_switch)              word |= bit_masks[count] << (32 - word_weight);            h_bit -= count;            word_weight -= count;            count = 0;          } else            if (count >= h_bit && h_bit <= word_weight) {              if (paint_switch)                word |= bit_masks[h_bit] << (32 - word_weight);              *cp++ = word;              /* "output" row(s) */              for (i = PK_repeat_count * bytes_wide / 4; i > 0; --i) {                *cp = *SUB(cp, bytes_wide);                ++cp;              }              rows_left -= PK_repeat_count + 1;              PK_repeat_count = 0;              word = 0;              word_weight = 32;              count -= h_bit;              h_bit = characterBitmaps[ch]->w;            } else {              if (paint_switch)                word |= bit_masks[word_weight] << (32 - word_weight);              *cp++ = word;              word = 0;              count -= word_weight;              h_bit -= word_weight;              word_weight = 32;            }        }        paint_switch = 1 - paint_switch;      }      if (cp != ((quint32 *) (characterBitmaps[ch]->bits + bytes_wide * characterBitmaps[ch]->h)))        oops(i18n("Wrong number of bits stored:  char. %1, font %2", ch, parent->filename));      if (rows_left != 0 || h_bit != characterBitmaps[ch]->w)        oops(i18n("Bad pk file (%1), too many bits", parent->filename));    }  } // endif: big or small Endian?}void TeXFont_PK::read_PK_index(){#ifdef DEBUG_PK  kDebug(kvs::dvi) << "TeXFont_PK::read_PK_index() called" << endl;#endif  if (file == 0) {    kError(kvs::dvi) << "TeXFont_PK::read_PK_index(): file == 0" << endl;    return;  }  int magic      = two(file);  if (magic != PK_MAGIC) {    kError(kvs::dvi) << "TeXFont_PK::read_PK_index(): file is not a PK file" << endl;    return;  }  fseek(file, (long) one(file), SEEK_CUR);      /* skip comment */  (void) four(file);                /* skip design size */  checksum = four(file);  int hppp = sfour(file);  int vppp = sfour(file);  if (hppp != vppp)    kWarning(kvs::dvi) << i18n("Font has non-square aspect ratio ") << vppp << ":" << hppp << endl;  // Read glyph directory (really a whole pass over the file).  for (;;) {    int bytes_left, flag_low_bits;    unsigned int ch;    PK_skip_specials();    if (PK_flag_byte == PK_POST)      break;    flag_low_bits = PK_flag_byte & 0x7;    if (flag_low_bits == 7) {      bytes_left = four(file);      ch = four(file);    } else      if (flag_low_bits > 3) {        bytes_left = ((flag_low_bits - 4) << 16) + two(file);        ch = one(file);      } else {        bytes_left = (flag_low_bits << 8) + one(file);        ch = one(file);      }    glyphtable[ch].addr = ftell(file);    glyphtable[ch].x2 = PK_flag_byte;    fseek(file, (long) bytes_left, SEEK_CUR);#ifdef DEBUG_PK    kDebug(kvs::dvi) << "Scanning pk char " << ch << "at " << glyphtable[ch].addr << endl;#endif  }#ifdef DEBUG_PK  kDebug(kvs::dvi) << "TeXFont_PK::read_PK_index() called" << endl;#endif}

⌨️ 快捷键说明

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