[BACK]Return to term_ps.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/term_ps.c, Revision 1.13

1.13    ! kristaps    1: /*     $Id: term_ps.c,v 1.12 2010/06/25 19:50:23 kristaps Exp $ */
1.1       kristaps    2: /*
1.10      kristaps    3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
1.4       kristaps   21: #include <sys/param.h>
                     22:
1.2       kristaps   23: #include <assert.h>
1.4       kristaps   24: #include <stdarg.h>
1.2       kristaps   25: #include <stdio.h>
1.1       kristaps   26: #include <stdlib.h>
1.4       kristaps   27: #include <string.h>
1.13    ! kristaps   28: #include <time.h>
1.1       kristaps   29:
                     30: #include "out.h"
                     31: #include "main.h"
                     32: #include "term.h"
                     33:
1.13    ! kristaps   34: struct glyph {
        !            35:        int               wx; /* WX in AFM */
        !            36: };
        !            37:
        !            38: #define        MAXCHAR           95
        !            39:
        !            40: struct font {
        !            41:        const char       *name; /* FontName in AFM */
        !            42:        struct glyph      gly[MAXCHAR]; /* glyph metrics */
        !            43: };
        !            44:
        !            45: /*
        !            46:  * We define, for the time being, three fonts: bold, oblique/italic, and
        !            47:  * normal (roman).  The following table hard-codes the font metrics for
        !            48:  * ASCII, i.e., 32--127.
        !            49:  */
        !            50:
        !            51: static const struct font fonts[3] = {
        !            52:        { "Courier", {
        !            53:                { 600 },
        !            54:                { 600 },
        !            55:                { 600 },
        !            56:                { 600 },
        !            57:                { 600 },
        !            58:                { 600 },
        !            59:                { 600 },
        !            60:                { 600 },
        !            61:                { 600 },
        !            62:                { 600 },
        !            63:                { 600 },
        !            64:                { 600 },
        !            65:                { 600 },
        !            66:                { 600 },
        !            67:                { 600 },
        !            68:                { 600 },
        !            69:                { 600 },
        !            70:                { 600 },
        !            71:                { 600 },
        !            72:                { 600 },
        !            73:                { 600 },
        !            74:                { 600 },
        !            75:                { 600 },
        !            76:                { 600 },
        !            77:                { 600 },
        !            78:                { 600 },
        !            79:                { 600 },
        !            80:                { 600 },
        !            81:                { 600 },
        !            82:                { 600 },
        !            83:                { 600 },
        !            84:                { 600 },
        !            85:                { 600 },
        !            86:                { 600 },
        !            87:                { 600 },
        !            88:                { 600 },
        !            89:                { 600 },
        !            90:                { 600 },
        !            91:                { 600 },
        !            92:                { 600 },
        !            93:                { 600 },
        !            94:                { 600 },
        !            95:                { 600 },
        !            96:                { 600 },
        !            97:                { 600 },
        !            98:                { 600 },
        !            99:                { 600 },
        !           100:                { 600 },
        !           101:                { 600 },
        !           102:                { 600 },
        !           103:                { 600 },
        !           104:                { 600 },
        !           105:                { 600 },
        !           106:                { 600 },
        !           107:                { 600 },
        !           108:                { 600 },
        !           109:                { 600 },
        !           110:                { 600 },
        !           111:                { 600 },
        !           112:                { 600 },
        !           113:                { 600 },
        !           114:                { 600 },
        !           115:                { 600 },
        !           116:                { 600 },
        !           117:                { 600 },
        !           118:                { 600 },
        !           119:                { 600 },
        !           120:                { 600 },
        !           121:                { 600 },
        !           122:                { 600 },
        !           123:                { 600 },
        !           124:                { 600 },
        !           125:                { 600 },
        !           126:                { 600 },
        !           127:                { 600 },
        !           128:                { 600 },
        !           129:                { 600 },
        !           130:                { 600 },
        !           131:                { 600 },
        !           132:                { 600 },
        !           133:                { 600 },
        !           134:                { 600 },
        !           135:                { 600 },
        !           136:                { 600 },
        !           137:                { 600 },
        !           138:                { 600 },
        !           139:                { 600 },
        !           140:                { 600 },
        !           141:                { 600 },
        !           142:                { 600 },
        !           143:                { 600 },
        !           144:                { 600 },
        !           145:                { 600 },
        !           146:                { 600 },
        !           147:                { 600 },
        !           148:        } },
        !           149:        { "Courier-Bold", {
        !           150:                { 600 },
        !           151:                { 600 },
        !           152:                { 600 },
        !           153:                { 600 },
        !           154:                { 600 },
        !           155:                { 600 },
        !           156:                { 600 },
        !           157:                { 600 },
        !           158:                { 600 },
        !           159:                { 600 },
        !           160:                { 600 },
        !           161:                { 600 },
        !           162:                { 600 },
        !           163:                { 600 },
        !           164:                { 600 },
        !           165:                { 600 },
        !           166:                { 600 },
        !           167:                { 600 },
        !           168:                { 600 },
        !           169:                { 600 },
        !           170:                { 600 },
        !           171:                { 600 },
        !           172:                { 600 },
        !           173:                { 600 },
        !           174:                { 600 },
        !           175:                { 600 },
        !           176:                { 600 },
        !           177:                { 600 },
        !           178:                { 600 },
        !           179:                { 600 },
        !           180:                { 600 },
        !           181:                { 600 },
        !           182:                { 600 },
        !           183:                { 600 },
        !           184:                { 600 },
        !           185:                { 600 },
        !           186:                { 600 },
        !           187:                { 600 },
        !           188:                { 600 },
        !           189:                { 600 },
        !           190:                { 600 },
        !           191:                { 600 },
        !           192:                { 600 },
        !           193:                { 600 },
        !           194:                { 600 },
        !           195:                { 600 },
        !           196:                { 600 },
        !           197:                { 600 },
        !           198:                { 600 },
        !           199:                { 600 },
        !           200:                { 600 },
        !           201:                { 600 },
        !           202:                { 600 },
        !           203:                { 600 },
        !           204:                { 600 },
        !           205:                { 600 },
        !           206:                { 600 },
        !           207:                { 600 },
        !           208:                { 600 },
        !           209:                { 600 },
        !           210:                { 600 },
        !           211:                { 600 },
        !           212:                { 600 },
        !           213:                { 600 },
        !           214:                { 600 },
        !           215:                { 600 },
        !           216:                { 600 },
        !           217:                { 600 },
        !           218:                { 600 },
        !           219:                { 600 },
        !           220:                { 600 },
        !           221:                { 600 },
        !           222:                { 600 },
        !           223:                { 600 },
        !           224:                { 600 },
        !           225:                { 600 },
        !           226:                { 600 },
        !           227:                { 600 },
        !           228:                { 600 },
        !           229:                { 600 },
        !           230:                { 600 },
        !           231:                { 600 },
        !           232:                { 600 },
        !           233:                { 600 },
        !           234:                { 600 },
        !           235:                { 600 },
        !           236:                { 600 },
        !           237:                { 600 },
        !           238:                { 600 },
        !           239:                { 600 },
        !           240:                { 600 },
        !           241:                { 600 },
        !           242:                { 600 },
        !           243:                { 600 },
        !           244:                { 600 },
        !           245:        } },
        !           246:        { "Courier-Oblique", {
        !           247:                { 600 },
        !           248:                { 600 },
        !           249:                { 600 },
        !           250:                { 600 },
        !           251:                { 600 },
        !           252:                { 600 },
        !           253:                { 600 },
        !           254:                { 600 },
        !           255:                { 600 },
        !           256:                { 600 },
        !           257:                { 600 },
        !           258:                { 600 },
        !           259:                { 600 },
        !           260:                { 600 },
        !           261:                { 600 },
        !           262:                { 600 },
        !           263:                { 600 },
        !           264:                { 600 },
        !           265:                { 600 },
        !           266:                { 600 },
        !           267:                { 600 },
        !           268:                { 600 },
        !           269:                { 600 },
        !           270:                { 600 },
        !           271:                { 600 },
        !           272:                { 600 },
        !           273:                { 600 },
        !           274:                { 600 },
        !           275:                { 600 },
        !           276:                { 600 },
        !           277:                { 600 },
        !           278:                { 600 },
        !           279:                { 600 },
        !           280:                { 600 },
        !           281:                { 600 },
        !           282:                { 600 },
        !           283:                { 600 },
        !           284:                { 600 },
        !           285:                { 600 },
        !           286:                { 600 },
        !           287:                { 600 },
        !           288:                { 600 },
        !           289:                { 600 },
        !           290:                { 600 },
        !           291:                { 600 },
        !           292:                { 600 },
        !           293:                { 600 },
        !           294:                { 600 },
        !           295:                { 600 },
        !           296:                { 600 },
        !           297:                { 600 },
        !           298:                { 600 },
        !           299:                { 600 },
        !           300:                { 600 },
        !           301:                { 600 },
        !           302:                { 600 },
        !           303:                { 600 },
        !           304:                { 600 },
        !           305:                { 600 },
        !           306:                { 600 },
        !           307:                { 600 },
        !           308:                { 600 },
        !           309:                { 600 },
        !           310:                { 600 },
        !           311:                { 600 },
        !           312:                { 600 },
        !           313:                { 600 },
        !           314:                { 600 },
        !           315:                { 600 },
        !           316:                { 600 },
        !           317:                { 600 },
        !           318:                { 600 },
        !           319:                { 600 },
        !           320:                { 600 },
        !           321:                { 600 },
        !           322:                { 600 },
        !           323:                { 600 },
        !           324:                { 600 },
        !           325:                { 600 },
        !           326:                { 600 },
        !           327:                { 600 },
        !           328:                { 600 },
        !           329:                { 600 },
        !           330:                { 600 },
        !           331:                { 600 },
        !           332:                { 600 },
        !           333:                { 600 },
        !           334:                { 600 },
        !           335:                { 600 },
        !           336:                { 600 },
        !           337:                { 600 },
        !           338:                { 600 },
        !           339:                { 600 },
        !           340:                { 600 },
        !           341:                { 600 },
        !           342:        } },
        !           343: };
        !           344:
