CSharpMath icon indicating copy to clipboard operation
CSharpMath copied to clipboard

Text wrapping does not work properly for accented characters

Open MartinZikmund opened this issue 6 years ago • 47 comments

Describe the bug

Text wrapping does not properly work for accented characters like ěščřžýáíé.

To Reproduce

  1. Open sample app for Xamarin.Forms
  2. Select Text tab
  3. Enter: ščěěščž čšřžščřž čšřžščř čšřžščř čšřžščř čšřžščř čšřžščř
  4. Resize the window. Notice the line breaks anywhere within the "words"

Expected behavior

Words with accented characters should not be broken between lines.

Environment (please complete the following information):

  • Platform: CSharpMath.SkiaSharp (in general, not just XF)
  • Package Version or Commit: latest
  • Device: Windows

MartinZikmund avatar Jun 21 '20 10:06 MartinZikmund

@prepare Probably a bug of Typography.TextBreak.

Happypig375 avatar Jun 21 '20 14:06 Happypig375

Confirmed a bug of Typography.TextBreak.

Happypig375 avatar Jun 21 '20 15:06 Happypig375

This Typography bug was fixed,

see => https://github.com/LayoutFarm/Typography/commit/f350e2268ab2236d07d58a49647cf1e60a6764c4

include_extenedLatin

prepare avatar Jun 22 '20 06:06 prepare

@prepare Thanks a lot!

MartinZikmund avatar Jun 22 '20 06:06 MartinZikmund

Still need to fix this for diacritics via LaTeX commands instead of Unicode, i.e. a\r aa should be one group.

Happypig375 avatar Jun 22 '20 07:06 Happypig375

Screenshot_1593169397 That's what happen when I try to show chinese text (appear squares), is this relate to this issue?

BenjaNapo avatar Jun 26 '20 11:06 BenjaNapo

You should provide your own font like in #142.

Happypig375 avatar Jun 26 '20 11:06 Happypig375

@BenjaNapo See https://github.com/verybadcat/CSharpMath/issues/20.

Happypig375 avatar Jun 26 '20 11:06 Happypig375

@BenjaNapo See #20.

I wrote in the constructor of App.cs: CSharpMath.Settings.GlobalTypefaces = new Typography.OpenFont.OpenFontReader().Read(File.Open("Cabin-Regular.ttf", FileMode.Open));

but it says that GlobalTypefaces is an onlyread attribute

BenjaNapo avatar Jun 26 '20 13:06 BenjaNapo

For GlobalTypefaces, you call Add.

Happypig375 avatar Jun 26 '20 13:06 Happypig375

For GlobalTypefaces, you call Add.

App.xaml

           <OnPlatform x:Key="Regular" x:TypeArguments="x:String">
               <On Platform="Android" Value="Cabin-Regular.ttf#Cabin" />
               <On Platform="iOS" Value="Cabin-Regular" />
           </OnPlatform>

App.cs

       public App()
       {
           InitializeComponent();
           [... various initialization ...]
           object s = new object();
           Resources.TryGetValue("Regular", out s);
           CSharpMath.Settings.GlobalTypefaces.Add(new Typography.OpenFont.OpenFontReader().Read(s as Stream));
       }

Sorry but I never imported Font from code, where did I go wrong?

BenjaNapo avatar Jun 26 '20 17:06 BenjaNapo

Are you trying to override the font? The default is AddSupplement. For overrides, use AddOverride.

Happypig375 avatar Jun 27 '20 02:06 Happypig375

Are you trying to override the font? The default is AddSupplement. For overrides, use AddOverride.

Changed with:

            object s = new object();
            Resources.TryGetValue("Regular", out s);
            Typeface t = new Typography.OpenFont.OpenFontReader().Read(s as Stream);
            CSharpMath.Settings.GlobalTypefaces.AddOverride(t);

But 3rd line throws ArgumentNullException, I think that the problem is in reading font file in this way

BenjaNapo avatar Jul 03 '20 09:07 BenjaNapo

The null means that s is probably not a Stream. Please check.

Happypig375 avatar Jul 03 '20 10:07 Happypig375

        public async void LoadFont() {
            using (var stream = await FileSystem.OpenAppPackageFileAsync("Helvetica-Bold.otf"))
            {
                Typeface t = new Typography.OpenFont.OpenFontReader().Read(stream as Stream);
                CSharpMath.Settings.GlobalTypefaces.AddOverride(t);
            }
        }

Now it loads the font from the stream but crash on the 4th line (Typeface t = ...) throwing this exception: System.NotSupportedException: 'Specified method is not supported.'

BenjaNapo avatar Jul 14 '20 17:07 BenjaNapo

Try following https://github.com/verybadcat/CSharpMath#sourcelink-for-ci-packages and debug into the source of Typography.

Happypig375 avatar Jul 14 '20 17:07 Happypig375

@BenjaNapo Or you can upload a zipped file containing your file and let me investigate what changes are needed from Typography's side.

Happypig375 avatar Jul 16 '20 15:07 Happypig375

This bug's fix depends on a decision on updating Typography in LayoutFarm/Typography#192. The fix for

Still need to fix this for diacritics via LaTeX commands instead of Unicode, i.e. a\r aa should be one group.

is scheduled after #143 and #58.

Happypig375 avatar Jul 16 '20 15:07 Happypig375

https://drive.google.com/file/d/1zlvyQ2XXvb0fQJ8k-otYZ4hiR_8L3H-d/view?usp=sharing

Here you are, with this you could note all the issues that I had 'til now (text alignment, change font and height of textview)

Thanks for all the help ^^ Hope this will contribute with the evolution of the library

BenjaNapo avatar Jul 16 '20 16:07 BenjaNapo

@BenjaNapo #144 should fix "text alignment" and "height of textview".

This leaves "change font" as to-do.

Thanks for all the help ^^ Hope this will contribute with the evolution of the library

Thank you for taking the time to report problems too!

Happypig375 avatar Jul 16 '20 17:07 Happypig375