|
|
1.1 ! root 1: #ifndef lint ! 2: static char *rcsid_textutil_c = "$Header: textutil.c,v 10.2 86/02/01 16:21:27 tony Rel $"; ! 3: #endif lint ! 4: #ifdef sun ! 5: /* ! 6: * The Sun X drivers are a product of Sun Microsystems, Inc. and are provided ! 7: * for unrestricted use provided that this legend is included on all tape ! 8: * media and as a part of the software program in whole or part. Users ! 9: * may copy or modify these drivers without charge, but are not authorized ! 10: * to license or distribute them to anyone else except as part of a product or ! 11: * program developed by the user. ! 12: * ! 13: * THE SUN X DRIVERS ARE PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND ! 14: * INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A ! 15: * PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE ! 16: * PRACTICE. ! 17: * ! 18: * The Sun X Drivers are provided with no support and without any obligation ! 19: * on the part of Sun Microsystems, Inc. to assist in their use, correction, ! 20: * modification or enhancement. ! 21: * ! 22: * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE ! 23: * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THE SUN X ! 24: * DRIVERS OR ANY PART THEREOF. ! 25: * ! 26: * In no event will Sun Microsystems, Inc. be liable for any lost revenue ! 27: * or profits or other special, indirect and consequential damages, even if ! 28: * Sun has been advised of the possibility of such damages. ! 29: * ! 30: * Sun Microsystems, Inc. ! 31: * 2550 Garcia Avenue ! 32: * Mountain View, California 94043 ! 33: */ ! 34: ! 35: #ifndef lint ! 36: static char sccsid[] = "@(#)textutil.c 2.1 86/01/28 Copyright 1986 Sun Micro"; ! 37: #endif ! 38: ! 39: /*- ! 40: * Copyright (c) 1986 by Sun Microsystems, Inc. ! 41: */ ! 42: ! 43: /* textutil.c text related utility routines. ! 44: * ! 45: * CopyText Copy text to bitmap ! 46: * TextWidth Returns width of a piece of text in a font ! 47: * CharWidth Returns width of a character in a font ! 48: * ! 49: */ ! 50: ! 51: /* ! 52: * ToDo: ! 53: * Use static pixrects ! 54: */ ! 55: ! 56: #include "Xsun.h" ! 57: ! 58: CopyText (string, strlen, font, bm) ! 59: char *string; ! 60: int strlen; ! 61: FONT *font; ! 62: BITMAP *bm; ! 63: { ! 64: struct pixrect *region; ! 65: int i; ! 66: register struct pixfont *pf = (struct pixfont *) font->data; ! 67: char *buf = (char *) Xalloc(strlen + 1); ! 68: ! 69: strncpy(buf, string, strlen); /* XXX - to guarantee ! 70: * zero-termination (BARF!) */ ! 71: region = mem_point(bm->width, bm->height, 1, (short *) bm->data); /* XXX - slow!! */ ! 72: #define CHUNK 80 ! 73: for (i = 0; i < strlen; i += CHUNK) { ! 74: register int j; ! 75: struct pr_prpos bat[CHUNK]; ! 76: ! 77: for (j = 0; j < CHUNK && i + j < strlen; j++) { ! 78: int c = string[i + j]; ! 79: register struct pixchar *pc = &(pf->pf_char[c]); ! 80: ! 81: bat[j].pr = pc->pc_pr; ! 82: bat[j].pos = pc->pc_adv; ! 83: } ! 84: pr_batchrop(region, 0 - bat[0].pos.x, 0 - bat[0].pos.y, PIX_SRC, bat, j); ! 85: } ! 86: pr_destroy(region); /* XXX - slow */ ! 87: free((caddr_t) buf); ! 88: } ! 89: ! 90: /* Returns the width of a string in a font */ ! 91: ! 92: int TextWidth (string, strlen, spacepad, font) ! 93: register char *string; ! 94: register int strlen; ! 95: int spacepad; ! 96: register FONT *font; ! 97: { ! 98: register unsigned int c; ! 99: register int width = 0; ! 100: ! 101: if (font->fixed) { ! 102: width = strlen * font->avg_width; ! 103: if (spacepad) { ! 104: while (--strlen >= 0) ! 105: if (*string++ == font->space) ! 106: width += spacepad; ! 107: } ! 108: } else { ! 109: register struct pixfont *pf = (struct pixfont *)font->data; ! 110: while (--strlen >= 0) { ! 111: c = *string++; ! 112: if (c >= font->first && c <= font->last) { ! 113: if (c == font->space) ! 114: width += spacepad; ! 115: width += pf->pf_char[c].pc_adv.x; ! 116: } ! 117: } ! 118: } ! 119: ! 120: return (width); ! 121: } ! 122: ! 123: /* Returns width of a character in a font. */ ! 124: ! 125: int CharWidth(c, font) ! 126: register unsigned int c; ! 127: register FONT *font; ! 128: { ! 129: ! 130: if (c < font->first || c > font->last) ! 131: return (0); ! 132: else if (font->fixed) ! 133: return (font->avg_width); ! 134: else ! 135: return (((struct pixfont *) font->data)->pf_char[c].pc_adv.x); ! 136: } ! 137: #endif sun
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.