|
|
1.1 root 1: #include <X/mit-copyright.h>
2:
3: /* $Header: XStringWidth.c,v 10.4 86/02/01 15:40:32 tony Rel $ */
4: /* Copyright Massachusetts Institute of Technology 1985 */
5:
6: #include "XlibInternal.h"
7: int XStringWidth (string, info, charpad, spacepad)
8: register char *string;
9: register FontInfo *info;
10: register int charpad, spacepad;
11: {
12: register int result = 0;
13: if (!*string) /* zero length string */
14: return (0);
15:
16: if (info->fixedwidth) {
17: int length = strlen (string);
18: result = length * (info->width + charpad) - charpad;
19: /* don't pad last character */
20: if (spacepad) {
21: char *sub = string, *index();
22: while (sub = index (sub, ' ')) {
23: result += spacepad;
24: sub++;
25: }
26: if (string[length-1] == ' ')
27: result -= spacepad;
28: /* don't pad terminating space character */
29: }
30: }
31:
32: else { /* variable width font */
33: unsigned char c;
34: register short *widths = info->widths - info->firstchar;
35: while (c = *(string++)) {
36: if ((c >= info->firstchar) && (c <= info->lastchar))
37: result += (widths[c] + charpad);
38: if (c == ' ')
39: result += spacepad;
40: }
41: result -= charpad; /* don't pad last character */
42: if (*(string-1) == ' ')
43: result -= spacepad;
44: /* don't pad terminating space character */
45: }
46:
47: return (result);
48: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.