1.2       kristaps  345: #define        PS_CHAR_HEIGHT    12
                    346: #define        PS_CHAR_TOPMARG  (792 - 24)
                    347: #define        PS_CHAR_TOP      (PS_CHAR_TOPMARG - 36)
                    348: #define        PS_CHAR_LEFT      36
                    349: #define        PS_CHAR_BOTMARG   24
                    350: #define        PS_CHAR_BOT      (PS_CHAR_BOTMARG + 36)
                    351:
1.4       kristaps  352: #define        PS_BUFSLOP        128
                    353: #define        PS_GROWBUF(p, sz) \
                    354:        do if ((p)->engine.ps.psmargcur + (sz) > \
                    355:                        (p)->engine.ps.psmargsz) { \
                    356:                (p)->engine.ps.psmargsz += /* CONSTCOND */ \
                    357:                        MAX(PS_BUFSLOP, (sz)); \
                    358:                (p)->engine.ps.psmarg = realloc \
                    359:                        ((p)->engine.ps.psmarg,  \
                    360:                         (p)->engine.ps.psmargsz); \
                    361:                if (NULL == (p)->engine.ps.psmarg) { \
                    362:                        perror(NULL); \
                    363:                        exit(EXIT_FAILURE); \
                    364:                } \
                    365:        } while (/* CONSTCOND */ 0)
                    366:
