Annotation of 43BSDTahoe/new/X/libis/text.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     $Source: /u1/X/libis/RCS/text.c,v $
        !             3:  *     $Header: text.c,v 1.1 86/11/17 14:34:33 swick Rel $
        !             4:  */
        !             5: 
        !             6: #ifndef lint
        !             7: static char *rcsid_text_c = "$Header: text.c,v 1.1 86/11/17 14:34:33 swick Rel $";
        !             8: #endif lint
        !             9: 
        !            10: #include "is-copyright.h"
        !            11: 
        !            12: /*     text.c
        !            13:  *
        !            14:  *     PrintText               Prints text with source font
        !            15:  *     PrintTextMask           Prints text with mask font
        !            16:  *     CopyText                Copy text to bitmap
        !            17:  *     TextWidth               Returns width of a piece of text in a font
        !            18:  *     CharWidth               Returns width of a character in a font
        !            19:  *
        !            20:  *     Copyright (c) 1986, Integrated Solutions, Inc.
        !            21:  */
        !            22: 
        !            23: #include "Xis.h"
        !            24: 
        !            25: extern PIXMAP *MakePixmap();
        !            26: extern PIXMAP *MakeFontPixmap();
        !            27: 
        !            28: /*
        !            29:  *     PrintText                       Prints text with source font
        !            30:  */
        !            31: PrintText(string, strlen, font, fore, back, charpad, spacepad, dstx, dsty, clips, clipcount, func, zmask)
        !            32: char           *string;        /* string to print */
        !            33: int            strlen;         /* length of string */
        !            34: register FONT  *font;          /* source font */
        !            35: int            fore;           /* foreground source pixel */
        !            36: int            back;           /* background source pixel */
        !            37: register int   charpad;        /* inter-character pad */
        !            38: int            spacepad;       /* space-character pad */
        !            39: int            dstx, dsty;     /* destination */
        !            40: register CLIP  *clips;         /* clipping rectangles */
        !            41: register int   clipcount;      /* count of clipping rectangles */
        !            42: int            func;           /* GX display function */
        !            43: int            zmask;          /* plane mask */
        !            44: {
        !            45:     register FontPriv *fdata = FDATA(font);
        !            46:     PIXMAP *font_pixmap;
        !            47: 
        !            48:     CLIP bounds, i;
        !            49: 
        !            50:     bounds.top = dsty;
        !            51:     bounds.height = font->height;
        !            52: 
        !            53: #ifdef DEBUG
        !            54: if (debug & D_Text)
        !            55:     printf("PrintText(\"%.*s\")\n", strlen, string);
        !            56: #endif DEBUG
        !            57: 
        !            58:     font_pixmap = MakeFontPixmap(font, fore, back);
        !            59: 
        !            60:     for ( ; clipcount > 0; clipcount--, ++clips) {
        !            61:        register int len = strlen;
        !            62:        register char *p = string;
        !            63:        register int x = dstx;
        !            64: 
        !            65:        while (len--) {
        !            66:            register int char_x;
        !            67: 
        !            68:            /* complete clip rectangle for character */
        !            69:            bounds.left = x;
        !            70:            if (font->fixed) {
        !            71:                char_x = font->avg_width * (*p - font->first);
        !            72:                bounds.width = font->avg_width;
        !            73:            } else {
        !            74:                char_x = fdata->xpos[*p - font->first];
        !            75:                bounds.width = fdata->widths[*p - font->first];
        !            76:            }
        !            77: 
        !            78:            /* advance x position for next character */
        !            79:            x += bounds.width + charpad;
        !            80:            if (*p == font->space) {
        !            81:                x+= spacepad;
        !            82:            }
        !            83: 
        !            84:            /* If clip rectangle and destination bounds overlap, display
        !            85:             * character in the area the two intersect */
        !            86:            if (Overlap(clips[0], bounds)) {
        !            87:                i = Intersection(clips[0], bounds);
        !            88:                CheckCursor(i);
        !            89:                GIP_RasterOp((unsigned char)func,
        !            90:                    font_pixmap, char_x + (i.left - bounds.left),
        !            91:                            i.top-bounds.top,
        !            92:                    &ScreenPixmap, i.left, i.top,
        !            93:                    (BITMAP *)NULL, 0, 0,
        !            94:                    i.width, i.height,
        !            95:                    zmask);
        !            96:            }
        !            97:            ++p;
        !            98:        }
        !            99:     }
        !           100:     RestoreCursor();
        !           101: }
        !           102: 
        !           103: /*
        !           104:  *     PrintTextMask
        !           105:  */
        !           106: 
        !           107: PrintTextMask(string, strlen, font, srcpix, charpad, spacepad, dstx, dsty, clips, clipcount, func, zmask)
        !           108: char           *string;        /* string to print */
        !           109: int            strlen;         /* length of string */
        !           110: register FONT  *font;          /* source font */
        !           111: int            srcpix;         /* source pixel */
        !           112: register int   charpad;        /* inter-character pad */
        !           113: int            spacepad;       /* space-character pad */
        !           114: int            dstx, dsty;     /* destination */
        !           115: register CLIP  *clips;         /* clipping rectangles */
        !           116: register int   clipcount;      /* count of clipping rectangles */
        !           117: int            func;           /* GX display function */
        !           118: int            zmask;          /* plane mask */
        !           119: {
        !           120:     register FontPriv *fdata = FDATA(font);
        !           121:     CLIP bounds, i;
        !           122:     PIXMAP     *textpix;
        !           123: 
        !           124: #ifdef DEBUG
        !           125: if (debug & D_Text)
        !           126:     printf("PrintTextMask(string=\"%.*s\", srcpix=0x%x, func=%d, zmask=0x%04x)\n",
        !           127:        strlen, string, srcpix, func, zmask);
        !           128: #endif DEBUG
        !           129: 
        !           130:     textpix = (PIXMAP *) MakePixmap((BITMAP *)NULL, srcpix, 0);
        !           131: 
        !           132:     bounds.top = dsty;
        !           133:     bounds.height = font->height;
        !           134: 
        !           135:     for ( ; clipcount > 0; clipcount--, ++clips) {
        !           136:        register int len = strlen;
        !           137:        register char *p = string;
        !           138:        register int x = dstx;
        !           139: 
        !           140:        while (len--) {
        !           141:            register int char_x;
        !           142: 
        !           143:            /* complete clip rectangle for character */
        !           144:            bounds.left = x;
        !           145:            if (font->fixed) {
        !           146:                char_x = font->avg_width * (*p - font->first);
        !           147:                bounds.width = font->avg_width;
        !           148:            } else {
        !           149:                char_x = fdata->xpos[*p - font->first];
        !           150:                bounds.width = fdata->widths[*p - font->first];
        !           151:            }
        !           152: 
        !           153:            /* advance x position for next character */
        !           154:            x += bounds.width + charpad;
        !           155:            if (*p == font->space) {
        !           156:                x+= spacepad;
        !           157:            }
        !           158: 
        !           159:            /* If clip rectangle and destination bounds overlap, display
        !           160:             * character in the area the two intersect */
        !           161:            if (Overlap(clips[0], bounds)) {
        !           162:                i = Intersection(clips[0], bounds);
        !           163:                CheckCursor(i);
        !           164:                GIP_RasterOp((unsigned char)func,
        !           165:                    textpix, 0, 0,
        !           166:                    &ScreenPixmap, i.left, i.top,
        !           167:                    fdata->mask, char_x + (i.left - bounds.left),
        !           168:                            i.top-bounds.top,
        !           169:                    i.width, i.height,
        !           170:                    zmask);
        !           171:            }
        !           172:            ++p;
        !           173:        }
        !           174:     }
        !           175:     RestoreCursor();
        !           176:     if (!--textpix->refcnt)
        !           177:        FreePixmap(textpix);
        !           178: }
        !           179: 
        !           180: /*
        !           181:  *     CopyText
        !           182:  */
        !           183: CopyText(string, strlen, font, dst)
        !           184: register char  *string;        /* string to copy */
        !           185: register int   strlen;         /* length of string */
        !           186: register FONT  *font;          /* source font */
        !           187: BITMAP         *dst;           /* destination bitmap */
        !           188: {
        !           189:     register FontPriv *fdata = FDATA(font);
        !           190:     PIXMAP *font_pixmap, *dst_pixmap;
        !           191:     register int height = font->height;
        !           192:     register x = 0;
        !           193: 
        !           194: #ifdef DEBUG
        !           195: if (debug & D_Text)
        !           196:     printf("CopyText(string=\"%.*s\")\n", strlen, string);
        !           197: #endif DEBUG
        !           198: 
        !           199:     font_pixmap = MakePixmap(fdata->mask, 1, 0);
        !           200:     dst_pixmap = MakePixmap(dst, 1, 0);
        !           201: 
        !           202:     while (strlen--) {
        !           203:        register int width;
        !           204: 
        !           205:        /* get width of this character */
        !           206:        if (font->fixed) {
        !           207:            width = font->avg_width;
        !           208:        } else {
        !           209:            width = fdata->widths[*string - font->first];
        !           210:        }
        !           211: 
        !           212:        GIP_RasterOp(GXcopy,
        !           213:            font_pixmap, fdata->xpos[*string - font->first], 0,
        !           214:            dst_pixmap, x, 0,
        !           215:            (BITMAP *)NULL, 0, 0,
        !           216:            width, height,
        !           217:            1);
        !           218: 
        !           219:        /* advance x position for next character */
        !           220:        x += width;
        !           221: 
        !           222:        ++string;
        !           223:     }
        !           224: 
        !           225:     FreePixmap(font_pixmap);
        !           226:     FreePixmap(dst_pixmap);
        !           227: }
        !           228: 
        !           229: /*
        !           230:  *     TextWidth       Returns the width of a string in a font
        !           231:  */
        !           232: int
        !           233: TextWidth(string, strlen, spacepad, font)
        !           234: char           *string;
        !           235: register int   strlen;
        !           236: register int   spacepad;
        !           237: register FONT  *font;
        !           238: {
        !           239:     register u_char *strptr = (u_char *) string;
        !           240:     register short c;
        !           241:     register short *widths;
        !           242:     register int width = 0;
        !           243: 
        !           244:     if (font->fixed) {
        !           245:        width = strlen * font->avg_width;
        !           246:        if (spacepad) {
        !           247:            while (strlen--) {
        !           248:                if (*strptr++ == font->space)
        !           249:                    width += spacepad;
        !           250:            }
        !           251:        }
        !           252: 
        !           253:     } else {
        !           254:        widths = FDATA(font)->widths;
        !           255:        while (strlen--) {
        !           256:            c = *strptr++;
        !           257:            if (c >= font->first && c <= font->last) {
        !           258:                if (c == font->space)
        !           259:                    width += spacepad;
        !           260:                width += widths[c - font->first];
        !           261:            }
        !           262:        }
        !           263:     }
        !           264: 
        !           265:     return (width);
        !           266: }
        !           267: 
        !           268: /*
        !           269:  *     CharWidth       Returns width of a character in a font.
        !           270:  */
        !           271: int
        !           272: CharWidth(c, font)
        !           273: unsigned int   c;
        !           274: register FONT  *font;
        !           275: {
        !           276: 
        !           277:     if (c < font->first || c > font->last)
        !           278:        return (0);
        !           279:     else if (font->fixed)
        !           280:        return (font->avg_width);
        !           281:     else
        !           282:        return (FDATA(font)->widths[c - font->first]);
        !           283: }

unix.superglobalmegacorp.com

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