Skip to content

Commit

Permalink
Merge pull request #932 from Calinou/bidi-font-features-add-variable-…
Browse files Browse the repository at this point in the history
…fonts-system-fonts

Add variable fonts and system fonts to BiDi and Font Features demo
  • Loading branch information
akien-mga authored Jan 19, 2024
2 parents 62db0c9 + 179f945 commit 7176ff1
Show file tree
Hide file tree
Showing 10 changed files with 507 additions and 23 deletions.
4 changes: 4 additions & 0 deletions gui/bidi_and_font_features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ Renderer: Compatibility
![Screenshot](screenshots/line_break_and_fill.png)

![Screenshot](screenshots/font_features.png)

![Screenshot](screenshots/variable_fonts.webp)

![Screenshot](screenshots/system_fonts.webp)
126 changes: 111 additions & 15 deletions gui/bidi_and_font_features/bidi.gd
Original file line number Diff line number Diff line change
@@ -1,33 +1,129 @@
extends Control

func _ready():
var tree = $"TabContainer/Text direction/Tree"
var root = tree.create_item()
@onready var variable_font_variation: FontVariation = $"TabContainer/Variable fonts/VariableFontPreview".get_theme_font("font")

func _ready() -> void:
var tree: Tree = $"TabContainer/Text direction/Tree"
var root := tree.create_item()
tree.set_hide_root(true)
var first = tree.create_item(root)
var first := tree.create_item(root)
first.set_text(0, "רֵאשִׁית")
var second = tree.create_item(first)
var second := tree.create_item(first)
second.set_text(0, "שֵׁנִי")
var third = tree.create_item(second)
var third := tree.create_item(second)
third.set_text(0, "שְׁלִישִׁי")
var fourth = tree.create_item(third)
var fourth := tree.create_item(third)
fourth.set_text(0, "fourth")

func _on_Tree_item_selected():
var tree = $"TabContainer/Text direction/Tree"
var path = ""
var item = tree.get_selected()
func _on_Tree_item_selected() -> void:
var tree: Tree = $"TabContainer/Text direction/Tree"
var path := ""
var item := tree.get_selected()
while item != null:
path = item.get_text(0) + "/" + path
item = item.get_parent()
$"TabContainer/Text direction/LineEditST".text = path
$"TabContainer/Text direction/LineEditNoST".text = path

func _on_LineEditCustomSTDst_text_changed(new_text):
func _on_LineEditCustomSTDst_text_changed(new_text: String) -> void:
$"TabContainer/Text direction/LineEditCustomSTSource".text = new_text

func _on_LineEditCustomSTSource_text_changed(new_text):
func _on_LineEditCustomSTSource_text_changed(new_text: String) -> void:
$"TabContainer/Text direction/LineEditCustomSTDst".text = new_text

func _on_LineEditCustomSTDst_tree_entered():
$"TabContainer/Text direction/LineEditCustomSTDst".text = $"TabContainer/Text direction/LineEditCustomSTSource".text # Refresh text to apply custom script once it's loaded.
func _on_LineEditCustomSTDst_tree_entered() -> void:
# Refresh text to apply custom script once it's loaded.
$"TabContainer/Text direction/LineEditCustomSTDst".text = $"TabContainer/Text direction/LineEditCustomSTSource".text


func _on_variable_size_value_changed(value: float) -> void:
$"TabContainer/Variable fonts/Variables/Size/Value".text = str(value)
# This is also available on non-variable fonts.
$"TabContainer/Variable fonts/VariableFontPreview".add_theme_font_size_override("font_size", value)


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


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


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


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


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


func _on_system_font_value_text_changed(new_text: String) -> void:
for label in [
$"TabContainer/System fonts/VBoxContainer/SansSerif/Value",
$"TabContainer/System fonts/VBoxContainer/Serif/Value",
$"TabContainer/System fonts/VBoxContainer/Monospace/Value",
$"TabContainer/System fonts/VBoxContainer/Cursive/Value",
$"TabContainer/System fonts/VBoxContainer/Fantasy/Value",
$"TabContainer/System fonts/VBoxContainer/Custom/Value"
]:
label.text = new_text


func _on_system_font_weight_value_changed(value: float) -> void:
$"TabContainer/System fonts/Weight/Value".text = str(value)
for label in [
$"TabContainer/System fonts/VBoxContainer/SansSerif/Value",
$"TabContainer/System fonts/VBoxContainer/Serif/Value",
$"TabContainer/System fonts/VBoxContainer/Monospace/Value",
$"TabContainer/System fonts/VBoxContainer/Cursive/Value",
$"TabContainer/System fonts/VBoxContainer/Fantasy/Value",
$"TabContainer/System fonts/VBoxContainer/Custom/Value"
]:
var system_font: SystemFont = label.get_theme_font("font")
system_font.font_weight = value

func _on_system_font_italic_toggled(button_pressed: bool) -> void:
for label in [
$"TabContainer/System fonts/VBoxContainer/SansSerif/Value",
$"TabContainer/System fonts/VBoxContainer/Serif/Value",
$"TabContainer/System fonts/VBoxContainer/Monospace/Value",
$"TabContainer/System fonts/VBoxContainer/Cursive/Value",
$"TabContainer/System fonts/VBoxContainer/Fantasy/Value",
$"TabContainer/System fonts/VBoxContainer/Custom/Value"
]:
var system_font: SystemFont = label.get_theme_font("font")
system_font.font_italic = button_pressed


func _on_system_font_name_text_changed(new_text: String) -> void:
var system_font: SystemFont = $"TabContainer/System fonts/VBoxContainer/Custom/FontName".get_theme_font("font")
system_font.font_names[0] = new_text




Loading

0 comments on commit 7176ff1

Please sign in to comment.