Skip to content

egui_extras: feature svg_text#4659

Closed
xNWP wants to merge 3 commits intoemilk:masterfrom
xNWP:master
Closed

egui_extras: feature svg_text#4659
xNWP wants to merge 3 commits intoemilk:masterfrom
xNWP:master

Conversation

@xNWP
Copy link
Copy Markdown

@xNWP xNWP commented Jun 14, 2024

Added

  • Adds svg text rendering support via the svg_text feature flag.

Changed

  • Updates resvg from 0.37 to 0.42.

Copy link
Copy Markdown
Contributor

@drac-dot-gay drac-dot-gay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that allow(unused_mut) caught my eye but otherwise lgtm

edit: i should really read commit messages first, could you put in a comment explaining it?

@xNWP
Copy link
Copy Markdown
Author

xNWP commented Jun 14, 2024

that allow(unused_mut) caught my eye but otherwise lgtm

edit: i should really read commit messages first, could you put in a comment explaining it?

commented!

@drac-dot-gay
Copy link
Copy Markdown
Contributor

i think for demonstration purposes (and to make testing easier in the future), it'd be a good idea to add an example that shows text in svgs in action

Copy link
Copy Markdown
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that an example would be nice, but LGTM anyway.

Would this text rendering work on web?

@xNWP
Copy link
Copy Markdown
Author

xNWP commented Jun 20, 2024

Would this text rendering work on web?

I was wondering the same thing shortly after making the PR 😅, I'm not great at web dev stuff but I'll take a look at it now and test some things.

i think for demonstration purposes (and to make testing easier in the future), it'd be a good idea to add an example that shows text in svgs in action

after checking the web stuff I'll also look at how y'all test/write example code and see what I can do 😊

@xNWP
Copy link
Copy Markdown
Author

xNWP commented Jun 22, 2024

Would this text rendering work on web?

Short answer, no.
Long answer is that the main workhorse of this PR is the load_system_fonts function on the Font Database type that resvg re-exports from the fontdb crate (https://github.com/RazrFalcon/fontdb/blob/fd24f8c9d7b57f30a6f6ba560c697a7854c94858/src/lib.rs#L352). This function is just a conditional compilation switch based on the target os which simply does nothing for wasm. I looked into how support could be added to this crate, however it looks like the way to do it would be the Local Font Access API which has little to no browser support (only experimental Chrome + Edge support) https://developer.mozilla.org/en-US/docs/Web/API/Local_Font_Access_API

@emilk
Copy link
Copy Markdown
Owner

emilk commented Jun 23, 2024

Thanks for testing web. Please document your findings, i.e. document that the svg_text won't work on web, and why (linking to relevant issues, if any).

We should also figure out a solution to the duplicated dependencies.

@xNWP
Copy link
Copy Markdown
Author

xNWP commented Aug 24, 2024

Disregard this PR (for now).

Apologies for the delay in this, adhd is a bitch. But while looking at this again I realized that I mistakenly have it set up in a way that the system fonts are being loaded EVERY single time egui loads a new svg, instead it should be loaded once (during the install image loaders call likely), and that font database should be reused by the SVG loader. I also realized that I could likely solve the problem of no fonts on the web by allowing you to load/embed the font data directly (moving the problem onto the egui user). When I find the time to reimplement this in a better way I'll open a new PR and reference this one :)

@xNWP xNWP closed this Aug 24, 2024
emilk pushed a commit that referenced this pull request Apr 14, 2025
**Added**
* Create `svg_text` feature flag to support text rendering & loading of
system fonts.

**Changed**
* Updates `resvg` to `0.45`.
* Adds `usvg::Options` field to the `SvgLoader` structure.
* Change function signatures to support passing `usvg::Options` to
downstream `load_svg_bytes_with_size`.

**Additional Info**
* I used this PR as a reference:
#4659. @xNWP can you see if this
adequately resolves your concern from your original PR?
* Closes #5977 (we may want to open
another issue for my other thoughts in this issue)
* Also, I would like to thank @xNWP and their original PR for being a
good reference for this one.
* [x] I have followed the instructions in the PR template
darkwater pushed a commit to darkwater/egui that referenced this pull request Aug 24, 2025
**Added**
* Create `svg_text` feature flag to support text rendering & loading of
system fonts.

**Changed**
* Updates `resvg` to `0.45`.
* Adds `usvg::Options` field to the `SvgLoader` structure.
* Change function signatures to support passing `usvg::Options` to
downstream `load_svg_bytes_with_size`.

**Additional Info**
* I used this PR as a reference:
emilk#4659. @xNWP can you see if this
adequately resolves your concern from your original PR?
* Closes emilk#5977 (we may want to open
another issue for my other thoughts in this issue)
* Also, I would like to thank @xNWP and their original PR for being a
good reference for this one.
* [x] I have followed the instructions in the PR template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants