|
|
1.1 root 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: char *string;
58: register int strlen;
59: int spacepad;
60: register FONT *font;
61: {
62: register u_char *strptr = (u_char *) string;
63: short c;
64: register short *widths;
65: int width = 0;
66:
67: if (font->fixed) {
68: width = strlen * font->avg_width;
69: if (spacepad) {
70: while (--strlen >= 0)
71: if (*strptr++ == font->space)
72: width += spacepad;
73: }
74: } else {
75: widths = FDATA(font)->widths;
76: while (--strlen >= 0) {
77: c = *strptr++;
78: if (c >= font->first && c <= font->last) {
79: if (c == font->space)
80: width += spacepad;
81: width += widths[c];
82: }
83: }
84: }
85:
86: return (width);
87: }
88:
89: /* Returns width of a character in a font. */
90:
91: int CharWidth(c, font)
92: register unsigned int c;
93: register FONT *font;
94: {
95:
96: if (c < font->first || c > font->last)
97: return (0);
98: else if (font->fixed)
99: return (font->avg_width);
100: else
101: return (FDATA(font)->widths[c]);
102: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.