[comp.text] DVI-LaserJetII converter - Part 4 of 4

mah@hpuviea.UUCP (Michael Haberler) (01/19/89)

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by Michael Haberler <mah@hpuviea> on Wed Jan 18 17:58:00 1989
#
# This archive contains:
#	dvilj.c-part3	
#

unset LANG

echo x - dvilj.c-part3
cat >dvilj.c-part3 <<'@EOF'
                while (count > 0) {
                    if ((count < wordweight) && (count < hbit)) {
                        if (turnon)
                                word +=
                                    gpower[wordweight] -
                                    gpower[wordweight - count] ;
     
                        hbit -= count ;
                        wordweight -= count ;
                        count = 0 ;
                    } else if ((count >= hbit) && (hbit <=
                        wordweight)) {
     
                        if (turnon)
                                word +=
                                    gpower[wordweight] -
                                    gpower[wordweight - hbit] ;
     
                        row[rp] = word ;
     
                        /* printf(" @<Send row@> \n");*/
                        for (i = 0; i <= (long) repeatcount; i++) { int ii;
                            /* printf("***  |");*/
                            for (ii = 1; ii < wordwidth; ii++) {
                                tl = row[ii];
     
                                OUTCHAR((tl >> 24 & 0xFF));
                                OUTCHAR((tl >> 16 & 0xFF));
                                OUTCHAR((tl >> 8  & 0xFF));
                                OUTCHAR((tl       & 0xFF));
/*
 * { int k;
 *   for (k=31; k>=0; k--)  {
 *       if ((power[k] & row[ii])!=0) printf("M");
 *       else printf(".");
 *   }
 * }
 */
                            }
                            tl = row[wordwidth];
                            for (j = 3; j >= (wordwidth *4 - (long)nbpl);
                                 j--) {
     
                                 OUTCHAR(((tl >> (j << 3)) & 0xff));
/*
 * { int k;
 *   for (k=7; k>=0; k--) {
 *       if ((power[k] & temp)!=0) printf("M");
 *       else printf(".");
 *   }
 * }
 */
                            }
     
                            if (raster) {
                                    RasterLine(ce,
                                        (unsigned int)nbpl,
                                         current_line,
                                         raster_line_buf);
                                    current_line++;
                            } else
                                    EMITL(bp, raster_line_buf);
     
                            bp = 0;
     
                    /*printf("|  "); */
                    /*for (j=1;j<=(long)wordwidth;j++) printf("%lX/",row[j]);*/
                    /*printf("\n");*/
                        }
     
                        rowsleft -=  (long)repeatcount + 1 ;
                        repeatcount = 0 ;
                        rp = 1 ;
                        word = 0 ;
                        wordweight = 32 ;
                        count -= hbit ;
                        hbit = (long)ce->width ;
                    } else {
                        if (turnon) word += gpower[wordweight] ;
                        row[rp] = word ;
                        rp = rp + 1 ;
                        word = 0 ;
                        count -= wordweight ;
                        hbit -= wordweight ;
                        wordweight = 32 ;
                    }
                }   /* .....while count > 0 */
                if (turnon)
                        turnon = FALSE;
                else
                        turnon = TRUE;
            } /* ...... rowsleft > 0 */
            if ((rowsleft != 0) || (hbit != (long)ce->width))
                    Fatal("Bad pk file----more bits than required!\n");
    } /* .... create normally packed raster */
}
     
     
unsigned char   getnyb ()
{
        register unsigned char  temp ;
        if ( bitweight == 0 ) {
                inputbyte = PKBYTE ;
                bitweight = 16 ;
        }
        temp = inputbyte / bitweight ;
        inputbyte -= temp * bitweight ;
        bitweight /= 16 ;
        return ( temp ) ;
}
     
     
long
pk_packed_num ()
{ /*@<Packed number procedure@>= */
        register int    i;
        long    j;
     
        i = (int)getnyb();
        if (i == 0) {
                do {
                        j = (long)getnyb();
                        i++;
                } while (j == 0) ;
                while (i > 0) {
                        j = j * 16 + (long)getnyb() ;
                        i--;
                };
                return (j - 15 + (13 - dyn_f) * 16 + dyn_f) ;
        } else if (i <= (int)dyn_f) {
                return ((long)i);
        } else if (i < 14) {
                return ((i-(long)dyn_f - 1) * 16 + (long)getnyb() + dyn_f + 1);
        } else {
                if (i == 14) {
                        repeatcount = (int) pk_packed_num() ;
                } else {
                        repeatcount = 1 ;
                }
                /*      printf("repeatcount = [%d]\n",repeatcount);    */
                return (pk_packed_num()) ;    /* tail end recursion !! */
        }
}
     
     


