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 has_char(...) to Font class. #1450

Closed
Error7Studios opened this issue Sep 2, 2020 · 3 comments
Closed

Add has_char(...) to Font class. #1450

Error7Studios opened this issue Sep 2, 2020 · 3 comments
Milestone

Comments

@Error7Studios
Copy link

Describe the project you are working on:
(Any project which supports multiple languages)

Describe the problem or limitation you are having in your project:
If the currently selected Font doesn't contain a glyph/character you're trying to use, it will just be ignored/skipped, which can look like a bug.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
There is already a proposal for using a placeholder glyph in this case #591.
I am simply proposing that we add a has_char_str(char_str: String) and has_char_code(char_code: int) to the Font class.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
You could make a custom Label scene, with this script to ensure that every character is supported by the Font.

extends Label

func set_text(__text: String): #override
	assert_font_supports_all_characters(__text)
	text = __text

func assert_font_supports_all_characters(__text: String):
	var __font := get_font("font")
	var __font_path := __font.resource_path
	for __char_str in __text:
		if !__font.has_char_str(__char_str):
			assert(false, str("Unsupported char '", __char_str, "' in Font (", __font_path, ")"))

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Not sure, but I don't think so.

Is there a reason why this should be core and not an add-on in the asset library?:
This could help in catching some confusing bugs relating to having multiple fonts for different languages.

By adding these functions, an invalid char/glyph could be caught and throw an error so the problem can be fixed instead of slipping by unnoticed.

If you're creating your own font, this would also help to track down any characters which you may have forgotten to add glyphs for.

@Calinou
Copy link
Member

Calinou commented Sep 2, 2020

godotengine/godot#40491 partially addresses this. You can use if "E" in some_dynamic_font.get_available_chars():.

It's not implemented in BitmapFont though.

@bruvzg
Copy link
Member

bruvzg commented Jun 29, 2021

In 4.0 both bool has_char(char32_t p_char) and String get_supported_chars() are part of the Font, since Font is unified it's available for bitmap fonts as well.

If the currently selected Font doesn't contain a glyph/character you're trying to use, it will just be ignored/skipped, which can look like a bug.

In 4.0, instead of ignoring missing chars, char hex code is drawn (by default, this feature can be disabled).
Screenshot 2021-06-29 at 14 38 50

@Error7Studios
Copy link
Author

In 4.0 both bool has_char(char32_t p_char) and String get_supported_chars() are part of the Font, since Font is unified it's available for bitmap fonts as well.
In 4.0, instead of ignoring missing chars, char hex code is drawn (by default, this feature can be disabled).

Awesome. Thank you. Closing, then.

@Calinou Calinou added this to the 4.0 milestone Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants