aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/obm/ObmW/TextWidth.c
blob: b213d1988f2c305fe600ce18e4047cb31328e3dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include "TabString.h"

/*
 *	Like TextWidth, except it takes an additional  "tabs"
 *	argument, used to specify what horizontal pixel position to
 *	move to when tab characters are present in the string.  If
 *	the "tabs" argument is NULL, works exactly like its
 *	counterpart.
 */
int
XfwfTextWidth(font, str, length, tabs)
     XFontStruct *font;
     String str;
     int length;
     int *tabs;
{
	register char	*p, *ep;
	register int	tx, tab, rc;

	tab = tx = 0;
 	if (length == 0) return 0;
	for (p = str; length; )
	{
		ep = strnchr(p, '\t', length);
		if (ep && tabs)
		{
			tx = tabs[tab++];
			length -= ep - p + 1;
			p = ep + 1;
		}
		else
		{
			rc = XTextWidth(font, p, length);
			if (rc < 0) return rc; else return rc + tx;
		}
	}
}