1.9       kristaps  367:
1.2       kristaps  368: static void              ps_letter(struct termp *, char);
                    369: static void              ps_begin(struct termp *);
                    370: static void              ps_end(struct termp *);
                    371: static void              ps_advance(struct termp *, size_t);
                    372: static void              ps_endline(struct termp *);
1.9       kristaps  373: static void              ps_fclose(struct termp *);
1.11      kristaps  374: static size_t            ps_width(const struct termp *, char);
1.9       kristaps  375: static void              ps_pclose(struct termp *);
1.13    ! kristaps  376: static void              ps_pletter(struct termp *, int);
1.4       kristaps  377: static void              ps_printf(struct termp *, const char *, ...);
                    378: static void              ps_putchar(struct termp *, char);
1.9       kristaps  379: static void              ps_setfont(struct termp *, enum termfont);
1.2       kristaps  380:
                    381:
1.1       kristaps  382: void *
                    383: ps_alloc(void)
                    384: {
                    385:        struct termp    *p;
                    386:
                    387:        if (NULL == (p = term_alloc(TERMENC_ASCII)))
                    388:                return(NULL);
                    389:
1.11      kristaps  390:        p->defrmargin = 78;
                    391:        p->tabwidth = 5;
                    392:
1.1       kristaps  393:        p->type = TERMTYPE_PS;
1.2       kristaps  394:        p->letter = ps_letter;
                    395:        p->begin = ps_begin;
                    396:        p->end = ps_end;
                    397:        p->advance = ps_advance;
                    398:        p->endline = ps_endline;
1.11      kristaps  399:        p->width = ps_width;
1.1       kristaps  400:        return(p);
                    401: }
                    402:
                    403:
                    404: void
                    405: ps_free(void *arg)
                    406: {
1.4       kristaps  407:        struct termp    *p;
                    408:
                    409:        p = (struct termp *)arg;
                    410:
                    411:        if (p->engine.ps.psmarg)
                    412:                free(p->engine.ps.psmarg);
                    413:
                    414:        term_free(p);
                    415: }
                    416:
                    417:
                    418: static void
                    419: ps_printf(struct termp *p, const char *fmt, ...)
                    420: {
                    421:        va_list          ap;
                    422:        int              pos;
                    423:
                    424:        va_start(ap, fmt);
                    425:
                    426:        /*
                    427:         * If we're running in regular mode, then pipe directly into
                    428:         * vprintf().  If we're processing margins, then push the data
                    429:         * into our growable margin buffer.
                    430:         */
1.1       kristaps  431:
1.4       kristaps  432:        if ( ! (PS_MARGINS & p->engine.ps.psstate)) {
                    433:                vprintf(fmt, ap);
                    434:                va_end(ap);
                    435:                return;
                    436:        }
                    437:
                    438:        /*
                    439:         * XXX: I assume that the in-margin print won't exceed
                    440:         * PS_BUFSLOP (128 bytes), which is reasonable but still an
                    441:         * assumption that will cause pukeage if it's not the case.
                    442:         */
                    443:
                    444:        PS_GROWBUF(p, PS_BUFSLOP);
                    445:
                    446:        pos = (int)p->engine.ps.psmargcur;
                    447:        vsnprintf(&p->engine.ps.psmarg[pos], PS_BUFSLOP, fmt, ap);
                    448:        p->engine.ps.psmargcur = strlen(p->engine.ps.psmarg);
1.5       kristaps  449:
                    450:        va_end(ap);
1.4       kristaps  451: }
                    452:
                    453:
                    454: static void
                    455: ps_putchar(struct termp *p, char c)
                    456: {
                    457:        int              pos;
                    458:
                    459:        /* See ps_printf(). */
                    460:
                    461:        if ( ! (PS_MARGINS & p->engine.ps.psstate)) {
                    462:                putchar(c);
                    463:                return;
                    464:        }
                    465:
                    466:        PS_GROWBUF(p, 2);
                    467:
                    468:        pos = (int)p->engine.ps.psmargcur++;
1.5       kristaps  469:        p->engine.ps.psmarg[pos++] = c;
1.4       kristaps  470:        p->engine.ps.psmarg[pos] = '\0';
1.2       kristaps  471: }
                    472:
                    473:
