#include "Xlibint.h"
#define min_byte2 min_char_or_byte2
#define max_byte2 max_char_or_byte2
int
#if NeedFunctionPrototypes
XTextExtents16 (
XFontStruct *fs,
_Xconst XChar2b *string,
int nchars,
int *dir,
int *font_ascent,
int *font_descent,
register XCharStruct *overall)
#else
XTextExtents16 (fs, string, nchars, dir, font_ascent, font_descent, overall)
XFontStruct *fs;
XChar2b *string;
int nchars;
int *dir, *font_ascent, *font_descent;
register XCharStruct *overall;
#endif
{
int i;
Bool singlerow = (fs->max_byte1 == 0);
int nfound = 0;
XCharStruct *def;
if (singlerow) {
CI_GET_DEFAULT_INFO_1D (fs, def);
} else {
CI_GET_DEFAULT_INFO_2D (fs, def);
}
*dir = fs->direction;
*font_ascent = fs->ascent;
*font_descent = fs->descent;
for (i = 0; i < nchars; i++, string++) {
register XCharStruct *cs;
unsigned int r = (unsigned int) string->byte1;
unsigned int c = (unsigned int) string->byte2;
if (singlerow) {
unsigned int ind = ((r << 8) | c);
CI_GET_CHAR_INFO_1D (fs, ind, def, cs);
} else {
CI_GET_CHAR_INFO_2D (fs, r, c, def, cs);
}
if (cs) {
if (nfound++ == 0) {
*overall = *cs;
} else {
overall->ascent = max (overall->ascent, cs->ascent);
overall->descent = max (overall->descent, cs->descent);
overall->lbearing = min (overall->lbearing,
overall->width + cs->lbearing);
overall->rbearing = max (overall->rbearing,
overall->width + cs->rbearing);
overall->width += cs->width;
}
}
}
if (nfound == 0) {
overall->width = overall->ascent = overall->descent =
overall->lbearing = overall->rbearing = 0;
}
return 0;
}
#if NeedFunctionPrototypes
int XTextWidth16 (
XFontStruct *fs,
_Xconst XChar2b *string,
int count)
#else
int XTextWidth16 (fs, string, count)
XFontStruct *fs;
XChar2b *string;
int count;
#endif
{
int i;
Bool singlerow = (fs->max_byte1 == 0);
XCharStruct *def;
int width = 0;
if (singlerow) {
CI_GET_DEFAULT_INFO_1D (fs, def);
} else {
CI_GET_DEFAULT_INFO_2D (fs, def);
}
if (def && fs->min_bounds.width == fs->max_bounds.width)
return (fs->min_bounds.width * count);
for (i = 0; i < count; i++, string++) {
register XCharStruct *cs;
unsigned int r = (unsigned int) string->byte1;
unsigned int c = (unsigned int) string->byte2;
if (singlerow) {
unsigned int ind = ((r << 8) | c);
CI_GET_CHAR_INFO_1D (fs, ind, def, cs);
} else {
CI_GET_CHAR_INFO_2D (fs, r, c, def, cs);
}
if (cs) width += cs->width;
}
return width;
}
#if NeedFunctionPrototypes
int _XTextHeight16 (
XFontStruct *fs,
_Xconst XChar2b *string,
int count)
#else
int _XTextHeight16 (fs, string, count)
XFontStruct *fs;
XChar2b *string;
int count;
#endif
{
int i;
Bool singlerow = (fs->max_byte1 == 0);
XCharStruct *def;
int height = 0;
if (singlerow) {
CI_GET_DEFAULT_INFO_1D (fs, def);
} else {
CI_GET_DEFAULT_INFO_2D (fs, def);
}
if (def && (fs->min_bounds.ascent == fs->max_bounds.ascent)
&& (fs->min_bounds.descent == fs->max_bounds.descent))
return ((fs->min_bounds.ascent + fs->min_bounds.descent) * count);
for (i = 0; i < count; i++, string++) {
register XCharStruct *cs;
unsigned int r = (unsigned int) string->byte1;
unsigned int c = (unsigned int) string->byte2;
if (singlerow) {
unsigned int ind = ((r << 8) | c);
CI_GET_CHAR_INFO_1D (fs, ind, def, cs);
} else {
CI_GET_CHAR_INFO_2D (fs, r, c, def, cs);
}
if (cs) height += (cs->ascent + cs->descent);
}
return height;
}