Style cleanup in blenfont (spaces, C++ comments, etc.).

This commit is contained in:
Bastien Montagne 2012-03-12 09:22:16 +00:00
parent 51c553befb
commit 30907594b6
10 changed files with 549 additions and 559 deletions

@ -76,61 +76,49 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
void BLF_draw(int fontid, const char *str, size_t len);
void BLF_draw_ascii(int fontid, const char *str, size_t len);
/*
* This function return the bounding box of the string
/* This function return the bounding box of the string
* and are not multiplied by the aspect.
*/
void BLF_boundbox(int fontid, const char *str, struct rctf *box);
/*
* The next both function return the width and height
/* The next both function return the width and height
* of the string, using the current font and both value
* are multiplied by the aspect of the font.
*/
float BLF_width(int fontid, const char *str);
float BLF_height(int fontid, const char *str);
/*
* Return dimensions of the font without any sample text.
*/
/* Return dimensions of the font without any sample text. */
float BLF_height_max(int fontid);
float BLF_width_max(int fontid);
float BLF_descender(int fontid);
float BLF_ascender(int fontid);
/*
* The following function return the width and height of the string, but
/* The following function return the width and height of the string, but
* just in one call, so avoid extra freetype2 stuff.
*/
void BLF_width_and_height(int fontid, const char *str, float *width, float *height);
/*
* For fixed width fonts only, returns the width of a
/* For fixed width fonts only, returns the width of a
* character.
*/
float BLF_fixed_width(int fontid);
/*
* and this two function return the width and height
/* and this two function return the width and height
* of the string, using the default font and both value
* are multiplied by the aspect of the font.
*/
float BLF_width_default(const char *str);
float BLF_height_default(const char *str);
/*
* Set rotation for default font.
*/
/* Set rotation for default font. */
void BLF_rotation_default(float angle);
/*
* Enable/disable options to the default font.
*/
/* Enable/disable options to the default font. */
void BLF_enable_default(int option);
void BLF_disable_default(int option);
/*
* By default, rotation and clipping are disable and
/* By default, rotation and clipping are disable and
* have to be enable/disable using BLF_enable/disable.
*/
void BLF_rotation(int fontid, float angle);
@ -141,39 +129,34 @@ void BLF_blur(int fontid, int size);
void BLF_enable(int fontid, int option);
void BLF_disable(int fontid, int option);
/*
* Shadow options, level is the blur level, can be 3, 5 or 0 and
/* Shadow options, level is the blur level, can be 3, 5 or 0 and
* the other argument are the rgba color.
* Take care that shadow need to be enable using BLF_enable!!.
* Take care that shadow need to be enable using BLF_enable!!!
*/
void BLF_shadow(int fontid, int level, float r, float g, float b, float a);
/*
* Set the offset for shadow text, this is the current cursor
/* Set the offset for shadow text, this is the current cursor
* position plus this offset, don't need call BLF_position before
* this function, the current position is calculate only on
* BLF_draw, so it's safe call this whenever you like.
*/
void BLF_shadow_offset(int fontid, int x, int y);
/*
* Set the buffer, size and number of channels to draw, one thing to take care is call
/* Set the buffer, size and number of channels to draw, one thing to take care is call
* this function with NULL pointer when we finish, for example:
* BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4);
*
* ... set color, position and draw ...
* BLF_buffer(my_fbuf, my_cbuf, 100, 100, 4);
*
* BLF_buffer(NULL, NULL, 0, 0, 0);
* ... set color, position and draw ...
*
* BLF_buffer(NULL, NULL, 0, 0, 0);
*/
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch);
/*
* Set the color to be used for text.
*/
/* Set the color to be used for text. */
void BLF_buffer_col(int fontid, float r, float g, float b, float a);
/*
* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_
/* Draw the string into the buffer, this function draw in both buffer, float and unsigned char _BUT_
* it's not necessary set both buffer, NULL is valid here.
*/
void BLF_draw_buffer(int fontid, const char *str);
@ -200,8 +183,8 @@ void BLF_dir_free(char **dirs, int count);
#define BLF_DRAW_STR_DUMMY_MAX 1024
// XXX, bad design
/* XXX, bad design */
extern int blf_mono_font;
extern int blf_mono_font_render; // dont mess drawing with render threads.
extern int blf_mono_font_render; /* dont mess drawing with render threads. */
#endif /* __BLF_API_H__ */

@ -47,8 +47,7 @@ const char *BLF_pgettext(const char *context, const char *message);
/* blf_lang.c */
/*
* Search the path directory to the locale files, this try all
/* Search the path directory to the locale files, this try all
* the case for Linux, Win and Mac.
*/
void BLF_lang_init(void);
@ -66,7 +65,7 @@ const char *BLF_translate_do_iface(const char *msgid);
const char *BLF_translate_do_tooltip(const char *msgid);
/*#define _(msgid) BLF_gettext(msgid)*/
/* #define _(msgid) BLF_gettext(msgid) */
/* The "translation-marker" macro. */
#define N_(msgid) msgid
/* Those macros should be used everywhere in UI code. */