1.3       kristaps  474: /* ARGSUSED */
1.2       kristaps  475: static void
                    476: ps_end(struct termp *p)
                    477: {
                    478:
1.4       kristaps  479:        /*
                    480:         * At the end of the file, do one last showpage.  This is the
                    481:         * same behaviour as groff(1) and works for multiple pages as
                    482:         * well as just one.
                    483:         */
                    484:
1.8       kristaps  485:        assert(0 == p->engine.ps.psstate);
                    486:        assert('\0' == p->engine.ps.last);
1.4       kristaps  487:        assert(p->engine.ps.psmarg && p->engine.ps.psmarg[0]);
                    488:        printf("%s", p->engine.ps.psmarg);
                    489:        printf("showpage\n");
1.2       kristaps  490:        printf("%s\n", "%%EOF");
                    491: }
                    492:
                    493:
                    494: static void
                    495: ps_begin(struct termp *p)
                    496: {
1.13    ! kristaps  497:        time_t           t;
1.2       kristaps  498:
1.9       kristaps  499:        /*
                    500:         * Print margins into margin buffer.  Nothing gets output to the
                    501:         * screen yet, so we don't need to initialise the primary state.
1.2       kristaps  502:         */
                    503:
1.4       kristaps  504:        if (p->engine.ps.psmarg) {
                    505:                assert(p->engine.ps.psmargsz);
                    506:                p->engine.ps.psmarg[0] = '\0';
                    507:        }
                    508:
                    509:        p->engine.ps.psmargcur = 0;
1.9       kristaps  510:        p->engine.ps.psstate = PS_MARGINS;
1.4       kristaps  511:        p->engine.ps.pscol = PS_CHAR_LEFT;
                    512:        p->engine.ps.psrow = PS_CHAR_TOPMARG;
                    513:
1.9       kristaps  514:        ps_setfont(p, TERMFONT_NONE);
1.4       kristaps  515:
                    516:        (*p->headf)(p, p->argf);
                    517:        (*p->endline)(p);
                    518:
                    519:        p->engine.ps.pscol = PS_CHAR_LEFT;
                    520:        p->engine.ps.psrow = PS_CHAR_BOTMARG;
                    521:
                    522:        (*p->footf)(p, p->argf);
                    523:        (*p->endline)(p);
                    524:
                    525:        p->engine.ps.psstate &= ~PS_MARGINS;
1.9       kristaps  526:
1.4       kristaps  527:        assert(0 == p->engine.ps.psstate);
1.9       kristaps  528:        assert(p->engine.ps.psmarg);
                    529:        assert('\0' != p->engine.ps.psmarg[0]);
                    530:
                    531:        /*
                    532:         * Print header and initialise page state.  Following this,
                    533:         * stuff gets printed to the screen, so make sure we're sane.
                    534:         */
1.4       kristaps  535:
1.13    ! kristaps  536:        t = time(NULL);
        !           537:
        !           538:        printf("%%!PS\n");
        !           539:        printf("%%%%Creator: mandoc-%s\n", VERSION);
        !           540:        printf("%%%%CreationDate: %s", ctime(&t));
        !           541:        printf("%%%%PageOrder: Ascend\n");
        !           542:        printf("%%%%Orientation: Portrait\n");
        !           543:        printf("%%%%EndComments\n");
        !           544:
1.9       kristaps  545:        ps_setfont(p, TERMFONT_NONE);
1.4       kristaps  546:        p->engine.ps.pscol = PS_CHAR_LEFT;
                    547:        p->engine.ps.psrow = PS_CHAR_TOP;
1.2       kristaps  548: }
                    549:
                    550:
                    551: static void
