From 9eff8b7007f7604904d5ec87728002d5df3e4760 Mon Sep 17 00:00:00 2001 From: volzhs Date: Wed, 27 Nov 2019 03:35:44 +0900 Subject: Show thumbnail for DynamicFont resource --- editor/plugins/editor_preview_plugins.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'editor') diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 007ce58bd7..204562ac38 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -827,19 +827,23 @@ void EditorFontPreviewPlugin::_bind_methods() { bool EditorFontPreviewPlugin::handles(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "DynamicFontData"); + return ClassDB::is_parent_class(p_type, "DynamicFontData") || ClassDB::is_parent_class(p_type, "DynamicFont"); } Ref EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { - Ref SampledFont; - SampledFont.instance(); - SampledFont->set_font_path(p_path); - + RES res = ResourceLoader::load(p_path); Ref sampled_font; - sampled_font.instance(); + if (res->is_class("DynamicFont")) { + sampled_font = res->duplicate(); + if (sampled_font->get_outline_color() == Color(1, 1, 1, 1)) { + sampled_font->set_outline_color(Color(0, 0, 0, 1)); + } + } else if (res->is_class("DynamicFontData")) { + sampled_font.instance(); + sampled_font->set_font_data(res); + } sampled_font->set_size(50); - sampled_font->set_font_data(SampledFont); String sampled_text = "Abg"; Vector2 size = sampled_font->get_string_size(sampled_text); -- cgit v1.2.3