Skip to content

Commit

Permalink
Remove custom font injection (#656)
Browse files Browse the repository at this point in the history
# Why
We load custom font from a file, and it generates the *.import files any
time new

# What
Fallback to the original editor provided fonts
  • Loading branch information
MikeSchulze authored Jan 30, 2025
1 parent 6ee0fda commit 6a35acd
Show file tree
Hide file tree
Showing 32 changed files with 17 additions and 796 deletions.
41 changes: 17 additions & 24 deletions addons/gdUnit4/src/ui/GdUnitFonts.gd
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
@tool
class_name GdUnitFonts
extends RefCounted

const FONT_MONO = "res://addons/gdUnit4/src/update/assets/fonts/static/RobotoMono-Regular.ttf"
const FONT_MONO_BOLT = "res://addons/gdUnit4/src/update/assets/fonts/static/RobotoMono-Bold.ttf"
const FONT_MONO_BOLT_ITALIC = "res://addons/gdUnit4/src/update/assets/fonts/static/RobotoMono-BoldItalic.ttf"
const FONT_MONO_ITALIC = "res://addons/gdUnit4/src/update/assets/fonts/static/RobotoMono-Italic.ttf"


static func init_fonts(item: CanvasItem) -> float:
# add a default fallback font
item.set("theme_override_fonts/font", load_and_resize_font(FONT_MONO, 16))
item.set("theme_override_fonts/normal_font", load_and_resize_font(FONT_MONO, 16))
# set default size
item.set("theme_override_font_sizes/font_size", 16)

if Engine.is_editor_hint():
var base_control := EditorInterface.get_base_control()
# source modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
# https://github.com/godotengine/godot/blob/9ee1873ae1e09c217ac24a5800007f63cb895615/editor/editor_log.cpp#L65
var output_source_mono := base_control.get_theme_font("output_source_mono", "EditorFonts")
var output_source_bold_italic := base_control.get_theme_font("output_source_bold_italic", "EditorFonts")
var output_source_italic := base_control.get_theme_font("output_source_italic", "EditorFonts")
var output_source_bold := base_control.get_theme_font("output_source_bold", "EditorFonts")
var output_source := base_control.get_theme_font("output_source", "EditorFonts")
var settings := EditorInterface.get_editor_settings()
var scale_factor := EditorInterface.get_editor_scale()
var font_size: float = settings.get_setting("interface/editor/main_font_size")

font_size *= scale_factor
var font_mono := load_and_resize_font(FONT_MONO, font_size)
item.set("theme_override_fonts/normal_font", font_mono)
item.set("theme_override_fonts/bold_font", load_and_resize_font(FONT_MONO_BOLT, font_size))
item.set("theme_override_fonts/italics_font", load_and_resize_font(FONT_MONO_ITALIC, font_size))
item.set("theme_override_fonts/bold_italics_font", load_and_resize_font(FONT_MONO_BOLT_ITALIC, font_size))
item.set("theme_override_fonts/mono_font", font_mono)
item.set("theme_override_fonts/normal_font", output_source)
item.set("theme_override_fonts/bold_font", output_source_bold)
item.set("theme_override_fonts/italics_font", output_source_italic)
item.set("theme_override_fonts/bold_italics_font", output_source_bold_italic)
item.set("theme_override_fonts/mono_font", output_source_mono)
item.set("theme_override_font_sizes/font_size", font_size)
item.set("theme_override_font_sizes/normal_font_size", font_size)
item.set("theme_override_font_sizes/bold_font_size", font_size)
Expand All @@ -31,13 +34,3 @@ static func init_fonts(item: CanvasItem) -> float:
item.set("theme_override_font_sizes/mono_font_size", font_size)
return font_size
return 16.0


static func load_and_resize_font(font_resource: String, size: float) -> FontFile:
var font: FontFile = ResourceLoader.load(font_resource, "FontFile")
if font == null:
push_error("Can't load font '%s'" % font_resource)
return null
var resized_font: FontFile = font.duplicate()
resized_font.fixed_size = int(size)
return resized_font
202 changes: 0 additions & 202 deletions addons/gdUnit4/src/update/assets/fonts/LICENSE.txt

This file was deleted.

77 changes: 0 additions & 77 deletions addons/gdUnit4/src/update/assets/fonts/README.txt

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Loading

0 comments on commit 6a35acd

Please sign in to comment.