1.13    ! kristaps  552: ps_pletter(struct termp *p, int c)
1.2       kristaps  553: {
                    554:
1.9       kristaps  555:        /*
                    556:         * If we're not in a PostScript "word" context, then open one
                    557:         * now at the current cursor.
                    558:         */
                    559:
1.2       kristaps  560:        if ( ! (PS_INLINE & p->engine.ps.psstate)) {
1.4       kristaps  561:                ps_printf(p, "%zu %zu moveto\n(",
1.2       kristaps  562:                                p->engine.ps.pscol,
                    563:                                p->engine.ps.psrow);
                    564:                p->engine.ps.psstate |= PS_INLINE;
                    565:        }
                    566:
                    567:        /*
                    568:         * We need to escape these characters as per the PostScript
                    569:         * specification.  We would also escape non-graphable characters
                    570:         * (like tabs), but none of them would get to this point and
                    571:         * it's superfluous to abort() on them.
                    572:         */
                    573:
                    574:        switch (c) {
                    575:        case ('('):
                    576:                /* FALLTHROUGH */
                    577:        case (')'):
                    578:                /* FALLTHROUGH */
                    579:        case ('\\'):
1.4       kristaps  580:                ps_putchar(p, '\\');
1.2       kristaps  581:                break;
                    582:        default:
                    583:                break;
                    584:        }
                    585:
                    586:        /* Write the character and adjust where we are on the page. */
1.9       kristaps  587:
1.13    ! kristaps  588:        /*
        !           589:         * FIXME: at this time we emit only blacnks on non-ASCII
        !           590:         * letters.
        !           591:         */
        !           592:
        !           593:        if (c < 32 || (c - 32 > MAXCHAR)) {
        !           594:                ps_putchar(p, ' ');
        !           595:                p->engine.ps.pscol +=
        !           596:                        (fonts[p->engine.ps.lastf].gly[32].wx / 100);
        !           597:                return;
        !           598:        }
        !           599:
1.4       kristaps  600:        ps_putchar(p, c);
1.13    ! kristaps  601:        p->engine.ps.pscol +=
        !           602:                (fonts[p->engine.ps.lastf].gly[(int)c - 32].wx / 100);
1.2       kristaps  603: }
                    604:
                    605:
                    606: static void
