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:
Diffstat (limited to 'source/blender/blenfont/intern/blf_glyph.c')
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c78
1 files changed, 29 insertions, 49 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index a38cb323777..ce17069e53f 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -212,7 +212,7 @@ void blf_glyph_cache_free(GlyphCacheBLF *gc)
GlyphBLF *g;
unsigned int i;
- for (i = 0; i < 257; i++) {
+ for (i = 0; i < ARRAY_SIZE(gc->bucket); i++) {
while ((g = BLI_pophead(&gc->bucket[i]))) {
blf_glyph_free(g);
}
@@ -327,26 +327,27 @@ GlyphBLF *blf_glyph_add(FontBLF *font, GlyphCacheBLF *gc, unsigned int index, un
g->c = c;
g->idx = (FT_UInt)index;
bitmap = slot->bitmap;
- g->width = (int)bitmap.width;
- g->height = (int)bitmap.rows;
+ g->dims[0] = (int)bitmap.width;
+ g->dims[1] = (int)bitmap.rows;
- if (g->width && g->height) {
+ const int buffer_size = g->dims[0] * g->dims[1];
+
+ if (buffer_size != 0) {
if (font->flags & BLF_MONOCHROME) {
/* 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 (int i = 0; i < buffer_size; i++) {
bitmap.buffer[i] = bitmap.buffer[i] ? 255 : 0;
}
}
- g->bitmap = (unsigned char *)MEM_mallocN((size_t)g->width * (size_t)g->height, "glyph bitmap");
- memcpy((void *)g->bitmap, (void *)bitmap.buffer, (size_t)g->width * (size_t)g->height);
+ g->bitmap = MEM_mallocN((size_t)buffer_size, "glyph bitmap");
+ memcpy(g->bitmap, bitmap.buffer, (size_t)buffer_size);
}
g->advance = ((float)slot->advance.x) / 64.0f;
g->advance_i = (int)g->advance;
- g->pos_x = (float)slot->bitmap_left;
- g->pos_y = (float)slot->bitmap_top;
+ g->pos[0] = slot->bitmap_left;
+ g->pos[1] = slot->bitmap_top;
g->pitch = slot->bitmap.pitch;
FT_Outline_Get_CBox(&(slot->outline), &bbox);
@@ -431,10 +432,10 @@ static void blf_texture3_draw(const unsigned char color_in[4],
static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
{
- rect->xmin = floorf(x + g->pos_x);
- rect->xmax = rect->xmin + (float)g->width;
- rect->ymin = floorf(y + g->pos_y);
- rect->ymax = rect->ymin - (float)g->height;
+ rect->xmin = floorf(x + (float)g->pos[0]);
+ rect->xmax = rect->xmin + (float)g->dims[0];
+ rect->ymin = floorf(y + (float)g->pos[1]);
+ rect->ymax = rect->ymin - (float)g->dims[1];
}
static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
@@ -443,9 +444,9 @@ static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
* width used by BLF_width. This allows that the text slightly
* overlaps the clipping border to achieve better alignment. */
rect->xmin = floorf(x);
- rect->xmax = rect->xmin + MIN2(g->advance, (float)g->width);
+ rect->xmax = rect->xmin + MIN2(g->advance, (float)g->dims[0]);
rect->ymin = floorf(y);
- rect->ymax = rect->ymin - (float)g->height;
+ rect->ymax = rect->ymin - (float)g->dims[1];
}
static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y, FontBLF *font)
@@ -455,7 +456,7 @@ static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y
void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, float y)
{
- if ((!g->width) || (!g->height)) {
+ if ((!g->dims[0]) || (!g->dims[1])) {
return;
}
@@ -466,7 +467,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
g->offset = gc->bitmap_len;
- int buff_size = g->width * g->height;
+ int buff_size = g->dims[0] * g->dims[1];
int bitmap_len = gc->bitmap_len + buff_size;
if (bitmap_len > gc->bitmap_len_alloc) {
@@ -514,7 +515,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
if (font->shadow == 0) {
blf_texture_draw(font->shadow_color,
- (int[2]){g->width, g->height},
+ g->dims,
g->offset,
rect_ofs.xmin,
rect_ofs.ymin,
@@ -523,7 +524,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
}
else if (font->shadow <= 4) {
blf_texture3_draw(font->shadow_color,
- (int[2]){g->width, g->height},
+ g->dims,
g->offset,
rect_ofs.xmin,
rect_ofs.ymin,
@@ -532,7 +533,7 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
}
else {
blf_texture5_draw(font->shadow_color,
- (int[2]){g->width, g->height},
+ g->dims,
g->offset,
rect_ofs.xmin,
rect_ofs.ymin,
@@ -547,39 +548,18 @@ void blf_glyph_render(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, fl
#if BLF_BLUR_ENABLE
switch (font->blur) {
case 3:
- blf_texture3_draw(font->color,
- (int[2]){g->width, g->height},
- g->offset,
- rect.xmin,
- rect.ymin,
- rect.xmax,
- rect.ymax);
+ blf_texture3_draw(
+ font->color, g->dims, g->offset, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
case 5:
- blf_texture5_draw(font->color,
- (int[2]){g->width, g->height},
- g->offset,
- rect.xmin,
- rect.ymin,
- rect.xmax,
- rect.ymax);
+ blf_texture5_draw(
+ font->color, g->dims, g->offset, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
default:
- blf_texture_draw(font->color,
- (int[2]){g->width, g->height},
- g->offset,
- rect.xmin,
- rect.ymin,
- rect.xmax,
- rect.ymax);
+ blf_texture_draw(
+ font->color, g->dims, g->offset, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
#else
- blf_texture_draw(font->color,
- (int[2]){g->width, g->height},
- g->offset,
- rect.xmin,
- rect.ymin,
- rect.xmax,
- rect.ymax);
+ blf_texture_draw(font->color, g->dims, g->offset, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
#endif
}