User avatar
goldsaucer
Topic Author
Posts: 13
Joined: 06 Dec 2018, 17:53

Noesis and FontAwesome

17 Dec 2018, 10:07

Hey,

I'm trying to use FontAwesome in my noesis project. I put it into our theme like this:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <FontFamily x:Key="FontAwesome">UIAssets/Fonts/FontAwesome.ttf#FontAwesome</FontFamily>
</ResourceDictionary>
Then I'm trying to use it in a label like this:
<Label FontFamily="#FontAwesome" FontSize="{Binding TitleFontSize, FallbackValue=48}">Play</Label>
At first I wasn't sure if that syntax was even going to find the font file but it does.
But then it fails making a font family out of that anyway.
We're getting the following exception:
NoesisException: Assets/MyTheme.xaml(38): Can't convert 'UIAssets/Fonts/FontAwesome.ttf#FontAwesome' into a 'FontFamily' object.
Rethrow as NoesisException
Noesis.Error.Check () (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:17)
Noesis.GUI.Noesis_LoadComponent_ (System.Runtime.InteropServices.HandleRef component, System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:282)
Noesis.GUI.LoadComponent (System.Object component, System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:135)
[...]
(wrapper dynamic-method) System.Object.lambda_method(System.Runtime.CompilerServices.Closure)
Noesis.Extend.CreateInstance (System.IntPtr nativeType, System.IntPtr cPtr) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:3933)
Rethrow as NoesisException
Noesis.Error.Check () (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:17)
Noesis.GUI.Noesis_LoadXaml_ (System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:275)
Noesis.GUI.LoadXaml (System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:125)
NoesisXaml.Load () (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:31)
NoesisView.LoadXaml (System.Boolean force) (at Assets/NoesisGUI/Plugins/NoesisView.cs:333)
NoesisView.OnEnable () (at Assets/NoesisGUI/Plugins/NoesisView.cs:398)
I used the ttf file from: https://github.com/FortAwesome/Font-Awe ... id-900.ttf

What am I doing wrong?
 
User avatar
sfernandez
Site Admin
Posts: 1524
Joined: 22 Dec 2011, 19:20

Re: Noesis and FontAwesome

17 Dec 2018, 12:37

Hi,

I don't know if you renamed it, but if I download the file its name is fa-solid-900.ttf.
And after the # you have to write the font family name exposed by the ttf, in that font it is 'Font Awesome 5 Free'.

The following syntax should work:
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <FontFamily x:Key="FontAwesome">UIAssets/Fonts/fa-solid-900.ttf#Font Awesome 5 Free</FontFamily>
</ResourceDictionary>
Apart from that, when using the font, you should reference it as an StaticResource.
<Label FontFamily="{StaticResource FontAwesome}" FontSize="{Binding TitleFontSize, FallbackValue=48}">Play</Label>
Let us know if this works.
 
User avatar
goldsaucer
Topic Author
Posts: 13
Joined: 06 Dec 2018, 17:53

Re: Noesis and FontAwesome

17 Dec 2018, 13:49

Yeah I renamed the file. I used the original file now and still get this error:
NoesisException: Assets/MyTheme.xaml(38): Can't convert '/Assets/UIAssets/Fonts/fa-solid-900.ttf#Font Awesome 5 Free' into a 'FontFamily' object.
Rethrow as NoesisException
Noesis.Error.Check () (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:17)
Noesis.GUI.Noesis_LoadXaml_ (System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:275)
Noesis.GUI.LoadXaml (System.String xaml) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:125)
NoesisXaml.Load () (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:31)
NoesisUnity.LoadApplicationResources () (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:34)
UnityEngine.Debug:LogException(Exception)
NoesisUnity:LoadApplicationResources() (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:47)
NoesisUnity:Init() (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:24)
NoesisXaml:RegisterDependencies() (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:55)
NoesisXaml:OnEnable() (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:10)
with
<FontFamily x:Key="FontAwesome">/Assets/UIAssets/Fonts/fa-solid-900.ttf#Font Awesome 5 Free</FontFamily>
Could it be that Noesis simply can't find the file and we have to put it into the streaming assets somehow?
 
User avatar
sfernandez
Site Admin
Posts: 1524
Joined: 22 Dec 2011, 19:20

Re: Noesis and FontAwesome

17 Dec 2018, 14:31

I just tried with an absolute path and it works fine also.

Could you verify if the NoesisFont asset was generated for the ttf?
Go to /Assets/UIAssets/Fonts/, right-click fa-solid-900.ttf, and select Reimport. It should generate a fa-solid.asset next to it.
Now got to /Assets/MyTheme.xaml and reimport it too. Is it working now?
 
User avatar
goldsaucer
Topic Author
Posts: 13
Joined: 06 Dec 2018, 17:53

Re: Noesis and FontAwesome

20 Dec 2018, 09:17

There's definitely an .asset file for the font and for the theme xaml too. I get the same error as above when I reimport the theme. :S

I'll try to create a self-contained project to reproduce the issue independently from our project.
 
User avatar
sfernandez
Site Admin
Posts: 1524
Joined: 22 Dec 2011, 19:20

Re: Noesis and FontAwesome

20 Dec 2018, 09:56

Ok, if you can isolate the problem in a small example, could you please report it in our bugtracker attaching that project?
Thanks.

Who is online

Users browsing this forum: No registered users and 5 guests