diff --git a/source/blender/editors/interface/regions/interface_region_tooltip.cc b/source/blender/editors/interface/regions/interface_region_tooltip.cc index bbdf5ad5982..abc2914daea 100644 --- a/source/blender/editors/interface/regions/interface_region_tooltip.cc +++ b/source/blender/editors/interface/regions/interface_region_tooltip.cc @@ -1897,7 +1897,7 @@ static void ui_tooltip_from_vfont(const VFont &font, uiTooltipData &data) float color[4]; const uiWidgetColors *theme = ui_tooltip_get_theme(); rgba_uchar_to_float(color, theme->text); - ImBuf *ibuf = IMB_font_preview(filepath_abs, 200 * UI_SCALE_FAC, color); + ImBuf *ibuf = IMB_font_preview(filepath_abs, 256 * UI_SCALE_FAC, color, "ABCDabefg&0123"); if (ibuf) { uiTooltipImage image_data; image_data.width = ibuf->x; diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index d52cf7f6ffb..42532d1172b 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -279,6 +279,16 @@ static void file_draw_tooltip_custom_func(bContext & /*C*/, } } } + else if (file->typeflag & FILE_TYPE_FTFONT) { + float color[4]; + bTheme *btheme = UI_GetTheme(); + rgba_uchar_to_float(color, btheme->tui.wcol_tooltip.text); + thumb = IMB_font_preview(full_path, + 512 * UI_SCALE_FAC, + color, + TIP_("The five boxing wizards jump quickly! 0123456789")); + free_imbuf = true; + } char date_str[FILELIST_DIRENTRY_DATE_LEN], time_str[FILELIST_DIRENTRY_TIME_LEN]; bool is_today, is_yesterday; @@ -321,7 +331,20 @@ static void file_draw_tooltip_custom_func(bContext & /*C*/, } } - if (thumb && params->display != FILE_IMGDISPLAY) { + if (thumb && file->typeflag & FILE_TYPE_FTFONT) { + const float scale = (512.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y)); + uiTooltipImage image_data; + image_data.ibuf = thumb; + image_data.width = short(float(thumb->x) * scale); + image_data.height = short(float(thumb->y) * scale); + image_data.background = uiTooltipImageBackground::None; + image_data.premultiplied = false; + image_data.text_color = true; + image_data.border = false; + UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); + UI_tooltip_image_field_add(tip, image_data); + } + else if (thumb && params->display != FILE_IMGDISPLAY) { UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL); diff --git a/source/blender/imbuf/IMB_thumbs.hh b/source/blender/imbuf/IMB_thumbs.hh index 3962b564035..a43ee11a19f 100644 --- a/source/blender/imbuf/IMB_thumbs.hh +++ b/source/blender/imbuf/IMB_thumbs.hh @@ -93,7 +93,10 @@ ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const ImBuf *IMB_thumb_load_font(const char *filepath, unsigned int x, unsigned int y); bool IMB_thumb_load_font_get_hash(char *r_hash); -ImBuf *IMB_font_preview(const char *filepath, unsigned int width, const float color[4]); +ImBuf *IMB_font_preview(const char *filepath, + unsigned int width, + const float color[4], + const char *sample_text = nullptr); /* Threading */ diff --git a/source/blender/imbuf/intern/thumbs_font.cc b/source/blender/imbuf/intern/thumbs_font.cc index 016af84c9b7..85d5579155e 100644 --- a/source/blender/imbuf/intern/thumbs_font.cc +++ b/source/blender/imbuf/intern/thumbs_font.cc @@ -45,27 +45,30 @@ bool IMB_thumb_load_font_get_hash(char *r_hash) return true; } -ImBuf *IMB_font_preview(const char *filepath, uint width, const float color[4]) +ImBuf *IMB_font_preview(const char *filepath, + uint width, + const float color[4], + const char *sample_text) { int font_id = (filepath[0] != '<') ? BLF_load(filepath) : 0; if (font_id == -1) { return nullptr; } - const char sample[] = "ABCDEFGH\nabcdefg123"; + const char default_sample[] = "ABCDabefg&0123"; + const char *sample = sample_text ? sample_text : default_sample; BLF_buffer_col(font_id, color); BLF_size(font_id, 50.0f); - BLF_enable(font_id, BLF_WORD_WRAP); float name_w; float name_h; - BLF_width_and_height(font_id, sample, sizeof(sample), &name_w, &name_h); - float scale = float(width) / name_w; + BLF_width_and_height(font_id, sample, strlen(sample), &name_w, &name_h); + const float scale = float(width) / name_w * 0.98f; BLF_size(font_id, scale * 50.0f); name_w *= scale; name_h *= scale; - int height = int(name_h * 1.3f); + const int height = int(name_h * 1.8f); ImBuf *ibuf = IMB_allocImBuf(width, height, 32, IB_byte_data); /* fill with white and zero alpha */ const float col[4] = {1.0f, 1.0f, 1.0f, 0.0f}; @@ -73,7 +76,7 @@ ImBuf *IMB_font_preview(const char *filepath, uint width, const float color[4]) BLF_buffer(font_id, ibuf->float_buffer.data, ibuf->byte_buffer.data, width, height, nullptr); - BLF_position(font_id, 0.0f, name_h * 0.8f, 0.0f); + BLF_position(font_id, 0.0f, height * 0.3f, 0.0f); BLF_draw_buffer(font_id, sample, 1024); BLF_buffer(font_id, nullptr, nullptr, 0, 0, nullptr);