1.9       kristaps  607: ps_pclose(struct termp *p)
                    608: {
                    609:
                    610:        /*
                    611:         * Spit out that we're exiting a word context (this is a
                    612:         * "partial close" because we don't check the last-char buffer
                    613:         * or anything).
                    614:         */
                    615:
                    616:        if ( ! (PS_INLINE & p->engine.ps.psstate))
                    617:                return;
                    618:
                    619:        ps_printf(p, ") show\n");
                    620:        p->engine.ps.psstate &= ~PS_INLINE;
                    621: }
                    622:
                    623:
                    624: static void
                    625: ps_fclose(struct termp *p)
                    626: {
                    627:
                    628:        /*
                    629:         * Strong closure: if we have a last-char, spit it out after
                    630:         * checking that we're in the right font mode.  This will of
                    631:         * course open a new scope, if applicable.
                    632:         *
                    633:         * Following this, close out any scope that's open.
                    634:         */
                    635:
                    636:        if ('\0' != p->engine.ps.last) {
                    637:                if (p->engine.ps.lastf != TERMFONT_NONE) {
                    638:                        ps_pclose(p);
                    639:                        ps_setfont(p, TERMFONT_NONE);
                    640:                }
                    641:                ps_pletter(p, p->engine.ps.last);
                    642:                p->engine.ps.last = '\0';
                    643:        }
                    644:
                    645:        if ( ! (PS_INLINE & p->engine.ps.psstate))
                    646:                return;
                    647:
                    648:        ps_pclose(p);
                    649: }
                    650:
                    651:
                    652: static void
