
#include <exec/types.h>
#include <graphics/text.h>


UWORD AvgFontXSize(struct TextFont *tf)
{
	UWORD xsize;

	if (tf->tf_Flags & FPF_PROPORTIONAL)
	{
		ULONG	sum;
		WORD	*spacing = (WORD *)tf->tf_CharSpace,
				*kerning = (WORD *)tf->tf_CharKern;
		UBYTE	lo, hi, i;

		lo = (' ' >= tf->tf_LoChar) ? ' ' : tf->tf_LoChar;
		hi = ('z' <= tf->tf_HiChar) ? 'z' : tf->tf_HiChar;
		
		sum = -kerning[0];

		for (i=lo; i <= hi; i++)
			sum += spacing[i] + kerning[i];

		sum /= hi - lo + 1;
		xsize = sum;
	}
	else
		xsize = tf->tf_XSize;

	return xsize;
}


