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 options to embolden and transform font outlines to simulate bold and italic typefaces. #59013

Merged
merged 1 commit into from
Mar 11, 2022

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Mar 11, 2022

  • Adds options to embolden and transform font outlines to simulate bold and italic typefaces.
  • Adds bold, bold italics, and italics modified font versions to the default theme (for RichTextLabel style). With 1.2 embolden and Transform2D(1.0, 0.4, 0.0, 1.0, 0.0, 0.0) transform.
Normal
[b]Bold[/b]
[i]Italic[/i]

Screenshot 2022-03-11 at 09 28 55

Fixes #58988

@bruvzg
Copy link
Member Author

bruvzg commented Mar 11, 2022

Screen.Recording.2022-03-11.at.12.05.55.mov

@akien-mga
Copy link
Member

akien-mga commented Mar 11, 2022

Playing a bit with dynamic updates to slant and embolden:

simplescreenrecorder-2022-03-11_11.42.13.mp4

It works well but seems to be fairly expensive, the above drops from 1670 FPS with just the RichTextEffects, to 20 FPS with both slant and embolden set dynamically in _process. Or down to 2-3 FPS if set in _physics_process.

If I double the font size from 48 to 96px, I get 5 FPS in _process.

Using this code:

var fd = get_theme_font("normal_font").get_data(0)

func _process(delta):
	fd.slant = sin(Time.get_ticks_msec() / 1000.0)
	fd.embolden = clamp(cos(Time.get_ticks_msec() / 500.0), 0.2, 0.8)

@bruvzg bruvzg force-pushed the fake_bold_italics branch from 200e8cb to 3667e15 Compare March 11, 2022 11:06
@bruvzg
Copy link
Member Author

bruvzg commented Mar 11, 2022

Changed slant to full Transform2D, now it's possible to do more stuff:

Screen.Recording.2022-03-11.at.13.06.12.mov

Original slant is equivalent to Transform2D(1.0, slant, 0.0, 1.0, 0.0, 0.0)

@bruvzg bruvzg changed the title Add options to embolden and slant font outlines to simulate bold and italic typefaces. Add options to embolden and transform font outlines to simulate bold and italic typefaces. Mar 11, 2022
@akien-mga
Copy link
Member

akien-mga commented Mar 11, 2022

Changed slant to full Transform2D, now it's possible to do more stuff:

Heh I was suggesting this mostly in jest, I don't know if there's a real need for it.

It's nice to have the flexibility but at the same time I fear it might not be easy for users to edit the Transform2D directly if what they want is a simple slanting effect.

Maybe mention in the transform documentation that for italics-like slanting users should set the yx component?

I confirm that this still works fine from script (and doesn't seem slower than it was with slant):

var fd = get_theme_font("normal_font").get_data(0)

func _process(delta):
	fd.transform.x.y = sin(Time.get_ticks_msec() / 600.0)
	fd.embolden = abs(cos(Time.get_ticks_msec() / 800.0)) - 0.2

@bruvzg bruvzg force-pushed the fake_bold_italics branch from 3667e15 to b32e8d6 Compare March 11, 2022 12:02
@bruvzg
Copy link
Member Author

bruvzg commented Mar 11, 2022

Maybe mention in the transform documentation that for italics-like slanting users should set the yx component?

Added slant an example to the documentation.

Also changed max. font texture cache size to 1024x1024 (2048x2048 for MSDF, it's slow anyway and usually have large size glyphs rendered), it should be faster with larger font.

@akien-mga
Copy link
Member

Also changed max. font texture cache size to 1024x1024 (2048x2048 for MSDF, it's slow anyway and usually have large size glyphs rendered), it should be faster with larger font.

It doesn't seem to make much difference in my test project, still ~40 FPS with 64px font and 10 FPS with 65px font when changing embolden and transform every other _process call.

@bruvzg
Copy link
Member Author

bruvzg commented Mar 11, 2022

64px font and 10 FPS with 65px

This should be transition from 512 to 1024, so it's not changed.

@akien-mga akien-mga merged commit e56b692 into godotengine:master Mar 11, 2022
@akien-mga
Copy link
Member

Thanks!

@bruvzg bruvzg deleted the fake_bold_italics branch March 11, 2022 13:24
@markdibarry
Copy link
Contributor

markdibarry commented Mar 11, 2022

It seems this causes all font outlines to be anti-aliased. Is that intentional?
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Godot 4: RichTextLabel bold, italic and code Bbcodes aren't applied properly with the default font.
3 participants