Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-04-22 02:09:06 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-22 12:48:16 +0300
commit67454a282d701a852464785f18dd9589d983b3a1 (patch)
tree468ee4d38089c9e078352ddc1eebd46157dd2934 /source/blender/blenfont
parentf24bb62fc2b869f0798a98400ac488d6d6067b71 (diff)
Cleanup: style, use braces for blenfont
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf.c48
-rw-r--r--source/blender/blenfont/intern/blf_dir.c18
-rw-r--r--source/blender/blenfont/intern/blf_font.c114
-rw-r--r--source/blender/blenfont/intern/blf_font_win32_compat.c6
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c21
-rw-r--r--source/blender/blenfont/intern/blf_thumbs.c3
6 files changed, 140 insertions, 70 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 0da96226143..d16a4d7ed4d 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -86,8 +86,9 @@ int blf_mono_font_render = -1;
static FontBLF *blf_get(int fontid)
{
- if (fontid >= 0 && fontid < BLF_MAX_FONT)
+ if (fontid >= 0 && fontid < BLF_MAX_FONT) {
return global_font[fontid];
+ }
return NULL;
}
@@ -95,8 +96,9 @@ int BLF_init(void)
{
int i;
- for (i = 0; i < BLF_MAX_FONT; i++)
+ for (i = 0; i < BLF_MAX_FONT; i++) {
global_font[i] = NULL;
+ }
global_font_points = 11;
global_font_dpi = 72;
@@ -151,8 +153,9 @@ static int blf_search(const char *name)
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
- if (font && (STREQ(font->name, name)))
+ if (font && (STREQ(font->name, name))) {
return i;
+ }
}
return -1;
@@ -162,9 +165,11 @@ 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;
}
@@ -378,26 +383,32 @@ void BLF_position(int fontid, float x, float y, float z)
remainder = x - floorf(x);
if (remainder > 0.4f && remainder < 0.6f) {
- if (remainder < 0.5f)
+ if (remainder < 0.5f) {
x -= 0.1f * xa;
- else
+ }
+ else {
x += 0.1f * xa;
+ }
}
remainder = y - floorf(y);
if (remainder > 0.4f && remainder < 0.6f) {
- if (remainder < 0.5f)
+ if (remainder < 0.5f) {
y -= 0.1f * ya;
- else
+ }
+ else {
y += 0.1f * ya;
+ }
}
remainder = z - floorf(z);
if (remainder > 0.4f && remainder < 0.6f) {
- if (remainder < 0.5f)
+ if (remainder < 0.5f) {
z -= 0.1f * za;
- else
+ }
+ else {
z += 0.1f * za;
+ }
}
font->pos[0] = x;
@@ -554,27 +565,32 @@ static void blf_draw_gl__start(FontBLF *font)
/* always bind the texture for the first glyph */
font->tex_bind_state = 0;
- if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0)
+ if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0) {
return; /* glyphs will be translated individually and batched. */
+ }
GPU_matrix_push();
- if (font->flags & BLF_MATRIX)
+ if (font->flags & BLF_MATRIX) {
GPU_matrix_mul(font->m);
+ }
GPU_matrix_translate_3fv(font->pos);
- if (font->flags & BLF_ASPECT)
+ if (font->flags & BLF_ASPECT) {
GPU_matrix_scale_3fv(font->aspect);
+ }
- if (font->flags & BLF_ROTATION)
+ if (font->flags & BLF_ROTATION) {
GPU_matrix_rotate_2d(RAD2DEG(font->angle));
+ }
}
static void blf_draw_gl__end(FontBLF *font)
{
- if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0)
+ if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0) {
GPU_matrix_pop();
+ }
}
void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c
index 89378dc6181..204be5a86b2 100644
--- a/source/blender/blenfont/intern/blf_dir.c
+++ b/source/blender/blenfont/intern/blf_dir.c
@@ -55,8 +55,9 @@ static DirBLF *blf_dir_find(const char *path)
p = global_font_dir.first;
while (p) {
- if (BLI_path_cmp(p->path, path) == 0)
+ if (BLI_path_cmp(p->path, path) == 0) {
return p;
+ }
p = p->next;
}
return NULL;
@@ -67,8 +68,9 @@ void BLF_dir_add(const char *path)
DirBLF *dir;
dir = blf_dir_find(path);
- if (dir) /* already in the list ? just return. */
+ if (dir) { /* already in the list ? just return. */
return;
+ }
dir = (DirBLF *)MEM_callocN(sizeof(DirBLF), "BLF_dir_add");
dir->path = BLI_strdup(path);
@@ -95,8 +97,9 @@ char **BLF_dir_get(int *ndir)
int i, count;
count = BLI_listbase_count(&global_font_dir);
- if (!count)
+ if (!count) {
return NULL;
+ }
dirs = (char **)MEM_callocN(sizeof(char *) * count, "BLF_dir_get");
p = global_font_dir.first;
@@ -138,8 +141,9 @@ char *blf_dir_search(const char *file)
if (!s) {
/* check the current directory, why not ? */
- if (BLI_exists(file))
+ if (BLI_exists(file)) {
s = BLI_strdup(file);
+ }
}
return s;
@@ -166,14 +170,16 @@ char *blf_dir_metrics_search(const char *filename)
s[2] = 'm';
/* first check .afm */
- if (BLI_exists(mfile))
+ if (BLI_exists(mfile)) {
return mfile;
+ }
/* and now check .pfm */
s[0] = 'p';
- if (BLI_exists(mfile))
+ if (BLI_exists(mfile)) {
return mfile;
+ }
}
MEM_freeN(mfile);
return NULL;
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index ae406b103a7..7283ade3ae5 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -173,8 +173,9 @@ void blf_batch_draw_begin(FontBLF *font)
void blf_batch_draw(void)
{
- if (g_batch.glyph_len == 0)
+ if (g_batch.glyph_len == 0) {
return;
+ }
GPU_blend(true);
GPU_blend_set_func_separate(
@@ -235,8 +236,9 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
if (gc) {
font->glyph_cache = gc;
/* Optimization: do not call FT_Set_Char_Size if size did not change. */
- if (font->size == size && font->dpi == dpi)
+ if (font->size == size && font->dpi == dpi) {
return;
+ }
}
err = FT_Set_Char_Size(font->face, 0, (FT_F26Dot6)(size * 64), dpi, dpi);
@@ -251,10 +253,12 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
if (!gc) {
gc = blf_glyph_cache_new(font);
- if (gc)
+ if (gc) {
font->glyph_cache = gc;
- else
+ }
+ else {
font->glyph_cache = NULL;
+ }
}
}
@@ -371,12 +375,15 @@ static void blf_font_draw_ex(
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (UNLIKELY(c == BLI_UTF8_ERR))
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
- if (UNLIKELY(g == NULL))
+ }
+ if (UNLIKELY(g == NULL)) {
continue;
- if (has_kerning)
+ }
+ if (has_kerning) {
BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, 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);
@@ -416,10 +423,12 @@ static void blf_font_draw_ascii_ex(
while ((c = *(str++)) && len--) {
BLI_assert(c < 128);
- if ((g = glyph_ascii_table[c]) == NULL)
+ if ((g = glyph_ascii_table[c]) == NULL) {
continue;
- if (has_kerning)
+ }
+ if (has_kerning) {
BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, 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);
@@ -458,17 +467,20 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (UNLIKELY(c == BLI_UTF8_ERR))
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
- if (UNLIKELY(g == NULL))
+ }
+ if (UNLIKELY(g == NULL)) {
continue;
+ }
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
col = BLI_wcwidth((wchar_t)c);
- if (col < 0)
+ if (col < 0) {
col = 1;
+ }
columns += col;
pen_x += cwidth * col;
@@ -507,12 +519,15 @@ static void blf_font_draw_buffer_ex(
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (UNLIKELY(c == BLI_UTF8_ERR))
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
- if (UNLIKELY(g == NULL))
+ }
+ if (UNLIKELY(g == NULL)) {
continue;
- if (has_kerning)
+ }
+ if (has_kerning) {
BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
+ }
chx = pen_x + ((int)g->pos_x);
chy = pen_y_basis + g->height;
@@ -531,10 +546,12 @@ static void blf_font_draw_buffer_ex(
int height_clip = g->height;
int yb_start = g->pitch < 0 ? 0 : g->height - 1;
- if (width_clip + chx > buf_info->w)
+ if (width_clip + chx > buf_info->w) {
width_clip -= chx + width_clip - buf_info->w;
- if (height_clip + pen_y > buf_info->h)
+ }
+ if (height_clip + pen_y > buf_info->h) {
height_clip -= pen_y + height_clip - buf_info->h;
+ }
/* drawing below the image? */
if (pen_y < 0) {
@@ -570,10 +587,12 @@ static void blf_font_draw_buffer_ex(
}
}
- if (g->pitch < 0)
+ if (g->pitch < 0) {
yb++;
- else
+ }
+ else {
yb--;
+ }
}
}
@@ -606,10 +625,12 @@ static void blf_font_draw_buffer_ex(
}
}
- if (g->pitch < 0)
+ if (g->pitch < 0) {
yb++;
- else
+ }
+ else {
yb--;
+ }
}
}
}
@@ -762,27 +783,34 @@ static void blf_font_boundbox_ex(
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (UNLIKELY(c == BLI_UTF8_ERR))
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
- if (UNLIKELY(g == NULL))
+ }
+ if (UNLIKELY(g == NULL)) {
continue;
- if (has_kerning)
+ }
+ if (has_kerning) {
BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
+ }
gbox.xmin = (float)pen_x;
gbox.xmax = (float)pen_x + g->advance;
gbox.ymin = g->box.ymin + (float)pen_y;
gbox.ymax = g->box.ymax + (float)pen_y;
- if (gbox.xmin < box->xmin)
+ if (gbox.xmin < box->xmin) {
box->xmin = gbox.xmin;
- if (gbox.ymin < box->ymin)
+ }
+ if (gbox.ymin < box->ymin) {
box->ymin = gbox.ymin;
+ }
- if (gbox.xmax > box->xmax)
+ if (gbox.xmax > box->xmax) {
box->xmax = gbox.xmax;
- if (gbox.ymax > box->ymax)
+ }
+ if (gbox.ymax > box->ymax) {
box->ymax = gbox.ymax;
+ }
pen_x += g->advance_i;
g_prev = g;
@@ -854,12 +882,15 @@ static void blf_font_wrap_apply(
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
- if (UNLIKELY(c == BLI_UTF8_ERR))
+ if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
- if (UNLIKELY(g == NULL))
+ }
+ if (UNLIKELY(g == NULL)) {
continue;
- if (has_kerning)
+ }
+ if (has_kerning) {
BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+ }
/**
* Implementation Detail (utf8).
@@ -998,10 +1029,12 @@ float blf_font_width(FontBLF *font, const char *str, size_t len, struct ResultBL
float xa;
rctf box;
- if (font->flags & BLF_ASPECT)
+ if (font->flags & BLF_ASPECT) {
xa = font->aspect[0];
- else
+ }
+ else {
xa = 1.0f;
+ }
if (font->flags & BLF_WORD_WRAP) {
blf_font_boundbox__wrap(font, str, len, &box, r_info);
@@ -1017,10 +1050,12 @@ float blf_font_height(FontBLF *font, const char *str, size_t len, struct ResultB
float ya;
rctf box;
- if (font->flags & BLF_ASPECT)
+ if (font->flags & BLF_ASPECT) {
ya = font->aspect[1];
- else
+ }
+ else {
ya = 1.0f;
+ }
if (font->flags & BLF_WORD_WRAP) {
blf_font_boundbox__wrap(font, str, len, &box, r_info);
@@ -1084,10 +1119,12 @@ void blf_font_free(FontBLF *font)
blf_kerning_cache_clear(font);
FT_Done_Face(font->face);
- if (font->filename)
+ if (font->filename) {
MEM_freeN(font->filename);
- if (font->name)
+ }
+ if (font->name) {
MEM_freeN(font->name);
+ }
MEM_freeN(font);
}
@@ -1100,8 +1137,9 @@ static void blf_font_fill(FontBLF *font)
font->pos[1] = 0.0f;
font->angle = 0.0f;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++) {
font->m[i] = 0;
+ }
/* annoying bright color so we can see where to add BLF_color calls */
font->color[0] = 255;
diff --git a/source/blender/blenfont/intern/blf_font_win32_compat.c b/source/blender/blenfont/intern/blf_font_win32_compat.c
index c609d67ece1..e73df4dbfc7 100644
--- a/source/blender/blenfont/intern/blf_font_win32_compat.c
+++ b/source/blender/blenfont/intern/blf_font_win32_compat.c
@@ -59,13 +59,15 @@ static unsigned long ft_ansi_stream_io(FT_Stream stream,
unsigned long count)
{
FILE *file;
- if (!count && offset > stream->size)
+ if (!count && offset > stream->size) {
return 1;
+ }
file = STREAM_FILE(stream);
- if (stream->pos != offset)
+ if (stream->pos != offset) {
fseek(file, offset, SEEK_SET);
+ }
return fread(buffer, 1, count, file);
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 8f9db604434..049af7678d5 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -63,8 +63,9 @@ KerningCacheBLF *blf_kerning_cache_find(FontBLF *font)
p = (KerningCacheBLF *)font->kerning_caches.first;
while (p) {
- if (p->mode == font->kerning_mode)
+ if (p->mode == font->kerning_mode) {
return p;
+ }
p = p->next;
}
return NULL;
@@ -120,8 +121,9 @@ GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned i
p = (GlyphCacheBLF *)font->cache.first;
while (p) {
- if (p->size == size && p->dpi == dpi)
+ if (p->size == size && p->dpi == dpi) {
return p;
+ }
p = p->next;
}
return NULL;
@@ -254,8 +256,9 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
key = blf_hash(c);
p = gc->bucket[key].first;
while (p) {
- if (p->c == c)
+ if (p->c == c) {
return p;
+ }
p = p->next;
}
return NULL;
@@ -271,8 +274,9 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
unsigned int key;
g = blf_glyph_search(font->glyph_cache, c);
- if (g)
+ if (g) {
return g;
+ }
/* glyphs are dynamically created as needed by font rendering. this means that
* to make font rendering thread safe we have to do locking here. note that this
@@ -388,8 +392,9 @@ void blf_glyph_free(GlyphBLF *g)
/* don't need free the texture, the GlyphCache already
* have a list of all the texture and free it.
*/
- if (g->bitmap)
+ if (g->bitmap) {
MEM_freeN(g->bitmap);
+ }
MEM_freeN(g);
}
@@ -480,14 +485,16 @@ static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y
void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
- if ((!g->width) || (!g->height))
+ if ((!g->width) || (!g->height)) {
return;
+ }
if (g->build_tex == 0) {
GlyphCacheBLF *gc = font->glyph_cache;
- if (font->tex_size_max == -1)
+ if (font->tex_size_max == -1) {
font->tex_size_max = GPU_max_texture_size();
+ }
if (gc->texture_current == BLF_TEXTURE_UNSET) {
blf_glyph_cache_texture(font, gc);
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index f334511ac7a..2b34b1f8324 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -97,8 +97,9 @@ void BLF_thumb_preview(const char *filename,
blf_font_size(font, (unsigned int)MAX2(font_size_min, font_size_curr), dpi);
/* font->glyph_cache remains NULL if blf_font_size() failed to set font size */
- if (!font->glyph_cache)
+ if (!font->glyph_cache) {
break;
+ }
/* decrease font size each time */
font_size_curr -= (font_size_curr / font_shrink);