Cleanup: avoid redundant float/int conversions in BLF

Internally many offsets for BLF were integers but exposed as floats,
since these are used in pixel-space, many callers were converging them
back to integers. Simplify logic by using ints.
This commit is contained in:
Campbell Barton 2022-04-13 12:45:41 +10:00
parent ae43872ad5
commit 21ae323dbf
14 changed files with 138 additions and 136 deletions

View File

@ -109,7 +109,7 @@ typedef bool (*BLF_GlyphBoundsFn)(const char *str,
size_t str_step_ofs,
const struct rcti *glyph_step_bounds,
int glyph_advance_x,
const struct rctf *glyph_bounds,
const struct rcti *glyph_bounds,
const int glyph_bearing[2],
void *user_data);
@ -151,9 +151,9 @@ size_t BLF_width_to_rstrlen(
void BLF_boundbox_ex(int fontid,
const char *str,
size_t str_len,
struct rctf *box,
struct rcti *box,
struct ResultBLF *r_info) ATTR_NONNULL(2);
void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rctf *box) ATTR_NONNULL();
void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rcti *box) ATTR_NONNULL();
/**
* The next both function return the width and height
@ -173,9 +173,9 @@ float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_R
* Return dimensions of the font without any sample text.
*/
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
float BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
float BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
int BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT;
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT;
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
/**
* The following function return the width and height of the string, but
@ -195,7 +195,7 @@ float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT;
* have to be enable/disable using BLF_enable/disable.
*/
void BLF_rotation(int fontid, float angle);
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax);
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax);
void BLF_wordwrap(int fontid, int wrap_width);
#if BLF_BLUR_ENABLE

View File

