Fix negative glyph index in Team Arena text functions

Team Arena's text functions cast signed char values to int and use as an array index.
This works fine for values 0 to 127, but not for -128 to -1 which are a negative array index.
Instead use "character & 255" like client and original Q3 ui/cgame string drawing code.
This commit is contained in:
Zack Middleton 2014-12-01 21:53:06 -06:00
parent 08ddb99732
commit b21a59af8c
3 changed files with 10 additions and 16 deletions

View File

@ -49,8 +49,6 @@ int CG_Text_Width(const char *text, float scale, int limit) {
float out;
glyphInfo_t *glyph;
float useScale;
// FIXME: see ui_main.c, same problem
// const unsigned char *s = text;
const char *s = text;
fontInfo_t *font = &cgDC.Assets.textFont;
if (scale <= cg_smallFont.value) {
@ -71,7 +69,7 @@ int CG_Text_Width(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
out += glyph->xSkip;
s++;
count++;
@ -86,8 +84,6 @@ int CG_Text_Height(const char *text, float scale, int limit) {
float max;
glyphInfo_t *glyph;
float useScale;
// TTimo: FIXME
// const unsigned char *s = text;
const char *s = text;
fontInfo_t *font = &cgDC.Assets.textFont;
if (scale <= cg_smallFont.value) {
@ -108,7 +104,7 @@ int CG_Text_Height(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if (max < glyph->height) {
max = glyph->height;
}
@ -141,8 +137,6 @@ void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text
}
useScale = scale * font->glyphScale;
if (text) {
// TTimo: FIXME
// const unsigned char *s = text;
const char *s = text;
trap_R_SetColor( color );
memcpy(&newColor[0], &color[0], sizeof(vec4_t));
@ -152,7 +146,7 @@ void CG_Text_Paint(float x, float y, float scale, vec4_t color, const char *text
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {

View File

@ -1214,7 +1214,7 @@ static void CG_Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];

View File

@ -284,7 +284,7 @@ int Text_Width(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s];
glyph = &font->glyphs[*s & 255];
out += glyph->xSkip;
s++;
count++;
@ -319,7 +319,7 @@ int Text_Height(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if (max < glyph->height) {
max = glyph->height;
}
@ -361,7 +361,7 @@ void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, f
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
@ -429,9 +429,9 @@ void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const cha
len = limit;
}
count = 0;
glyph2 = &font->glyphs[ (int) cursor];
glyph2 = &font->glyphs[cursor & 255];
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
@ -528,7 +528,7 @@ static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];