1.8       kristaps  653: ps_letter(struct termp *p, char c)
                    654: {
                    655:        char            cc;
1.9       kristaps  656:
                    657:        /*
                    658:         * State machine dictates whether to buffer the last character
                    659:         * or not.  Basically, encoded words are detected by checking if
                    660:         * we're an "8" and switching on the buffer.  Then we put "8" in
                    661:         * our buffer, and on the next charater, flush both character
                    662:         * and buffer.  Thus, "regular" words are detected by having a
                    663:         * regular character and a regular buffer character.
                    664:         */
                    665:
1.8       kristaps  666:        if ('\0' == p->engine.ps.last) {
                    667:                assert(8 != c);
                    668:                p->engine.ps.last = c;
                    669:                return;
                    670:        } else if (8 == p->engine.ps.last) {
                    671:                assert(8 != c);
1.9       kristaps  672:                p->engine.ps.last = '\0';
1.8       kristaps  673:        } else if (8 == c) {
                    674:                assert(8 != p->engine.ps.last);
1.9       kristaps  675:                if ('_' == p->engine.ps.last) {
                    676:                        if (p->engine.ps.lastf != TERMFONT_UNDER) {
                    677:                                ps_pclose(p);
                    678:                                ps_setfont(p, TERMFONT_UNDER);
                    679:                        }
                    680:                } else if (p->engine.ps.lastf != TERMFONT_BOLD) {
                    681:                        ps_pclose(p);
                    682:                        ps_setfont(p, TERMFONT_BOLD);
                    683:                }
1.8       kristaps  684:                p->engine.ps.last = c;
                    685:                return;
                    686:        } else {
1.9       kristaps  687:                if (p->engine.ps.lastf != TERMFONT_NONE) {
                    688:                        ps_pclose(p);
                    689:                        ps_setfont(p, TERMFONT_NONE);
                    690:                }
1.8       kristaps  691:                cc = p->engine.ps.last;
                    692:                p->engine.ps.last = c;
                    693:                c = cc;
                    694:        }
                    695:
1.9       kristaps  696:        ps_pletter(p, c);
1.8       kristaps  697: }
                    698:
                    699:
                    700: static void
1.2       kristaps  701: ps_advance(struct termp *p, size_t len)
                    702: {
                    703:
1.9       kristaps  704:        /*
                    705:         * Advance some spaces.  This can probably be made smarter,
                    706:         * i.e., to have multiple space-separated words in the same
                    707:         * scope, but this is easier:  just close out the current scope
                    708:         * and readjust our column settings.
                    709:         */
1.8       kristaps  710:
1.9       kristaps  711:        ps_fclose(p);
1.13    ! kristaps  712:        p->engine.ps.pscol += 0 == len ? 0 :
        !           713:                len * (fonts[p->engine.ps.lastf].gly[0].wx / 100);
1.2       kristaps  714: }
                    715:
                    716:
                    717: static void
                    718: ps_endline(struct termp *p)
                    719: {
1.8       kristaps  720:
1.9       kristaps  721:        /* Close out any scopes we have open: we're at eoln. */
                    722:
                    723:        ps_fclose(p);
1.2       kristaps  724:
1.9       kristaps  725:        /*
                    726:         * If we're in the margin, don't try to recalculate our current
                    727:         * row.  XXX: if the column tries to be fancy with multiple
                    728:         * lines, we'll do nasty stuff.
                    729:         */
1.2       kristaps  730:
                    731:        if (PS_MARGINS & p->engine.ps.psstate)
                    732:                return;
                    733:
1.9       kristaps  734:        /*
                    735:         * Put us down a line.  If we're at the page bottom, spit out a
                    736:         * showpage and restart our row.
                    737:         */
                    738:
1.2       kristaps  739:        p->engine.ps.pscol = PS_CHAR_LEFT;
                    740:        if (p->engine.ps.psrow >= PS_CHAR_HEIGHT + PS_CHAR_BOT) {
                    741:                p->engine.ps.psrow -= PS_CHAR_HEIGHT;
                    742:                return;
                    743:        }
                    744:
1.4       kristaps  745:        assert(p->engine.ps.psmarg && p->engine.ps.psmarg[0]);
                    746:        printf("%s", p->engine.ps.psmarg);
1.2       kristaps  747:        printf("showpage\n");
                    748:        p->engine.ps.psrow = PS_CHAR_TOP;
1.1       kristaps  749: }
1.9       kristaps  750:
                    751:
                    752: static void
                    753: ps_setfont(struct termp *p, enum termfont f)
                    754: {
                    755:
1.13    ! kristaps  756:        ps_printf(p, "/%s 10 selectfont\n", fonts[(int)f].name);
1.9       kristaps  757:        p->engine.ps.lastf = f;
                    758: }
                    759:
1.11      kristaps  760:
1.12      kristaps  761: /* ARGSUSED */
1.11      kristaps  762: static size_t
                    763: ps_width(const struct termp *p, char c)
                    764: {
                    765:
                    766:        return(1);
                    767: }

CVSweb