-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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
Font.get_char_size()
documentation is either incorrect or very confusing
#88348
Comments
This is an outdated description from 3.x. Kerning is controlled automatically when using |
Totally understand that that is the use case, but it still sounds like it would be very useful in my situation. I want to fade in a word character by character, so I use draw_string to draw the visible substring and then draw_char to fade in the next character By not being able to account for kerning of the next character, it causes some jittering as the substring goes from x characters to x+1 characters, as that most recent character might have kerning applied and sneak in a bit How else can this be achieved if |
That's pretty much a type of misuse it's trying to prevent, since it won't work with complex scripts. The next character in the string is not necessary the next visible character, and adding a character to the string might change the look of the whole string. A proper way to implement it would be using extends Control
var glyphs = []
func _ready() -> void:
var font = get_theme_font("font")
var font_size = 16
# Prerpcessing
var text_line = TextLine.new()
text_line.add_string("text", font, font_size) # You can add multiple spans of text with different font and size.
var ts = TextServerManager.get_primary_interface()
glyphs = ts.shaped_text_get_glyphs(text_line.get_rid()) # Store "glyphs" for actual rendering
func _draw() -> void:
var color = Color(1, 0, 0)
var position = Vector2(100, 100)
var ci = get_canvas_item()
var ts = TextServerManager.get_primary_interface()
# Draw shaped glyphs left-to-right.
for gl in glyphs:
if gl["font_rid"].is_valid():
ts.font_draw_glyph(gl["font_rid"], ci, gl["font_size"], position + gl["offset"], gl["index"], color) # Do your custom drawing, you can check which part of original string glyph correspong to by checeking gl["start"] and gl["end"]
else:
ts.draw_hex_code_box(ci, gl["font_size"], position + gl["offset"], gl["index"], color) # Glyph not found in the font.
position.x = position.x + gl["advance"]
|
Thank you very much for the code example! Are there any references for this other than the Like the docs, and your example, show |
Or even just a high level "Hey here's what you should know about drawing text to the screen from code". I imagine this would be a fairly common issue. I almost just decided to use a monospace font to not deal with it since it seemed like these functions were being used as intended, and the |
Tested versions
Documentation related. Using Godot 4.2
System information
Windows 11, Godot 4.2
Issue description
The docs, located here, indicate that there is a way to pass in the following character to account for kerning. That doesn't seem to be the case based on the underlying code or the param indications.
Steps to reproduce
Read the docs here
Minimal reproduction project (MRP)
Hopefully not necessary, just documentation related
The text was updated successfully, but these errors were encountered: