solaris783
Topic Author
Posts: 5
Joined: 07 Oct 2019, 03:41

Specified Font not showing up

12 Oct 2019, 03:34

I have some xaml that works correctly in WPF but doesn't in Noesis. Working off of IntegrationGLUT from the SDK.

Simple control:
<ToggleButton  Content="&#xF06E;"  FontStyle="Normal"  FontWeight="Regular"  FontFamily="#Font Awesome 5 Free"  FontSize="10">
C++ code:
GUI::SetFontProvider(MakePtr<NoesisApp::LocalFontProvider>("../IntegrationGLUT-blend/Fonts/"));
Should have a character that looks like a little eye, but I get the "character not found" square instead: 

In the xaml, I tried putting a full path like:
FontFamily="../IntegrationGLUT-blend/Fonts/fa-solid-900.ttf#Font Awesome 5 Free Solid"
and other relative path combinations to no avail. Shows up in VS blend, not in Noesis.

No errors in the output window or console window .

Worth noting I tried not using LocalFontProvider and instead use this:
	EmbeddedFont fonts[] =
	{
		{ "Fonts", fa_solid_900_ttf, sizeof(fa_solid_900_ttf) },
	};
	Ptr<EmbeddedFontProvider> fp = MakePtr<EmbeddedFontProvider>(fonts, 1, fontProv);
	GUI::SetFontProvider(fp);
which yields the same results.

Edit: using LocalFontProvider fails because FamilyExists always returns false, no matter how I try to reference the font. I tried every type of URI available and not having a URI as well to no avail. ScanFolder successfully calls RegisterFont with "Fonts" as the folder and "fa-brands-900.ttf" as the filename (among others of the same family). There's no visibility in the Noesis library to see how these things are stored internally. EmbeddedFontProvider also returns false for FamilyExists.

eg:
EmbeddedFont fonts[] =
{
	{ "", fa_solid_900_ttf, sizeof(fa_solid_900_ttf) },
};
Ptr<EmbeddedFontProvider> fp = MakePtr<EmbeddedFontProvider>(fonts, 1, fontProv);
bool ret = ((FontProvider*)fp)->FamilyExists("", "#Font Awesome 5 Free Solid");
return false

Both LocalFontProvider and EmbeddedFontProvider call CachedFontProvider and I can't debug any further since that code is not visible (.cpp not provided)

EDIT2:
I got a version working by extending LocalFontProvider and hardcoding the base file directory to the Windows absolute path. Then in my xaml I use:
FontFamily="../IntegrationGLUT-blend/Fonts/fa-solid-900.ttf#Font Awesome 5 Free"
Not sure if this is the right way to do it.
For the EmbeddedFontProvider I defined it as having the same relative path as Local:
EmbeddedFont fonts[] =
{
	{ "../IntegrationGLUT-blend/Fonts", fa_solid_900_ttf, sizeof(fa_solid_900_ttf) },
};
then in xaml I use:
FontFamily="../IntegrationGLUT-blend/Fonts/fa-solid-900.ttf#Font Awesome 5 Free"
In making LocalFontProvider work, I saw a key assumption I was making was wrong.
LocalFontProvider *lfp = new LocalFontProvider("");
This statement assumes the directory referenced ("") is where the executable is OR when
running from VS, where the .vcxproj is.
doing this now:
FontFamily="../IntegrationGLUT-blend/Fonts/fa-solid-900.ttf#Font Awesome 5 Free"
will find it when running from VS.
I have to fix my paths now and VS Debugging settings such that it always looks in the same dir.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Specified Font not showing up

14 Oct 2019, 08:19

In making LocalFontProvider work, I saw a key assumption I was making was wrong.
LocalFontProvider *lfp = new LocalFontProvider("");
This statement assumes the directory referenced ("") is where the executable is OR when
running from VS, where the .vcxproj is.
The LocalFontProvider, whose source code is available and you can inspect and debug, uses the passed string to prepend it to all requests made to the provider. By default, the "", means, "open from the current working directory". You can adjust accordingly your working directory in Visual Studio while debugging.

Or you can even create your own implementation for your specific scenario.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Specified Font not showing up

14 Oct 2019, 08:21

By the way, I think this post is related and helpful here.

viewtopic.php?f=3&t=1828

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 9 guests