Samsung / Tizen.CircularUI

Tizen Wearable CircularUI project is to develop an open source software motivate software developer to creating Tizen Wearable Xamarin Forms app more easily and efficiently.
Other
80 stars 32 forks source link

Custom fonts not working in Tizen .NET #139

Closed Digifais closed 5 years ago

Digifais commented 5 years ago

Custom fonts are not working in Tizen .NET as described by the following guide: https://samsung.github.io/Tizen.CircularUI/guide/HowToSetTheCustomFont.html

    class Program : Xamarin.Forms.Platform.Tizen.FormsApplication
    {
        protected override void OnCreate()
        {
            base.OnCreate();

            Utility.AppendGlobalFontPath(Current.DirectoryInfo.Resource);

            LoadApplication(new App(new AppSetup()));
        }

        static void Main(string[] args)
        {
            var app = new Program();
            Xamarin.Forms.Platform.Tizen.Forms.Init(app);
            global::Tizen.Wearable.CircularUI.Forms.Renderer.FormsCircularUI.Init();
            app.Run(args);
        }
    }

I add the resources path as a global font path as described in the guide and then try to set the FontFamily of a Label control in XAML to the PostScript name of the font as described in the guide, but it doesn't do anything.

You can find the fonts in this ZIP file attached here: Lato Fonts.zip

rookiejava commented 5 years ago

/cc @yourina and @jkpu , PTAL

jkpu commented 5 years ago

Could you write your code of label that used the custom font(Lato font). Above code snippet has only including font resource using "Utility.AppendGlobalFontPath". In the guide, custom font postscriptname (e.g YiSunShinBold) should be inserted at Label code. please refer to below code.

 new Label {
       HorizontalTextAlignment = TextAlignment.Center,
       FontFamily = "YiSunShinBold",
       Text = "Welcome to Xamarin Forms!"
  }

$fc-query ./Lato-Bold.ttf

Pattern has 22 elts (size 32)
    family: "Lato"(s)
    familylang: "en"(s)
    style: "Bold"(s)
    stylelang: "en"(s)
    fullname: "Lato Bold"(s)

.............................

    decorative: False(s)
    hash: "sha256:14f7de6b616950395062902eb8f70f01c0a901223db5d40f2a05728ac4a830f6"(s)
    postscriptname: "Lato-Bold"(s)

You should insert FontFamily value with "Lato-Bold".

  new Label {
        HorizontalTextAlignment = TextAlignment.Center,
        FontFamily = "Lato-Bold",
        Text = "Welcome to Xamarin Forms!"
  }
Digifais commented 5 years ago

I am using XAML to build my layouts though. You can see an example snippet below which doesn't work either.

<Label
    Style="{StaticResource StyleBodyText}"
    FontFamily="Lato-Regular"
    Text="Test" />
jkpu commented 5 years ago

When I have tested with following to the guide. Custom font is working properly But only Lato font was not applied.

device default font device_default_font

Yisunshin font yisunsin_font

Lato font lato_font

Bloomsburg font bloomsburg_font

I'm attaching my test app code. please refer to the following code.

TizenWearableXamlApp2.zip

jkpu commented 5 years ago

When I have tested more font file with downloading from the internet. Some font file was not applied as "postscriptname". I found the way fixing this problem. Setting FontFamily property with real family name will work properly. and style can be set with FontAttribute property. (But Xamarin's FontAttribute property is enum value, so only enum value(Regular, Bold, Italic) can be applied ) Please refer to following code and attached test app code. You can find the way appliying your custom font.

  <Label Text="Lato Regular"
       FontFamily="Lato" />

  <Label Text="Lato Bold"
       FontFamily="Lato"
       FontAttributes="Bold" />

  <Label Text="Lato BoldItalic"
       FontFamily="Lato"
       FontAttributes="Bold, Italic" />

dump_screen

dump_screen2

TizenWearableXamlApp2.zip

Digifais commented 5 years ago

Thanks for the amazing support jkpu, I can confirm this does work!