Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes
pk_loader Struct Reference

#include <load_pk.hpp>

Collaboration diagram for pk_loader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 pk_loader (url pk_file_name, tex_font_metric tfm, int dpi)
HI pkbyte ()
SI pkquad ()
SI pktrio ()
SI pkduo ()
HI getnyb ()
bool getbit ()
HN pkpackednum ()
HN rest ()
HN realfunc ()
HN handlehuge (HN i, HN k)
void unpack (glyph &gl)
glyphload_pk ()

Public Attributes

url file_name
string input_s
int input_pos
tex_font_metric tfm
int dpi
HN inputbyte
HN flagbyte
HN bitweight
HN dynf
HN repeatcount
long remainder
bool real_func_flag
int bc
int ec
int * char_pos
HNchar_flag
bool * unpacked

Detailed Description

Definition at line 19 of file load_pk.hpp.


Constructor & Destructor Documentation

pk_loader::pk_loader ( url  pk_file_name,
tex_font_metric  tfm,
int  dpi 
)

Definition at line 25 of file load_pk.cpp.

                                                                     :
  file_name (pk_file_name), tfm (tfm2), dpi (dpi2),
  inputbyte (0), flagbyte (0), bitweight (0), dynf (0),
  repeatcount (0), remainder (0), real_func_flag (true),
  bc (tfm->bc), ec (tfm->ec),
  char_pos(0), char_flag(0), unpacked(0)
{
  (void) load_string (pk_file_name, input_s, true);
  input_pos= 0;
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 100 of file load_pk.cpp.

{
  bitweight >>= 1; 
  if (bitweight == 0) {
    inputbyte = pkbyte ();
    bitweight = 128;
  } 
  return (inputbyte & bitweight);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 86 of file load_pk.cpp.

                   {
  HN temp;
  if (bitweight == 0) {
    bitweight = 16; 
    inputbyte = pkbyte ();
    temp = inputbyte >> 4;
  } else {
    bitweight = 0;
    temp = inputbyte & 15;
  }
  return temp;
} 

Here is the call graph for this function:

Here is the caller graph for this function:

HN pk_loader::handlehuge ( HN  i,
HN  k 
)

Definition at line 155 of file load_pk.cpp.

                                  {
  register long j = k;
  
  while (i) {
    j = (j << 4L) + getnyb();
    i--;
  }
  remainder = j - 15 + (13 - dynf) * 16 + dynf;
  real_func_flag = false;
  return (rest ());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 276 of file load_pk.cpp.

                    {
  register HI i;
  register SI k;
  register SI length = 0, startpos = 0;

  register HI charcode= 0;
  register SI cwidth;
  register SI cheight;
  register SI xoff;
  register SI yoff;
  
  bench_start ("decode pk");
  glyph* fng= tm_new_array<glyph> (ec+1-bc);
  char_pos = tm_new_array<int> (ec+1-bc);
  unpacked = tm_new_array<bool> (ec+1-bc);
  char_flag = tm_new_array<HN> (ec+1-bc);
  for(i=0;i<ec+1-bc;i++) {
    char_pos[i] = 0;
    char_flag[i] = 0;
    unpacked[i] = true; // set to false for still unpacked glyphs
  }

  // Preamble
  if (pkbyte ()!=247) {
    cerr << "\npk file= " << file_name << "\n";
    FAILED ("bad pk file");
  }
  if (pkbyte ()!=89) {
    cerr << "\npk file= " << file_name << "\n";
    FAILED ("bad version of pk file");
  }
  for(i=pkbyte (); i>0; i--) (void) pkbyte (); /* creator of pkfile */
  (void) pkquad (); /* design size */
  k = pkquad ();    /* checksum    */
  k = pkquad ();    /* hppp        */
  k = pkquad ();    /* vppp   */

  // The character definition
  while ((flagbyte=pkbyte ())!=245) {
    if (flagbyte < 240) {
      switch (flagbyte & 7) {
      case 0:
      case 1:
      case 2:
      case 3:
       length = (flagbyte & 7) * 256 + pkbyte ();
       charcode = pkbyte ();
       startpos = input_pos;
       i = pktrio ();  /* TFM width */
       i = pkbyte ();       /* pixel width */
       break;
      case 4:
       length = pkbyte () * 256;
       length = length + pkbyte ();
       charcode = pkbyte ();
       startpos = input_pos;
       i = pktrio ();                  /* TFM width */
       i = pkbyte ();
       i = i * 256 + pkbyte ();        /* pixelwidth */
       break;
      case 5:
       cerr << "\npk file= " << file_name << "\n";
       cerr << "last charcode= " << charcode << "\n";
       FAILED ("lost sync in pk file (character too big / status = 5)");
       break;
      case 6:
       cerr << "\npk file= " << file_name << "\n";
       cerr << "last charcode= " << charcode << "\n";
       FAILED ("lost sync in pk file (character too big / status = 6)");
       break;
      case 7:
       length = pkquad ();
       charcode = pkquad ();
       startpos = input_pos;
       (void) pkquad ();           /* TFMwidth */
                          /* pixelwidth = (pkquad () + 32768) >> 16; */
       (void) pkquad ();           /* pixelwidth */
       k = pkquad ();
      }
      /*
      cout << "---------------------------------------------------------------------------\n";
      cout << "Reading character " << charcode << "\n";
      cout << "---------------------------------------------------------------------------\n";
      */
      if (flagbyte & 4) { // the long and extended formats are bugged !
       if ((flagbyte & 7) == 7) { // extended format
         cwidth = pkquad ();;
         cheight = pkquad ();
         xoff = pkquad ();
         yoff = pkquad ();
       } else { // long format
         cwidth = pkduo ();
         cheight = pkduo ();
         xoff = pkduo ();
         yoff = pkduo ();
       }
      } else { // short format
       cwidth = pkbyte ();
       cheight = pkbyte ();
       xoff = pkbyte ();
       yoff = pkbyte ();
       if (xoff > 127) xoff -= 256;
       if (yoff > 127) yoff -= 256;
      }
      if ((cwidth > 0) && (cheight > 0) &&
         (((QN) charcode) >= bc) && (((QN) charcode) <= ec)) {
       // cout << "---> unpacking " << charcode
       //     << " at " << input_pos 
       //     << " (start " << startpos << ", length " << length << ")!\n";
       glyph gl (cwidth, cheight, xoff, yoff);

       /* needed for lazy unpacking */
       char_pos[((QN) charcode)- bc] = input_pos;
       char_flag[((QN) charcode)- bc] = flagbyte;
       unpacked[((QN) charcode)- bc] = false;
       /* skip packed bitmap */
       input_pos = startpos + length;

       fng [((QN) charcode)- bc]= gl;
       // cout << "---> " << charcode << " done !\n";
       // cout << fng [((QN) charcode)- bc] << "\n";
      }
    }

    else {
      k = 0;
      switch (flagbyte) {
      case 243: k = pkbyte (); if (k > 127) k -= 256;
      case 242: k = k * 256 + pkbyte ();
      case 241: k = k * 256 + pkbyte ();
      case 240: k = k * 256 + pkbyte ();
       while (k-- > 0) i = pkbyte ();
       break;
      case 244: k = pkquad (); break;
      case 246: break;
      default :
       cerr << "\npk file= " << file_name << "\n";
       cerr << "last charcode= " << charcode << "\n";
       cerr << "flagbyte= " << flagbyte << "\n";
       FAILED ("lost sync in pk file");
      }
    }
  }

  register int c;
  for (c=0; c<=ec-bc; c++)
    if (!is_nil (fng[c])) {
      SI design_size = tfm->design_size () >> 12;
      SI display_size= (((design_size*dpi)/72)*PIXEL) >> 8;
      double unit    = ((double) display_size) / ((double) (1<<20));
      SI lwidth= (SI) (((double) (tfm->w(c+bc))) * unit);
      fng[c]->lwidth= ((lwidth+(PIXEL>>1)) / PIXEL);
    }

  bench_cumul ("decode pk");
  return fng;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 41 of file load_pk.cpp.

                   {
  if (input_pos == N(input_s)) {
    cerr << "\npk file= " << file_name << "\n";
    FAILED ("unexpected eof in pk file");
  }
  return (HI) ((QN) input_s [input_pos++]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 50 of file load_pk.cpp.

                  {
  register SI i;

  i = pkbyte ();
  if (i > 127) i -= 256;
  i = i * 256 + pkbyte ();
  return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file load_pk.cpp.

                        {
  register HN i, j; 
  i = getnyb (); 
  if (i == 0) {
    do { j = getnyb (); i++; } while (! (j != 0)); 
    if (i > 3) return handlehuge (i, j);
    while (i > 0) {
      j= j*16 + getnyb (); 
      i--; 
    } 
    return (j-15 + (13-dynf)*16 + dynf); 
  }
  else if (i <= dynf) return i; 
  else if (i < 14) return ((i-dynf-1)*16+ getnyb()+ dynf+ 1); 
  else {
    if (i == 14) repeatcount = pkpackednum (); 
    else repeatcount = 1; 
    return realfunc ();
  } 
} 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file load_pk.cpp.

                   {
  register SI i;

  i = pkbyte ();
  if (i > 127) i -= 256;
  i = i * 256 + pkbyte ();
  i = i * 256 + pkbyte ();
  i = i * 256 + pkbyte ();
  return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 60 of file load_pk.cpp.

                   {
  register SI i;

  i = pkbyte ();
  i = i * 256 + pkbyte ();
  i = i * 256 + pkbyte ();
  return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 168 of file load_pk.cpp.

                     {
  if (real_func_flag) return pkpackednum ();
  else return rest ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 133 of file load_pk.cpp.

                 {
  HN i;

  if (remainder < 0) {
    remainder = - remainder;
    return 0;
  } else if (remainder > 0) {
    if (remainder > 4000) {
      remainder = 4000 - remainder;
      return (4000);
    }
    i = remainder;
    remainder = 0;
    real_func_flag = true;
    return i;
  }
  cerr << "\npk file= " << file_name << "\n";
  FAILED ("unexpected situation");
  return 0;
}

Here is the caller graph for this function:

void pk_loader::unpack ( glyph gl)

Definition at line 213 of file load_pk.cpp.

                            { 
  register SI i, j;
  register HN wordweight;
  HI rowsleft; 
  bool turnon;
  HI hbit;
  HN count; 
  char_bitstream bit_out (gl);

  real_func_flag = true;
  dynf = flagbyte / 16; 
  turnon = flagbyte & 8; 

  if (dynf == 14) {
    bitweight = 0 ; 
    for (j=0; j<gl->height; j++)
      for (i=0; i<gl->width; i++)
       bit_out.write (getbit ()? 1: 0);
  }

  else {
    rowsleft = gl->height; 
    hbit = gl->width; 
    repeatcount = 0; 
    wordweight = 16;
    bitweight = 0;
    while (rowsleft > 0) {
      count = realfunc (); 
      bit_out.write (turnon? 1: 0, count, repeatcount);

      while (count != 0) {
       if ((count < wordweight) && (count < hbit)) {
         hbit -= count;
         wordweight -= count; 
         count = 0; 
       } 
       else if ((count >= hbit) && (hbit <= wordweight)) {
         rowsleft -= repeatcount + 1; 
         repeatcount = 0; 
         count -= hbit; 
         hbit = gl->width; 
         wordweight = 16; 
       } 
       else {
         count -= wordweight; 
         hbit -= wordweight; 
         wordweight = 16; 
       } 
      }
      turnon = ! turnon; 
    }
    if ((rowsleft != 0) || (hbit != gl->width)) {
      cerr << "\npk file= " << file_name << "\n";
      FAILED ("more bits than required while unpacking");
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 33 of file load_pk.hpp.

Definition at line 28 of file load_pk.hpp.

Definition at line 38 of file load_pk.hpp.

Definition at line 37 of file load_pk.hpp.

Definition at line 24 of file load_pk.hpp.

Definition at line 29 of file load_pk.hpp.

Definition at line 34 of file load_pk.hpp.

Definition at line 20 of file load_pk.hpp.

Definition at line 27 of file load_pk.hpp.

Definition at line 22 of file load_pk.hpp.

Definition at line 21 of file load_pk.hpp.

Definition at line 26 of file load_pk.hpp.

Definition at line 32 of file load_pk.hpp.

Definition at line 31 of file load_pk.hpp.

Definition at line 30 of file load_pk.hpp.

tex_font_metric pk_loader::tfm

Definition at line 23 of file load_pk.hpp.

Definition at line 39 of file load_pk.hpp.


The documentation for this struct was generated from the following files: