|
|
1.1 ! root 1: #ifndef lint ! 2: static char *rcsid_textutil_c = "$Header: textutil.c,v 10.1 86/11/29 13:53:04 jg Rel $"; ! 3: #endif lint ! 4: /* ! 5: ! 6: Copyright 1986 by the University of Utah ! 7: ! 8: Permission to use, copy, modify, and distribute this ! 9: software and its documentation for any purpose and without ! 10: fee is hereby granted, provided that the above copyright ! 11: notice appear in all copies and that both that copyright ! 12: notice and this permission notice appear in supporting ! 13: documentation, and that the name of the University of Utah ! 14: not be used in advertising or publicity pertaining to ! 15: distribution of the software without specific, written ! 16: prior permission. The University of Utah makes no ! 17: representations about the suitability of this software for ! 18: any purpose. It is provided "as is" without express or ! 19: implied warranty. ! 20: ! 21: */ ! 22: ! 23: /* textutil.c text related utility routines. ! 24: * ! 25: * CopyText Copy text to bitmap ! 26: * TextWidth Returns width of a piece of text in a font ! 27: * CharWidth Returns width of a character in a font ! 28: * ! 29: */ ! 30: ! 31: #include "Xapollo.h" ! 32: ! 33: status_$t status; ! 34: ! 35: CopyText (string, strlen, font, bm) ! 36: char *string; ! 37: int strlen; ! 38: FONT *font; ! 39: BITMAP *bm; ! 40: { ! 41: FontPriv * fp; ! 42: ! 43: fp = (FontPriv *)font->data; ! 44: gpr_$set_text_font( (short)fp->ap_font_id, status); ! 45: gpr_$set_bitmap( bm->data, status); ! 46: gpr_$text(*string, (short)strlen, status); ! 47: gpr_$set_bitmap(Screen.bm); ! 48: } ! 49: ! 50: /* Returns the width of a string in a font ! 51: * Works only for Apollo-type fonts ! 52: */ ! 53: int TextWidth (string, strlen, spacepad, font) ! 54: register char *string; ! 55: register int strlen; ! 56: int spacepad; ! 57: register FONT *font; ! 58: { ! 59: register int width = 0; ! 60: ! 61: if (font->fixed) { ! 62: width = strlen * font->avg_width; ! 63: if (spacepad) { ! 64: while (--strlen >= 0) ! 65: if (*string++ == font->space) ! 66: width += spacepad; ! 67: } ! 68: } else { ! 69: FontPriv * fp; ! 70: gpr_$offset_t size; ! 71: ! 72: fp = (FontPriv *)font->data; ! 73: gpr_$set_text_font( (short)fp->ap_font_id, status); ! 74: gpr_$inq_text_extent(*string, (short)strlen, size, status); ! 75: width = size.x_size; ! 76: } ! 77: ! 78: return (width); ! 79: } ! 80: ! 81: /* Returns width of a character in a font. ! 82: * Works only for Apollo-type fonts ! 83: */ ! 84: int ! 85: CharWidth(c, font) ! 86: register unsigned int c; ! 87: register FONT *font; ! 88: { ! 89: FontPriv * fp; ! 90: int width; ! 91: ! 92: if (c < font->first || c > font->last) ! 93: return (0); ! 94: fp = (FontPriv *)font->data; ! 95: gpr_$inq_character_width( (short)fp->ap_font_id, c, (short)width, status); ! 96: return(width); ! 97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.