davidxuang / FluentIcons

A multi-framework wrapper of https://github.com/microsoft/fluentui-system-icons
MIT License
72 stars 6 forks source link

Issue with RTL language support #4

Closed KeyMetricSoft closed 7 months ago

KeyMetricSoft commented 7 months ago

Hello,

I have a WPF application that uses FluentIcons, and recently came across an interesting issue. A user sent me a screenshot of my application with all the icons either missing entirely or incorrectly positioned.

I struggled to reproduce the problem at first, but eventually tracked it down to his use of Arabic as his system display language.

I believe the problem is with this line of code in the SymbolIcon class:

_formattedText = new FormattedText( Symbol.ToString(IsFilled), CultureInfo.CurrentCulture, CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight, _font, FontSize, Foreground, VisualTreeHelper.GetDpi(this).PixelsPerDip);

As you can see, the FlowDirection of the FormattedText object is changed based on the current culture, but I believe WPF always defaults to FlowDirection.LeftToRight.

I pulled the code into a local repo and changed it to pass FlowDirection.LeftToRight as the third argument to the FormattedText constructor. Doing so resolved the problem, and allowed the icons to appear correctly on the user's Arabic language system.

Interestingly, even if I change the FlowDirection of my entire application the icons will only appear (on systems using Arabic language) if I use the code change described above. They never show otherwise, regardless of FlowDirection.

I'm not sure if my testing is thorough enough to warrant a permanent code change, but I wanted to share the results of my tests in case they help someone else.

davidxuang commented 7 months ago

Could you test the patch (27e3d27eb97bf0e45cd15649cf4b539a76432c61) please?

Interestingly, even if I change the FlowDirection of my entire application the icons will only appear (on systems using Arabic language) if I use the code change described above. They never show otherwise, regardless of FlowDirection.

Maybe it's that you changed FlowDirection instead of CultureInfo.CurrentCulture. The former will defaults to the latter, but changing the former will not affect the latter (your locale).

KeyMetricSoft commented 7 months ago

Hi David,

After testing in various language environments, I can confirm that your patch corrects the issue.

Thanks for your rapid response to this problem.