godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Font class's get_char_size() method doesn't return the font's height.

Open DrAlta opened this issue 2 years ago • 6 comments

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

DrAlta avatar Jun 18 '22 22:06 DrAlta

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?

Calinou avatar Jun 18 '22 22:06 Calinou

I tested it and label.get_font("") is returning a BitmapFont. Using a DynamicFont does appear to return the font height.

DrAlta avatar Jun 18 '22 23:06 DrAlta

cc @bruvzg

Calinou avatar Jun 19 '22 00:06 Calinou

Just to be clear, your example in OP compares two different characters. Is that intentional or a typo?

YuriSizov avatar Jun 19 '22 17:06 YuriSizov

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.

bruvzg avatar Jun 19 '22 17:06 bruvzg

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

DrAlta avatar Jun 19 '22 18:06 DrAlta