[Change] Unified some font stuff.
This commit is contained in:
parent
ef6220ad86
commit
b39876bb2b
54
src/font.c
54
src/font.c
@ -33,7 +33,28 @@ glFont gl_smallFont; /**< Small font. */
|
|||||||
static void glFontMakeDList(FT_Face face, char ch,
|
static void glFontMakeDList(FT_Face face, char ch,
|
||||||
GLuint list_base, GLuint* tex_base,
|
GLuint list_base, GLuint* tex_base,
|
||||||
int* width_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,
|
* @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. */
|
/*float h = ft_font->h / .63; // Slightly increases font size. */
|
||||||
char txt[256];
|
char txt[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i, n, len, ret;
|
int ret;
|
||||||
|
|
||||||
if(ft_font == NULL) ft_font = &gl_defFont;
|
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. */
|
/* Limit the size. */
|
||||||
len = (int)strlen(txt);
|
ret = font_limitSize(ft_font, NULL, txt, max);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Display the text. */
|
/* Display the text. */
|
||||||
glEnable(GL_TEXTURE_2D);
|
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.);
|
if(c == NULL) glColor4d(1., 1., 1., 1.);
|
||||||
else COLOUR(*c);
|
else COLOUR(*c);
|
||||||
glCallLists(i, GL_UNSIGNED_BYTE, &txt);
|
glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
|
||||||
|
|
||||||
glPopMatrix(); /* Translation matrix. */
|
glPopMatrix(); /* Translation matrix. */
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
gl_checkErr();
|
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. */
|
/*float h = ft_font->h / .63; // Slightly increases font size. */
|
||||||
char txt[256];
|
char txt[256];
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i, n, len, ret;
|
int n, ret;
|
||||||
|
|
||||||
ret = 0; /* Default return value. */
|
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. */
|
/* Limit the size. */
|
||||||
len = (int)strlen(txt);
|
ret = font_limitSize(ft_font, &n, txt, width);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
x += (double)(width-n)/2.;
|
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.);
|
if(c == NULL) glColor4d(1., 1., 1., 1.);
|
||||||
else COLOUR(*c);
|
else COLOUR(*c);
|
||||||
glCallLists(i, GL_UNSIGNED_BYTE, &txt);
|
glCallLists(ret, GL_UNSIGNED_BYTE, &txt);
|
||||||
|
|
||||||
glPopMatrix(); /* Translation matrix. */
|
glPopMatrix(); /* Translation matrix. */
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
gl_checkErr();
|
gl_checkErr();
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user