Annotation of coherent/d/bin/nroff/drv/hpljet.c,v, revision 1.1.1.1

1.1       root        1: head     1.1;
                      2: access   ;
                      3: symbols  ;
                      4: locks    ;
                      5: comment  @ * @;
                      6: 
                      7: 
                      8: 1.1
                      9: date     91.02.04.16.45.44;  author bin;  state Exp;
                     10: branches ;
                     11: next   ;
                     12: 
                     13: 
                     14: desc
                     15: @init ver prov by stevesf
                     16: @
                     17: 
                     18: 
                     19: 
                     20: 1.1
                     21: log
                     22: @Initial revision
                     23: @
                     24: text
                     25: @/* (-lgl
                     26:  *     The information contained herein is a trade secret of Mark Williams
                     27:  *     Company, and  is confidential information.  It is provided  under a
                     28:  *     license agreement,  and may be  copied or disclosed  only under the
                     29:  *     terms of  that agreement.  Any  reproduction or disclosure  of this
                     30:  *     material without the express written authorization of Mark Williams
                     31:  *     Company or persuant to the license agreement is unlawful.
                     32:  * 
                     33:  *     troff-nroff Version 002
                     34:  *     Copyright (c) 1984-1986.
                     35:  *     An unpublished work by Mark Williams Company, Chicago.
                     36:  *     All rights reserved.
                     37:  -lgl) */
                     38: /*
                     39:  * Nroff/Troff.
                     40:  * Hewlett-Packard LaserJet 2686A driver.
                     41:  */
                     42: #include <stdio.h>
                     43: #include <ctype.h>
                     44: #include "roff.h"
                     45: #include "code.h"
                     46: #include "char.h"
                     47: #include "env.h"
                     48: #include "font.h"
                     49: 
                     50: 
                     51: #define        bool    int
                     52: #define        not     !
                     53: #define        TRUE    (0==0)
                     54: #define FALSE  (not TRUE)
                     55: #define        LINEH   (720 / 6)               /* amount moved by line feed */
                     56: #define        LBIAS   (11*720/80)             /* laser printer horiz. bias */
                     57: #define        QUANTA  300                     /* actual device resolution */
                     58: #define RESET  "\033E"                 /* Resets laser printer */
                     59: 
                     60: /*
                     61:  * The typedef fwtab is used to hold data on a font.
                     62:  * The entries in f_width * f_psz * f_num / f_den should
                     63:  * be the widths in atomic units (thus, if the table is
                     64:  * in 300ths of an inch then f_psz * f_num / f_den should be
                     65:  * 12/5).
                     66:  */
                     67: typedef struct fwtab {
                     68:        char            *f_cmd;         /* command to select font */
                     69:        int             f_psz;          /* point size (internal units) */
                     70:        long            f_num,          /* width table numerator */
                     71:                        f_den;          /* width table denominator */
                     72:        unsigned char   f_width[99];    /* width table */
                     73: }      fwtab;
                     74: 
                     75: 
                     76: /*
                     77:  * Laser printer initialization string.  This string performs the following
                     78:  * functions:
                     79:  *     reset printer
                     80:  *     6 lines per inch
                     81:  *     66 lines per page
                     82:  *     clear margins
                     83:  *     0 top margin
                     84:  *     66 lines text length
                     85:  *     move to horizontal 0
                     86:  *     move to vertical 0
                     87:  *     select font B
                     88:  */
                     89: static char    linit[] = "\
                     90: \033E\
                     91: \033&l6D\
                     92: \033&l66P\
                     93: \0339\
                     94: \033&l0E\
                     95: \033&l66F\
                     96: \033&a0H\
                     97: \033&a0V\
                     98: \033&l0O\033(0U\033(s1p10v0s0b5T\
                     99: ";
                    100: 
                    101: /*
                    102:  * The string lmove is used to move vertically or horizontally.
                    103:  * It is used by
                    104:  *     printf(lmove, arg, 'V');                for vertical movement
                    105:  *     printf(lmove, arg-LBIAS, 'H');          for horizontal movement
                    106:  */
                    107: static char    lmove[] = "\033&a%d%c";
                    108: 
                    109: /*
                    110:  * Device parameters.
                    111:  */
                    112: int    ntroff  =       TROFF;          /* Programme is TROFF type */
                    113: 
                    114: long   sinmul  =       720;            /* Multiplier for inch */
                    115: long   sindiv  =       1;              /* Divisor for inch */
                    116: 
                    117: long   semmul  =       1;              /* Multiplier for em space */
                    118: long   semdiv  =       1;              /* Divisor for em space */
                    119: 
                    120: long   senmul  =       1;              /* Multiplier for en space */
                    121: long   sendiv  =       2;              /* Divisor for en space */
                    122: 
                    123: long   snrmul  =       1;              /* Narrow space (mul) */
                    124: long   snrdiv  =       6;              /* Narrow space (div) */
                    125: 
                    126: long   swdmul;                         /* Multiplier for width tables */
                    127: long   swddiv;                         /* Divisor for width tables */
                    128: 
                    129: long   shrmul  =       12;             /* Horizontal resolution (mul) */
                    130: long   shrdiv  =       5;              /* Horizontal resolution (div) */
                    131: 
                    132: long   svrmul  =       12;             /* Vertical resolution (mul) */
                    133: long   svrdiv  =       5;              /* Vertical resolution (div) */
                    134: 
                    135: 
                    136: /*
                    137:  * Table to convert from the internal character set to ASCII.
                    138:  */
                    139: char intasc[] ={
                    140:        0,      '0',    '1',    '2',    '3',    '4',    '5',    '6',
                    141:        '7',    '8',    '9',    'A',    'B',    'C',    'D',    'E',
                    142:        'F',    'G',    'H',    'I',    'J',    'K',    'L',    'M',
                    143:        'N',    'O',    'P',    'Q',    'R',    'S',    'T',    'U',
                    144:        'V',    'W',    'X',    'Y',    'Z',    'a',    'b',    'c',
                    145:        'd',    'e',    'f',    'g',    'h',    'i',    'j',    'k',
                    146:        'l',    'm',    'n',    'o',    'p',    'q',    'r',    's',
                    147:        't',    'u',    'v',    'w',    'x',    'y',    'z',    '!',
                    148:        '"',    '#',    '$',    '%',    '&',    '(',    ')',    '*',
                    149:        '+',    ',',    '-',    '.',    '/',    ':',    ';',    '<',
                    150:        '=',    '>',    '?',    '@@',   '[',    '\\',   ']',    '^',
                    151:        '_',    '{',    '|',    '}',    '~',    '`',    '\'',   '\'',
                    152:        '`',    '^',    '-'
                    153: };
                    154: 
                    155: /*
                    156:  * For mapping user fonts to real fonts.
                    157:  */
                    158: FTB fontab[] ={
                    159:        { 'R',  '\0', TRMED },
                    160:        { 'I',  '\0', TRITL },
                    161:        { 'B',  '\0', TRBLD },
                    162:        { 'S',  '\0', TRSML },
                    163:        { 'H',  '\0', HELV },
                    164:        { 'L',  '\0', LPTR },
                    165:        { 'C',  'M', COURMED },
                    166:        { '\0' }
                    167: };
                    168: 
                    169: /*
                    170:  * Driver font information (indexed by font number).
                    171:  */
                    172: fwtab  dfont[] = {
                    173:        {                               /* 92286B Tms Rmn medium upright */
                    174:                "\033&l0O\033(0U\033(s1p10v0s0b5T",
                    175:                100,
                    176:                (long)3, (long)125,
                    177:                {
                    178:                0,      23,     23,     23,     23,     23,     23,     23,
                    179:                23,     23,     23,     35,     29,     31,     34,     30,
                    180:                28,     36,     35,     16,     20,     36,     30,     42,
                    181:                35,     33,     26,     33,     34,     22,     30,     37,
                    182:                34,     38,     36,     33,     31,     21,     25,     21,
                    183:                25,     21,     19,     23,     25,     14,     17,     25,
                    184:                13,     37,     25,     23,     25,     24,     18,     17,
                    185:                15,     25,     24,     34,     24,     24,     20,     12,
                    186:                15,     30,     23,     35,     35,     15,     16,     22,
                    187:                23,     14,     23,     12,     21,     10,     12,     24,
                    188:                24,     24,     22,     39,     13,     21,     14,     24,
                    189:                35,     16,     8,      17,     26,     12,     12,     12,
                    190:                12,     24,     23
                    191:                }
                    192:        },
                    193:        {                               /* 92286B Tms Rmn medium italic */
                    194:                "\033&10O\033(0U\033(s1p10v1s0b5T",
                    195:                100,
                    196:                (long)3, (long)125,
                    197:                {
                    198:                0,      23,     23,     23,     23,     23,     23,     23,
                    199:                23,     23,     23,     30,     29,     31,     33,     29,
                    200:                29,     30,     35,     19,     24,     31,     30,     40,
                    201:                33,     33,     28,     33,     32,     28,     30,     33,
                    202:                31,     35,     34,     29,     33,     23,     22,     20,
                    203:                26,     20,     21,     25,     23,     14,     21,     24,
                    204:                15,     36,     23,     22,     24,     22,     18,     19,
                    205:                14,     22,     19,     31,     26,     23,     23,     17,
                    206:                18,     27,     23,     32,     32,     20,     20,     21,
                    207:                23,     11,     24,     12,     31,     18,     17,     31,
                    208:                26,     31,     21,     42,     24,     13,     24,     23,
                    209:                33,     22,     7,      21,     25,     10,     10,     10,
                    210:                10,     23,     24
                    211:                }
                    212:        },
                    213:        {                               /* 92286B Tms Rmn bold upright */
                    214:                "\033&10O\033(0U\033(s1p10v0s1b5T",
                    215:                100,
                    216:                (long)3, (long)125,
                    217:                {
                    218:                0,      24,     24,     24,     24,     24,     24,     24,
                    219:                24,     24,     24,     34,     32,     31,     32,     29,
                    220:                27,     35,     37,     18,     24,     33,     29,     39,
                    221:                33,     34,     28,     34,     33,     26,     33,     35,
                    222:                33,     40,     32,     31,     32,     23,     24,     21,
                    223:                24,     21,     19,     23,     27,     14,     17,     26,
                    224:                14,     36,     25,     23,     24,     24,     18,     16,
                    225:                16,     24,     20,     31,     24,     23,     20,     14,
                    226:                17,     28,     24,     39,     34,     18,     19,     18,
                    227:                24,     14,     24,     14,     22,     12,     12,     25,
                    228:                26,     25,     22,     40,     13,     22,     14,     26,
                    229:                33,     16,     8,      17,     30,     12,     12,     12,
                    230:                12,     26,     24
                    231:                }
                    232:        },
                    233:        {                               /* 92286B Tms Rmn small */
                    234:                "\033&10O\033(0U\033(s1p8.0v0s-1b5T",
                    235:                80,
                    236:                (long)3, (long)100,
                    237:                {
                    238:                0,      18,     18,     18,     18,     18,     18,     18,
                    239:                18,     18,     18,     26,     25,     25,     27,     24,
                    240:                23,     28,     26,     13,     18,     27,     22,     32,
                    241:                26,     27,     24,     27,     26,     20,     25,     26,
                    242:                26,     36,     26,     26,     22,     18,     20,     16,
                    243:                20,     16,     11,     18,     20,     10,     13,     19,
                    244:                10,     29,     20,     18,     20,     19,     14,     14,
                    245:                14,     20,     19,     25,     19,     19,     16,     10,
                    246:                15,     29,     18,     29,     27,     14,     14,     18,
                    247:                27,     10,     16,     10,     18,     10,     10,     27,
                    248:                27,     27,     17,     27,     10,     18,     10,     18,
                    249:                36,     20,     9,      20,     18,     10,     10,     10,
                    250:                10,     18,     16
                    251:                }
                    252:        },
                    253:        {                               /* 92286B Helvetica */
                    254:                "\033&l0O\033(0U\033(s1p14.4v0s1b4T",
                    255:                144,
                    256:                (long)1, (long)60,
                    257:                {
                    258:                0,      33,     33,     33,     33,     33,     33,     33,
                    259:                33,     33,     33,     43,     41,     41,     44,     37,
                    260:                34,     42,     43,     16,     27,     44,     31,     54,
                    261:                43,     45,     40,     45,     40,     39,     43,     41,
                    262:                44,     61,     42,     41,     39,     31,     34,     29,
                    263:                33,     29,     20,     33,     34,     15,     20,     32,
                    264:                15,     52,     34,     33,     34,     34,     22,     29,
                    265:                24,     34,     32,     48,     32,     32,     28,     22,
                    266:                28,     55,     33,     58,     50,     26,     26,     33,
                    267:                33,     18,     30,     18,     31,     18,     18,     51,
                    268:                51,     51,     35,     52,     22,     31,     20,     33,
                    269:                47,     28,     12,     28,     42,     18,     18,     18,
                    270:                18,     33,     30
                    271:                }
                    272:        },
                    273:        {                       /* 92286F Line Ptr medium upright */
                    274:                "\033&l0O\033(0U\033(sp16.66h8.5vsbT",
                    275:                85,
                    276:                (long)36, (long)425,
                    277:                {
                    278:                0,      6,      6,      6,      6,      6,      6,      6,
                    279:                6,      6,      6,      6,      6,      6,      6,      6,
                    280:                6,      6,      6,      6,      6,      6,      6,      6,
                    281:                6,      6,      6,      6,      6,      6,      6,      6,
                    282:                6,      6,      6,      6,      6,      6,      6,      6,
                    283:                6,      6,      6,      6,      6,      6,      6,      6,
                    284:                6,      6,      6,      6,      6,      6,      6,      6,
                    285:                6,      6,      6,      6,      6,      6,      6,      6,
                    286:                6,      6,      6,      6,      6,      6,      6,      6,
                    287:                6,      6,      6,      6,      6,      6,      6,      6,
                    288:                6,      6,      6,      6,      6,      6,      6,      6,
                    289:                6,      6,      6,      6,      6,      6,      6,      6,
                    290:                6,      6,      6
                    291:                }
                    292:        },
                    293:                                        /* Internal Courier medium upright */
                    294:                "\033&l0O\033(8U\033(s0p10h12v0s0b0T",
                    295:                120,
                    296:                (long)6, (long)100,
                    297:                {
                    298:                0,      18,     18,     18,     18,     18,     18,     18,
                    299:                18,     18,     18,     18,     18,     18,     18,     18,
                    300:                18,     18,     18,     18,     18,     18,     18,     18,
                    301:                18,     18,     18,     18,     18,     18,     18,     18,
                    302:                18,     18,     18,     18,     18,     18,     18,     18,
                    303:                18,     18,     18,     18,     18,     18,     18,     18,
                    304:                18,     18,     18,     18,     18,     18,     18,     18,
                    305:                18,     18,     18,     18,     18,     18,     18,     18,
                    306:                18,     18,     18,     18,     18,     18,     18,     18,
                    307:                18,     18,     18,     18,     18,     18,     18,     18,
                    308:                18,     18,     18,     18,     18,     18,     18,     18,
                    309:                18,     18,     18,     18,     18,     18,     18,     18,
                    310:                18,     18,     18
                    311:                }
                    312:        };
                    313: 
                    314: 
                    315: /*
                    316:  * Set up the non constant parameters that are dependent on a
                    317:  * particular device.  Namely pointsize and font.
                    318:  * Initializes the laser printer.
                    319:  */
                    320: devparm()
                    321: {
                    322:        CODE    cb;
                    323: 
                    324:        printf("%s", linit);
                    325:        cb.c_code = DFONT;
                    326:        cb.c_iarg = TRMED;
                    327:        flushl(&cb, &cb + 1);
                    328:        devfont(TRMED);
                    329: }
                    330: 
                    331: 
                    332: /*
                    333:  * Given a font, consisting of the font number, set the new font
                    334:  * to the one given.
                    335:   */
                    336: devfont(font)
                    337: unsigned       font;
                    338: {
                    339:        register fwtab  *fp;
                    340: 
                    341:        if (font >= sizeof(dfont)/sizeof(*dfont))
                    342:                panic("Bad font %d at devfont", font);
                    343:        newfont = font;
                    344:        fp = &dfont[font];
                    345:        swdmul = fp->f_num;
                    346:        swddiv = fp->f_den;
                    347:        fonwidt = fp->f_width;
                    348:        devpsze(fp->f_psz);
                    349: }
                    350: 
                    351: 
                    352: /*
                    353:  * Change the pointsize to the one specified.
                    354:  */
                    355: devpsze(n)
                    356: {
                    357:        psz = newpsz = n;
                    358: }
                    359: 
                    360: 
                    361: /*
                    362:  * Change the vertical spacing.
                    363:  */
                    364: devvlsp()
                    365: {
                    366:        vls = unit(SMINCH, 6*SDINCH);
                    367: }
                    368: 
                    369: 
                    370: /*
                    371:  * Given a pointer to a buffer containing stream directives
                    372:  * and a pointer to the end of the buffer, print the buffer
                    373:  * out.
                    374:  */
                    375: flushl(buffer, bufend)
                    376: CODE *buffer;
                    377: CODE *bufend;
                    378: {
                    379:        register CODE   *cp;
                    380:        register fwtab  *fp;
                    381:        register int    n;
                    382:        static int      hposd,          /* device horiz. pos (u's) */
                    383:                        hpost,          /* troff horiz. pos (u's) */
                    384:                        vposd,          /* device ver. pos (u's) */
                    385:                        vpost,          /* troff ver. pos (u's) */
                    386:                        font    = -1;   /* current CODE font */
                    387:        static unsigned char *wtab;     /* current CODE width table */
                    388:        static long     wnum,
                    389:                        wden;
                    390:        static int      wpsz;
                    391: 
                    392:        for (cp=buffer; cp<bufend; cp++) {
                    393:                switch (cp->c_code) {
                    394:                case DNULL:             /* Null code */
                    395:                case DHYPH:             /* place to hyphenate */
                    396:                        continue;
                    397:                case DHMOV:             /* move horizontal */
                    398:                case DPADC:             /* paddable character */
                    399:                        hpost += cp->c_iarg;
                    400:                        if (hpost < 0)
                    401:                                hpost = 0;
                    402:                        continue;
                    403:                case DVMOV:             /* move vertically */
                    404:                        vpost += cp->c_iarg;
                    405:                        if (vpost < 0)
                    406:                                vpost = 0;
                    407:                        continue;
                    408:                case DFONT:             /* change font */
                    409:                        if (cp->c_iarg == font)
                    410:                                continue;
                    411:                        if ((unsigned)cp->c_iarg
                    412:                                >= sizeof(dfont) / sizeof(*dfont))
                    413:                                panic("Bad font %d in code stream",
                    414:                                        cp->c_iarg);
                    415:                        font = cp->c_iarg;
                    416:                        fp = &dfont[font];
                    417:                        wtab = fp->f_width;
                    418:                        wnum = fp->f_num * fp->f_psz;
                    419:                        wden = fp->f_den;
                    420:                        wpsz = fp->f_psz;
                    421:                        printf("%s", fp->f_cmd);
                    422:                        continue;
                    423:                case DPSZE:             /* change  pointsize */
                    424:                        /* not implimented yet (Henry) */
                    425:                        if (cp->c_iarg != wpsz)
                    426:                                printe("Code DPSZE not implemented yet");
                    427:                        continue;
                    428:                case DSPAR:             /* space  down and return */
                    429:                        hpost = 0;
                    430:                        vpost += cp->c_iarg;
                    431:                        if (vpost < 0)
                    432:                                vpost = 0;
                    433:                        while (vposd + LINEH <= vpost) {
                    434:                                putchar('\n');
                    435:                                vposd += LINEH;
                    436:                                hposd = 0;
                    437:                        }
                    438:                        continue;
                    439:                default:                /* print something */
                    440:                        /*
                    441:                         * If we need to, we now note we are on a new page.
                    442:                         * Note, the laser goes to funny places when it
                    443:                         * crosses a page boundary.
                    444:                         */
                    445:                        if (vpost >= pgl) {
                    446:                                vpost %= pgl;
                    447:                                vposd = vpost;
                    448:                                printf(lmove, vposd, 'V');
                    449:                                hposd = hpost;
                    450:                                if (hposd < LBIAS)
                    451:                                        hposd = LBIAS;
                    452:                                printf(lmove, hposd-LBIAS, 'H');
                    453:                        } else {
                    454:                                if (vpost != vposd) {
                    455:                                        vposd = vpost;
                    456:                                        printf(lmove, vposd, 'V');
                    457:                                }
                    458:                                if (hpost != hposd) {
                    459:                                        hposd = hpost;
                    460:                                        if (hposd < LBIAS)
                    461:                                                hposd = LBIAS;
                    462:                                        printf(lmove, hposd-LBIAS, 'H');
                    463:                                }
                    464:                        }
                    465:                        n = cp->c_code;
                    466:                        if (n == DHYPC)
                    467:                                n = CMINUS;
                    468:                        if (n <= 0 || n >= sizeof(intasc))
                    469:                                panic("Bad directive %d", n);
                    470:                        hpost += cp->c_move;
                    471:                        hposd += unit(wnum*wtab[n], wden);
                    472:                        n = intasc[n];
                    473:                        putchar(n);
                    474:                }
                    475:        }
                    476: }
                    477: 
                    478: /*
                    479:  * Print proper escape sequence to reset the laser printer so that the
                    480:  * last page is ejected.
                    481:  *
                    482:  */
                    483: 
                    484: void
                    485: resetdev()
                    486: {
                    487:        printf(RESET);
                    488: }
                    489: @

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.