Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add variable fonts and system fonts to BiDi and Font Features demo #932

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jul 7, 2023

Note that some of the code could be simplified once godotengine/godot#79166 is merged, but I don't know if that PR will be cherry-picked for 4.1.x.

Preview

variable_fonts webp

system_fonts webp

@Calinou Calinou force-pushed the bidi-font-features-add-variable-fonts-system-fonts branch from a1cde8e to 179f945 Compare July 7, 2023 18:56
@Calinou
Copy link
Member Author

Calinou commented Oct 18, 2023

I've tried replacing the workarounds with setting dictionary keys directly like this:

diff --git a/gui/bidi_and_font_features/bidi.gd b/gui/bidi_and_font_features/bidi.gd
index ea2f64d4..6bba4a61 100644
--- a/gui/bidi_and_font_features/bidi.gd
+++ b/gui/bidi_and_font_features/bidi.gd
@@ -44,42 +44,27 @@ func _on_variable_size_value_changed(value: float) -> void:
 
 func _on_variable_weight_value_changed(value: float) -> void:
 	$"TabContainer/Variable fonts/Variables/Weight/Value".text = str(value)
-	# Workaround to make the variable font axis value effective. This requires duplicating the dictionary.
-	var dict = variable_font_variation.variation_opentype.duplicate()
-	dict["weight"] = value
-	variable_font_variation.variation_opentype = dict
+	variable_font_variation.variation_opentype["weight"] = value
 
 
 func _on_variable_slant_value_changed(value: float) -> void:
 	$"TabContainer/Variable fonts/Variables/Slant/Value".text = str(value)
-	# Workaround to make the variable font axis value effective. This requires duplicating the dictionary.
-	var dict = variable_font_variation.variation_opentype.duplicate()
-	dict["slant"] = value
-	variable_font_variation.variation_opentype = dict
+	variable_font_variation.variation_opentype["slant"] = value
 
 
 func _on_variable_cursive_toggled(button_pressed: bool) -> void:
 	$"TabContainer/Variable fonts/Variables/Cursive".button_pressed = button_pressed
-	# Workaround to make the variable font axis value effective. This requires duplicating the dictionary.
-	var dict = variable_font_variation.variation_opentype.duplicate()
-	dict["custom_CRSV"] = int(button_pressed)
-	variable_font_variation.variation_opentype = dict
+	variable_font_variation.variation_opentype["custom_CRSV"] = int(button_pressed)
 
 
 func _on_variable_casual_toggled(button_pressed: bool) -> void:
 	$"TabContainer/Variable fonts/Variables/Casual".button_pressed = button_pressed
-	# Workaround to make the variable font axis value effective. This requires duplicating the dictionary.
-	var dict = variable_font_variation.variation_opentype.duplicate()
-	dict["custom_CASL"] = int(button_pressed)
-	variable_font_variation.variation_opentype = dict
+	variable_font_variation.variation_opentype["custom_CASL"] = int(button_pressed)
 
 
 func _on_variable_monospace_toggled(button_pressed: bool) -> void:
 	$"TabContainer/Variable fonts/Variables/Monospace".button_pressed = button_pressed
-	# Workaround to make the variable font axis value effective. This requires duplicating the dictionary.
-	var dict = variable_font_variation.variation_opentype.duplicate()
-	dict["custom_MONO"] = int(button_pressed)
-	variable_font_variation.variation_opentype = dict
+	variable_font_variation.variation_opentype["custom_MONO"] = int(button_pressed)
 
 
 func _on_system_font_value_text_changed(new_text: String) -> void:
 

However, this has no effect in 4.2.beta1. @bruvzg Any ideas?

@bruvzg
Copy link
Member

bruvzg commented Oct 18, 2023

However, this has no effect in 4.2.beta1. @bruvzg Any ideas?

That's not gonna work, and I do not think there's any way to make it work. The only thing that can be removed for the old version is .duplicate().

@Calinou
Copy link
Member Author

Calinou commented Oct 30, 2023

That's not gonna work, and I do not think there's any way to make it work. The only thing that can be removed for the old version is .duplicate().

I've tried removing .duplicate() and it didn't seem to work either. That said, I don't think this is critical for this demo to be mergeable.

@akien-mga akien-mga merged commit 7176ff1 into godotengine:master Jan 19, 2024
@akien-mga
Copy link
Member

Thanks!

@Calinou Calinou deleted the bidi-font-features-add-variable-fonts-system-fonts branch January 24, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants