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

Can't render arabic text in Labels, Buttons and other widgets #1819

Open
nomad-scl opened this issue Jun 5, 2021 · 8 comments
Open

Can't render arabic text in Labels, Buttons and other widgets #1819

nomad-scl opened this issue Jun 5, 2021 · 8 comments
Labels
shell/gtk concerns the GTK backend shell/win concerns the Windows backend shell/x11 concerns the X11 backend text

Comments

@nomad-scl
Copy link

basically if I try to do this :

let btn = Button::new("ابدأ");
let label = Label::new("عدد").padding(5.0).center();
Flex::column().with_child(btn).with_child(label)

the button and the label are in the form but the text is empty
also I tried using the arabic_reshaper crate (which works in terminal and in image proc to render arabic text correctly) like this

let btn = Button::new(arabic_reshape("ابدأ"));
let label = Label::new(arabic_reshape("عدد")).padding(5.0).center();
Flex::column().with_child(btn).with_child(label)

but the problem is the same

@psychon
Copy link
Contributor

psychon commented Jun 6, 2021

What backend are you using?

I just replaced "Clear" in the flex example with "ابدأ" and the result when run with the Gtk backend is... well, different than "but the text is empty":
foo

I get the same result with the x11 backend.

The same text looks different in my browser and yet again different in gvim (but at least there it does not "bleed into the surrounding").

@psychon
Copy link
Contributor

psychon commented Jun 6, 2021

I would guess that piet has some problems with right-to-left text.

diff --git a/druid/src/widget/label.rs b/druid/src/widget/label.rs
index cd3cb661..e717d07c 100644
--- a/druid/src/widget/label.rs
+++ b/druid/src/widget/label.rs
@@ -604,11 +604,13 @@ impl<T: TextStorage> Widget<T> for RawLabel<T> {
         self.layout.rebuild_if_needed(ctx.text(), env);
 
         let text_metrics = self.layout.layout_metrics();
+        println!("{:?}", text_metrics);
         ctx.set_baseline_offset(text_metrics.size.height - text_metrics.first_baseline);
         let size = bc.constrain(Size::new(
             text_metrics.size.width + 2. * LABEL_X_PADDING,
             text_metrics.size.height,
         ));
+        println!("{:?}", size);
         trace!("Computed size: {}", size);
         size
     }

results in

LayoutMetrics { size: 0.0W×18.0H, first_baseline: 14.0, trailing_whitespace_width: 20.0 }
4.0W×18.0H

A width of zero seems... insufficient.

Edit: Possibly related: linebender/piet#432

@raphlinus
Copy link
Contributor

We are definitely not officially supporting BiDi yet, but hope to in a future cycle.

@cmyr
Copy link
Member

cmyr commented Jun 7, 2021

This is also going to be highly backend specific. The situation may be worse on linux than on macos or windows. That said, RTL text (but not BiDi) is supported in piet, so it's possible this is just an error in the integration?

@nomad-rst can you confirm that you're on linux?

@cmyr cmyr added the text label Jun 7, 2021
@nomad-scl
Copy link
Author

nomad-scl commented Jun 7, 2021

I should have mentioned, I'm not on Linux, the issue I posted above is me using windows 10 x64
also regarding @psychon post above on what backend am I not using any backend I just added druid to my cargo.toml file and was able to run things from the examples

@cmyr
Copy link
Member

cmyr commented Jun 8, 2021

@nomad-rst when you run a druid app, druid auto-selects an appropriate 'backend' based on your platform; e.g. on windows it uses the windows backend. :)

@cmyr cmyr added the shell/win concerns the Windows backend label Jun 8, 2021
@psychon
Copy link
Contributor

psychon commented Jun 9, 2021

@cmyr Please also tag this with shell/gtk and shell/x11 as per #1819 (comment) (although this might also be a different issue, it still looks similar enough to me....)

@cmyr
Copy link
Member

cmyr commented Jun 11, 2021

Hmm interesting. This does appear to be working on macOS, so I'm not sure if these will end up being exactly the same bugs or not.

@cmyr cmyr added shell/gtk concerns the GTK backend shell/x11 concerns the X11 backend labels Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell/gtk concerns the GTK backend shell/win concerns the Windows backend shell/x11 concerns the X11 backend text
Projects
None yet
Development

No branches or pull requests

4 participants