Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenfont/intern/blf_font.c
| Show First 20 Lines • Show All 914 Lines • ▼ Show 20 Lines | static void blf_font_wrap_apply(FontBLF *font, | ||||
| void *userdata) | void *userdata) | ||||
| { | { | ||||
| GlyphBLF *g, *g_prev = NULL; | GlyphBLF *g, *g_prev = NULL; | ||||
| ft_pix pen_x = 0; | ft_pix pen_x = 0; | ||||
| ft_pix pen_y = 0; | ft_pix pen_y = 0; | ||||
| size_t i = 0; | size_t i = 0; | ||||
| int lines = 0; | int lines = 0; | ||||
| ft_pix pen_x_next = 0; | ft_pix pen_x_next = 0; | ||||
campbellbarton: Worth noting why floor is needed in this case (with a reference to T97310). | |||||
| /* Space between lines needs to be aligned to the pixel grid (T97310). */ | |||||
| ft_pix line_height = FT_PIX_FLOOR(blf_font_height_max_ft_pix(font)); | |||||
| GlyphCacheBLF *gc = blf_glyph_cache_acquire(font); | GlyphCacheBLF *gc = blf_glyph_cache_acquire(font); | ||||
| struct WordWrapVars { | struct WordWrapVars { | ||||
| ft_pix wrap_width; | ft_pix wrap_width; | ||||
| size_t start, last[2]; | size_t start, last[2]; | ||||
| } wrap = {font->wrap_width != -1 ? ft_pix_from_int(font->wrap_width) : INT_MAX, 0, {0, 0}}; | } wrap = {font->wrap_width != -1 ? ft_pix_from_int(font->wrap_width) : INT_MAX, 0, {0, 0}}; | ||||
| // printf("%s wrapping (%d, %d) `%s`:\n", __func__, str_len, strlen(str), str); | // printf("%s wrapping (%d, %d) `%s`:\n", __func__, str_len, strlen(str), str); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | while ((i < str_len) && str[i]) { | ||||
| if (UNLIKELY(do_draw)) { | if (UNLIKELY(do_draw)) { | ||||
| // printf("(%03d..%03d) `%.*s`\n", | // printf("(%03d..%03d) `%.*s`\n", | ||||
| // wrap.start, wrap.last[0], (wrap.last[0] - wrap.start) - 1, &str[wrap.start]); | // wrap.start, wrap.last[0], (wrap.last[0] - wrap.start) - 1, &str[wrap.start]); | ||||
| callback(font, gc, &str[wrap.start], (wrap.last[0] - wrap.start) - 1, pen_y, userdata); | callback(font, gc, &str[wrap.start], (wrap.last[0] - wrap.start) - 1, pen_y, userdata); | ||||
| wrap.start = wrap.last[0]; | wrap.start = wrap.last[0]; | ||||
| i = wrap.last[1]; | i = wrap.last[1]; | ||||
| pen_x = 0; | pen_x = 0; | ||||
| pen_y -= blf_font_height_max_ft_pix(font); | pen_y -= line_height; | ||||
| g_prev = NULL; | g_prev = NULL; | ||||
| lines += 1; | lines += 1; | ||||
| continue; | continue; | ||||
| } | } | ||||
| pen_x = pen_x_next; | pen_x = pen_x_next; | ||||
| g_prev = g; | g_prev = g; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 393 Lines • Show Last 20 Lines | |||||
Worth noting why floor is needed in this case (with a reference to T97310).