Annotation of researchv9/X11/src/X.V11R1/lib/X/XTextExt.c, revision 1.1

1.1     ! root        1: /* $Header: XTextExt.c,v 11.11 87/09/11 08:09:21 toddb Exp $ */
        !             2: /************************************************************************
        !             3: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
        !             4: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
        !             5: 
        !             6:                         All Rights Reserved
        !             7: 
        !             8: Permission to use, copy, modify, and distribute this software and its 
        !             9: documentation for any purpose and without fee is hereby granted, 
        !            10: provided that the above copyright notice appear in all copies and that
        !            11: both that copyright notice and this permission notice appear in 
        !            12: supporting documentation, and that the names of Digital or MIT not be
        !            13: used in advertising or publicity pertaining to distribution of the
        !            14: software without specific, written prior permission.  
        !            15: 
        !            16: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            17: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            18: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            19: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            20: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            21: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            22: SOFTWARE.
        !            23: 
        !            24: ************************************************************************/
        !            25: 
        !            26: #define NEED_REPLIES
        !            27: 
        !            28: #include "Xlibint.h"
        !            29: 
        !            30: /* text support routines. Three different access methods, a */
        !            31: /* charinfo array builder, and a bounding box calculator */
        !            32: 
        !            33: /*ARGSUSED*/
        !            34: static
        !            35: XCharStruct *GetCS(min_bounds, pCS, firstCol, numCols, firstRow, numRows, ind, 
        !            36:        chars, chDefault)
        !            37:     XCharStruct *min_bounds;
        !            38:     XCharStruct pCS[];
        !            39:     unsigned int firstCol, numCols, firstRow, numRows, ind, chDefault;
        !            40:     char *chars;
        !            41: {
        !            42:     XCharStruct *cs;
        !            43:     unsigned int c;
        !            44: 
        !            45:     c = chars[ind] - firstCol;
        !            46:     if (c < numCols) {
        !            47:        if ( pCS == NULL ) return min_bounds;
        !            48:        cs = &pCS[c];
        !            49:        if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
        !            50:     }
        !            51:     c = chDefault - firstCol;
        !            52:     if (c >= numCols) return NULL;
        !            53:     if ( pCS == NULL ) return min_bounds;
        !            54:     cs = &pCS[c];
        !            55:     if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
        !            56:     return NULL;
        !            57: }
        !            58: 
        !            59: static
        !            60: XCharStruct *GetCS2d(min_bounds, pCS, firstCol, numCols, firstRow, numRows, ind, 
        !            61:        chars, chDefault)
        !            62:     XCharStruct *min_bounds;
        !            63:     XCharStruct pCS[];
        !            64:     unsigned int firstCol, numCols, firstRow, numRows, ind, chDefault;
        !            65:     char *chars;
        !            66: {
        !            67:     XCharStruct *cs;
        !            68:     unsigned int row, col, c;
        !            69: 
        !            70:     row = (chars[ind] >> 8)-firstRow;
        !            71:     col = (chars[ind] & 0xff)-firstCol;
        !            72:     if ((row < numRows) && (col < numCols)) {
        !            73:        if ( pCS == NULL ) return min_bounds;
        !            74:         c = row*numCols + col;
        !            75:        cs = &pCS[c];
        !            76:        if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
        !            77:     }
        !            78:     row = (chDefault >> 8)-firstRow;
        !            79:     col = (chDefault & 0xff)-firstCol;
        !            80:     if ((row >= numRows) || (col >= numCols)) return NULL;
        !            81:     if ( pCS == NULL ) return min_bounds;
        !            82:     c = row*numCols + col;
        !            83:     cs = &pCS[c];
        !            84:     if (! (cs->attributes & CI_NONEXISTCHAR)) return cs;
        !            85:     return NULL;
        !            86: }
        !            87: 
        !            88: static void
        !            89: GetGlyphs(font, count, chars, getGlyph, glyphcount, glyphs)
        !            90:     XFontStruct *font;
        !            91:     int count;
        !            92:     char *chars;
        !            93:     XCharStruct *(*getGlyph)();
        !            94:     unsigned int *glyphcount;  /* RETURN */
        !            95:     XCharStruct *glyphs[];     /* RETURN */
        !            96: {
        !            97:     unsigned int    firstCol = font->min_char_or_byte2;
        !            98:     unsigned int    numCols = font->max_char_or_byte2 - firstCol + 1;
        !            99:     unsigned int    firstRow = font->min_byte1;
        !           100:     unsigned int    numRows = font->max_byte1 - firstRow + 1;
        !           101:     unsigned int    chDefault = font->default_char;
        !           102:     int                    i, n;
        !           103:     XCharStruct            *cs;
        !           104: 
        !           105:     n = 0;
        !           106:     for (i=0; i < count; i++) {
        !           107:        cs = (* getGlyph)(
        !           108:            &font->min_bounds, font->per_char, firstCol, numCols, firstRow, numRows,
        !           109:            i, chars, chDefault);
        !           110:        if (cs != NULL) glyphs[n++] = cs;
        !           111:     }
        !           112:     *glyphcount = n;
        !           113: }
        !           114: 
        !           115: XTextExtents (fontstruct, string, nchars, dir, font_ascent, font_descent,
        !           116:                   overall)
        !           117:     XFontStruct *fontstruct;
        !           118:     register char *string;
        !           119:     register int nchars;
        !           120:     int *dir;
        !           121:     int *font_ascent, *font_descent;
        !           122:     register XCharStruct *overall;
        !           123: {
        !           124:     int        i;
        !           125:     unsigned int n;
        !           126: 
        !           127:     *dir = fontstruct->direction;
        !           128:     *font_ascent = fontstruct->max_bounds.ascent;
        !           129:     *font_descent = fontstruct->max_bounds.descent;
        !           130: 
        !           131:     {
        !           132:        XCharStruct **charstruct =
        !           133:            (XCharStruct **)Xmalloc((unsigned)nchars*sizeof(XCharStruct *));
        !           134:     
        !           135:        if (fontstruct->max_byte1 == 0)
        !           136:            GetGlyphs(fontstruct, nchars, string, GetCS, &n, charstruct);
        !           137:        else
        !           138:            GetGlyphs(fontstruct, nchars, string, GetCS2d, &n, charstruct);
        !           139:     
        !           140:        if (n != 0) {
        !           141:     
        !           142:            overall->ascent  = charstruct[0]->ascent;
        !           143:            overall->descent = charstruct[0]->descent;
        !           144:            overall->width   = charstruct[0]->width;
        !           145:            overall->lbearing    = charstruct[0]->lbearing;
        !           146:            overall->rbearing   = charstruct[0]->rbearing;
        !           147:     
        !           148:            for (i=1; i < nchars; i++) {
        !           149:                overall->ascent = max(
        !           150:                    overall->ascent,
        !           151:                    charstruct[i]->ascent);
        !           152:                overall->descent = max(
        !           153:                    overall->descent,
        !           154:                    charstruct[i]->descent);
        !           155:                overall->lbearing = min(
        !           156:                    overall->lbearing,
        !           157:                    overall->width+charstruct[i]->lbearing);
        !           158:                overall->rbearing = max(
        !           159:                    overall->rbearing,
        !           160:                    overall->width+charstruct[i]->rbearing);
        !           161:                overall->width += charstruct[i]->width;
        !           162:            }
        !           163:     
        !           164:        } else {
        !           165:     
        !           166:            overall->ascent  = 0;
        !           167:            overall->descent = 0;
        !           168:            overall->width   = 0;
        !           169:            overall->lbearing = 0;
        !           170:            overall->rbearing = 0;
        !           171:        }
        !           172:     
        !           173:        Xfree((char *)charstruct);
        !           174:     } 
        !           175:     return (1);
        !           176: }
        !           177: 
        !           178: int XTextWidth (fontstruct, string, count)
        !           179:     XFontStruct *fontstruct;
        !           180:     register char *string;
        !           181:     int count;
        !           182: {
        !           183:     int        i, width;
        !           184:     unsigned int n;
        !           185: 
        !           186:     {
        !           187:        XCharStruct **charstruct =
        !           188:            (XCharStruct **)Xmalloc((unsigned)count*sizeof(XCharStruct *));
        !           189:     
        !           190:        if (fontstruct->max_byte1 == 0)
        !           191:            GetGlyphs(fontstruct, count, string, GetCS, &n, charstruct);
        !           192:        else
        !           193:            GetGlyphs(fontstruct, count, string, GetCS2d, &n, charstruct);
        !           194:     
        !           195:        if (n != 0) {
        !           196:            width = 0;
        !           197:            for (i=0; i < n; i++) {
        !           198:                width += charstruct[i]->width;
        !           199:            }
        !           200:     
        !           201:        } else {
        !           202:            width   = 0;
        !           203:        }
        !           204:     
        !           205:        Xfree((char *)charstruct);
        !           206:     
        !           207:     } 
        !           208:     return (width);
        !           209: }
        !           210: 

unix.superglobalmegacorp.com

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