float H_GetTextWidth( const char *text, fontInfo_t *font, float scale )
{
glyphInfo_t *glyphs;
int count, len;
float w, t;
w = t = count = 0;
glyphs = H_GetGlyphInfo(font);
if (text && glyphs) {
const char *s = text;
len = strlen(text);
while (s && *s && count < len) {
if (Q_IsColorString(s)) {
s+=2, count+=2;
continue;
} else if (*s == '\n') {
w = 0;
} else if (*s >= GLYPH_CHARSTART && *s < GLYPH_CHAREND) {
w += glyphs[*s - GLYPH_CHARSTART].xSkip;
t = max(t, w);
}
s++;
count++;
}
}
return t * scale;
}
float H_GetTextHeight( const char *text, fontInfo_t *font, float scale )
{
glyphInfo_t *glyphs;
int count, len;
float h, t;
h = t = count = 0;
glyphs = H_GetGlyphInfo(font);
if (text && glyphs) {
const char *s = text;
len = strlen(text);
while (s && *s && count < len) {
if (Q_IsColorString(s)) {
s+=2, count+=2;
continue;
} else if (*s == '\n') {
t += h; // add our height to our total height
h = 0; // reset our height
}
else if (*s >= GLYPH_CHARSTART && *s < GLYPH_CHAREND) {
h = max(h, glyphs[*s - GLYPH_CHARSTART].imageHeight);
}
s++;
count++;
}
t += h; // add our last line height
}
return t * scale;
}
float H_GetLineWidth( const char *text, fontInfo_t *font, float scale )
{
glyphInfo_t *glyphs;
int count, len;
float w;
w = count = 0;
glyphs = H_GetGlyphInfo(font);
if (text && glyphs) {
const char *s = text;
len = strlen(text);
while (s && *s && count < len) {
if (Q_IsColorString(s)) {
s+=2, count+=2;
continue;
} else if (*s == '\n') {
break;
} else if (*s >= GLYPH_CHARSTART && *s < GLYPH_CHAREND) {
w += glyphs[*s - GLYPH_CHARSTART].xSkip;
}
s++;
count++;
}
}
return w * scale;
}
float H_GetLineHeight( const char *text, fontInfo_t *font, float scale )
{
glyphInfo_t *glyphs;
int count, len;
float h;
h = count = 0;
glyphs = H_GetGlyphInfo(font);
if (text && glyphs) {
const char *s = text;
len = strlen(text);
while (s && *s && count < len) {
if (Q_IsColorString(s)) {
s+=2, count+=2;
continue;
} else if (*s == '\n') {
break;
} else if (*s >= GLYPH_CHARSTART && *s < GLYPH_CHAREND) {
h = max(h, glyphs[*s - GLYPH_CHARSTART].imageHeight);
}
s++;
count++;
}
}
return h * scale;
}
void H_DrawString( const char *text, fontInfo_t *font, float x, float y, float scale, vec4_t color )
{
glyphInfo_t *glyphs, *glyph;
float h, xadj, yadj;
vec4_t newColor;
int len, count;
glyphs = H_GetGlyphInfo(font);
if (text && glyphs) {
char *s = (char*)text, c[2];
len = strlen(text);
c[1] = h = xadj = yadj = count = 0;
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
while (s && *s && count < len) {
glyph = &glyphs[*s - GLYPH_CHARSTART];
if (h == 0) {
h = H_GetLineHeight(s, font, scale);
}
if (Q_IsColorString(s)) {
memcpy(&newColor[0], &g_color_table[ColorIndex(*(s+1))][0], sizeof(vec4_t));
s+=2, count+=2;
continue;
} else if (*s == '\n') {
y += h;
h = xadj = 0;
} else {
c[0] = *s; // this makes me sad, need to find DrawChar stuff
yadj = glyph->top + (h - (glyph->imageHeight * scale));
CG_DrawString(c, 0x7FFFFFFF, font, x + xadj, y + yadj - (glyph->pitch * scale), scale, scale, newColor, 0);
xadj += glyph->xSkip * scale;
}
s++;
count++;
}
}
}