iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
24.8k stars 1.17k forks source link

Most text characters not rendering #2005

Closed christofferaakre closed 9 months ago

christofferaakre commented 1 year ago

Is there an existing issue for this?

Is this issue related to iced?

What happened?

Most characters do not render when trying to render text. It happens with text widgets, button widgets, etc. The only thing I've been able to find that correctly renders text is the text input. I tried to render just a simple text widget:

    fn view(&self) -> iced::Element<'_, Self::Message> {
        text("asd123+-=';*").into()
    }

, and here is what I get: image

When running the todos example, I get this: image As you can see, the button has no text and the spacing looks weird for the text input. If I type into the text input, I see this: image Suspiciously, those same characters that actually render for me show up weird here, with what looks like a different font, colour, and spacing. I tried playing around with changing the font, but to no avail.

What is the expected behavior?

I expected text to render correctly with no problems. I have successfully used iced 0.9 in the past and it worked fine, but 0.10 is broken for me.

Version

crates.io release

Operating System

Linux

Do you have any log output?

No response

christofferaakre commented 1 year ago

Update: switching to 0.9 fixes the issue, but I want to use 0.10 because I need the new font-shaping capability. Anyone have any pointers on how to troubleshoot this?

genusistimelord commented 1 year ago

have you tried to see if this renders correctly with the master branch?

christofferaakre commented 1 year ago

@genusistimelord Thank you for the suggestion; it doesn't unfortunately. I see the issue both on master and the 0.10 tag, but the 0.9 tag works as expected

genusistimelord commented 1 year ago

what font size do you have it set as and can you try reducing it? or what Font do you have set is it default or did you set one yourself.

christofferaakre commented 1 year ago

in my hello world example, I was uing the default font/size. I tried setting the font size to 5, and then 100, but nothing changed (other than the text being bigger obviously). I tried using a font like this:

Font {
            family: iced::font::Family::SansSerif,
            monospaced: false,
            ..Default::default()
     }

, also with monospaced: true, and with Serif and Monospace for the family, same result for all of them. As for the todos example I have tried, as far as I can tell it uses the default font as well as an icons.ttf for icons.

genusistimelord commented 1 year ago

ok thank you this should give some more details for Hector to look into closer. Can you tell us what GPU's your computer has and show us a full example of the code? as that will also help too.

dumski commented 1 year ago

I confirm this issue. For me there is no visible characters for any text. Buttons are rendered properly, but no text at all. Mac Studio, GPU: Apple M1 Max

genusistimelord commented 1 year ago

can you run the program using https://renderdoc.org/ and take a screenshot of the program with most of the options clicked image like the above and just put the executable path to the program and the working directory where you want it to read data from. this will help us to know if its a graphic issue or a logic issue.

So load the program and then hit image

then double click on the screenshot to access it. After that go to "File-> save Capture as" give it a name and save it to a place you can easily find. and upload it to here.

kaimast commented 1 year ago

I have had this issue on Arch Linux as well since iced moved to cosmic-text.

turai commented 1 year ago

I can also confirm. Capture attached, font atlas looks weird.

font_issue.zip

genusistimelord commented 1 year ago

this one had a Error in the draw call of no vertex shader bound at a draw call. hmm

turai commented 1 year ago

I was investigating the misaligned '3' I showed on discord yesterday, turns out using Font::MONOSPACE makes it all disappear. Screenshot from 2023-08-13 06-37-46 image captures.zip

Tested with different fonts no issues: C059, Liberation Mono, Liberation Sans, Liberation Serif, Meslo LG L, Meslo LG L DZ, Nimbus Sans broken (these don't seem to load at all, act like default_font commented out?): Cantarell, Nimbus Sans Narrow, System-ui

genusistimelord commented 1 year ago

OK so I know there was a issue with the wgpu crate and it did have a patch release. So can you try to run cargo update OR use the master branch and see if these issue's still occur?

turai commented 1 year ago

Nothing changed, still broken.

realDelta2 commented 1 year ago

Yep, I am having this exact issue too. I thought it was a nixos issue at first.

turai commented 1 year ago

No, it's related to swash failing to parse the font: https://discord.com/channels/628993209984614400/1136639744890114128 Use a different one, preferably ttf as a workaround.

genusistimelord commented 1 year ago

@christofferaakre have you tried enforcing the font to be of one that is a TTF font in the system? Just curious if that fixes the issues. as we found out the GTK fonts have loading issues which cause things to not work right due to them not being supported. So was thinking maybe the rendering issues or missing characters could also be caused by something similar.

martinhalford commented 1 year ago

Hi team, FYI... I'm having the same issue too, using 0.10.0. The UI renders fine when deployed as a desktop app but I get the same issue when deploying as a web app.

Try replicating this for the "todos" example in the iced repo

cd iced/
cargo run --package todos

You get this... image

Now try this...

cd iced/examples/todos
trunk build
trunk serve --open

You get this... image

cat cargo.toml
[package]
name = "todos"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
publish = false

[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
once_cell = "1.15"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-std = "1.0"
directories-next = "2.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window", "Storage"] }
wasm-timer = "0.2"

[package.metadata.deb]
assets = [
    ["target/release-opt/todos", "usr/bin/iced-todos", "755"],
    ["iced-todos.desktop", "usr/share/applications/", "644"],
]
genusistimelord commented 1 year ago