@ -342,9 +342,9 @@ void BLF_position(int fontid, float x, float y, float z)
}
}
font->pos[0] = x;
font->pos[1] = y;
font->pos[2] = z;
font->pos[0] = round_fl_to_int(x);
font->pos[1] = round_fl_to_int(y);
font->pos[2] = round_fl_to_int(z);
}
}
@ -488,7 +488,7 @@ static void blf_draw_gl__start(FontBLF *font)
GPU_matrix_mul(font->m);
}
GPU_matrix_translate_3fv(font->pos);
GPU_matrix_translate_3f(font->pos[0], font->pos[1], font->pos[2]);
if (font->flags & BLF_ASPECT) {
GPU_matrix_scale_3fv(font->aspect);
@ -589,9 +589,10 @@ size_t BLF_width_to_strlen(
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
ret = blf_font_width_to_strlen(font, str, str_len, width / xa, r_width);
int width_result;
ret = blf_font_width_to_strlen(font, str, str_len, width / xa, &width_result);
if (r_width) {
*r_width *= xa;
*r_width = (float)width_result * xa;
}
return ret;
}
@ -610,9 +611,10 @@ size_t BLF_width_to_rstrlen(
if (font) {
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
size_t ret;
ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, r_width);
int width_result;
ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, &width_result);
if (r_width) {
*r_width *= xa;
*r_width = (float)width_result * xa;
}
return ret;
}
@ -624,7 +626,7 @@ size_t BLF_width_to_rstrlen(
}
void BLF_boundbox_ex(
int fontid, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
int fontid, const char *str, const size_t str_len, rcti *r_box, struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
@ -640,7 +642,7 @@ void BLF_boundbox_ex(
}
}
void BLF_boundbox(int fontid, const char *str, const size_t str_len, rctf *r_box)
void BLF_boundbox(int fontid, const char *str, const size_t str_len, rcti *r_box)
{
BLF_boundbox_ex(fontid, str, str_len, r_box, NULL);
}
@ -716,7 +718,7 @@ int BLF_height_max(int fontid)
return 0;
}
float BLF_width_max(int fontid)
int BLF_width_max(int fontid)
{
FontBLF *font = blf_get(fontid);
@ -724,10 +726,10 @@ float BLF_width_max(int fontid)
return blf_font_width_max(font);
}
return 0.0f;
return 0;
}
float BLF_descender(int fontid)
int BLF_descender(int fontid)
{
FontBLF *font = blf_get(fontid);
@ -735,10 +737,10 @@ float BLF_descender(int fontid)
return blf_font_descender(font);
}
return 0.0f;
return 0;
}
float BLF_ascender(int fontid)
int BLF_ascender(int fontid)
{
FontBLF *font = blf_get(fontid);
@ -758,7 +760,7 @@ void BLF_rotation(int fontid, float angle)
}
}
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
{
FontBLF *font = blf_get(fontid);
@ -889,7 +891,7 @@ void BLF_state_print(int fontid)
printf(" name: '%s'\n", font->name);
printf(" size: %f\n", font->size);
printf(" dpi: %u\n", font->dpi);
printf(" pos: %.6f %.6f %.6f\n", UNPACK3(font->pos));
printf(" pos: %d %d %d\n", UNPACK3(font->pos));
printf(" aspect: (%d) %.6f %.6f %.6f\n",
(font->flags & BLF_ROTATION) != 0,
UNPACK3(font->aspect));

View File

@ -138,12 +138,12 @@ void blf_batch_draw_begin(FontBLF *font)
if (simple_shader) {
/* Offset is applied to each glyph. */
g_batch.ofs[0] = floorf(font->pos[0]);
g_batch.ofs[1] = floorf(font->pos[1]);
g_batch.ofs[0] = font->pos[0];
g_batch.ofs[1] = font->pos[1];
}
else {
/* Offset is baked in modelview mat. */
zero_v2(g_batch.ofs);
zero_v2_int(g_batch.ofs);
}
if (g_batch.active) {
@ -425,8 +425,8 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
ft_pix pen_y)
{
GlyphBLF *g, *g_prev = NULL;
ft_pix pen_x = ft_pix_from_float(font->pos[0]);
ft_pix pen_y_basis = ft_pix_from_float(font->pos[1]) + pen_y;
ft_pix pen_x = ft_pix_from_int(font->pos[0]);
ft_pix pen_y_basis = ft_pix_from_int(font->pos[1]) + pen_y;
size_t i = 0;
/* buffer specific vars */
@ -586,7 +586,7 @@ static bool blf_font_width_to_strlen_glyph_process(
}
size_t blf_font_width_to_strlen(
FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
{
GlyphBLF *g, *g_prev;
ft_pix pen_x;
@ -606,7 +606,7 @@ size_t blf_font_width_to_strlen(
}
if (r_width) {
*r_width = (float)ft_pix_to_int(width_new);
*r_width = ft_pix_to_int(width_new);
}
blf_glyph_cache_release(font);
@ -614,7 +614,7 @@ size_t blf_font_width_to_strlen(
}
size_t blf_font_width_to_rstrlen(
FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
FontBLF *font, const char *str, const size_t str_len, int width, int *r_width)
{
GlyphBLF *g, *g_prev;
ft_pix pen_x, width_new;
@ -622,7 +622,6 @@ size_t blf_font_width_to_rstrlen(
const char *s, *s_prev;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
const int width_i = (int)width;
i = BLI_strnlen(str, str_len);
s = BLI_str_find_prev_char_utf8(&str[i], str);
@ -643,13 +642,13 @@ size_t blf_font_width_to_rstrlen(
BLI_assert(i_tmp == i);
}
if (blf_font_width_to_strlen_glyph_process(font, g_prev, g, &pen_x, width_i)) {
if (blf_font_width_to_strlen_glyph_process(font, g_prev, g, &pen_x, width)) {
break;
}
}
if (r_width) {
*r_width = (float)ft_pix_to_int(width_new);
*r_width = ft_pix_to_int(width_new);
}
blf_glyph_cache_release(font);
@ -666,7 +665,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
const size_t str_len,
rctf *box,
rcti *box,
struct ResultBLF *r_info,
ft_pix pen_y)
{
@ -718,10 +717,10 @@ static void blf_font_boundbox_ex(FontBLF *font,
box_ymax = 0;
}
box->xmin = (float)ft_pix_to_int_floor(box_xmin);
box->xmax = (float)ft_pix_to_int_ceil(box_xmax);
box->ymin = (float)ft_pix_to_int_floor(box_ymin);
box->ymax = (float)ft_pix_to_int_ceil(box_ymax);
box->xmin = ft_pix_to_int_floor(box_xmin);
box->xmax = ft_pix_to_int_ceil(box_xmax);
box->ymin = ft_pix_to_int_floor(box_ymin);
box->ymax = ft_pix_to_int_ceil(box_ymax);
if (r_info) {
r_info->lines = 1;
@ -729,7 +728,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
}
}
void blf_font_boundbox(
FontBLF *font, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
FontBLF *font, const char *str, const size_t str_len, rcti *r_box, struct ResultBLF *r_info)
{
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
blf_font_boundbox_ex(font, gc, str, str_len, r_box, r_info, 0);
@ -744,7 +743,7 @@ void blf_font_width_and_height(FontBLF *font,
struct ResultBLF *r_info)
{
float xa, ya;
rctf box;
rcti box;
if (font->flags & BLF_ASPECT) {
xa = font->aspect[0];
@ -761,8 +760,8 @@ void blf_font_width_and_height(FontBLF *font,
else {
blf_font_boundbox(font, str, str_len, &box, r_info);
}
*r_width = (BLI_rctf_size_x(&box) * xa);
*r_height = (BLI_rctf_size_y(&box) * ya);
*r_width = ((float)BLI_rcti_size_x(&box) * xa);
*r_height = ((float)BLI_rcti_size_y(&box) * ya);
}
float blf_font_width(FontBLF *font,
@ -771,7 +770,7 @@ float blf_font_width(FontBLF *font,
struct ResultBLF *r_info)
{
float xa;
rctf box;
rcti box;
if (font->flags & BLF_ASPECT) {
xa = font->aspect[0];
@ -786,7 +785,7 @@ float blf_font_width(FontBLF *font,
else {
blf_font_boundbox(font, str, str_len, &box, r_info);
}
return BLI_rctf_size_x(&box) * xa;
return (float)BLI_rcti_size_x(&box) * xa;
}
float blf_font_height(FontBLF *font,
@ -795,7 +794,7 @@ float blf_font_height(FontBLF *font,
struct ResultBLF *r_info)
{
float ya;
rctf box;
rcti box;
if (font->flags & BLF_ASPECT) {
ya = font->aspect[1];
@ -810,7 +809,7 @@ float blf_font_height(FontBLF *font,
else {
blf_font_boundbox(font, str, str_len, &box, r_info);
}
return BLI_rctf_size_y(&box) * ya;
return (float)BLI_rcti_size_y(&box) * ya;
}
float blf_font_fixed_width(FontBLF *font)
@ -858,11 +857,11 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
pen_x = pen_x_next;
rctf box_px;
box_px.xmin = (float)ft_pix_to_int_floor(g->box_xmin);
box_px.xmax = (float)ft_pix_to_int_ceil(g->box_xmax);
box_px.ymin = (float)ft_pix_to_int_floor(g->box_ymin);
box_px.ymax = (float)ft_pix_to_int_ceil(g->box_ymax);
rcti box_px;
box_px.xmin = ft_pix_to_int_floor(g->box_xmin);
box_px.xmax = ft_pix_to_int_ceil(g->box_xmax);
box_px.ymin = ft_pix_to_int_floor(g->box_ymin);
box_px.ymax = ft_pix_to_int_ceil(g->box_ymax);
if (user_fn(str, i_curr, &gbox_px, advance_x_px, &box_px, g->pos, user_data) == false) {
break;
@ -1026,19 +1025,19 @@ static void blf_font_boundbox_wrap_cb(FontBLF *font,
ft_pix pen_y,
void *userdata)
{
rctf *box = userdata;
rctf box_single;
rcti *box = userdata;
rcti box_single;
blf_font_boundbox_ex(font, gc, str, str_len, &box_single, NULL, pen_y);
BLI_rctf_union(box, &box_single);
BLI_rcti_union(box, &box_single);
}
void blf_font_boundbox__wrap(
FontBLF *font, const char *str, const size_t str_len, rctf *box, struct ResultBLF *r_info)
FontBLF *font, const char *str, const size_t str_len, rcti *box, struct ResultBLF *r_info)
{
box->xmin = 32000.0f;
box->xmax = -32000.0f;
box->ymin = 32000.0f;
box->ymax = -32000.0f;
box->xmin = 32000;
box->xmax = -32000;
box->ymin = 32000;
box->ymax = -32000;
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_boundbox_wrap_cb, box);
}
@ -1141,14 +1140,14 @@ int blf_font_width_max(FontBLF *font)
return ft_pix_to_int(blf_font_width_max_ft_pix(font));
}
float blf_font_descender(FontBLF *font)
int blf_font_descender(FontBLF *font)
{
return ((float)font->face->size->metrics.descender) / 64.0f;
return ft_pix_to_int((ft_pix)font->face->size->metrics.descender);
}
float blf_font_ascender(FontBLF *font)
int blf_font_ascender(FontBLF *font)
{
return ((float)font->face->size->metrics.ascender) / 64.0f;
return ft_pix_to_int((ft_pix)font->face->size->metrics.ascender);
}
char *blf_display_name(FontBLF *font)
@ -1197,8 +1196,8 @@ static void blf_font_fill(FontBLF *font)
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->pos[0] = 0;
font->pos[1] = 0;
font->angle = 0.0f;
for (int i = 0; i < 16; i++) {

View File

@ -491,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((float)ft_pix_to_int(g->advance_x), (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);
}
/** \} */
@ -524,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;
@ -550,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 */
@ -566,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 */
@ -579,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, int x, int 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;
@ -618,11 +619,11 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int x, int y)
}
if (font->flags & BLF_CLIPPING) {
rctf rect_test;
blf_glyph_calc_rect_test(&rect_test, g, (float)x, (float)y);
BLI_rctf_translate(&rect_test, font->pos[0], font->pos[1]);
rcti rect_test;
blf_glyph_calc_rect_test(&rect_test, g, x, y);
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;
}
}
@ -633,8 +634,8 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int x, int y)
}
if (font->flags & BLF_SHADOW) {
rctf rect_ofs;
blf_glyph_calc_rect_shadow(&rect_ofs, g, (float)x, (float)y, font);
rcti rect_ofs;
blf_glyph_calc_rect_shadow(&rect_ofs, g, x, y, font);
if (font->shadow == 0) {
blf_texture_draw(font->shadow_color,
@ -665,8 +666,8 @@ void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int x, int y)
}
}
rctf rect;
blf_glyph_calc_rect(&rect, g, (float)x, (float)y);
rcti rect;
blf_glyph_calc_rect(&rect, g, x, y);
#if BLF_BLUR_ENABLE
switch (font->blur) {

View File

@ -67,18 +67,18 @@ void blf_font_draw_buffer__wrap(struct FontBLF *font,
size_t str_len,
struct ResultBLF *r_info);
size_t blf_font_width_to_strlen(
struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
struct FontBLF *font, const char *str, size_t str_len, int width, int *r_width);
size_t blf_font_width_to_rstrlen(
struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
struct FontBLF *font, const char *str, size_t str_len, int width, int *r_width);
void blf_font_boundbox(struct FontBLF *font,
const char *str,
size_t str_len,
struct rctf *r_box,
struct rcti *r_box,
struct ResultBLF *r_info);
void blf_font_boundbox__wrap(struct FontBLF *font,
const char *str,
size_t str_len,
struct rctf *r_box,
struct rcti *r_box,
struct ResultBLF *r_info);
void blf_font_width_and_height(struct FontBLF *font,
const char *str,
@ -97,8 +97,8 @@ float blf_font_height(struct FontBLF *font,
float blf_font_fixed_width(struct FontBLF *font);
int blf_font_height_max(struct FontBLF *font);
int blf_font_width_max(struct FontBLF *font);
float blf_font_descender(struct FontBLF *font);
float blf_font_ascender(struct FontBLF *font);
int blf_font_descender(struct FontBLF *font);
int blf_font_ascender(struct FontBLF *font);
char *blf_display_name(struct FontBLF *font);
@ -109,7 +109,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
size_t str_step_ofs,
const struct rcti *glyph_step_bounds,
int glyph_advance_x,
const struct rctf *glyph_bounds,
const struct rcti *glyph_bounds,
const int glyph_bearing[2],
void *user_data),
void *user_data,

View File

@ -101,7 +101,7 @@ typedef struct BatchBLF {
struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step;
unsigned int pos_loc, col_loc, offset_loc, glyph_size_loc;
unsigned int glyph_len;
float ofs[2]; /* copy of font->pos */
int ofs[2]; /* copy of font->pos */
float mat[4][4]; /* previous call modelmatrix. */
bool enabled, active, simple_shader;
struct GlyphCacheBLF *glyph_cache;
@ -231,7 +231,7 @@ typedef struct FontBLF {
float aspect[3];
/* initial position for draw the text. */
float pos[3];
int pos[3];
/* angle in radians. */
float angle;
@ -260,7 +260,7 @@ typedef struct FontBLF {
float m[16];
/* clipping rectangle. */
rctf clip_rec;
rcti clip_rec;
/* the width to wrap the text, see BLF_WORD_WRAP */
int wrap_width;

View File

@ -64,7 +64,7 @@ void BLF_thumb_preview(const char *filepath,
/* Always create the image with a white font,
* the caller can theme how it likes */
memcpy(font->buf_info.col_init, font_color, sizeof(font->buf_info.col_init));
font->pos[1] = (float)h;
font->pos[1] = h;
font_size_curr = font_size;
@ -84,7 +84,7 @@ void BLF_thumb_preview(const char *filepath,
font_size_curr -= (font_size_curr / font_shrink);
font_shrink += 1;
font->pos[1] -= blf_font_ascender(font) * 1.1f;
font->pos[1] -= (int)((float)blf_font_ascender(font) * 1.1f);
/* We fallback to default english strings in case not enough chars are available in current
* font for given translated string (useful in non-latin i18n context, like Chinese,

View File

@ -1806,9 +1806,9 @@ void BKE_image_stamp_buf(Scene *scene,
int channels)
{
struct StampData stamp_data;
float w, h, pad;
int w, h, pad;
int x, y, y_ofs;
float h_fixed;
int h_fixed;
const int mono = blf_mono_font_render; /* XXX */
struct ColorManagedDisplay *display;
const char *display_device;
@ -1816,20 +1816,20 @@ void BKE_image_stamp_buf(Scene *scene,
/* vars for calculating wordwrap */
struct {
struct ResultBLF info;
rctf rect;
rcti rect;
} wrap;
/* this could be an argument if we want to operate on non linear float imbuf's
* for now though this is only used for renders which use scene settings */
#define TEXT_SIZE_CHECK(str, w, h) \
((str[0]) && ((void)(h = h_fixed), (w = BLF_width(mono, str, sizeof(str)))))
((str[0]) && ((void)(h = h_fixed), (w = (int)BLF_width(mono, str, sizeof(str)))))
/* must enable BLF_WORD_WRAP before using */
#define TEXT_SIZE_CHECK_WORD_WRAP(str, w, h) \
((str[0]) && (BLF_boundbox_ex(mono, str, sizeof(str), &wrap.rect, &wrap.info), \
(void)(h = h_fixed * wrap.info.lines), \
(w = BLI_rctf_size_x(&wrap.rect))))
(w = BLI_rcti_size_x(&wrap.rect))))
#define BUFF_MARGIN_X 2
#define BUFF_MARGIN_Y 1

View File

@ -3018,12 +3018,12 @@ static bool ui_textedit_set_cursor_pos_foreach_glyph(const char *UNUSED(str),
const size_t str_step_ofs,
const rcti *glyph_step_bounds,
const int UNUSED(glyph_advance_x),
const rctf *glyph_bounds,
const rcti *glyph_bounds,
const int UNUSED(glyph_bearing[2]),
void *user_data)
{
int *cursor_data = user_data;
const float center = glyph_step_bounds->xmin + (BLI_rctf_size_x(glyph_bounds) / 2.0f);
const int center = glyph_step_bounds->xmin + (BLI_rcti_size_x(glyph_bounds) / 2.0f);
if (cursor_data[0] < center) {
cursor_data[1] = str_step_ofs;
return false;

View File

@ -161,7 +161,7 @@ void UI_fontstyle_draw_ex(const uiFontStyle *fs,
}
else {
/* Draw from bound-box center. */
const float height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
const int height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id);
yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
}
@ -279,9 +279,9 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs,
UI_fontstyle_set(fs);
{
const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
const float height = BLF_height_max(fs->uifont_id);
const float decent = BLF_descender(fs->uifont_id);
const int width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
const int height = BLF_height_max(fs->uifont_id);
const int decent = BLF_descender(fs->uifont_id);
const float margin = height / 4.0f;
rctf rect;

View File

@ -1859,15 +1859,15 @@ static bool widget_draw_text_underline_calc_position(const char *UNUSED(str),
const size_t str_step_ofs,
const rcti *glyph_step_bounds,
const int UNUSED(glyph_advance_x),
const rctf *glyph_bounds,
const rcti *glyph_bounds,
const int UNUSED(glyph_bearing[2]),
void *user_data)
{
struct UnderlineData *ul_data = user_data;
if (ul_data->str_offset == str_step_ofs) {
/* Full width of this glyph including both bearings. */
const float width = glyph_bounds->xmin + BLI_rctf_size_x(glyph_bounds) + glyph_bounds->xmin;
ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) * 0.5f);
const int width = glyph_bounds->xmin + BLI_rcti_size_x(glyph_bounds) + glyph_bounds->xmin;
ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) / 2);
/* One line-width below the lower glyph bounds. */
ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize;
/* Early exit. */

View File

@ -248,7 +248,7 @@ static void file_draw_string_multiline(int sx,
int font_id = style->widgetlabel.uifont_id;
int len = strlen(string);
rctf textbox;
rcti textbox;
BLF_wordwrap(font_id, wrap_width);
BLF_enable(font_id, BLF_WORD_WRAP);
BLF_boundbox(font_id, string, len, &textbox);
@ -260,7 +260,7 @@ static void file_draw_string_multiline(int sx,
rect.xmax = sx + wrap_width;
/* Need to increase the clipping rect by one more line, since the #UI_fontstyle_draw_ex() will
* actually start drawing at (ymax - line-height). */
rect.ymin = sy - round_fl_to_int(BLI_rctf_size_y(&textbox)) - line_height;
rect.ymin = sy - BLI_rcti_size_y(&textbox) - line_height;
rect.ymax = sy;
struct ResultBLF result;

View File

@ -711,7 +711,7 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
if (i == 4) {
struct {
struct ResultBLF info;
rctf rect;
rcti rect;
} wrap;
BLF_enable(fontid, BLF_WORD_WRAP);

View File

@ -3381,7 +3381,7 @@ static ImBuf *do_text_effect(const SeqRenderData *context,
/* vars for calculating wordwrap and optional box */
struct {
struct ResultBLF info;
rctf rect;
rcti rect;
} wrap;
BLF_boundbox_ex(font, data->text, sizeof(data->text), &wrap.rect, &wrap.info);
@ -3391,10 +3391,10 @@ static ImBuf *do_text_effect(const SeqRenderData *context,
}
else {
if (data->align == SEQ_TEXT_ALIGN_X_RIGHT) {
x -= BLI_rctf_size_x(&wrap.rect);
x -= BLI_rcti_size_x(&wrap.rect);
}
else if (data->align == SEQ_TEXT_ALIGN_X_CENTER) {
x -= BLI_rctf_size_x(&wrap.rect) / 2;
x -= BLI_rcti_size_x(&wrap.rect) / 2;
}
if (data->align_y == SEQ_TEXT_ALIGN_Y_TOP) {