godot-docs
godot-docs copied to clipboard
Font class's get_char_size() method doesn't return the font's height.
Your Godot version: v3.4.4.stable.official [419e713a2]
Issue description: says
Vector2 get_char_size ( int char, int next=0 ) const
Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see get_height) and has no relation to the glyph height.
but
var label = Label.new()
font = label.get_font("")
print(font.get_char_size(ord(".")), "=", font.get_string_size(","))
label.free()
prints "(4, 2)=(4, 14)"
14 in the value returned by get_height ( )
URL to the documentation page: https://docs.godotengine.org/en/stable/classes/class_font.html?highlight=draw_char#class-font-method-get-char-size
To my knowledge, label.get_font("")
will not return a valid font (except the default project BitmapFont, maybe). Can you try this with a DynamicFont?
I tested it and label.get_font("") is returning a BitmapFont. Using a DynamicFont does appear to return the font height.
cc @bruvzg
Just to be clear, your example in OP compares two different characters. Is that intentional or a typo?
Indeed, 3.x bitmap font return actual char height, dynamic font and 4.0 use font height instead. Probably it should be changed to do the same, for consistently.
Just to be clear, your example in OP compares two different characters. Is that intentional or a typo?
It's a typo, I'd check a few different chars to see if the height returned by get_char_size() was based off the char or not and didn't change it back