home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / CreativeComputers.iso / shareware / text / dvi_3.62 / source / dvisrc.lha / dlwpkch.c < prev    next >
C/C++ Source or Header  |  1993-10-26  |  2KB  |  118 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include "dvi.h"
  4. #include "dvilw.h"
  5.  
  6. static int  repeat_count;
  7. static int  q;
  8. static byte *p;
  9. static char hex_char[]="0123456789ABCDEF";
  10.  
  11. #define EMIT_HEX(c) {pschar(hex_char[c>>4]); pschar(hex_char[c&15]);}
  12. #define get_pk_nyb(p,q) ( ((q)=!(q))==0 ? *(p)++&15 : *(p)>>4)
  13.  
  14. static int pk_pnum(int dyn_f)
  15. {
  16.     int i;
  17.     if ( (i=get_pk_nyb(p,q))==0 )
  18.     {
  19.     int j; i++;
  20.     while ( (j=get_pk_nyb(p,q))==0 ) i++;
  21.     while ( i-- ) j = (j<<4)+get_pk_nyb(p,q);
  22.     return j-15+((13-dyn_f)<<4)+dyn_f;
  23.     }
  24.     if (i<=dyn_f) return i;
  25.     if (i<14) return ((i-dyn_f-1)<<4) + get_pk_nyb(p,q) + dyn_f +1;
  26.     if (i==14) repeat_count=pk_pnum(dyn_f);
  27.     else repeat_count=1;
  28.     return pk_pnum(dyn_f);
  29. }
  30.  
  31.  
  32. void def_char(pk_char *c, double hconv)
  33. {
  34.     int     dyn_f   = c->dyn_f;
  35.     int     state   = !c->state;
  36.     int     h       = (int)c->h;
  37.     int     w       = (int)c->w;
  38.  
  39.     p  =  c->data;
  40.     q  =  0;
  41.  
  42.     if (w==0 || h==0) return;
  43.     repeat_count=0;
  44.  
  45.     psprint("[<");
  46.  
  47.     if (dyn_f==14)
  48.     {
  49.     register byte *pa = c->data;
  50.     register byte  pm = 128;
  51.     register int   pb = 7;
  52.     register int   ww;
  53.     register byte  lm;
  54.     register int   lb;
  55.     register int   the_byte;
  56.  
  57.     while(h--)
  58.     {
  59.         lb=7; lm=128;
  60.         the_byte=0;
  61.         for (ww=w; ww--;)
  62.         {
  63.         if (pm & *pa) the_byte |= lm;
  64.         if (lb--) lm >>= 1;
  65.         else { lb=7; lm=128; EMIT_HEX(the_byte) the_byte=0;}
  66.         if (pb--) pm >>= 1;
  67.         else { pb=7; pm=128; pa++; }
  68.         }
  69.         if (lb!=7) EMIT_HEX(the_byte)
  70.         if (readable) pschar('\n');
  71.     }
  72.     }
  73.     else
  74.     {
  75.     register int    r=0, rep_mode=0;
  76.  
  77.     while( h > 0)
  78.     {
  79.         register int   lm=128, lb=7, the_byte=0;
  80.         register int   ww;
  81.         register byte *rp;
  82.         register int   rq,rstate,rr;
  83.  
  84.         rp=p; rq=q; rstate=state; rr=r;
  85.         for(ww=w; ww--;)
  86.         {
  87.         if (r==0) { state=!state; r=pk_pnum(dyn_f); }
  88.         r--;
  89.         if (state) the_byte |= lm;
  90.         if (lb--) lm>>=1;
  91.         else { lb=7; lm=128; EMIT_HEX(the_byte) the_byte=0;}
  92.         }
  93.         if (lb!=7) EMIT_HEX(the_byte)
  94.         if (readable) pschar('\n');
  95.         h--;
  96.  
  97.         if (rep_mode==0 && repeat_count) rep_mode=repeat_count+1;
  98.         repeat_count=0;
  99.         if (rep_mode)
  100.         {
  101.         if (--rep_mode==0) continue;
  102.         p=rp; q=rq; state=rstate; r=rr;
  103.         }
  104.     }
  105.     }
  106.     pschar('>');
  107.     psprint("%d %d %d %d %g] %d D\n",
  108.         (int)c->hoff,(int)c->voff,(int)c->w,(int)c->h,
  109.         (double)c->tfm*hconv,(int)c->cc);
  110.  
  111. }
  112.  
  113. void draw_rule(int x, int y, int w, int h)
  114. {
  115.     psprint("%d %d M %d %d B\n",x,y,w,h);
  116. }
  117.  
  118.