1: /* Copyright 1985, Massachusetts Institute of Technology */ 2: 3: /* textutil.c text related utility routines. 4: * 5: * CopyText Copy text to bitmap 6: * TextWidth Returns width of a piece of text in a font 7: * CharWidth Returns width of a character in a font 8: * 9: */ 10: 11: #include "ddxqvss.h" 12: #include "vstagbl.h" 13: 14: CopyText (string, strlen, font, bm) 15: register char *string; 16: register int strlen; 17: FONT *font; 18: register BITMAP *bm; 19: { 20: 21: int dstx,srcx,w,h; 22: FontPriv *pfont; 23: BITMAP *fbm; 24: 25: pfont = FDATA(font); 26: fbm = pfont->strike; 27: 28: dstx = 0; 29: h = font->height; 30: 31: while (strlen--) 32: { 33: 34: /* SET THE WIDTH OF THE CHARACTER */ 35: 36: w = pfont->widths[*string]; 37: srcx = pfont->leftarray[*string++]; 38: 39: /* CALL THE COPY BITMAP PROCEDURE TO COPY THE CHARACTER 40: FROM THE FONT BITMAP TO THE DESTINATION BITMAP */ 41: 42: copyrmsk(VSTA$K_SRC_BITMAP, (short *)fbm->data, fbm->width, 43: fbm->height, srcx, 0, w, h, 44: (short *)bm->data, bm->width, bm->height, dstx, 0, 45: VSTA$K_MAP_SRC, 0, 0); 46: 47: /* ADD THE WIDTH OF THE CHARACTER TO THE DST OFFSET */ 48: 49: dstx += w; 50: 51: }; 52: } 53: 54: /* Returns the width of a string in a font */ 55: 56: int TextWidth (string, strlen, spacepad, font) 57: register char *string; 58: register int strlen; 59: int spacepad; 60: register FONT *font; 61: { 62: register unsigned int c; 63: register short *widths; 64: int width = 0; 65: 66: if (font->fixed) { 67: width = strlen * font->avg_width; 68: if (spacepad) { 69: while (--strlen >= 0) 70: if (*string++ == font->space) 71: width += spacepad; 72: } 73: } else { 74: widths = FDATA(font)->widths; 75: while (--strlen >= 0) { 76: c = *string++; 77: if (c >= font->first && c <= font->last) { 78: if (c == font->space) 79: width += spacepad; 80: width += widths[c - font->first]; 81: } 82: } 83: } 84: 85: return (width); 86: } 87: 88: /* Returns width of a character in a font. */ 89: 90: int CharWidth(c, font) 91: register unsigned int c; 92: register FONT *font; 93: { 94: 95: if (c < font->first || c > font->last) 96: return (0); 97: else if (font->fixed) 98: return (font->avg_width); 99: else 100: return (FDATA(font)->widths[c - font->first]); 101: }