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.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 28531c5afc1..2694b179a11 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -183,8 +183,7 @@ static GlyphBLF *blf_glyph_cache_add_glyph(
GlyphBLF *g = (GlyphBLF *)MEM_callocN(sizeof(GlyphBLF), "blf_glyph_get");
g->c = charcode;
g->idx = glyph_index;
- g->advance = ((float)glyph->advance.x) / 64.0f;
- g->advance_i = (int)g->advance;
+ g->advance_x = (ft_pix)glyph->advance.x;
g->pos[0] = glyph->bitmap_left;
g->pos[1] = glyph->bitmap_top;
g->dims[0] = (int)glyph->bitmap.width;
@@ -193,10 +192,14 @@ static GlyphBLF *blf_glyph_cache_add_glyph(
FT_BBox bbox;
FT_Outline_Get_CBox(&(glyph->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 = (ft_pix)bbox.xMin;
+ g->box_xmax = (ft_pix)bbox.xMax;
+ g->box_ymin = (ft_pix)bbox.yMin;
+ g->box_ymax = (ft_pix)bbox.yMax;
+
+ /* Used to improve advance when hinting is enabled. */
+ g->lsb_delta = (ft_pix)glyph->lsb_delta;
+ g->rsb_delta = (ft_pix)glyph->rsb_delta;
const int buffer_size = (int)(glyph->bitmap.width * glyph->bitmap.rows);
if (buffer_size != 0) {
@@ -488,28 +491,29 @@ void blf_glyph_free(GlyphBLF *g)
/** \name Glyph Bounds Calculation
* \{ */
-static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
+static void blf_glyph_calc_rect(rcti *rect, GlyphBLF *g, const int x, const int y)
{
- 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];
+ rect->xmin = x + g->pos[0];
+ rect->xmax = rect->xmin + g->dims[0];
+ rect->ymin = y + g->pos[1];
+ rect->ymax = rect->ymin - g->dims[1];
}
-static void blf_glyph_calc_rect_test(rctf *rect, GlyphBLF *g, float x, float y)
+static void blf_glyph_calc_rect_test(rcti *rect, GlyphBLF *g, const int x, const int y)
{
/* Intentionally check with `g->advance`, because this is the
* 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->dims[0]);
- rect->ymin = floorf(y);
- rect->ymax = rect->ymin - (float)g->dims[1];
+ rect->xmin = x;
+ rect->xmax = rect->xmin + MIN2(ft_pix_to_int(g->advance_x), g->dims[0]);
+ rect->ymin = y;
+ rect->ymax = rect->ymin - g->dims[1];
}
-static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y, FontBLF *font)
+static void blf_glyph_calc_rect_shadow(
+ rcti *rect, GlyphBLF *g, const int x, const int y, FontBLF *font)
{
- blf_glyph_calc_rect(rect, g, x + (float)font->shadow_x, y + (float)font->shadow_y);
+ blf_glyph_calc_rect(rect, g, x + font->shadow_x, y + font->shadow_y);
}
/** \} */
@@ -521,18 +525,18 @@ static void blf_glyph_calc_rect_shadow(rctf *rect, GlyphBLF *g, float x, float y
static void blf_texture_draw(const unsigned char color[4],
const int glyph_size[2],
const int offset,
- float x1,
- float y1,
- float x2,
- float y2)
+ const int x1,
+ const int y1,
+ const int x2,
+ const int y2)
{
/* Only one vertex per glyph, geometry shader expand it into a quad. */
/* TODO: Get rid of Geom Shader because it's not optimal AT ALL for the GPU. */
copy_v4_fl4(GPU_vertbuf_raw_step(&g_batch.pos_step),
- x1 + g_batch.ofs[0],
- y1 + g_batch.ofs[1],
- x2 + g_batch.ofs[0],
- y2 + g_batch.ofs[1]);
+ (float)(x1 + g_batch.ofs[0]),
+ (float)(y1 + g_batch.ofs[1]),
+ (float)(x2 + g_batch.ofs[0]),
+ (float)(y2 + g_batch.ofs[1]));
copy_v4_v4_uchar(GPU_vertbuf_raw_step(&g_batch.col_step), color);
copy_v2_v2_int(GPU_vertbuf_raw_step(&g_batch.glyph_size_step), glyph_size);
*((int *)GPU_vertbuf_raw_step(&g_batch.offset_step)) = offset;
@@ -547,10 +551,10 @@ static void blf_texture_draw(const unsigned char color[4],
static void blf_texture5_draw(const unsigned char color_in[4],
const int glyph_size[2],
const int offset,
- float x1,
- float y1,
- float x2,
- float y2)
+ const int x1,
+ const int y1,
+ const int x2,
+ const int y2)
{
int glyph_size_flag[2];
/* flag the x and y component signs for 5x5 blurring */
@@ -563,10 +567,10 @@ static void blf_texture5_draw(const unsigned char color_in[4],
static void blf_texture3_draw(const unsigned char color_in[4],
const int glyph_size[2],
const int offset,
- float x1,
- float y1,
- float x2,
- float y2)
+ const int x1,
+ const int y1,
+ const int x2,
+ const int y2)
{
int glyph_size_flag[2];
/* flag the x component sign for 3x3 blurring */
@@ -576,7 +580,7 @@ static void blf_texture3_draw(const unsigned char color_in[4],
blf_texture_draw(color_in, glyph_size_flag, offset, x1, y1, x2, y2);
}
-void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, float y)
+void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, const int y)
{
if ((!g->dims[0]) || (!g->dims[1])) {
return;
@@ -615,11 +619,11 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, floa
}
if (font->flags & BLF_CLIPPING) {
- rctf rect_test;
+ rcti rect_test;
blf_glyph_calc_rect_test(&rect_test, g, x, y);
- BLI_rctf_translate(&rect_test, font->pos[0], font->pos[1]);
+ BLI_rcti_translate(&rect_test, font->pos[0], font->pos[1]);
- if (!BLI_rctf_inside_rctf(&font->clip_rec, &rect_test)) {
+ if (!BLI_rcti_inside_rcti(&font->clip_rec, &rect_test)) {
return;
}
}
@@ -630,7 +634,7 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, floa
}
if (font->flags & BLF_SHADOW) {
- rctf rect_ofs;
+ rcti rect_ofs;
blf_glyph_calc_rect_shadow(&rect_ofs, g, x, y, font);
if (font->shadow == 0) {
@@ -662,7 +666,7 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, float x, floa
}
}
- rctf rect;
+ rcti rect;
blf_glyph_calc_rect(&rect, g, x, y);
#if BLF_BLUR_ENABLE