it might be loading a default font that cant be used due to not being supported. Also when you have these issues Please try to force tiny_skia rendering to see if it fixes the issue or not.

martinhalford commented 1 year ago

@genusistimelord - I don't think it's a font issue. Note that the buttons do not render either in the webapp version. It looks to be something more fundamental.

Apologies but I'm new here - only learned of Iced today but got excited and have been having fun playing with it!

martinhalford commented 1 year ago

@genusistimelord - I forced tiny_skia and got the following render.

image

This is the cargo.toml used:

[package]
name = "todos"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
publish = false

[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
once_cell = "1.15"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-std = "1.0"
directories-next = "2.0"

[dependencies.iced_tiny_skia]
version = "0.1"
path = "../../tiny_skia/"

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window", "Storage"] }
wasm-timer = "0.2"

[package.metadata.deb]
assets = [
    ["target/release-opt/todos", "usr/bin/iced-todos", "755"],
    ["iced-todos.desktop", "usr/share/applications/", "644"],
]
kaimast commented 1 year ago

Can we use a separate issue for WebAssembly? It seems to be related but is not the same bug.

This issue was already reported a while ago.

martinhalford commented 1 year ago

@kaimast @genusistimelord - it certainly seems to be a web assembly issue, since it works fine in desktop.

However, I'm a bit perplexed as to why the fixation on fonts? It looks more widespread than just a font issue. (Might be wrong. Just looks to be affecting other components too.)

genusistimelord commented 1 year ago

its hard to tell really. not sure what fonts its using on the web side nor what OS its affected on since each OS has its own set of fonts. We just have had issues with loading certain fonts which have caused rendering issues. Generally why I asked. so if the Web side is loading these certain fonts then it could prevent it from rendering.

Also the other thing is to make sure your Iced wgpu and tiny-skia libs are fully up to date as in the first release there was a issue that got fixed due to layering. So if you could do a Cargo clean + Cargo update and then try it that also would be nice since it guarantees its all up to date.

martinhalford commented 1 year ago

@genusistimelord - I've done a cargo clean and a cargo update. I've even done a cargo install trunk --force and tried compiling the code using both the stable rustc 1.71.0 (8ede3aae2 2023-07-12) and nightly rustc 1.73.0-nightly (07438b092 2023-08-16) builds. The issue still remains.

I tested using Microsoft Edge and Safari - the bug presents slightly differently in each browser. However, it does look more like a font issue on Safari, whereas Edge has more challenges.

See video for details: Loom video

cargo 1.71.0 (cfd3bbd8f 2023-06-08)
trunk 0.17.3
rustc 1.71.0 (8ede3aae2 2023-07-12)
macOS 13.5 (22G74)
genusistimelord commented 1 year ago

ok so it seems you are having laying issues in wasm and also font layer is not rendering at all. This is indeed a separate issue from this issue. it is possibly more related too https://github.com/iced-rs/iced/issues/1900

I will see if I can get this recreated or not tomorrow.

martinhalford commented 1 year ago

@genusistimelord - I'm not sure which issue it is more related to. Thanks for looking into this. Please let me know if you need more info.

kaimast commented 1 year ago

For people who have this issue, could you test whether cosmic-text works fine for you? I reported a while ago here that even their examples do not find any fonts for me.

martinhalford commented 1 year ago

@genusistimelord @kaimast - I've added a comment to issue 1900.

ph commented 1 year ago

Hello, I've been hit by the invisible text mentioned above using either the master or the stable release of this crate. I've investigated the issue and I was able to find why it doesn't work for everyone, at least why it doesn't work for me. Some context, I am running Guix Linux which is a transactional distribution, you might be more familliar to NixOS, which uses the same concepts.

In simplier terms, both distribution uses a different file structures than the common HFS, multiples symlinks are used to make application or support file font available to the end user. The system mainly relies on fontconfig to ensure that all the fonts are picked up correctly by GUI application.

Looking at the history of this project, it was recently updated to use cosmic-text, that library uses the crate fontdb to generalize the access of the fonts on the different operating system. By default the libary on Linux based system look for font in the following directories:

On the other hand Guix (I don't remember NixOS' installation path) install them in ~/.guix-home/profile/share/fonts/ and it updates fontconfig configuration with the path.

By default fontdb doesn't use fontconfig, see https://github.com/RazrFalcon/fontdb/blob/master/src/lib.rs#L392-L407, there an open issue https://github.com/RazrFalcon/fontdb/issues/56 that suggest enabling it by default.

Looking at the cosmic-text repository, the fontconfig feature was just enabled in https://github.com/pop-os/cosmic-text/pull/174 but there are no official release of the library that include the change.

If you update iced to use the main branch of cosmic-text, it correctly find the font to render.

So for now the possible solution are:

I hope it help other people.

genusistimelord commented 1 year ago

They did get the changes requested though but have not updated the crate yet. the fixes do help with any none wasm based applications to load fonts correctly. If you are using WASM with iced just note that you must manually load all the fonts you need.

rijkvp commented 1 year ago

Thanks @ph, I fixed this on NixOS by changing the cosmic-text dependency to the following in tiny_skia/Cargo.toml:

cosmic-text = { git = "https://github.com/pop-os/cosmic-text", branch = "main" }
gurinderu commented 1 year ago

Still have the same issue in the main branch