@ -62,13 +62,13 @@
static FontBLF *global_font[BLF_MAX_FONT] = {0};
/* Default size and dpi, for BLF_draw_default. */
static int global_font_default= -1;
static int global_font_points= 11;
static int global_font_dpi= 72;
static int global_font_default = -1;
static int global_font_points = 11;
static int global_font_dpi = 72;
// XXX, should these be made into global_font_'s too?
int blf_mono_font= -1;
int blf_mono_font_render= -1;
/* XXX, should these be made into global_font_'s too? */
int blf_mono_font = -1;
int blf_mono_font_render = -1;
static FontBLF *BLF_get(int fontid)
{
@ -81,11 +81,11 @@ int BLF_init(int points, int dpi)
{
int i;
for (i= 0; i < BLF_MAX_FONT; i++)
global_font[i]= NULL;
for (i = 0; i < BLF_MAX_FONT; i++)
global_font[i] = NULL;
global_font_points= points;
global_font_dpi= dpi;
global_font_points = points;
global_font_dpi = dpi;
return blf_font_init();
}
@ -94,11 +94,11 @@ void BLF_exit(void)
FontBLF *font;
int i;
for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
if (font) {
blf_font_free(font);
global_font[i]= NULL;
global_font[i] = NULL;
}
}
@ -110,8 +110,8 @@ void BLF_cache_clear(void)
FontBLF *font;
int i;
for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
if (font)
blf_glyph_cache_clear(font);
}
@ -122,8 +122,8 @@ static int blf_search(const char *name)
FontBLF *font;
int i;
for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
if (font && (!strcmp(font->name, name)))
return i;
}
@ -135,8 +135,8 @@ static int blf_search_available(void)
{
int i;
for (i= 0; i < BLF_MAX_FONT; i++)
if(!global_font[i])
for (i = 0; i < BLF_MAX_FONT; i++)
if (!global_font[i])
return i;
return -1;
@ -152,7 +152,7 @@ int BLF_load(const char *name)
return -1;
/* check if we already load this font. */
i= blf_search(name);
i = blf_search(name);
if (i >= 0) {
/*font= global_font[i];*/ /*UNUSED*/
return i;
@ -164,13 +164,13 @@ int BLF_load(const char *name)
return -1;
}
filename= blf_dir_search(name);
filename = blf_dir_search(name);
if (!filename) {
printf("Can't find font: %s\n", name);
return -1;
}
font= blf_font_new(name, filename);
font = blf_font_new(name, filename);
MEM_freeN(filename);
if (!font) {
@ -178,7 +178,7 @@ int BLF_load(const char *name)
return -1;
}
global_font[i]= font;
global_font[i] = font;
return i;
}
@ -200,13 +200,13 @@ int BLF_load_unique(const char *name)
return -1;
}
filename= blf_dir_search(name);
filename = blf_dir_search(name);
if (!filename) {
printf("Can't find font: %s\n", name);
return -1;
}
font= blf_font_new(name, filename);
font = blf_font_new(name, filename);
MEM_freeN(filename);
if (!font) {
@ -214,13 +214,13 @@ int BLF_load_unique(const char *name)
return -1;
}
global_font[i]= font;
global_font[i] = font;
return i;
}
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
blf_font_attach_from_mem(font, mem, mem_size);
@ -235,7 +235,7 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
if (!name)
return -1;
i= blf_search(name);
i = blf_search(name);
if (i >= 0) {
/*font= global_font[i];*/ /*UNUSED*/
return i;
@ -252,13 +252,13 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
return -1;
}
font= blf_font_new_from_mem(name, mem, mem_size);
font = blf_font_new_from_mem(name, mem, mem_size);
if (!font) {
printf("Can't load font: %s from memory!!\n", name);
return -1;
}
global_font[i]= font;
global_font[i] = font;
return i;
}
@ -285,13 +285,13 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
return -1;
}
font= blf_font_new_from_mem(name, mem, mem_size);
font = blf_font_new_from_mem(name, mem, mem_size);
if (!font) {
printf("Can't load font: %s from memory!!\n", name);
return -1;
}
global_font[i]= font;
global_font[i] = font;
return i;
}
@ -300,19 +300,19 @@ void BLF_unload(const char *name)
FontBLF *font;
int i;
for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
if (font && (!strcmp(font->name, name))) {
blf_font_free(font);
global_font[i]= NULL;
global_font[i] = NULL;
}
}
}
void BLF_enable(int fontid, int option)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->flags |= option;
@ -321,7 +321,7 @@ void BLF_enable(int fontid, int option)
void BLF_disable(int fontid, int option)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->flags &= ~option;
@ -330,7 +330,7 @@ void BLF_disable(int fontid, int option)
void BLF_enable_default(int option)
{
FontBLF *font= BLF_get(global_font_default);
FontBLF *font = BLF_get(global_font_default);
if (font) {
font->flags |= option;
@ -339,7 +339,7 @@ void BLF_enable_default(int option)
void BLF_disable_default(int option)
{
FontBLF *font= BLF_get(global_font_default);
FontBLF *font = BLF_get(global_font_default);
if (font) {
font->flags &= ~option;
@ -348,18 +348,18 @@ void BLF_disable_default(int option)
void BLF_aspect(int fontid, float x, float y, float z)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->aspect[0]= x;
font->aspect[1]= y;
font->aspect[2]= z;
font->aspect[0] = x;
font->aspect[1] = y;
font->aspect[2] = z;
}
}
void BLF_matrix(int fontid, const double m[16])
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
memcpy(font->m, m, sizeof(font->m));
@ -368,24 +368,24 @@ void BLF_matrix(int fontid, const double m[16])
void BLF_position(int fontid, float x, float y, float z)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
float xa, ya, za;
float remainder;
if (font->flags & BLF_ASPECT) {
xa= font->aspect[0];
ya= font->aspect[1];
za= font->aspect[2];
xa = font->aspect[0];
ya = font->aspect[1];
za = font->aspect[2];
}
else {
xa= 1.0f;
ya= 1.0f;
za= 1.0f;
xa = 1.0f;
ya = 1.0f;
za = 1.0f;
}
remainder= x - floorf(x);
remainder = x - floorf(x);
if (remainder > 0.4f && remainder < 0.6f) {
if (remainder < 0.5f)
x -= 0.1f * xa;
@ -393,7 +393,7 @@ void BLF_position(int fontid, float x, float y, float z)
x += 0.1f * xa;
}
remainder= y - floorf(y);
remainder = y - floorf(y);
if (remainder > 0.4f && remainder < 0.6f) {
if (remainder < 0.5f)
y -= 0.1f * ya;
@ -401,7 +401,7 @@ void BLF_position(int fontid, float x, float y, float z)
y += 0.1f * ya;
}
remainder= z - floorf(z);
remainder = z - floorf(z);
if (remainder > 0.4f && remainder < 0.6f) {
if (remainder < 0.5f)
z -= 0.1f * za;
@ -409,15 +409,15 @@ void BLF_position(int fontid, float x, float y, float z)
z += 0.1f * za;
}
font->pos[0]= x;
font->pos[1]= y;
font->pos[2]= z;
font->pos[0] = x;
font->pos[1] = y;
font->pos[2] = z;
}
}
void BLF_size(int fontid, int size, int dpi)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
blf_font_size(font, size, dpi);
@ -426,10 +426,10 @@ void BLF_size(int fontid, int size, int dpi)
void BLF_blur(int fontid, int size)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->blur= size;
font->blur = size;
}
}
@ -439,7 +439,7 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
return;
if (global_font_default == -1)
global_font_default= blf_search("default");
global_font_default = blf_search("default");
if (global_font_default == -1) {
printf("Warning: Can't found default font!!\n");
@ -458,7 +458,7 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
return;
if (global_font_default == -1)
global_font_default= blf_search("default");
global_font_default = blf_search("default");
if (global_font_default == -1) {
printf("Warning: Can't found default font!!\n");
@ -472,10 +472,10 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
void BLF_rotation_default(float angle)
{
FontBLF *font= BLF_get(global_font_default);
FontBLF *font = BLF_get(global_font_default);
if (font) {
font->angle= angle;
font->angle = angle;
}
}
@ -511,11 +511,11 @@ static void blf_draw__start(FontBLF *font, GLint *mode, GLint *param)
if (font->flags & BLF_ROTATION)
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
if(font->shadow || font->blur)
if (font->shadow || font->blur)
glGetFloatv(GL_CURRENT_COLOR, font->orig_col);
/* always bind the texture for the first glyph */
font->tex_bind_state= -1;
font->tex_bind_state = -1;
/* Save the current parameter to restore it later. */
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
@ -544,7 +544,7 @@ static void blf_draw__end(GLint mode, GLint param)
void BLF_draw(int fontid, const char *str, size_t len)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
GLint mode, param;
if (font && font->glyph_cache) {
@ -556,7 +556,7 @@ void BLF_draw(int fontid, const char *str, size_t len)
void BLF_draw_ascii(int fontid, const char *str, size_t len)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
GLint mode, param;
if (font && font->glyph_cache) {
@ -568,7 +568,7 @@ void BLF_draw_ascii(int fontid, const char *str, size_t len)
void BLF_boundbox(int fontid, const char *str, rctf *box)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
blf_font_boundbox(font, str, box);
@ -577,7 +577,7 @@ void BLF_boundbox(int fontid, const char *str, rctf *box)
void BLF_width_and_height(int fontid, const char *str, float *width, float *height)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
blf_font_width_and_height(font, str, width, height);
@ -586,7 +586,7 @@ void BLF_width_and_height(int fontid, const char *str, float *width, float *heig
float BLF_width(int fontid, const char *str)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return blf_font_width(font, str);
@ -597,7 +597,7 @@ float BLF_width(int fontid, const char *str)
float BLF_fixed_width(int fontid)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return blf_font_fixed_width(font);
@ -609,7 +609,7 @@ float BLF_fixed_width(int fontid)
float BLF_width_default(const char *str)
{
if (global_font_default == -1)
global_font_default= blf_search("default");
global_font_default = blf_search("default");
if (global_font_default == -1) {
printf("Error: Can't found default font!!\n");
@ -622,7 +622,7 @@ float BLF_width_default(const char *str)
float BLF_height(int fontid, const char *str)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return blf_font_height(font, str);
@ -633,7 +633,7 @@ float BLF_height(int fontid, const char *str)
float BLF_height_max(int fontid)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->max_glyph_height;
@ -644,7 +644,7 @@ float BLF_height_max(int fontid)
float BLF_width_max(int fontid)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->max_glyph_width;
@ -655,7 +655,7 @@ float BLF_width_max(int fontid)
float BLF_descender(int fontid)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->descender;
@ -666,7 +666,7 @@ float BLF_descender(int fontid)
float BLF_ascender(int fontid)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache) {
return font->glyph_cache->ascender;
@ -678,7 +678,7 @@ float BLF_ascender(int fontid)
float BLF_height_default(const char *str)
{
if (global_font_default == -1)
global_font_default= blf_search("default");
global_font_default = blf_search("default");
if (global_font_default == -1) {
printf("Error: Can't found default font!!\n");
@ -692,88 +692,88 @@ float BLF_height_default(const char *str)
void BLF_rotation(int fontid, float angle)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->angle= angle;
font->angle = angle;
}
}
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->clip_rec.xmin= xmin;
font->clip_rec.ymin= ymin;
font->clip_rec.xmax= xmax;
font->clip_rec.ymax= ymax;
font->clip_rec.xmin = xmin;
font->clip_rec.ymin = ymin;
font->clip_rec.xmax = xmax;
font->clip_rec.ymax = ymax;
}
}
void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
{
FontBLF *font= BLF_get(global_font_default);
FontBLF *font = BLF_get(global_font_default);
if (font) {
font->clip_rec.xmin= xmin;
font->clip_rec.ymin= ymin;
font->clip_rec.xmax= xmax;
font->clip_rec.ymax= ymax;
font->clip_rec.xmin = xmin;
font->clip_rec.ymin = ymin;
font->clip_rec.xmax = xmax;
font->clip_rec.ymax = ymax;
}
}
void BLF_shadow(int fontid, int level, float r, float g, float b, float a)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->shadow= level;
font->shadow_col[0]= r;
font->shadow_col[1]= g;
font->shadow_col[2]= b;
font->shadow_col[3]= a;
font->shadow = level;
font->shadow_col[0] = r;
font->shadow_col[1] = g;
font->shadow_col[2] = b;
font->shadow_col[3] = a;
}
}
void BLF_shadow_offset(int fontid, int x, int y)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->shadow_x= x;
font->shadow_y= y;
font->shadow_x = x;
font->shadow_y = y;
}
}
void BLF_buffer(int fontid, float *fbuf, unsigned char *cbuf, int w, int h, int nch)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->b_fbuf= fbuf;
font->b_cbuf= cbuf;
font->bw= w;
font->bh= h;
font->bch= nch;
font->b_fbuf = fbuf;
font->b_cbuf = cbuf;
font->bw = w;
font->bh = h;
font->bch = nch;
}
}
void BLF_buffer_col(int fontid, float r, float g, float b, float a)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font) {
font->b_col[0]= r;
font->b_col[1]= g;
font->b_col[2]= b;
font->b_col[3]= a;
font->b_col[0] = r;
font->b_col[1] = g;
font->b_col[2] = b;
font->b_col[3] = a;
}
}
void BLF_draw_buffer(int fontid, const char *str)
{
FontBLF *font= BLF_get(fontid);
FontBLF *font = BLF_get(fontid);
if (font && font->glyph_cache && (font->b_fbuf || font->b_cbuf)) {
blf_font_buffer(font, str);

@ -51,17 +51,17 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
static ListBase global_font_dir= { NULL, NULL };
static ListBase global_font_dir = { NULL, NULL };
static DirBLF *blf_dir_find(const char *path)
{
DirBLF *p;
p= global_font_dir.first;
p = global_font_dir.first;
while (p) {
if (BLI_path_cmp(p->path, path) == 0)
return p;
p= p->next;
p = p->next;
}
return NULL;
}
@ -70,12 +70,12 @@ void BLF_dir_add(const char *path)
{
DirBLF *dir;
dir= blf_dir_find(path);
dir = blf_dir_find(path);
if (dir) /* already in the list ? just return. */
return;
dir= (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add");
dir->path= BLI_strdup(path);
dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add");
dir->path = BLI_strdup(path);
BLI_addhead(&global_font_dir, dir);
}
@ -83,7 +83,7 @@ void BLF_dir_rem(const char *path)
{
DirBLF *dir;
dir= blf_dir_find(path);
dir = blf_dir_find(path);
if (dir) {
BLI_remlink(&global_font_dir, dir);
MEM_freeN(dir->path);
@ -98,19 +98,19 @@ char **BLF_dir_get(int *ndir)
char *path;
int i, count;
count= BLI_countlist(&global_font_dir);
count = BLI_countlist(&global_font_dir);
if (!count)
return NULL;
dirs= (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get");
p= global_font_dir.first;
i= 0;
dirs = (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get");
p = global_font_dir.first;
i = 0;
while (p) {
path= BLI_strdup(p->path);
dirs[i]= path;
p= p->next;
path = BLI_strdup(p->path);
dirs[i] = path;
p = p->next;
}
*ndir= i;
*ndir = i;
return dirs;
}
@ -119,8 +119,8 @@ void BLF_dir_free(char **dirs, int count)
char *path;
int i;
for (i= 0; i < count; i++) {
path= dirs[i];
for (i = 0; i < count; i++) {
path = dirs[i];
MEM_freeN(path);
}
MEM_freeN(dirs);
@ -130,12 +130,12 @@ char *blf_dir_search(const char *file)
{
DirBLF *dir;
char full_path[FILE_MAX];
char *s= NULL;
char *s = NULL;
for(dir=global_font_dir.first; dir; dir= dir->next) {
for (dir = global_font_dir.first; dir; dir = dir->next) {
BLI_join_dirfile(full_path, sizeof(full_path), dir->path, file);
if (BLI_exists(full_path)) {
s= BLI_strdup(full_path);
s = BLI_strdup(full_path);
break;
}
}
@ -143,32 +143,32 @@ char *blf_dir_search(const char *file)
if (!s) {
/* check the current directory, why not ? */
if (BLI_exists(file))
s= BLI_strdup(file);
s = BLI_strdup(file);
}
return s;
}
#if 0 // UNUSED
#if 0 /* UNUSED */
int blf_dir_split(const char *str, char *file, int *size)
{
int i, len;
char *s;
/* Window, Linux or Mac, this is always / */
s= strrchr(str, '/');
s = strrchr(str, '/');
if (s) {
len= s - str;
for (i= 0; i < len; i++)
file[i]= str[i];
len = s - str;
for (i = 0; i < len; i++)
file[i] = str[i];
file[i]= '.';
file[i+1]= 't';
file[i+2]= 't';
file[i+3]= 'f';
file[i+4]= '\0';
file[i] = '.';
file[i+1] = 't';
file[i+2] = 't';
file[i+3] = 'f';
file[i+4] = '\0';
s++;
*size= atoi(s);
*size = atoi(s);
return 1;
}
return 0;
@ -183,24 +183,24 @@ char *blf_dir_metrics_search(const char *filename)
char *mfile;
char *s;
mfile= BLI_strdup(filename);
s= strrchr(mfile, '.');
mfile = BLI_strdup(filename);
s = strrchr(mfile, '.');
if (s) {
if (BLI_strnlen(s, 4) < 4) {
MEM_freeN(mfile);
return NULL;
}
s++;
s[0]= 'a';
s[1]= 'f';
s[2]= 'm';
s[0] = 'a';
s[1] = 'f';
s[2] = 'm';
/* first check .afm */
if (BLI_exists(s))
return s;
/* and now check .pfm */
s[0]= 'p';
s[0] = 'p';
if (BLI_exists(s))
return s;

@ -73,43 +73,43 @@ void blf_font_size(FontBLF *font, int size, int dpi)
GlyphCacheBLF *gc;
FT_Error err;
err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi);
err = FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi);
if (err) {
/* FIXME: here we can go through the fixed size and choice a close one */
printf("The current font don't support the size, %d and dpi, %d\n", size, dpi);
return;
}
font->size= size;
font->dpi= dpi;
font->size = size;
font->dpi = dpi;
gc= blf_glyph_cache_find(font, size, dpi);
gc = blf_glyph_cache_find(font, size, dpi);
if (gc)
font->glyph_cache= gc;
font->glyph_cache = gc;
else {
gc= blf_glyph_cache_new(font);
gc = blf_glyph_cache_new(font);
if (gc)
font->glyph_cache= gc;
font->glyph_cache = gc;
else
font->glyph_cache= NULL;
font->glyph_cache = NULL;
}
}
static void blf_font_ensure_ascii_table(FontBLF *font)
{
GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
/* build ascii on demand */
if(glyph_ascii_table['0']==NULL) {
if (glyph_ascii_table['0'] == NULL) {
GlyphBLF *g;
unsigned int i;
for(i=0; i<256; i++) {
g= blf_glyph_search(font->glyph_cache, i);
for (i = 0; i<256; i++) {
g = blf_glyph_search(font->glyph_cache, i);
if (!g) {
FT_UInt glyph_index= FT_Get_Char_Index(font->face, i);
g= blf_glyph_add(font, glyph_index, i);
FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
g = blf_glyph_add(font, glyph_index, i);
}
glyph_ascii_table[i]= g;
glyph_ascii_table[i] = g;
}
}
}
@ -122,67 +122,69 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
/* Note,
* blf_font_ensure_ascii_table(font); must be called before this macro */
#define BLF_UTF8_NEXT_FAST(_font, _g, _str, _i, _c, _glyph_ascii_table) \
if(((_c)= (_str)[_i]) < 0x80) { \
_g= (_glyph_ascii_table)[_c]; \
_i++; \
} \
else if ((_c= BLI_str_utf8_as_unicode_step(_str, &(_i)))!=BLI_UTF8_ERR) { \
if ((_g= blf_glyph_search((_font)->glyph_cache, _c)) == NULL) { \
_g= blf_glyph_add(_font, \
FT_Get_Char_Index((_font)->face, _c), _c); \
} \
} \
#define BLF_UTF8_NEXT_FAST(_font, _g, _str, _i, _c, _glyph_ascii_table) \
if (((_c) = (_str)[_i]) < 0x80) { \
_g = (_glyph_ascii_table)[_c]; \
_i++; \
} \
else if ((_c = BLI_str_utf8_as_unicode_step(_str, &(_i))) != BLI_UTF8_ERR) { \
if ((_g = blf_glyph_search((_font)->glyph_cache, _c)) == NULL) { \
_g = blf_glyph_add(_font, \
FT_Get_Char_Index((_font)->face, _c), _c); \
} \
} \
#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \
const short _has_kerning= FT_HAS_KERNING((_font)->face); \
const FT_UInt _kern_mode= (_has_kerning == 0) ? 0 : \
(((_font)->flags & BLF_KERNING_DEFAULT) ? \
ft_kerning_default : FT_KERNING_UNFITTED) \
#define BLF_KERNING_VARS(_font, _has_kerning, _kern_mode) \
const short _has_kerning = FT_HAS_KERNING((_font)->face); \
const FT_UInt _kern_mode = (_has_kerning == 0) ? 0 : \
(((_font)->flags & BLF_KERNING_DEFAULT) ? \
ft_kerning_default : FT_KERNING_UNFITTED) \
#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \
{ \
if (_g_prev) { \
_delta.x= _delta.y= 0; \
if (FT_Get_Kerning((_font)->face, \
(_g_prev)->idx, \
(_g)->idx, \
_kern_mode, \
&(_delta)) == 0) \
{ \
_pen_x += delta.x >> 6; \
} \
} \
} \
#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \
{ \
if (_g_prev) { \
_delta.x = _delta.y = 0; \
if (FT_Get_Kerning((_font)->face, \
(_g_prev)->idx, \
(_g)->idx, \
_kern_mode, \
&(_delta)) == 0) \
{ \
_pen_x += delta.x >> 6; \
} \
} \
} \
void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
{
unsigned int c;
GlyphBLF *g, *g_prev= NULL;
GlyphBLF *g, *g_prev = NULL;
FT_Vector delta;
int pen_x= 0, pen_y= 0;
size_t i= 0;
GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
int pen_x = 0, pen_y = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
while (str[i] && i < len) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
if (c == BLI_UTF8_ERR) break;
if (g == NULL) continue;
if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
if (c == BLI_UTF8_ERR)
break;
if (g == NULL)
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
pen_x += g->advance;
g_prev= g;
g_prev = g;
}
}
@ -190,24 +192,26 @@ void blf_font_draw(FontBLF *font, const char *str, unsigned int len)
void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
{
unsigned char c;
GlyphBLF *g, *g_prev= NULL;
GlyphBLF *g, *g_prev = NULL;
FT_Vector delta;
int pen_x= 0, pen_y= 0;
GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
int pen_x = 0, pen_y = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
while ((c= *(str++)) && len--) {
if ((g= glyph_ascii_table[c]) == NULL) continue;
if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
while ((c = *(str++)) && len--) {
if ((g = glyph_ascii_table[c]) == NULL)
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
pen_x += g->advance;
g_prev= g;
g_prev = g;
}
}
@ -215,17 +219,17 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, unsigned int len)
void blf_font_buffer(FontBLF *font, const char *str)
{
unsigned int c;
GlyphBLF *g, *g_prev= NULL;
GlyphBLF *g, *g_prev = NULL;
FT_Vector delta;
int pen_x= (int)font->pos[0], pen_y= 0;
size_t i= 0;
GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
int pen_x = (int)font->pos[0], pen_y = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
/* buffer specific vars*/
const unsigned char b_col_char[4]= {font->b_col[0] * 255,
font->b_col[1] * 255,
font->b_col[2] * 255,
font->b_col[3] * 255};
const unsigned char b_col_char[4] = {font->b_col[0] * 255,
font->b_col[1] * 255,
font->b_col[2] * 255,
font->b_col[3] * 255};
unsigned char *cbuf;
int chx, chy;
int y, x;
@ -236,15 +240,17 @@ void blf_font_buffer(FontBLF *font, const char *str)
blf_font_ensure_ascii_table(font);
while (str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
if (c == BLI_UTF8_ERR) break;
if (g == NULL) continue;
if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
if (c == BLI_UTF8_ERR)
break;
if (g == NULL)
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
chx= pen_x + ((int)g->pos_x);
chy= (int)font->pos[1] + g->height;
chx = pen_x + ((int)g->pos_x);
chy = (int)font->pos[1] + g->height;
if (g->pitch < 0) {
pen_y = (int)font->pos[1] + (g->height - (int)g->pos_y);
@ -255,41 +261,42 @@ void blf_font_buffer(FontBLF *font, const char *str)
if ((chx + g->width) >= 0 && chx < font->bw && (pen_y + g->height) >= 0 && pen_y < font->bh) {
/* dont draw beyond the buffer bounds */
int width_clip= g->width;
int height_clip= g->height;
int yb_start= g->pitch < 0 ? 0 : g->height-1;
int width_clip = g->width;
int height_clip = g->height;
int yb_start = g->pitch < 0 ? 0 : g->height-1;
if (width_clip + chx > font->bw) width_clip -= chx + width_clip - font->bw;
if (height_clip + pen_y > font->bh) height_clip -= pen_y + height_clip - font->bh;
if (width_clip + chx > font->bw)
width_clip -= chx + width_clip - font->bw;
if (height_clip + pen_y > font->bh)
height_clip -= pen_y + height_clip - font->bh;
/* drawing below the image? */
if(pen_y < 0) {
if (pen_y < 0) {
yb_start += (g->pitch < 0) ? -pen_y : pen_y;
height_clip += pen_y;
pen_y= 0;
pen_y = 0;
}
if (font->b_fbuf) {
int yb= yb_start;
for (y=(chy >= 0 ? 0:-chy); y < height_clip; y++) {
for (x=(chx >= 0 ? 0:-chx); x < width_clip; x++) {
a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
int yb = yb_start;
for (y = (chy >= 0 ? 0:-chy); y < height_clip; y++) {
for (x = (chx >= 0 ? 0:-chx); x < width_clip; x++) {
a = *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
if(a > 0.0f) {
if (a > 0.0f) {
float alphatest;
fbuf= font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
fbuf = font->b_fbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
if (a >= 1.0f) {
fbuf[0]= font->b_col[0];
fbuf[1]= font->b_col[1];
fbuf[2]= font->b_col[2];
fbuf[3]= (alphatest= (fbuf[3] + (font->b_col[3]))) < 1.0f ? alphatest : 1.0f;
fbuf[0] = font->b_col[0];
fbuf[1] = font->b_col[1];
fbuf[2] = font->b_col[2];
fbuf[3] = (alphatest = (fbuf[3] + (font->b_col[3]))) < 1.0f ? alphatest : 1.0f;
}
else {
fbuf[0]= (font->b_col[0]*a) + (fbuf[0] * (1-a));
fbuf[1]= (font->b_col[1]*a) + (fbuf[1] * (1-a));
fbuf[2]= (font->b_col[2]*a) + (fbuf[2] * (1-a));
fbuf[3]= (alphatest= (fbuf[3] + (font->b_col[3]*a))) < 1.0f ? alphatest : 1.0f;
fbuf[0] = (font->b_col[0]*a) + (fbuf[0] * (1-a));
fbuf[1] = (font->b_col[1]*a) + (fbuf[1] * (1-a));
fbuf[2] = (font->b_col[2]*a) + (fbuf[2] * (1-a));
fbuf[3] = (alphatest = (fbuf[3] + (font->b_col[3]*a))) < 1.0f ? alphatest : 1.0f;
}
}
}
@ -302,25 +309,26 @@ void blf_font_buffer(FontBLF *font, const char *str)
}
if (font->b_cbuf) {
int yb= yb_start;
for (y= 0; y < height_clip; y++) {
for (x= 0; x < width_clip; x++) {
a= *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
int yb = yb_start;
for (y = 0; y < height_clip; y++) {
for (x = 0; x < width_clip; x++) {
a = *(g->bitmap + x + (yb * g->pitch)) / 255.0f;
if(a > 0.0f) {
if (a > 0.0f) {
int alphatest;
cbuf= font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
cbuf = font->b_cbuf + font->bch * ((chx + x) + ((pen_y + y)*font->bw));
if (a >= 1.0f) {
cbuf[0]= b_col_char[0];
cbuf[1]= b_col_char[1];
cbuf[2]= b_col_char[2];
cbuf[3]= (alphatest= ((int)cbuf[3] + (int)b_col_char[3])) < 255 ? alphatest : 255;
cbuf[0] = b_col_char[0];
cbuf[1] = b_col_char[1];
cbuf[2] = b_col_char[2];
cbuf[3] = (alphatest = ((int)cbuf[3] + (int)b_col_char[3])) < 255 ? alphatest : 255;
}
else {
cbuf[0]= (b_col_char[0]*a) + (cbuf[0] * (1-a));
cbuf[1]= (b_col_char[1]*a) + (cbuf[1] * (1-a));
cbuf[2]= (b_col_char[2]*a) + (cbuf[2] * (1-a));
cbuf[3]= (alphatest= ((int)cbuf[3] + (int)((font->b_col[3]*a)*255.0f))) < 255 ? alphatest : 255;
cbuf[0] = (b_col_char[0]*a) + (cbuf[0] * (1-a));
cbuf[1] = (b_col_char[1]*a) + (cbuf[1] * (1-a));
cbuf[2] = (b_col_char[2]*a) + (cbuf[2] * (1-a));
cbuf[3] = (alphatest = ((int)cbuf[3] + (int)((font->b_col[3]*a)*255.0f))) <
255 ? alphatest : 255;
}
}
}
@ -334,58 +342,60 @@ void blf_font_buffer(FontBLF *font, const char *str)
}
pen_x += g->advance;
g_prev= g;
g_prev = g;
}
}
void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
{
unsigned int c;
GlyphBLF *g, *g_prev= NULL;
GlyphBLF *g, *g_prev = NULL;
FT_Vector delta;
int pen_x= 0, pen_y= 0;
size_t i= 0;
GlyphBLF **glyph_ascii_table= font->glyph_cache->glyph_ascii_table;
int pen_x = 0, pen_y = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
rctf gbox;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
box->xmin= 32000.0f;
box->xmax= -32000.0f;
box->ymin= 32000.0f;
box->ymax= -32000.0f;
box->xmin = 32000.0f;
box->xmax = -32000.0f;
box->ymin = 32000.0f;
box->ymax = -32000.0f;
blf_font_ensure_ascii_table(font);
while (str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
if (c == BLI_UTF8_ERR) break;
if (g == NULL) continue;
if (has_kerning) BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
if (c == BLI_UTF8_ERR)
break;
if (g == NULL)
continue;
if (has_kerning)
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
gbox.xmin= pen_x;
gbox.xmax= pen_x + g->advance;
gbox.ymin= g->box.ymin + pen_y;
gbox.ymax= g->box.ymax + pen_y;
gbox.xmin = pen_x;
gbox.xmax = pen_x + g->advance;
gbox.ymin = g->box.ymin + pen_y;
gbox.ymax = g->box.ymax + pen_y;
if (gbox.xmin < box->xmin) box->xmin= gbox.xmin;
if (gbox.ymin < box->ymin) box->ymin= gbox.ymin;
if (gbox.xmin < box->xmin) box->xmin = gbox.xmin;
if (gbox.ymin < box->ymin) box->ymin = gbox.ymin;
if (gbox.xmax > box->xmax) box->xmax= gbox.xmax;
if (gbox.ymax > box->ymax) box->ymax= gbox.ymax;
if (gbox.xmax > box->xmax) box->xmax = gbox.xmax;
if (gbox.ymax > box->ymax) box->ymax = gbox.ymax;
pen_x += g->advance;
g_prev= g;
g_prev = g;
}
if (box->xmin > box->xmax) {
box->xmin= 0.0f;
box->ymin= 0.0f;
box->xmax= 0.0f;
box->ymax= 0.0f;
box->xmin = 0.0f;
box->ymin = 0.0f;
box->xmax = 0.0f;
box->ymax = 0.0f;
}
}
@ -395,17 +405,17 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo
rctf box;
if (font->flags & BLF_ASPECT) {
xa= font->aspect[0];
ya= font->aspect[1];
xa = font->aspect[0];
ya = font->aspect[1];
}
else {
xa= 1.0f;
ya= 1.0f;
xa = 1.0f;
ya = 1.0f;
}
blf_font_boundbox(font, str, &box);
*width= ((box.xmax - box.xmin) * xa);
*height= ((box.ymax - box.ymin) * ya);
*width = ((box.xmax - box.xmin) * xa);
*height = ((box.ymax - box.ymin) * ya);
}
float blf_font_width(FontBLF *font, const char *str)
@ -414,9 +424,9 @@ float blf_font_width(FontBLF *font, const char *str)
rctf box;
if (font->flags & BLF_ASPECT)
xa= font->aspect[0];
xa = font->aspect[0];
else
xa= 1.0f;
xa = 1.0f;
blf_font_boundbox(font, str, &box);
return (box.xmax - box.xmin) * xa;
@ -428,9 +438,9 @@ float blf_font_height(FontBLF *font, const char *str)
rctf box;
if (font->flags & BLF_ASPECT)
ya= font->aspect[1];
ya = font->aspect[1];
else
ya= 1.0f;
ya = 1.0f;
blf_font_boundbox(font, str, &box);
return (box.ymax - box.ymin) * ya;
@ -439,9 +449,9 @@ float blf_font_height(FontBLF *font, const char *str)
float blf_font_fixed_width(FontBLF *font)
{
const unsigned int c = ' ';
GlyphBLF *g= blf_glyph_search(font->glyph_cache, c);
GlyphBLF *g = blf_glyph_search(font->glyph_cache, c);
if (!g) {
g= blf_glyph_add(font, FT_Get_Char_Index(font->face, c), c);
g = blf_glyph_add(font, FT_Get_Char_Index(font->face, c), c);
/* if we don't find the glyph. */
if (!g) {
@ -456,9 +466,9 @@ void blf_font_free(FontBLF *font)
{
GlyphCacheBLF *gc;
font->glyph_cache= NULL;
font->glyph_cache = NULL;
while (font->cache.first) {
gc= font->cache.first;
gc = font->cache.first;
BLI_remlink(&font->cache, gc);
blf_glyph_cache_free(gc);
}
@ -475,38 +485,38 @@ static void blf_font_fill(FontBLF *font)
{
unsigned int i;
font->aspect[0]= 1.0f;
font->aspect[1]= 1.0f;
font->aspect[2]= 1.0f;
font->pos[0]= 0.0f;
font->pos[1]= 0.0f;
font->angle= 0.0f;
font->aspect[0] = 1.0f;
font->aspect[1] = 1.0f;
font->aspect[2] = 1.0f;
font->pos[0] = 0.0f;
font->pos[1] = 0.0f;
font->angle = 0.0f;
for (i= 0; i < 16; i++)
font->m[i]= 0;
for (i = 0; i < 16; i++)
font->m[i] = 0;
font->clip_rec.xmin= 0.0f;
font->clip_rec.xmax= 0.0f;
font->clip_rec.ymin= 0.0f;
font->clip_rec.ymax= 0.0f;
font->flags= 0;
font->dpi= 0;
font->size= 0;
font->cache.first= NULL;
font->cache.last= NULL;
font->glyph_cache= NULL;
font->blur= 0;
font->max_tex_size= -1;
font->b_fbuf= NULL;
font->b_cbuf= NULL;
font->bw= 0;
font->bh= 0;
font->bch= 0;
font->b_col[0]= 0;
font->b_col[1]= 0;
font->b_col[2]= 0;
font->b_col[3]= 0;
font->ft_lib= ft_lib;
font->clip_rec.xmin = 0.0f;
font->clip_rec.xmax = 0.0f;
font->clip_rec.ymin = 0.0f;
font->clip_rec.ymax = 0.0f;
font->flags = 0;
font->dpi = 0;
font->size = 0;
font->cache.first = NULL;
font->cache.last = NULL;
font->glyph_cache = NULL;
font->blur = 0;
font->max_tex_size = -1;
font->b_fbuf = NULL;
font->b_cbuf = NULL;
font->bw = 0;
font->bh = 0;
font->bch = 0;
font->b_col[0] = 0;
font->b_col[1] = 0;
font->b_col[2] = 0;
font->b_col[3] = 0;
font->ft_lib = ft_lib;
}
FontBLF *blf_font_new(const char *name, const char *filename)
@ -515,14 +525,14 @@ FontBLF *blf_font_new(const char *name, const char *filename)
FT_Error err;
char *mfile;
font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new");
err= FT_New_Face(ft_lib, filename, 0, &font->face);
font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new");
err = FT_New_Face(ft_lib, filename, 0, &font->face);
if (err) {
MEM_freeN(font);
return NULL;
}
err= FT_Select_Charmap(font->face, ft_encoding_unicode);
err = FT_Select_Charmap(font->face, ft_encoding_unicode);
if (err) {
printf("Can't set the unicode character map!\n");
FT_Done_Face(font->face);
@ -530,17 +540,17 @@ FontBLF *blf_font_new(const char *name, const char *filename)
return NULL;
}
mfile= blf_dir_metrics_search(filename);
mfile = blf_dir_metrics_search(filename);
if (mfile) {
err= FT_Attach_File(font->face, mfile);
if(err) {
err = FT_Attach_File(font->face, mfile);
if (err) {
fprintf(stderr, "FT_Attach_File failed to load '%s' with error %d\n", filename, (int)err);
}
MEM_freeN(mfile);
}
font->name= BLI_strdup(name);
font->filename= BLI_strdup(filename);
font->name = BLI_strdup(name);
font->filename = BLI_strdup(filename);
blf_font_fill(font);
return font;
}
@ -549,9 +559,9 @@ void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, int mem_s
{
FT_Open_Args open;
open.flags= FT_OPEN_MEMORY;
open.memory_base= (FT_Byte *)mem;
open.memory_size= mem_size;
open.flags = FT_OPEN_MEMORY;
open.memory_base = (FT_Byte *)mem;
open.memory_size = mem_size;
FT_Attach_Stream(font->face, &open);
}
@ -560,14 +570,14 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz
FontBLF *font;
FT_Error err;
font= (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem");
err= FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face);
font = (FontBLF *)MEM_callocN(sizeof(FontBLF), "blf_font_new_from_mem");
err = FT_New_Memory_Face(ft_lib, mem, mem_size, 0, &font->face);
if (err) {
MEM_freeN(font);
return NULL;
}
err= FT_Select_Charmap(font->face, ft_encoding_unicode);
err = FT_Select_Charmap(font->face, ft_encoding_unicode);
if (err) {
printf("Can't set the unicode character map!\n");
FT_Done_Face(font->face);
@ -575,8 +585,8 @@ FontBLF *blf_font_new_from_mem(const char *name, unsigned char *mem, int mem_siz
return NULL;
}
font->name= BLI_strdup(name);
font->filename= NULL;
font->name = BLI_strdup(name);
font->filename = NULL;
blf_font_fill(font);
return font;
}

@ -59,11 +59,11 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi)
{
GlyphCacheBLF *p;
p= (GlyphCacheBLF *)font->cache.first;
p = (GlyphCacheBLF *)font->cache.first;
while (p) {
if (p->size == size && p->dpi == dpi)
return p;
p= p->next;
p = p->next;
}
return NULL;
}
@ -73,43 +73,43 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
{
GlyphCacheBLF *gc;
gc= (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
gc->next= NULL;
gc->prev= NULL;
gc->size= font->size;
gc->dpi= font->dpi;
gc = (GlyphCacheBLF *)MEM_callocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new");
gc->next = NULL;
gc->prev = NULL;
gc->size = font->size;
gc->dpi = font->dpi;
memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
memset(gc->bucket, 0, sizeof(gc->bucket));
gc->textures= (GLuint *)malloc(sizeof(GLuint)*256);
gc->ntex= 256;
gc->cur_tex= -1;
gc->x_offs= 0;
gc->y_offs= 0;
gc->pad= 3;
gc->textures = (GLuint *)malloc(sizeof(GLuint)*256);
gc->ntex = 256;
gc->cur_tex = -1;
gc->x_offs = 0;
gc->y_offs = 0;
gc->pad = 3;
gc->num_glyphs= font->face->num_glyphs;
gc->rem_glyphs= font->face->num_glyphs;
gc->ascender= ((float)font->face->size->metrics.ascender) / 64.0f;
gc->descender= ((float)font->face->size->metrics.descender) / 64.0f;
gc->num_glyphs = font->face->num_glyphs;
gc->rem_glyphs = font->face->num_glyphs;
gc->ascender = ((float)font->face->size->metrics.ascender) / 64.0f;
gc->descender = ((float)font->face->size->metrics.descender) / 64.0f;
if (FT_IS_SCALABLE(font->face)) {
gc->max_glyph_width= (float)((font->face->bbox.xMax - font->face->bbox.xMin) *
(((float)font->face->size->metrics.x_ppem) /
((float)font->face->units_per_EM)));
gc->max_glyph_width = (float)((font->face->bbox.xMax - font->face->bbox.xMin) *
(((float)font->face->size->metrics.x_ppem) /
((float)font->face->units_per_EM)));
gc->max_glyph_height= (float)((font->face->bbox.yMax - font->face->bbox.yMin) *
(((float)font->face->size->metrics.y_ppem) /
((float)font->face->units_per_EM)));
gc->max_glyph_height = (float)((font->face->bbox.yMax - font->face->bbox.yMin) *
(((float)font->face->size->metrics.y_ppem) /
((float)font->face->units_per_EM)));
}
else {
gc->max_glyph_width= ((float)font->face->size->metrics.max_advance) / 64.0f;
gc->max_glyph_height= ((float)font->face->size->metrics.height) / 64.0f;
gc->max_glyph_width = ((float)font->face->size->metrics.max_advance) / 64.0f;
gc->max_glyph_height = ((float)font->face->size->metrics.height) / 64.0f;
}
gc->p2_width= 0;
gc->p2_height= 0;
gc->p2_width = 0;
gc->p2_height = 0;
BLI_addhead(&font->cache, gc);
return gc;
@ -121,10 +121,10 @@ void blf_glyph_cache_clear(FontBLF *font)
GlyphBLF *g;
int i;
for(gc=font->cache.first; gc; gc=gc->next) {
for (i= 0; i < 257; i++) {
for (gc = font->cache.first; gc; gc = gc->next) {
for (i = 0; i < 257; i++) {
while (gc->bucket[i].first) {
g= gc->bucket[i].first;
g = gc->bucket[i].first;
BLI_remlink(&(gc->bucket[i]), g);
blf_glyph_free(g);
}
@ -139,9 +139,9 @@ void blf_glyph_cache_free(GlyphCacheBLF *gc)
GlyphBLF *g;
int i;
for (i= 0; i < 257; i++) {
for (i = 0; i < 257; i++) {
while (gc->bucket[i].first) {
g= gc->bucket[i].first;
g = gc->bucket[i].first;
BLI_remlink(&(gc->bucket[i]), g);
blf_glyph_free(g);
}
@ -163,25 +163,25 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
if (gc->cur_tex >= gc->ntex) {
gc->ntex *= 2;
gc->textures= (GLuint *)realloc((void *)gc->textures, sizeof(GLuint)*gc->ntex);
gc->textures = (GLuint *)realloc((void *)gc->textures, sizeof(GLuint)*gc->ntex);
}
gc->p2_width= blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2));
gc->p2_width = blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2));
if (gc->p2_width > font->max_tex_size)
gc->p2_width= font->max_tex_size;
gc->p2_width = font->max_tex_size;
i= (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width);
gc->p2_height= blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height);
i = (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width);
gc->p2_height = blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height);
if (gc->p2_height > font->max_tex_size)
gc->p2_height= font->max_tex_size;
gc->p2_height = font->max_tex_size;
tot_mem= gc->p2_width * gc->p2_height;
buf= (unsigned char *)malloc(tot_mem);
tot_mem = gc->p2_width * gc->p2_height;
buf = (unsigned char *)malloc(tot_mem);
memset((void *)buf, 0, tot_mem);
glGenTextures(1, &gc->textures[gc->cur_tex]);
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= gc->textures[gc->cur_tex]));
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = gc->textures[gc->cur_tex]));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -196,12 +196,12 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
GlyphBLF *p;
unsigned int key;
key= blf_hash(c);
p= gc->bucket[key].first;
key = blf_hash(c);
p = gc->bucket[key].first;
while (p) {
if (p->c == c)
return p;
p= p->next;
p = p->next;
}
return NULL;
}
@ -216,7 +216,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
FT_BBox bbox;
unsigned int key;
g= blf_glyph_search(font->glyph_cache, c);
g = blf_glyph_search(font->glyph_cache, c);
if (g)
return g;
@ -228,7 +228,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
return NULL;
/* get the glyph. */
slot= font->face->glyph;
slot = font->face->glyph;
if (sharp) {
err = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO);
@ -246,40 +246,40 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
if (err || slot->format != FT_GLYPH_FORMAT_BITMAP)
return NULL;
g= (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_add");
g->c= c;
g->idx= (FT_UInt)index;
g->xoff= -1;
g->yoff= -1;
bitmap= slot->bitmap;
g->width= bitmap.width;
g->height= bitmap.rows;
g = (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_add");
g->c = c;
g->idx = (FT_UInt)index;
g->xoff = -1;
g->yoff = -1;
bitmap = slot->bitmap;
g->width = bitmap.width;
g->height = bitmap.rows;
if (g->width && g->height) {
if (sharp) {
/* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */
int i;
for (i=0; i < (g->width * g->height); i++) {
for (i = 0; i < (g->width * g->height); i++) {
bitmap.buffer[i] = 255 * bitmap.buffer[i];
}
}
g->bitmap= (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap");
g->bitmap = (unsigned char *)MEM_mallocN(g->width * g->height, "glyph bitmap");
memcpy((void *)g->bitmap, (void *)bitmap.buffer, g->width * g->height);
}
g->advance= ((float)slot->advance.x) / 64.0f;
g->pos_x= slot->bitmap_left;
g->pos_y= slot->bitmap_top;
g->pitch= slot->bitmap.pitch;
g->advance = ((float)slot->advance.x) / 64.0f;
g->pos_x = slot->bitmap_left;
g->pos_y = slot->bitmap_top;
g->pitch = slot->bitmap.pitch;
FT_Outline_Get_CBox(&(slot->outline), &bbox);
g->box.xmin= ((float)bbox.xMin) / 64.0f;
g->box.xmax= ((float)bbox.xMax) / 64.0f;
g->box.ymin= ((float)bbox.yMin) / 64.0f;
g->box.ymax= ((float)bbox.yMax) / 64.0f;
g->box.xmin = ((float)bbox.xMin) / 64.0f;
g->box.xmax = ((float)bbox.xMax) / 64.0f;
g->box.ymin = ((float)bbox.yMin) / 64.0f;
g->box.ymax = ((float)bbox.yMax) / 64.0f;
key= blf_hash(g->c);
key = blf_hash(g->c);
BLI_addhead(&(font->glyph_cache->bucket[key]), g);
return g;
}
@ -296,7 +296,6 @@ void blf_glyph_free(GlyphBLF *g)
static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
{
glBegin(GL_QUADS);
glTexCoord2f(uv[0][0], uv[0][1]);
glVertex2f(dx, y1);
@ -310,27 +309,26 @@ static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, floa
glTexCoord2f(uv[1][0], uv[0][1]);
glVertex2f(dx1, y1);
glEnd();
}
static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
{
float soft[25]= {1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f,
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f,
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
float soft[25] = {1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f,
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
2/60.0f, 5/60.0f, 8/60.0f, 5/60.0f, 2/60.0f,
1/60.0f, 3/60.0f, 5/60.0f, 3/60.0f, 1/60.0f,
1/60.0f, 1/60.0f, 2/60.0f, 1/60.0f, 1/60.0f};
float color[4], *fp= soft;
float color[4], *fp = soft;
int dx, dy;
color[0]= shadow_col[0];
color[1]= shadow_col[1];
color[2]= shadow_col[2];
color[0] = shadow_col[0];
color[1] = shadow_col[1];
color[2] = shadow_col[2];
for(dx=-2; dx<3; dx++) {
for(dy=-2; dy<3; dy++, fp++) {
color[3]= *(fp) * shadow_col[3];
for (dx = -2; dx < 3; dx++) {
for (dy = -2; dy < 3; dy++, fp++) {
color[3] = *(fp) * shadow_col[3];
glColor4fv(color);
blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
}
@ -341,20 +339,20 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x
static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
{
float soft[9]= {1/16.0f, 2/16.0f, 1/16.0f,
2/16.0f,4/16.0f, 2/16.0f,
1/16.0f, 2/16.0f, 1/16.0f};
float soft[9] = {1/16.0f, 2/16.0f, 1/16.0f,
2/16.0f,4/16.0f, 2/16.0f,
1/16.0f, 2/16.0f, 1/16.0f};
float color[4], *fp= soft;
float color[4], *fp = soft;
int dx, dy;
color[0]= shadow_col[0];
color[1]= shadow_col[1];
color[2]= shadow_col[2];
color[0] = shadow_col[0];
color[1] = shadow_col[1];
color[2] = shadow_col[2];
for(dx=-1; dx<2; dx++) {
for(dy=-1; dy<2; dy++, fp++) {
color[3]= *(fp) * shadow_col[3];
for (dx = -1; dx < 2; dx++) {
for (dy = -1; dy < 2; dy++, fp++) {
color[3] = *(fp) * shadow_col[3];
glColor4fv(color);
blf_texture_draw(uv, x1+dx, y1+dy, x2+dx, y2+dy);
}
@ -373,30 +371,30 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
return 1;
if (g->build_tex == 0) {
GlyphCacheBLF *gc= font->glyph_cache;
GlyphCacheBLF *gc = font->glyph_cache;
if (font->max_tex_size == -1)
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
if (gc->cur_tex == -1) {
blf_glyph_cache_texture(font, gc);
gc->x_offs= gc->pad;
gc->y_offs= gc->pad;
gc->x_offs = gc->pad;
gc->y_offs = gc->pad;
}
if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) {
gc->x_offs= gc->pad;
gc->x_offs = gc->pad;
gc->y_offs += gc->max_glyph_height;
if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) {
gc->y_offs= gc->pad;
gc->y_offs = gc->pad;
blf_glyph_cache_texture(font, gc);
}
}
g->tex= gc->textures[gc->cur_tex];
g->xoff= gc->x_offs;
g->yoff= gc->y_offs;
g->tex = gc->textures[gc->cur_tex];
g->xoff = gc->x_offs;
g->yoff = gc->y_offs;
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
@ -407,32 +405,32 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
glPopClientAttrib();
g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width);
g->uv[0][1]= ((float)g->yoff) / ((float)gc->p2_height);
g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)gc->p2_height);
g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);
g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height);
g->uv[1][0] = ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
g->uv[1][1] = ((float)(g->yoff + g->height)) / ((float)gc->p2_height);
/* update the x offset for the next glyph. */
gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad);
gc->rem_glyphs--;
g->build_tex= 1;
g->build_tex = 1;
}
xo= 0.0f;
yo= 0.0f;
xo = 0.0f;
yo = 0.0f;
if (font->flags & BLF_SHADOW) {
xo= x;
yo= y;
xo = x;
yo = y;
x += font->shadow_x;
y += font->shadow_y;
}
dx= floor(x + g->pos_x);
dx1= dx + g->width;
y1= y + g->pos_y;
y2= y + g->pos_y - g->height;
dx = floor(x + g->pos_x);
dx1 = dx + g->width;
y1 = y + g->pos_y;
y2 = y + g->pos_y - g->height;
if (font->flags & BLF_CLIPPING) {
if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
@ -446,12 +444,12 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
}
if (font->tex_bind_state != g->tex) {
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state= g->tex));
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
}
if (font->flags & BLF_SHADOW) {
switch(font->shadow) {
switch (font->shadow) {
case 3:
blf_texture3_draw(font->shadow_col, g->uv, dx, y1, dx1, y2);
break;
@ -466,16 +464,16 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
glColor4fv(font->orig_col);
x= xo;
y= yo;
x = xo;
y = yo;
dx= floor(x + g->pos_x);
dx1= dx + g->width;
y1= y + g->pos_y;
y2= y + g->pos_y - g->height;
dx = floor(x + g->pos_x);
dx1 = dx + g->width;
y1 = y + g->pos_y;
y2 = y + g->pos_y - g->height;
}
switch(font->blur) {
switch (font->blur) {
case 3:
blf_texture3_draw(font->orig_col, g->uv, dx, y1, dx1, y2);
break;

@ -41,7 +41,7 @@ unsigned int blf_hash(unsigned int val);
char *blf_dir_search(const char *file);
char *blf_dir_metrics_search(const char *filename);
// int blf_dir_split(const char *str, char *file, int *size); // UNUSED
/* int blf_dir_split(const char *str, char *file, int *size); *//* UNUSED */
int blf_font_init(void);
void blf_font_exit(void);

@ -55,7 +55,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_linklist.h" /* linknode */
#include "BLI_linklist.h" /* linknode */
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BLI_path_util.h"
@ -109,7 +109,7 @@ static const char *locales[] = {
void BLF_lang_init(void)
{
char *messagepath= BLI_get_folder(BLENDER_DATAFILES, "locale");
char *messagepath = BLI_get_folder(BLENDER_DATAFILES, "locale");
BLI_strncpy(global_encoding_name, SYSTEM_ENCODING_DEFAULT, sizeof(global_encoding_name));
@ -118,7 +118,7 @@ void BLF_lang_init(void)
}
else {
printf("%s: 'locale' data path for translations not found, continuing\n", __func__);
global_messagepath[0]= '\0';
global_messagepath[0] = '\0';
}
}
@ -126,18 +126,18 @@ void BLF_lang_init(void)
/* get LANG/LANGUAGE environment variable */
static void get_language_variable(const char *varname, char *var, int maxlen)
{
char *env= getenv(varname);
char *env = getenv(varname);
if(env) {
if (env) {
char *s;
/* store defaul locale */
BLI_strncpy(var, env, maxlen);
/* use first language as default */
s= strchr(var, ':');
if(s)
s[0]= 0;
s = strchr(var, ':');
if (s)
s[0] = 0;
}
}
@ -146,7 +146,7 @@ static void get_language_variable(const char *varname, char *var, int maxlen)
*/
static void get_language(const char *locale, const char *lang, char *language, int maxlen)
{
if(locale[0]) {
if (locale[0]) {
BLI_strncpy(language, locale, maxlen);
}
else {
@ -154,9 +154,9 @@ static void get_language(const char *locale, const char *lang, char *language, i
BLI_strncpy(language, lang, maxlen);
s= strchr(language, '.');
if(s)
s[0]= 0;
s = strchr(language, '.');
if (s)
s[0] = 0;
}
}
@ -165,22 +165,22 @@ void BLF_lang_set(const char *str)
{
char *locreturn;
const char *short_locale;
int ok= 1;
int ok = 1;
const char *long_locale = locales[2 * U.language];
if((U.transopts&USER_DOTRANSLATE)==0)
if ((U.transopts&USER_DOTRANSLATE) == 0)
return;
if(str)
if (str)
short_locale = str;
else
short_locale = locales[ 2 * U.language + 1];
#if defined (_WIN32) && !defined(FREE_WINDOWS)
if(short_locale) {
if (short_locale) {
char *envStr;
if( U.language==0 )/* use system setting */
if (U.language == 0)/* use system setting */
envStr = BLI_sprintfN( "LANG=%s", getenv("LANG") );
else
envStr = BLI_sprintfN( "LANG=%s", short_locale );
@ -189,48 +189,48 @@ void BLF_lang_set(const char *str)
MEM_freeN(envStr);
}
locreturn= setlocale(LC_ALL, long_locale);
locreturn = setlocale(LC_ALL, long_locale);
if (locreturn == NULL) {
if(G.f & G_DEBUG)
if (G.f & G_DEBUG)
printf("Could not change locale to %s\n", long_locale);
ok= 0;
ok = 0;
}
#else
{
static char default_lang[64]="\0";
static char default_language[64]="\0";
static char default_lang[64] ="\0";
static char default_language[64] ="\0";
if(default_lang[0]==0)
if (default_lang[0] == 0)
get_language_variable("LANG", default_lang, sizeof(default_lang));
if(default_language[0]==0)
if (default_language[0] == 0)
get_language_variable("LANGUAGE", default_language, sizeof(default_language));
if(short_locale[0]) {
if(G.f & G_DEBUG)
if (short_locale[0]) {
if (G.f & G_DEBUG)
printf("Setting LANG= and LANGUAGE to %s\n", short_locale);
BLI_setenv("LANG", short_locale);
BLI_setenv("LANGUAGE", short_locale);
}
else {
if(G.f & G_DEBUG)
if (G.f & G_DEBUG)
printf("Setting LANG=%s and LANGUAGE=%s\n", default_lang, default_language);
BLI_setenv("LANG", default_lang);
BLI_setenv("LANGUAGE", default_language);
}
locreturn= setlocale(LC_ALL, short_locale);
locreturn = setlocale(LC_ALL, short_locale);
if(locreturn == NULL) {
char *short_locale_utf8= NULL;
if (locreturn == NULL) {
char *short_locale_utf8 = NULL;
if(short_locale[0]) {
short_locale_utf8= BLI_sprintfN("%s.UTF-8", short_locale);
locreturn= setlocale(LC_ALL, short_locale_utf8);
if (short_locale[0]) {
short_locale_utf8 = BLI_sprintfN("%s.UTF-8", short_locale);
locreturn = setlocale(LC_ALL, short_locale_utf8);
}
if (locreturn == NULL) {
@ -238,8 +238,8 @@ void BLF_lang_set(const char *str)
get_language(long_locale, default_lang, language, sizeof(language));
if(G.f & G_DEBUG) {
if(short_locale[0])
if (G.f & G_DEBUG) {
if (short_locale[0])
printf("Could not change locale to %s nor %s\n", short_locale, short_locale_utf8);
else
printf("Could not reset locale\n");
@ -251,19 +251,19 @@ void BLF_lang_set(const char *str)
BLI_setenv("LANG", default_lang);
BLI_setenv("LANGUAGE", language);
locreturn= setlocale(LC_ALL, "");
locreturn = setlocale(LC_ALL, "");
ok= 0;
ok = 0;
}
if(short_locale_utf8)
if (short_locale_utf8)
MEM_freeN(short_locale_utf8);
}
}
#endif
if(ok) {
//printf("Change locale to %s\n", locreturn );
if (ok) {
/*printf("Change locale to %s\n", locreturn ); */
BLI_strncpy(global_language, locreturn, sizeof(global_language));
}

@ -57,34 +57,34 @@
#include "DNA_userdef_types.h" /* For user settings. */
#ifdef WITH_INTERNATIONAL
static const char unifont_filename[]="droidsans.ttf.gz";
static unsigned char *unifont_ttf= NULL;
static int unifont_size= 0;
static const char unifont_filename[] ="droidsans.ttf.gz";
static unsigned char *unifont_ttf = NULL;
static int unifont_size = 0;
unsigned char *BLF_get_unifont(int *unifont_size_r)
{
if(unifont_ttf==NULL) {
if (unifont_ttf == NULL) {
char *fontpath = BLI_get_folder(BLENDER_DATAFILES, "fonts");
if (fontpath) {
char unifont_path[1024];
BLI_snprintf(unifont_path, sizeof(unifont_path), "%s/%s", fontpath, unifont_filename);
unifont_ttf= (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size);
unifont_ttf = (unsigned char*)BLI_file_ungzip_to_mem(unifont_path, &unifont_size);
}
else {
printf("%s: 'fonts' data path not found for international font, continuing\n", __func__);
}
}
*unifont_size_r= unifont_size;
*unifont_size_r = unifont_size;
return unifont_ttf;
}
void BLF_free_unifont(void)
{
if(unifont_ttf)
if (unifont_ttf)
MEM_freeN(unifont_ttf);
}
@ -93,7 +93,7 @@ void BLF_free_unifont(void)
const char* BLF_gettext(const char *msgid)
{
#ifdef WITH_INTERNATIONAL
if( msgid[0] )
if (msgid[0])
return gettext(msgid);
return "";
#else
@ -157,7 +157,7 @@ int BLF_translate_tooltips(void)
const char *BLF_translate_do_iface(const char *msgid)
{
#ifdef WITH_INTERNATIONAL
if(BLF_translate_iface())
if (BLF_translate_iface())
return BLF_gettext(msgid);
else
return msgid;
@ -169,7 +169,7 @@ const char *BLF_translate_do_iface(const char *msgid)
const char *BLF_translate_do_tooltip(const char *msgid)
{
#ifdef WITH_INTERNATIONAL
if(BLF_translate_tooltips())
if (BLF_translate_tooltips())
return BLF_gettext(msgid);
else
return msgid;

@ -53,7 +53,7 @@ unsigned int blf_hash(unsigned int val)
{
unsigned int key;
key= val;
key = val;
key += ~(key << 16);
key ^= (key >> 5);
key += (key << 3);