Add back bitmap draw mode, right now only internal font, tomorrow
freetype2.
This commit is contained in:
@@ -91,4 +91,8 @@ void BLF_dir_free(char **dirs, int count);
|
||||
#define BLF_ROTATION (1<<0)
|
||||
#define BLF_CLIPPING (1<<1)
|
||||
|
||||
/* font->mode. */
|
||||
#define BLF_MODE_TEXTURE 0
|
||||
#define BLF_MODE_BITMAP 1
|
||||
|
||||
#endif /* BLF_API_H */
|
||||
|
||||
@@ -286,22 +286,31 @@ void BLF_draw(char *str)
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font && font->draw) {
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
if (font->mode == BLF_MODE_BITMAP) {
|
||||
/* the pixmap alignment is handle
|
||||
* in BLF_position (old ui_rasterpos_safe).
|
||||
*/
|
||||
glRasterPos3f(font->pos[0], font->pos[1], font->pos[2]);
|
||||
(*font->draw)(font, str);
|
||||
}
|
||||
else {
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
|
||||
glScalef(font->aspect, font->aspect, 1.0);
|
||||
glPushMatrix();
|
||||
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
|
||||
glScalef(font->aspect, font->aspect, 1.0);
|
||||
|
||||
if (font->flags & BLF_ROTATION)
|
||||
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
|
||||
if (font->flags & BLF_ROTATION)
|
||||
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
(*font->draw)(font, str);
|
||||
(*font->draw)(font, str);
|
||||
|
||||
glPopMatrix();
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopMatrix();
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,3 +364,12 @@ void BLF_clipping(float xmin, float ymin, float xmax, float ymax)
|
||||
font->clip_rec.ymax= ymax;
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_mode(int mode)
|
||||
{
|
||||
FontBLF *font;
|
||||
|
||||
font= global_font[global_font_cur];
|
||||
if (font)
|
||||
font->mode= mode;
|
||||
}
|
||||
|
||||
@@ -274,6 +274,7 @@ void blf_font_free(FontBLF *font)
|
||||
void blf_font_fill(FontBLF *font)
|
||||
{
|
||||
font->type= BLF_FONT_FREETYPE2;
|
||||
font->mode= BLF_MODE_TEXTURE;
|
||||
font->ref= 1;
|
||||
font->aspect= 1.0f;
|
||||
font->pos[0]= 0.0f;
|
||||
|
||||
@@ -144,7 +144,7 @@ void blf_internal_size(FontBLF *font, int size, int dpi)
|
||||
return;
|
||||
}
|
||||
|
||||
void blf_internal_draw(FontBLF *font, char *str)
|
||||
void blf_internal_texture_draw(FontBLF *font, char *str)
|
||||
{
|
||||
FontDataBLF *data;
|
||||
CharDataBLF *cd;
|
||||
@@ -207,6 +207,41 @@ void blf_internal_draw(FontBLF *font, char *str)
|
||||
}
|
||||
}
|
||||
|
||||
void blf_internal_bitmap_draw(FontBLF *font, char *str)
|
||||
{
|
||||
FontDataBLF *data;
|
||||
CharDataBLF *cd;
|
||||
unsigned char c;
|
||||
GLint alignment;
|
||||
|
||||
data= (FontDataBLF *)font->engine;
|
||||
|
||||
glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
while ((c= (unsigned char) *str++)) {
|
||||
cd= &data->chars[c];
|
||||
|
||||
if (cd->data_offset==-1) {
|
||||
GLubyte nullBitmap= 0;
|
||||
glBitmap(1, 1, 0, 0, cd->advance, 0, &nullBitmap);
|
||||
} else {
|
||||
GLubyte *bitmap= &data->bitmap_data[cd->data_offset];
|
||||
glBitmap(cd->width, cd->height, cd->xorig, cd->yorig, cd->advance, 0, bitmap);
|
||||
}
|
||||
}
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
|
||||
}
|
||||
|
||||
void blf_internal_draw(FontBLF *font, char *str)
|
||||
{
|
||||
if (font->mode == BLF_MODE_BITMAP)
|
||||
blf_internal_bitmap_draw(font, str);
|
||||
else
|
||||
blf_internal_texture_draw(font, str);
|
||||
}
|
||||
|
||||
void blf_internal_boundbox(FontBLF *font, char *str, rctf *box)
|
||||
{
|
||||
FontDataBLF *data;
|
||||
@@ -313,6 +348,7 @@ FontBLF *blf_internal_new(char *name)
|
||||
|
||||
font->type= BLF_FONT_INTERNAL;
|
||||
font->ref= 1;
|
||||
font->mode= BLF_MODE_TEXTURE;
|
||||
font->aspect= 1.0f;
|
||||
font->pos[0]= 0.0f;
|
||||
font->pos[1]= 0.0f;
|
||||
@@ -336,10 +372,12 @@ FontBLF *blf_internal_new(char *name)
|
||||
font->height_get= blf_internal_height;
|
||||
font->free= blf_internal_free;
|
||||
|
||||
if (blf_internal_get_texture(font) != 0) {
|
||||
MEM_freeN(font->name);
|
||||
MEM_freeN(font);
|
||||
return(NULL);
|
||||
if (font->mode == BLF_MODE_TEXTURE) {
|
||||
if (blf_internal_get_texture(font) != 0) {
|
||||
MEM_freeN(font->name);
|
||||
MEM_freeN(font);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return(font);
|
||||
|
||||
@@ -123,6 +123,9 @@ typedef struct FontBLF {
|
||||
/* font type, can be freetype2 or internal. */
|
||||
int type;
|
||||
|
||||
/* draw mode, texture or bitmap. */
|
||||
int mode;
|
||||
|
||||
/* reference count. */
|
||||
int ref;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user