/*-->ReadFontDef*/
/**********************************************************************/
/****************************  ReadFontDef  ***************************/
/**********************************************************************/
void
ReadFontDef(k)
long    k;
{
        long    t;
        unsigned short i;
        char    n[STRSIZE];
        struct font_entry *tfontptr; /* temporary font_entry pointer   */
        struct char_entry *tcharptr; /* temporary char_entry pointer  */
        static int      plusid = 1;
        bool font_found = FALSE;
#ifdef DEBUG
        if (Debug)
                printf("Mallocating %d Bytes)...\n",
                    sizeof(struct font_entry ));
#endif
     
        if ((tfontptr = NEW(struct font_entry )) == NULL)
                Fatal("can't malloc space for font_entry");
     
        allocated_storage += sizeof(struct font_entry );
     
        tfontptr->next = hfontptr;
        tfontptr->font_file_id = NULL;
        fontptr = hfontptr = tfontptr;
        tfontptr->ncdl = 0;
        tfontptr->k = k;
        tfontptr->c = NoSignExtend(dvifp, 4); /* checksum */
        tfontptr->s = NoSignExtend(dvifp, 4); /* space size */
        tfontptr->d = NoSignExtend(dvifp, 4); /* design size */
        tfontptr->a = (int) NoSignExtend(dvifp, 1); /* length for font name */
        tfontptr->l = (int) NoSignExtend(dvifp, 1); /* device length */
     
        GetBytes(dvifp, n, tfontptr->a + tfontptr->l);
        n[tfontptr->a+tfontptr->l] = '\0';
        /*   tfontptr->font_space = tfontptr->s/6;*/ /* never used */
     
        tfontptr->font_mag = (long)((
             ActualFactor((long)(1000.0*tfontptr->s/(double)tfontptr->d+0.5))
             * ActualFactor(mag)
             * RESOLUTION * 5.0
                   ) + 0.5);
/*
printf("[%ld]=%lf * %lf * %lf + 0.5 = %ld\n",
    ((long)(1000.0*tfontptr->s/(double)tfontptr->d+0.5)),
    ActualFactor((long)(1000.0*tfontptr->s/(double)tfontptr->d+0.5)),
    ActualFactor(mag),
    (double)RESOLUTION * 5,
    tfontptr->font_mag );
*/
     
/*
        tfontptr->font_mag =
            (long)((ActualFactor((long)(((double)tfontptr->s
            /(double)tfontptr->d)
            *1000.0 ))
            *ActualFactor(mag) *
            (double)RESOLUTION * 5.0) + 0.5);
*/
/*            *1000.0 + 0.5)) */
     
        if (!(font_found =
              findfile(PXLpath, n, tfontptr->font_mag, tfontptr->name))) {
                  Warning(tfontptr->name); /* contains error messsage */
                  tfontptr->font_file_id = NO_FILE;
            }
        else
        if (!( (G_noverbatim) || (G_quiet) ) )
                printf("using font <%s>\n", tfontptr->name);
     
        /* sprintf(tfontptr->psname,"%s.%ld.%d",
       tfontptr->n,tfontptr->font_mag,plusid);*/
     
        tfontptr->plusid = plusid;
        plusid++;
        if (tfontptr != pfontptr) {
                if (font_found)
                        OpenFontFile();
                else
                        pxlfp = NO_FILE;
        }
        if ( pxlfp == NO_FILE ) {                /* allow missing pxl files */
                tfontptr->magnification = 0;
                tfontptr->designsize = 0;
                for (i = FIRSTPXLCHAR; i <= LASTPXLCHAR; i++) {
                        tcharptr = &(tfontptr->ch[i]);
                        tcharptr->width = 0;
                        tcharptr->height = 0;
                        tcharptr->xOffset = 0;
                        tcharptr->yOffset = 0;
                        tcharptr->where.isloaded = FALSE;
                        tcharptr->where.address.fileOffset = NONEXISTANT;
                        tcharptr->tfmw = 0;
                }
                return;
        }
        t = (long) NoSignExtend(pxlfp, 1);
        if (t == 0) {
                t = (long) NoSignExtend(pxlfp, 1);
                t = (long) NoSignExtend(pxlfp, 2);
                if (t == 1002)
                        tfontptr->id = id1002;
                else if (t == 1001)
                        tfontptr->id = id1001;
                else
                        Fatal("Unknown Version of PXL-format\n");
        } else {
                if (t == PK_PRE)    {
                        unsigned char   temp_byte;
                        temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
                        if (temp_byte != PK_ID)
                               Fatal(
                           "Wrong Version of packed file!  (%d should be 89)\n",
                                                         (int)temp_byte);
                        else
                                tfontptr->id = pk89;
                } else
                        Fatal("unknown font format!\n");
        }
     
        if ((tfontptr->id == id1002) || (tfontptr->id == id1001)) {
                fseek(pxlfp, -20l, 2);
     
                t = NoSignExtend(pxlfp, 4);
                if ((tfontptr->c != 0) && (t != 0) && (tfontptr->c != t))
        Warning("font = \"%s\",\n->tfm checksum = %lX,\n->pxl checksum = %lX",
                                              tfontptr->name, tfontptr->c,
                            t);
                tfontptr->magnification = NoSignExtend(pxlfp, 4);
                tfontptr->designsize = NoSignExtend(pxlfp, 4);
     
                if (tfontptr->id == id1001)
                        fseek(pxlfp, (long) (NoSignExtend(pxlfp, 4) * 4),
                             0);
                else
                        fseek(pxlfp, (long) NoSignExtend(pxlfp, 4) , 0);
     
                for (i = FIRSTPXLCHAR; i <= LASTPXLCHAR; i++) {
                        tcharptr = &(tfontptr->ch[i]);
                        tcharptr->width =
                            (unsigned short) NoSignExtend(pxlfp, 2);
                        tcharptr->height =
                            (unsigned short) NoSignExtend(pxlfp, 2);
                        tcharptr->xOffset = (short) SignExtend(pxlfp, 2);
                        tcharptr->yOffset = (short) SignExtend(pxlfp, 2);
                        tcharptr->where.isloaded = FALSE;
                        if (tfontptr->id == id1001)
                                tcharptr->where.address.fileOffset =
                                      NoSignExtend(pxlfp, 4) * 4;
                        else
                                tcharptr->where.address.fileOffset =
                                      NoSignExtend(pxlfp, 4);
                        tcharptr->tfmw = (long)
                        (   (double)(NoSignExtend(pxlfp, 4))
                          * (double)tfontptr->s
                          / (double) 0x100000 );
                        tcharptr->cw = (long)(((double)tcharptr->tfmw /
                            (double)hconv) + 0.5);
     
                        if (tcharptr->width  > CHAR_WIDTH_LARGE  ||
                            tcharptr->height > CHAR_HEIGTH_LARGE )
                                tcharptr->charsize = LARGE_SIZE;
                        else
                                tcharptr->charsize = SMALL_SIZE;
     
                }
        } else { /* PK 89 format */
                unsigned char   temp_byte;
                register unsigned char  flag_byte;
                long    hppp, vppp, pkloc, packet_length, temp;
                int     car, ii;
     
                for (i = FIRSTPXLCHAR; i <= LASTPXLCHAR; i++) {
                        tcharptr = &(tfontptr->ch[i]);
                        tcharptr->width = 0;
                        tcharptr->height = 0;
                        tcharptr->xOffset = 0;
                        tcharptr->yOffset = 0;
                        tcharptr->where.isloaded = FALSE;
                        tcharptr->where.address.fileOffset = NONEXISTANT;
                        tcharptr->tfmw = 0;
                }
     
                /* read comment */
                temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
                for ( ii = 1 ; ii <= (int) temp_byte ; ii++) {
                        flag_byte = (unsigned char) NoSignExtend(pxlfp,
                             1);
#ifdef DEBUG
                        if (Debug)
                                fprintf(stdout, "%c", flag_byte ) ;
#endif
                }
#ifdef DEBUG
                if (Debug)
                        fprintf(stdout, "\n");
#endif
                pkloc = 3 + (int)temp_byte;
     
                tfontptr->designsize = NoSignExtend(pxlfp, 4);
                ;
     
                t = NoSignExtend(pxlfp, 4);
                if ((tfontptr->c != 0) && (t != 0) && (tfontptr->c != t))
         Warning("font = \"%s\",\n->tfm checksum = %lX,\n->pxl checksum = %lX",
                                     tfontptr->name, tfontptr->c, t);
     
                hppp = NoSignExtend(pxlfp, 4);
                vppp = NoSignExtend(pxlfp, 4);
                if (hppp != vppp)
                        Warning("aspect ratio is %ld:%ld (should be 1:1)!",
                        hppp,vppp) ;
                tfontptr->magnification = (long)(hppp * 72.27 * 5 / 65536l +
                    0.5) ;
     
                pkloc += 16;
                flag_byte = skip_specials(&pkloc);
     
                while (flag_byte != PK_POST) {
                        if ((flag_byte & 7) == 7) {
                           Fatal(
                           "\7\7\7  This PK-Packet type is NOT IMPLEMENTED!\n");
                        } else if (flag_byte & 4) {
     
                /*fprintf(stdout,"Read extended short character preamble\n");*/
     
                                packet_length = ((long) flag_byte & 3) *
                                    65536l +
                                    (unsigned short) NoSignExtend(pxlfp, 2);
                                car = (int)  NoSignExtend(pxlfp, 1);
                                if (car > 127)
                                        Fatal("Bad character in PK-File\n") ;
                                tcharptr = &(tfontptr->ch[car]);
                                tcharptr->where.address.fileOffset = pkloc;
                                /* set pkloc to end_of_packet */
                                pkloc += packet_length + 3;
                                { register unsigned short t;
                                  t = (unsigned short) NoSignExtend(pxlfp, 1);
                                  tcharptr->tfmw =
                                      t * 65536l +
                                      (unsigned short) NoSignExtend(pxlfp, 2);
                                }
                                /* horesc not used */
                                (void) NoSignExtend(pxlfp, 2) ;
                                tcharptr ->width   =
                                    (unsigned short) NoSignExtend(pxlfp, 2) ;
                                tcharptr ->height  =
                                    (unsigned short) NoSignExtend(pxlfp, 2);
                                tcharptr ->xOffset =
                                    (short) SignExtend(pxlfp, 2);
                                tcharptr ->yOffset =
                                    (short) SignExtend(pxlfp, 2);
                                tcharptr ->where.isloaded = FALSE;
                        } else {
/*               fprintf(stdout,"<Read short character preamble@>\n");*/
                                packet_length = ((long)flag_byte & 3) *
                                    256 +
                                    NoSignExtend(pxlfp, 1) ;
                                car = (int)  NoSignExtend(pxlfp, 1);
                                if (car > 127)
                                        Fatal("Bad character in PK-File\n") ;
                                tcharptr = &(tfontptr->ch[car]);
                                tcharptr->where.address.fileOffset = pkloc;
                                /* set pkloc to end_of_packet */
                                pkloc += packet_length + 2 ;
                                { register unsigned short t;
                                  t = (unsigned short) NoSignExtend(pxlfp, 1);
                                  tcharptr->tfmw =
                                      t * 65536l +
                                      (unsigned short) NoSignExtend(pxlfp, 2);
                                }
                                /* horesc not used */
                                (void) NoSignExtend(pxlfp, 1) ;
                                tcharptr ->width   =
                                    (unsigned short) NoSignExtend(pxlfp, 1) ;
                                tcharptr ->height  =
                                    (unsigned short) NoSignExtend(pxlfp, 1);
                                tcharptr ->xOffset =
                                    (short) SignExtend(pxlfp, 1);
                                tcharptr ->yOffset =
                                    (short) SignExtend(pxlfp, 1);
                                tcharptr ->where.isloaded = FALSE;
                        }
     
                        tcharptr->tfmw = (long)
                        (   tcharptr->tfmw * (double)tfontptr->s /
                            (double) 0x100000 );
     
                        tcharptr->cw = (long)(((double)tcharptr->tfmw /
                            (double)hconv) + 0.5);
     
                        if (tcharptr->width  > CHAR_WIDTH_LARGE  ||
                            tcharptr->height > CHAR_HEIGTH_LARGE )
                                tcharptr->charsize = LARGE_SIZE;
                        else
                                tcharptr->charsize = SMALL_SIZE;
     
                        tcharptr->flag_byte = flag_byte;
                        fseek(pxlfp, (long) pkloc, 0);
                        /*fprintf(stdout,"new pkloc is %ld\n",pkloc);*/
                        flag_byte = skip_specials(&pkloc);
     
                } /* end of while */
     
     
/*****************************************************************************/
/*if (tcharptr->charsize==LARGE_SIZE)                                         */
/*     printf("%d:\t <%c> w=%d h=%d xO=%d yO=%d tfmw=%ld cw=%ld %d\n",      */
/*     i,(char) i,                                                           */
/*     tcharptr->width,tcharptr->height,tcharptr->xOffset,tcharptr->yOffset, */
/*     tcharptr->tfmw, tcharptr->cw, (int)(tcharptr->charsize));             */
/*                                                                           */
/*****************************************************************************/
        }
}
     
     
unsigned char
skip_specials( pkloc )
long    *pkloc;
{
        long    i, j;
        register unsigned char  flag_byte;
        do {
                flag_byte = (unsigned char) NoSignExtend(pxlfp, 1) ;
                (*pkloc) ++;
                if (flag_byte  >= 240)
                        switch (flag_byte) {
                        case 240:
                        case 241:
                        case 242:
                        case 243 :
                                 {
                  /*fprintf(stdout,"flagbyte = %d\n",(int)flag_byte);*/
                                        i = 0 ;
                                        for (j = 240; j <= (long)flag_byte;
                                            j++) {
                                                i = 256 * i +
                                                    NoSignExtend(pxlfp, 1) ;
                                                (*pkloc) ++;
                                        }
                                        for (j = 1; j <= i; j++) {
                                                (void) NoSignExtend(pxlfp, 1) ;
                                                (*pkloc) ++;
                                        }
                                        break;
                                }
                        case 244 :
                                 {
                                        i = NoSignExtend(pxlfp, 4);
                                        (*pkloc) += 4;
                                        break;
                                }
                        case 245 :
                                break;
                        case 246 :
                                break ;
                        case 247:
                        case 248:
                        case 249:
                        case 250:
                        case 251:
                        case 252:
                        case 253:
                        case 254:
                        case 255:
                                 {
                                        Fatal("Unexpected flagbyte %d!\n",
                                             (int)flag_byte) ;
                                }
                        }
        } while (!((flag_byte < 240) || (flag_byte == PK_POST))) ;
        return(flag_byte);
}
     
     
/*-->ReadPostAmble*/
/**********************************************************************/
/**************************  ReadPostAmble  ***************************/
/**********************************************************************/
/***********************************************************************
    This  routine  is  used  to  read  in  the  postamble  values.    It
    initializes the magnification and checks  the stack height prior  to
    starting printing the document.
***********************************************************************/
void
ReadPostAmble(load)
bool load;
{
        FindPostAmblePtr (&postambleptr);
        if (NoSignExtend(dvifp, 1) != POST)
                Fatal ("POST missing at head of postamble");
#ifdef DEBUG
        if (Debug)
                printf("got POST command\n");
#endif
        ppagep = NoSignExtend(dvifp, 4);
        num = NoSignExtend(dvifp, 4);
        den = NoSignExtend(dvifp, 4);
        mag = NoSignExtend(dvifp, 4);
        if ( usermag > 0 && usermag != mag && (!G_quiet))
                Warning("DVI magnification of %ld over-ridden by user (%ld)",
                                     mag, usermag );
        if ( usermag > 0 )
                mag = usermag;
        hconv = DoConv(num, den, hconvRESOLUTION);
        vconv = DoConv(num, den, vconvRESOLUTION);
        (void) NoSignExtend(dvifp, 4);   /* height-plus-depth of tallest page */
        (void) NoSignExtend(dvifp, 4);   /* width of widest page */
        if (NoSignExtend(dvifp, 2) >= STACKSIZE)
                Fatal ("Stack size is too small");
        (void) NoSignExtend(dvifp, 2);   /* this reads the number of pages in */
                                         /* the DVI file */
#ifdef DEBUG
        if (Debug)
                printf("now reading font defs");
#endif
        if (load)
                GetFontDef ();
}
     
     
/*-->LoadAChar*/
/**********************************************************************/
/***************************** LoadAChar ******************************/
/**********************************************************************/
void
LoadAChar(c, ptr)
long    c;
register struct char_entry *ptr;
{
        long    *pr;
        long    bytes;
     
        if (ptr->where.address.fileOffset == NONEXISTANT) {
                ptr->where.address.pixptr = NULL;
                ptr->where.isloaded = TRUE;
                return;
        }
     
        OpenFontFile();
        fseek(pxlfp, ptr->where.address.fileOffset, 0);
     
        /***************************************************/
        /*printf("LoadAChar: <%c> from file at pos %ld\n", */
        /*    (char)c,ptr->where.address.fileOffset);      */
        /***************************************************/
     
        if (fontptr->id == pk89) {
#ifdef PARANOIA
                unsigned char   temp;
                temp = (unsigned short) NoSignExtend(pxlfp, 1);
     
                if ((int)ptr->flag_byte != (int)temp)
                        ) {
                                Fatal("oh boy! old flag %d, new flag %d\n",
                                              (int)ptr->flag_byte, (int)temp);
                        }
#endif
                if (ptr->flag_byte & 4) {
                        bytes = ((long)ptr->flag_byte & 3)
                                * 65536l + NoSignExtend(pxlfp, 2) - 13;
                        fseek(pxlfp, ptr->where.address.fileOffset + 16, 0);
                } else {
                        bytes = ((long)ptr->flag_byte & 3)
                                * 256 + NoSignExtend(pxlfp, 1) - 8;
                        fseek(pxlfp, ptr->where.address.fileOffset + 10, 0);
                }
        } else if (fontptr->id == id1002)
                bytes =  ((( (long)ptr->width + 7) >> 3) * (long) ptr->height);
        else if (fontptr->id == id1001)
                bytes =  4 * (((long)ptr->width + 31) >> 5) * (long)ptr->height;
     
     
        if (bytes > HUGE_CHAR_PATTERN) { /* do NOT load Huge characters */
                if (!G_quiet)
                        printf("Huge Character <%c> (%ld Bytes)\n", (char)c,
                             bytes);
                ptr->charsize = HUGE_SIZE;
                ptr->where.isloaded = FALSE;
        } else {
                if ( (pr = (long *)malloc( bytes )) == NULL )
                        Fatal("Unable to allocate %ld bytes for char <%c>\n",
                                             bytes, (char)c);
#ifdef DEBUG
                /* if (Debug) */
                printf(
                  "Allocating Char <%c>, FileOffset=%lX, Bytes=%ld (%d) <%d>\n",
                    (char) c, ptr->where.address.fileOffset, bytes,
                    (int)bytes, (unsigned int)bytes);
#endif
                allocated_storage += bytes;
                fread(pr, 1, (int) bytes , pxlfp);
                ptr->where.address.pixptr = pr;
        }
     
        ptr->where.isloaded = TRUE;
        if (ptr->charsize != SMALL_SIZE)
                return;
        EmitChar(c, ptr);
        /* we should really free the space used by the PXL data after this
           point, but it is not large, and besides, we may want to be
           more clever in the future, about sending bitmaps.  So keep
           the data around */
}
/*-->SetChar*/
/**********************************************************************/
/*****************************  SetChar  ******************************/
/**********************************************************************/
void
SetChar(c, command, PassNo, do_posn,in_string)
long    c;
short   command;
int     PassNo;
bool do_posn,in_string;
{
        register struct char_entry *ptr;  /* temporary char_entry pointer */
        bool pos_after = FALSE;
     
        ptr = &(fontptr->ch[c]);
        if (!((ptr->where.isloaded) || (ptr->charsize == HUGE_SIZE)))
                LoadAChar(c, ptr);
        if (PassNo == 0)
                return;
     
        if (do_posn) {
#ifdef IBM3812
            if (CharStringPos>0) {
                    printf("!!!! That should never happen!!!\n");
                    CharStringOut;
            }
#endif
            SetPosn(h, v);
        }
/*
printf("(%d) hh=%ld (+%ld/+%ld), h=%ld, xh=%ld,xhh=%ld, [%ld|%ld] ->%d\n",
        (int)do_posn,hh,(long)ptr->cw,(long)ptr->cw*(long)hconv,h,
        PIXROUND(h, hconv),
        PIXROUND(hh, hconv),
        labs((hh-h)),hconv,(labs((hh-h))>hconv)
        );
*/
        if (in_string && (labs((hh-h))>hconv)) {
#ifdef IBM3812
                CharStringOut;
#endif
                SetPosn(h, v);
        }
     
        if (fontptr->font_file_id != NO_FILE) {      /* ignore missing fonts */
                if (ptr->charsize != SMALL_SIZE) {
                        int     tmp;
                        char    sign;
#ifdef LJ
                        if (!do_posn)
                                SetPosn(h, v);
                        sign = '+';
                        tmp = (int) -ptr->yOffset;
                        if (tmp < 0)
                                sign = '-', tmp = -tmp;
                        EMIT(outfp, "\033*p%c%dY", sign, tmp);
                        sign = '+';
                        tmp = (int) -ptr->xOffset;
                        if (tmp < 0)
                                sign = '-', tmp = -tmp;
                        EMIT(outfp, "\033*p%c%dX", sign, tmp);
#endif
#ifdef IBM3812
                        CharStringOut;
#endif
                        RasterChar(c, ptr);
                        pos_after = TRUE;
                } else {
#ifdef IBM3812
                        if ( ptr->yyOffset || (!in_string) ) {
                                CharStringOut;
                                MoveVert(ptr->yyOffset);
                                sprintf(PMPformat, "\01%c", VisChar((char)c));
                                PMPout(2, PMPformat);
                                MoveVert((int)-(ptr->yyOffset));
                        } else {
                                if (CharStringPos==CHARSTRINGMAX)
                                        CharStringOut;
     
                                CharString[CharStringPos]=VisChar((char)c);
                                CharStringPos++;
                        }
#endif
#ifdef LJ
                        if (ptr->yyOffset) {
                                EMIT(outfp, "\033*p+%hdY", ptr->yyOffset);
                                EMITC((char) VisChar((char)c));
                                EMIT(outfp, "\033*p-%hdY", ptr->yyOffset);
                        } else
                                EMITC((char) VisChar((char)c));
#endif
                }
                hh += (long) ptr->cw*hconv;
        }
        if (command <= SET4)
                h += ptr->tfmw;
        if (pos_after)
                SetPosn(h, v);
}
     
     
void
DoBop()
{
        struct font_entry *p;
#ifdef LJ
        fonts_used_on_this_page = 0;
#endif
        for (p = hfontptr; p; p = p->next) {
                p->used_on_this_page = FALSE;
        }
}
     
     
/*-->SetFntNum*/
/**********************************************************************/
/****************************  SetFntNum  *****************************/
/**********************************************************************/
void
SetFntNum(k, Emitting)
long    k;
bool Emitting;
/*  this routine is used to specify the font to be used in printing future
    characters */
{
        fontptr = hfontptr;
        while ((fontptr != NULL) && (fontptr->k != k))
                fontptr = fontptr->next;
        if (fontptr == NULL)
                Fatal("font %ld undefined", k);
        if (Emitting && (fontptr->font_file_id != NO_FILE) ) {
                if (!fontptr->used_on_this_page) {
                        fontptr->used_on_this_page = TRUE;
                        ;
#ifdef LJ
                        if (++fonts_used_on_this_page > MAX_FONTS_PER_PAGE) {
                           Fatal("Too many fonts on a page! (maximum is %d)\n",
                                                           MAX_FONTS_PER_PAGE);
                        }
#endif
                }
     
                /* activate font */
#ifdef IBM3812
                sprintf(PMPformat, "\323%c", (unsigned char)fontptr->plusid);
                PMPout(2, PMPformat);
#endif
#ifdef LJ
                EMIT(outfp, "\033(%dX", fontptr->plusid);
#endif
        }
}
     
     
/*-->SetPosn*/
/**********************************************************************/
/*****************************  SetPosn  ******************************/
/**********************************************************************/
void                                  /* output a positioning command */
SetPosn(x, y)
long    x, y;
{
        int     rx, ry;
        rx = (int)PIXROUND(x, hconv);
        ry = (int)PIXROUND(y, vconv);
     
/*
printf("setposn to %d/%d  [%d,%d]\n",rx,ry,rx+x_goffset,ry+y_goffset);
*/
     
#ifdef IBM3812
        PMPcont(3);
        PMPoutC('\340');
        EMITWORD(rx + x_goffset);
     
        if (last_ry != ry) { /* necessary to set new y-position */
                PMPcont(3);
                PMPoutC('\341');
                EMITWORD(ry + y_goffset);
        }
#endif
#ifdef LJ
        if (last_ry != ry)   /* necessary to set new y-position */
                EMIT(outfp, "\033*p%dx%dY", rx + x_goffset, ry + y_goffset);
        else
                EMIT(outfp, "\033*p%dX", rx + x_goffset);
#endif
     
        last_ry = ry;        /* last y-position on output device */
/*
 * must know where device "really" is horizontally, for rel. posning.
 * (maybe in the future), but we always use direct positioning for
 * vertical movement.
 */
        /* hh = rx * hconv; */
        hh = x;
        vv = y;
/*
 *      printf("DoPosn: x=%ld, y=%ld, rx=%d, ry=%d, hh=%ld, vv=%ld\n",
 *                       x,y,rx,ry,hh,vv);
 */
}
     
     
#ifdef IBM3812
/*-->PMPLine*/
/**********************************************************************/
/*****************************  PMPLine  ******************************/
/**********************************************************************/
void           /* drawing lines on the 3812 using PMP vector commands */
PMPLine(w, y, x)
int     w, y, x;
{
     
        if ((w == 0) || ((x == 0) && (y == 0)))
                return;
     
        if ( ( (int)((char)(x & 0xff)) == x ) &&
            ( (int)((char)(y & 0xff)) == y ) ) {
                PMPcont(6);
                PMPout(1, "\370");
                EMITWORD(3);      /* length of vector */
                PMPoutC((unsigned char)(0x80 | 0x00 | (unsigned char) w));
                PMPoutC((char)(y & 0xff));
                PMPoutC((char)(x & 0xff));
                /* printf("F8 00 03: w=%d, x=%d(%d-%.2X), y=%d(%d-%.2X),\n",
            w,x,(char)(x & 0xff),(char)(x & 0xff),
              y,(char)(y & 0xff),(char)(y & 0xff));*/
        } else {
                PMPcont(8);
                PMPout(1, "\370");
                EMITWORD(4 + 1);      /* length of vector */
                PMPoutC((unsigned char)(0xC0 | 0x00 | (unsigned char) w));
                EMITWORD(y);
                EMITWORD(x);
                /*printf("F8 00 05: w=%d, x=%d, y=%d,\n", w,x,y);*/
        }
}
     
     
#endif
/*-->SetRule*/
/**********************************************************************/
/*****************************  SetRule  ******************************/
/**********************************************************************/
void                               /*   this routine will draw a rule */
SetRule(a, b, Set)
long    a, b;
int     Set;
{
        long    xx, yy;
        short   hor_offset, vert_offset, ll;
     
        if ( a > 0 && b > 0 ) {
                SetPosn(h, v);                     /* lower left corner */
                xx = (long)PIXROUND(b, hconv);     /* width */
                yy = (long)PIXROUND(a, vconv);     /* height */
     
#ifdef DEBUG
                if (Debug)
                        printf("Rule xx=%ld, yy=%ld\n", xx, yy);
#endif
     
#ifdef IBM3812
                if ((xx > 31) && (yy > 31)) {
/*
 *   fill area by multiple lines  (kind of a mess)
 *   process for simplicity always horizontally
 */
     
/* printf("large box: w=%d, x=%d, y=%d\n",(int)yy,(int)xx,0);*/
     
                        hor_offset  = HOR_HALF(30);
                        MoveHor(hor_offset);
                        vert_offset = VERT_HALF(30);
                        MoveVert(-vert_offset);
                        ll = (short)xx - 30;
     
                        for (; yy > 30; yy -= 30) {
                                PMPLine(30, 0, ll);
                                MoveHor(-ll);
                                MoveVert(-30);
                        }
     
                        hor_offset  = -hor_offset     + HOR_HALF(yy);
                        MoveHor(hor_offset);
                        vert_offset = (vert_offset - 30) + VERT_HALF(yy);
                        MoveVert(-vert_offset);
     
                        PMPLine((int)yy, 0, (int)(xx - yy));
     
                } else if ( (yy < xx) && (xx > 0) ) {
     
/* printf("hori rule: w=%d, x=%d, y=%d\n",(int)yy,(int)(xx-yy),0);*/
     
                        hor_offset  = HOR_HALF(yy);
                        vert_offset = VERT_HALF(yy);
     
                        MoveHor(hor_offset);
                        MoveVert(-vert_offset);
     
                        PMPLine((int)yy, 0, (int)(xx - yy));
                } else if ( (xx < yy) && (yy > 0)) {
     
                        hor_offset  = HOR_HALF(xx);
                        vert_offset = VERT_HALF(xx);
/*
 printf("move: x=%d, y=%d\n",hor_offset,-vert_offset);
 printf("vert rule: w=%d, x=%d, y=%d\n",(int)xx,0,(int)-(yy-xx));
*/
                        MoveHor(hor_offset);
                        MoveVert(-vert_offset);
     
                        PMPLine((int)xx, (int)-(yy - xx), 0);
                } else if (xx = yy) {
                        short     y0;  /* small square box!! */
     
                        y0 = (short)yy / 2;
                        hor_offset  = HOR_HALF(y0);
                        MoveHor(hor_offset);
                        vert_offset = VERT_HALF(y0);
                        MoveVert(-vert_offset);
                        ll = (short)xx - y0;
     
                        PMPLine((int)y0, 0, ll);
     
                        hor_offset  = -(ll + hor_offset);
                        vert_offset = (y0 - vert_offset);
     
                        yy -= (long)y0;
                        hor_offset  += HOR_HALF(yy);
                        MoveHor(hor_offset);
                        vert_offset += VERT_HALF(yy);
                        MoveVert(-vert_offset);
     
                        PMPLine((int)yy, 0, (int)xx - yy);
                }
#endif
#ifdef LJ
                EMIT(outfp, "\033*p-%ldY\033*c%lda%ldb0P", yy - 1, xx, yy);
#endif
                last_ry = UNKNOWN;           /* next time full positioning */
        }
        if (Set)
                h += b;
}
     
     
/*-->SetString*/
/**********************************************************************/
/*****************************  SetString  ****************************/
/**********************************************************************/
void
SetString(firstch, PassNo)    /* read and set a consecutive string of chars */
short   firstch;
int     PassNo;
{
        short   c;
        register unsigned short i;
     
/* printf("SetString\n"); */
        for (i = 0, c = firstch; c >= SETC_000 && c <= SETC_127; i++) {
                SetChar((long)c,  c, PassNo, (bool)(i==0),TRUE);
                c = (short) NoSignExtend(dvifp, 1);
        }
        fseek(dvifp, -1l, 1);        /* backup one character */
#ifdef IBM3812
        CharStringOut;
#endif
/* printf("...SetString\n");*/
}
     
     
/*-->SignExtend*/
/**********************************************************************/
/****************************  SignExtend  ****************************/
/**********************************************************************/
long
SignExtend(fp, n)   /* return n byte quantity from file fd */
register FILE *fp;  /* file pointer    */
register int    n;  /* number of bytes */
{
        int     n1;     /* number of bytes      */
        long    x;      /* number being constructed */
        x = getc(fp);   /* get first (high-order) byte */
        n1 = n--;
        while (n--)  {
                x <<= 8;
                x |= getc(fp);
        }
/*
 *   NOTE: This code assumes that the right-shift is an arithmetic, rather
 *   than logical, shift which will propagate the sign bit right.   According
 *   to Kernighan and Ritchie, this is compiler dependent!
 */
        x <<= 32 - 8 * n1;
        x >>= 32 - 8 * n1; /* sign extend */
#ifdef DEBUG
        if (Debug)
                printf("\tSignExtend(fp,%d)=%X\n", n1, x);
#endif
        return(x);
}
     
     
/*-->SkipFontDef*/
/**********************************************************************/
/****************************  SkipFontDef  ***************************/
/**********************************************************************/
void
SkipFontDef(k)
int     k;
{
        int     a, l;
        char    n[STRSIZE];
     
        (void) NoSignExtend(dvifp, 4);
        (void) NoSignExtend(dvifp, 4);
        (void) NoSignExtend(dvifp, 4);
        a = (int) NoSignExtend(dvifp, 1);
        l = (int) NoSignExtend(dvifp, 1);
        GetBytes(dvifp, n, a + l);
}
     
     


@EOF

chmod 666 dvilj.c-part3

exit 0
-- 
Michael Haberler		mah@hpuviea.uucp 
Hewlett-Packard Austria GmbH, 	...mcvax!tuvie!hpuviea!mah
Lieblgasse 1 			...hplabs!hpfcla!hpbbn!hpuviea!mah
A-1220 Vienna, Austria		Tel: (0043) (222) 2500 x412 (9-18 CET)