Annotation of 43BSDTahoe/new/X/libsun/textutil.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * textutil.c 
                      3:  *
                      4:  * Copyright (c) 1985 Massachusetts Institue of Technology
                      5:  * Copyright (c) 1986 Sun Microsystems, Inc.
                      6:  * Copyright (c) 1986 David C. Martin, UC Berkeley
                      7:  *
                      8:  * David C. Martin
                      9:  * ARPA: [email protected]
                     10:  * UUCP: ..!ucbvax!dcmartin
                     11:  *
                     12:  * $Log:       textutil.c,v $
                     13:  * Revision 10.3  86/11/29  13:49:03  jg
                     14:  * fixes from Berkeley
                     15:  * 
                     16:  * Revision 1.7  86/07/27  13:47:46  dcmartin
                     17:  * modifications to TextWidth() and CharWidth() to check for invalid characters
                     18:  * when determining width.
                     19:  * 
                     20:  * Revision 1.6  86/07/20  13:28:45  dcmartin
                     21:  * *** empty log message ***
                     22:  * 
                     23:  * Revision 1.5  86/07/17  10:38:19  dcmartin
                     24:  * release version w/ fix for correctly determining character widths in
                     25:  * variable width fonts
                     26:  * 
                     27:  * Revision 1.4  86/07/17  10:32:28  dcmartin
                     28:  *
                     29:  */
                     30: 
                     31: #ifndef lint
                     32: static char rcs_id[] = "$Header: textutil.c,v 10.3 86/11/29 13:49:03 jg Rel $";
                     33: #endif lint
                     34: 
                     35: #include <X/mit-copyright.h>
                     36: 
                     37: /*
                     38:  * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided
                     39:  * for unrestricted use provided that this legend is included on all tape
                     40:  * media and as a part of the software program in whole or part.  Users
                     41:  * may copy or modify these drivers without charge, but are not authorized
                     42:  * to license or distribute them to anyone else except as part of a product or
                     43:  * program developed by the user.
                     44:  * 
                     45:  * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND
                     46:  * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A
                     47:  * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE
                     48:  * PRACTICE.
                     49:  *
                     50:  * The Sun X Drivers are provided with no support and without any obligation
                     51:  * on the part of Sun Microsystems, Inc. to assist in their use, correction,
                     52:  * modification or enhancement.
                     53:  * 
                     54:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
                     55:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X
                     56:  * DRIVERS OR ANY PART THEREOF.
                     57:  * 
                     58:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
                     59:  * or profits or other special, indirect and consequential damages, even if
                     60:  * Sun has been advised of the possibility of such damages.
                     61:  * 
                     62:  * Sun Microsystems, Inc.
                     63:  * 2550 Garcia Avenue
                     64:  * Mountain View, California  94043
                     65:  */
                     66: 
                     67: #ifdef sun
                     68: 
                     69: /* textutil.c  text related utility routines.
                     70:  *
                     71:  *     CopyText        Copy text to bitmap
                     72:  *     TextWidth       Returns width of a piece of text in a font
                     73:  *     CharWidth       Returns width of a character in a font
                     74:  *
                     75:  */
                     76: 
                     77: /*
                     78:  *     ToDo:
                     79:  *             Use static pixrects
                     80:  */
                     81: 
                     82: #include "Xsun.h"
                     83: 
                     84: #define        CHUNK   80
                     85: 
                     86: extern int
                     87: CopyText (string, strlen, font, bm)
                     88: char   *string;
                     89: int    strlen;
                     90: FONT   *font;
                     91: BITMAP *bm;
                     92: {
                     93:        int                             i;
                     94:        struct pixrect                  *region;
                     95:        register struct pixfont         *pf = (struct pixfont *) font->data;
                     96:        char                            *buf = (char *) Xalloc(strlen + 1);
                     97: 
                     98:        /* XXX - to guarantee zero-termination (BARF!) */
                     99:        strncpy(buf, string, strlen);
                    100:        /* XXX - slow!! */
                    101:        region = mem_point(bm->width, bm->height, 1, (short *) bm->data);
                    102:        for (i = 0; i < strlen; i += CHUNK) {
                    103:                register int            j;
                    104:                struct pr_prpos         bat[CHUNK];
                    105: 
                    106:                for (j = 0; j < CHUNK && i + j < strlen; j++) {
                    107:                        int                             c = string[i + j];
                    108:                        register struct pixchar         *pc = &(pf->pf_char[c]);
                    109: 
                    110:                        bat[j].pr = pc->pc_pr;
                    111:                        bat[j].pos = pc->pc_adv;
                    112:                }
                    113:        pr_batchrop(region, 0 - bat[0].pos.x, 0 - bat[0].pos.y, 
                    114:                PIX_SRC, bat, j);
                    115:        }
                    116:        /* XXX - slow */
                    117:        pr_destroy(region);
                    118:        free((caddr_t) buf);
                    119: } /* end CopyText() */
                    120: 
                    121: #undef CHUNK
                    122: 
                    123: /* 
                    124:  * Returns the width of a string in a font 
                    125:  */
                    126: extern int 
                    127: TextWidth (string, strlen, spacepad, font)
                    128: register char  *string;
                    129: register int   strlen;
                    130: int            spacepad;
                    131: register FONT  *font;
                    132: {
                    133:        register unsigned int c;
                    134:        register int width = 0;
                    135: 
                    136:        if (font->fixed) {
                    137:                width = strlen * font->avg_width;
                    138:                if (spacepad) {
                    139:                        while (--strlen >= 0) {
                    140:                                if (*string++ == font->space)
                    141:                                        width += spacepad;
                    142:                        }
                    143:                }
                    144:        } else {
                    145:                register struct pixfont         *pf;
                    146: 
                    147:                pf = (struct pixfont *) font->data;
                    148:                while (--strlen >= 0) {
                    149:                        c = *string++;
                    150:                        if (c < font->first || c > font->last)
                    151:                                continue;
                    152:                        if (c == font->space)
                    153:                                width += spacepad;
                    154:                        if (pf->pf_char[c].pc_pr != (struct pixrect *) NULL)
                    155:                                width += pf->pf_char[c].pc_adv.x;
                    156:                }
                    157:        }
                    158:        return (width);
                    159: } /* end TextWidth() */
                    160: 
                    161: /* 
                    162:  * Returns width of a character in a font. 
                    163:  */
                    164: extern int
                    165: CharWidth(c, font)
                    166: register unsigned int  c;
                    167: register FONT          *font;
                    168: {
                    169:        register struct pixfont *pfp = (struct pixfont *) font->data;
                    170: 
                    171:        if (c < font->first || c > font->last)
                    172:                return (0);
                    173:        else if (font->fixed)
                    174:                return (font->avg_width);
                    175:        if (pfp->pf_char[c].pc_pr != (struct pixrect *) NULL)
                    176:                return(pfp->pf_char[c].pc_adv.x);
                    177:        else
                    178:                return(0);
                    179: } /* end CharWidth() */
                    180: 
                    181: #endif sun

unix.superglobalmegacorp.com

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