[Change] Unified some font stuff.

This commit is contained in:
Allanis 2014-02-09 15:52:03 +00:00
parent ef6220ad86
commit b39876bb2b

View File

@ -33,7 +33,28 @@ glFont gl_smallFont; /**< Small font. */
static void glFontMakeDList(FT_Face face, char ch,
GLuint list_base, GLuint* tex_base,
int* width_base);
static int font_limitSize(const glFont* ft_font, int* width,
char* text, const int max);
static int font_limitSize(const glFont* ft_font, int* width,
char* text, const int max) {
int n, len, i;
/* Limit size. */
len = (int)strlen(text);
n = 0;
for(i = 0; i < len; i++) {
n += ft_font->w[(int)text[i]];
if(n > max) {
n -= ft_font->w[(int)text[i]]; /* Actual size. */
text[i] = '\0';
break;
}
}
if(width != NULL)
(*width) = n;
return i;
}
/**
* @fn void gl_print(const glFont* ft_font, const double x, const double y,
@ -100,7 +121,7 @@ int gl_printMax(const glFont* ft_font, const int max,
/*float h = ft_font->h / .63; // Slightly increases font size. */
char txt[256];
va_list ap;
int i, n, len, ret;
int ret;
if(ft_font == NULL) ft_font = &gl_defFont;
@ -113,15 +134,7 @@ int gl_printMax(const glFont* ft_font, const int max,
}
/* Limit the size. */
len = (int)strlen(txt);
for(n = 0, i = 0; i < len; i++) {
n += ft_font->w[(int)txt[i]];
if(n > max) {
ret = len - i; /* Difference. */
txt[i] = '\0';
break;
}
}
ret = font_limitSize(ft_font, NULL, txt, max);
/* Display the text. */
glEnable(GL_TEXTURE_2D);
@ -134,14 +147,14 @@ int gl_printMax(const glFont* ft_font, const int max,
if(c == NULL) glColor4d(1., 1., 1., 1.);
else COLOUR(*c);
glCallLists(i, GL_UNSIGNED_BYTE, &txt);
glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
glPopMatrix(); /* Translation matrix. */
glDisable(GL_TEXTURE_2D);
gl_checkErr();
return ret;
return 0;
}
/**
@ -164,7 +177,7 @@ int gl_printMid(const glFont* ft_font, const int width, double x, const double y
/*float h = ft_font->h / .63; // Slightly increases font size. */
char txt[256];
va_list ap;
int i, n, len, ret;
int n, ret;
ret = 0; /* Default return value. */
@ -179,16 +192,7 @@ int gl_printMid(const glFont* ft_font, const int width, double x, const double y
}
/* Limit the size. */
len = (int)strlen(txt);
for(n = 0, i = 0; i < len; i++) {
n += ft_font->w[(int)txt[i]];
if(n > width) {
ret = len - i; /* Difference. */
n -= ft_font->w[(int)txt[i]]; /* Actual size. */
txt[i] = '\0';
break;
}
}
ret = font_limitSize(ft_font, &n, txt, width);
x += (double)(width-n)/2.;
@ -203,14 +207,14 @@ int gl_printMid(const glFont* ft_font, const int width, double x, const double y
if(c == NULL) glColor4d(1., 1., 1., 1.);
else COLOUR(*c);
glCallLists(i, GL_UNSIGNED_BYTE, &txt);
glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
glPopMatrix(); /* Translation matrix. */
glDisable(GL_TEXTURE_2D);
gl_checkErr();
return ret;
return 0;
}
/**