From bb0f4f102a4c8936d6955933875eeff76d8886ef Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Tue, 9 Sep 2025 18:00:31 +0300 Subject: [PATCH] fix font loading, and support for relative URLs in fonts --- flumi/Scripts/B9/HTMLParser.gd | 5 +++-- flumi/Scripts/Engine/StyleManager.gd | 6 +++++- flumi/Scripts/main.gd | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/flumi/Scripts/B9/HTMLParser.gd b/flumi/Scripts/B9/HTMLParser.gd index 7de3e2a..b239d71 100644 --- a/flumi/Scripts/B9/HTMLParser.gd +++ b/flumi/Scripts/B9/HTMLParser.gd @@ -404,7 +404,7 @@ func get_icon() -> String: var icon_element = find_first("icon") return icon_element.get_attribute("src") if icon_element != null else "" -func process_fonts() -> void: +func process_fonts(base_url: String = "") -> void: var font_elements = find_all("font") for font_element in font_elements: @@ -413,7 +413,8 @@ func process_fonts() -> void: var weight = font_element.get_attribute("weight", "400") if name_str and src: - FontManager.register_font(name_str, src, weight) + var resolved_src = URLUtils.resolve_url(base_url, src) + FontManager.register_font(name_str, resolved_src, weight) func get_meta_content(name_: String) -> String: var meta_elements = find_all("meta", "name") diff --git a/flumi/Scripts/Engine/StyleManager.gd b/flumi/Scripts/Engine/StyleManager.gd index 9c96e8c..47fa1bd 100644 --- a/flumi/Scripts/Engine/StyleManager.gd +++ b/flumi/Scripts/Engine/StyleManager.gd @@ -407,7 +407,7 @@ static func apply_margin_styles_to_container(margin_container: MarginContainer, if margin_val != null: margin_container.add_theme_constant_override(theme_key, margin_val) -static func apply_styles_to_label(label: Control, styles: Dictionary, element: HTMLParser.HTMLElement, parser, text_override: String = "") -> void: +static func apply_styles_to_label(label: Control, styles: Dictionary, element: HTMLParser.HTMLElement, parser, text_override: String = "", is_refresh: bool = false) -> void: if label is Button: apply_font_to_button(label, styles) return @@ -415,6 +415,10 @@ static func apply_styles_to_label(label: Control, styles: Dictionary, element: H if not label is RichTextLabel: return + if not is_refresh and styles.has("font-family") and styles["font-family"] not in ["sans-serif", "serif", "monospace"]: + var main_node = Engine.get_main_loop().current_scene + main_node.register_font_dependent_element(label, styles, element, parser) + var text = text_override if text_override != "" else (element.get_preserved_text() if element.tag_name == "pre" else element.get_bbcode_formatted_text(parser)) var font_size = 24 # default diff --git a/flumi/Scripts/main.gd b/flumi/Scripts/main.gd index e8242c0..ea2a1cb 100644 --- a/flumi/Scripts/main.gd +++ b/flumi/Scripts/main.gd @@ -388,7 +388,7 @@ func render_content(html_bytes: PackedByteArray) -> void: await parser.process_external_styles(current_domain) # Process and load all custom fonts defined in tags - parser.process_fonts() + parser.process_fonts(current_domain) FontManager.load_all_fonts() if parse_result.errors.size() > 0: @@ -819,7 +819,7 @@ func refresh_fonts(font_name: String) -> void: if styles.has("font-family") and styles["font-family"] == font_name: if is_instance_valid(label): - StyleManager.apply_styles_to_label(label, styles, element, parser) + StyleManager.apply_styles_to_label(label, styles, element, parser, "", true) func get_current_url() -> String: return current_domain if not current_domain.is_empty() else ""