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>2013-09-01 04:46:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-09-01 04:46:04 +0400
commit2924a02a3561eed7899d5087f2a7a6c31529e18f (patch)
treef7e30878a3492cd0e91e2eaa5c8010ff6f0b930a /source/blender/blenfont
parentce326e20c85bc91471e681fa77f71be528302af3 (diff)
move strict compiler checks into a header so its easier to manage in one place (pragmas were copied around).
also enable more strict warnings for BLF (which had some incorrect casts).
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_font.c45
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c54
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h4
3 files changed, 52 insertions, 51 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 1e604bd8107..c7f829a3a42 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -50,6 +50,7 @@
#include "BLI_string_utf8.h"
#include "BLI_threads.h"
#include "BLI_linklist.h" /* linknode */
+#include "BLI_strict_flags.h"
#include "BIF_gl.h"
#include "BLF_api.h"
@@ -59,10 +60,6 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic error "-Wsign-conversion"
-#endif
-
/* freetype2 handle ONLY for this file!. */
static FT_Library ft_lib;
static SpinLock ft_lib_mutex;
@@ -163,7 +160,7 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
_kern_mode, \
&(_delta)) == 0) \
{ \
- _pen_x += _delta.x >> 6; \
+ _pen_x += (int)_delta.x >> 6; \
} \
} \
} (void)0
@@ -194,7 +191,7 @@ void blf_font_draw(FontBLF *font, const char *str, size_t len)
/* 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;
+ pen_x += (int)g->advance;
g_prev = g;
}
}
@@ -221,7 +218,7 @@ void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len)
/* 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;
+ pen_x += (int)g->advance;
g_prev = g;
}
}
@@ -273,10 +270,11 @@ void blf_font_buffer(FontBLF *font, const char *str)
/* buffer specific vars */
FontBufInfoBLF *buf_info = &font->buf_info;
float b_col_float[4];
- const unsigned char b_col_char[4] = {buf_info->col[0] * 255,
- buf_info->col[1] * 255,
- buf_info->col[2] * 255,
- buf_info->col[3] * 255};
+ const unsigned char b_col_char[4] = {
+ (unsigned char)(buf_info->col[0] * 255),
+ (unsigned char)(buf_info->col[1] * 255),
+ (unsigned char)(buf_info->col[2] * 255),
+ (unsigned char)(buf_info->col[3] * 255)};
unsigned char *cbuf;
int chx, chy;
@@ -378,14 +376,15 @@ void blf_font_buffer(FontBLF *font, const char *str)
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[3] = (alphatest = ((int)cbuf[3] + (int)b_col_char[3])) < 255 ?
+ (unsigned char)(alphatest) : 255;
}
else {
- cbuf[0] = (b_col_char[0] * a) + (cbuf[0] * (1.0f - a));
- cbuf[1] = (b_col_char[1] * a) + (cbuf[1] * (1.0f - a));
- cbuf[2] = (b_col_char[2] * a) + (cbuf[2] * (1.0f - a));
- cbuf[3] = (alphatest = ((int)cbuf[3] + (int)((b_col_float[3] * a) * 255.0f))) <
- 255 ? alphatest : 255;
+ cbuf[0] = (unsigned char)((b_col_char[0] * a) + (cbuf[0] * (1.0f - a)));
+ cbuf[1] = (unsigned char)((b_col_char[1] * a) + (cbuf[1] * (1.0f - a)));
+ cbuf[2] = (unsigned char)((b_col_char[2] * a) + (cbuf[2] * (1.0f - a)));
+ cbuf[3] = (alphatest = ((int)cbuf[3] + (int)((b_col_float[3] * a) * 255.0f))) < 255 ?
+ (unsigned char)(alphatest) : 255;
}
}
}
@@ -398,7 +397,7 @@ void blf_font_buffer(FontBLF *font, const char *str)
}
}
- pen_x += g->advance;
+ pen_x += (int)g->advance;
g_prev = g;
}
}
@@ -433,10 +432,10 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
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 = (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) box->xmin = gbox.xmin;
if (gbox.ymin < box->ymin) box->ymin = gbox.ymin;
@@ -444,7 +443,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
if (gbox.xmax > box->xmax) box->xmax = gbox.xmax;
if (gbox.ymax > box->ymax) box->ymax = gbox.ymax;
- pen_x += g->advance;
+ pen_x += (int)g->advance;
g_prev = g;
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index ae8e2d17c54..2a8e91299b4 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -56,9 +56,7 @@
#include "blf_internal_types.h"
#include "blf_internal.h"
-#ifdef __GNUC__
-# pragma GCC diagnostic error "-Wsign-conversion"
-#endif
+#include "BLI_strict_flags.h"
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned int dpi)
{
@@ -89,28 +87,28 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->textures = (GLuint *)MEM_mallocN(sizeof(GLuint) * 256, __func__);
gc->ntex = 256;
- gc->cur_tex = -1;
+ gc->cur_tex = BLF_CURTEX_UNSET;
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->num_glyphs = (int)font->face->num_glyphs;
+ gc->rem_glyphs = (int)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 = (int)((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 = (int)((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 = (int)(((float)font->face->size->metrics.max_advance) / 64.0f);
+ gc->max_glyph_height = (int)(((float)font->face->size->metrics.height) / 64.0f);
}
gc->p2_width = 0;
@@ -148,8 +146,8 @@ void blf_glyph_cache_free(GlyphCacheBLF *gc)
}
}
- if (gc->cur_tex > -1)
- glDeleteTextures(gc->cur_tex + 1, gc->textures);
+ if (gc->cur_tex != BLF_CURTEX_UNSET)
+ glDeleteTextures((int)gc->cur_tex + 1, gc->textures);
MEM_freeN((void *)gc->textures);
MEM_freeN(gc);
}
@@ -283,7 +281,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
/* 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++) {
- bitmap.buffer[i] = 255 * bitmap.buffer[i];
+ bitmap.buffer[i] = bitmap.buffer[i] ? 255 : 0;
}
}
@@ -292,8 +290,8 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
}
g->advance = ((float)slot->advance.x) / 64.0f;
- g->pos_x = slot->bitmap_left;
- g->pos_y = slot->bitmap_top;
+ g->pos_x = (float)slot->bitmap_left;
+ g->pos_y = (float)slot->bitmap_top;
g->pitch = slot->bitmap.pitch;
FT_Outline_Get_CBox(&(slot->outline), &bbox);
@@ -347,7 +345,7 @@ static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x
const float *fp = soft;
float color[4];
- int dx, dy;
+ float dx, dy;
color[0] = shadow_col[0];
color[1] = shadow_col[1];
@@ -372,7 +370,7 @@ static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x
const float *fp = soft;
float color[4];
- int dx, dy;
+ float dx, dy;
color[0] = shadow_col[0];
color[1] = shadow_col[1];
@@ -391,10 +389,10 @@ static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x
static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
{
- rect->xmin = floor(x + g->pos_x);
- rect->xmax = rect->xmin + g->width;
+ rect->xmin = (float)floor(x + g->pos_x);
+ rect->xmax = rect->xmin + (float)g->width;
rect->ymin = y + g->pos_y;
- rect->ymax = y + g->pos_y - g->height;
+ rect->ymax = y + g->pos_y - (float)g->height;
}
void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
@@ -410,7 +408,7 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
if (font->max_tex_size == -1)
glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);
- if (gc->cur_tex == -1) {
+ if (gc->cur_tex == BLF_CURTEX_UNSET) {
blf_glyph_cache_texture(font, gc);
gc->x_offs = gc->pad;
gc->y_offs = 0;
@@ -458,7 +456,7 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
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)(BLI_rctf_size_x(&g->box) + gc->pad);
+ gc->x_offs += (int)BLI_rctf_size_x(&g->box) + gc->pad;
gc->rem_glyphs--;
g->build_tex = 1;
@@ -482,7 +480,9 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
if (font->flags & BLF_SHADOW) {
rctf rect_ofs;
- blf_glyph_calc_rect(&rect_ofs, g, x + font->shadow_x, y + font->shadow_y);
+ blf_glyph_calc_rect(&rect_ofs, g,
+ x + (float)font->shadow_x,
+ y + (float)font->shadow_y);
switch (font->shadow) {
case 3:
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 096ff50a3ca..c64b7e974e7 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -54,7 +54,7 @@ typedef struct GlyphCacheBLF {
unsigned int ntex;
/* and the last texture, aka. the current texture. */
- int cur_tex;
+ unsigned int cur_tex;
/* like bftgl, we draw every glyph in a big texture, so this is the
* current position inside the texture.
@@ -235,4 +235,6 @@ typedef struct DirBLF {
char *path;
} DirBLF;
+#define BLF_CURTEX_UNSET ((unsigned int)-1)
+
#endif /* __BLF_INTERNAL_TYPES_H__ */