|
|
BSD 4.3
#include <X/mit-copyright.h>
/* $Header: /var/lib/cvsd/repos/CSRG/43BSD/contrib/X/Xlib/XStringWidth.c,v 1.1.1.1 2018/04/24 16:12:54 root Exp $ */
/* Copyright Massachusetts Institute of Technology 1985 */
#include "XlibInternal.h"
int XStringWidth (string, info, charpad, spacepad)
register char *string;
register FontInfo *info;
register int charpad, spacepad;
{
register int result = 0;
if (!*string) /* zero length string */
return (0);
if (info->fixedwidth) {
int length = strlen (string);
result = length * (info->width + charpad) - charpad;
/* don't pad last character */
if (spacepad) {
char *sub = string, *index();
while (sub = index (sub, ' ')) {
result += spacepad;
sub++;
}
if (string[length-1] == ' ')
result -= spacepad;
/* don't pad terminating space character */
}
}
else { /* variable width font */
unsigned char c;
register short *widths = info->widths - info->firstchar;
while (c = *(string++)) {
if ((c >= info->firstchar) && (c <= info->lastchar))
result += (widths[c] + charpad);
if (c == ' ')
result += spacepad;
}
result -= charpad; /* don't pad last character */
if (*(string-1) == ' ')
result -= spacepad;
/* don't pad terminating space character */
}
return (result);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.