How can I use a TTF file to apply a custom font to the application?

I read the documentation of Iced on docs.rs. But, I could not learn how to apply a custom font from a TTF file. AI Chatbots answer for previous versions of Iced.
My apps needs to render Arabic. So please help me.

You can use the Settings of your application to specify fonts. Settings in iced::settings - Rust

I have tried passing the bytes of the ttf file to the font function of the Application struct. That did not work. Can you please provide me with some more details?

This works:

iced::application(...)
.font(include_bytes!("../fonts/FontName.ttf").as_slice())

and then you can:

const MY_FONT: Font = Font::with_name("FontName");

text("blabla").font(MY_FONT)

Can you please specify what kind of issue you experience with the above?

Here is the code and the problem.
Thanks a lot for the help.


Maybe the limited support for Vulkan is to blame.

I tested this, works OK for me both as a plain text and in other widgets (e.g. button):
image
What I did:

  1. Downloaded the font your are using from Google Fonts
  2. Doubled check the actual font name (Noto Naskh Arabic is correct)
  3. attached font to the app: .font(include_bytes!("../fonts/NotoNaskhArabic.ttf").as_slice())
  4. Create a font constant:
const TEST_FONT: Font = Font::with_name("Noto Naskh Arabic");
  1. Used the font:
text("ولما كانتيولد").font(TEST_FONT).size(18)

same in button:

button(text("ولما كانتيولد").font(TEST_FONT).size(18))