Jump to content
LaunchBox Community Forums
Jason Carr

Including Custom Fonts without Custom DLLs

Recommended Posts

Hello all, my latest goal was to figure out a solution for theme developers for all three types of themes to be able to include custom fonts without having to create a custom plugin/DLL or requiring the end user to manually install them. Microsoft really made it way more of a pain than it should have been, so I was struggling with it for hours, but I finally have a good solution. Unfortunately it did require changes to the LaunchBox codebase, so this solution will only work going forward, for LaunchBox/Big Box 9.6-beta-7 and later.

Previously it was not possible to automatically include custom fonts in startup themes, as plugins are not currently supported. This solution will allow you to use custom fonts in startup themes without requiring the user to manually install them, and this solution can be used for LaunchBox and Big Box themes as well (it's also now the recommended method).

Here's an example of a TextBlock with a custom font:

<TextBlock FontFamily="LAUNCHBOX_ROOT_FOLDER/Startup Themes/ExampleTheme/Blazed.ttf#Blazed" />

Obviously, only the FontFamily property is important here. It always starts with "LAUNCHBOX_ROOT_FOLDER", as LaunchBox and Big Box will automatically replace this with the LaunchBox folder, wherever it is located. This part was necessary because of Microsoft's bugs/security workarounds, none of which make sense, but it's impossible to load a font from a relative path in XAML without including it in a project or DLL, so LaunchBox just replaces this part with the full path to the LaunchBox folder.

In the above case, the "LaunchBox\Startup Themes\ExampleTheme\Blazed.ttf" font will be used for that TextBlock element. Note the "#Blazed" portion at the end however; unfortunately you also have to include the pound sign, followed by the name of the font. You can find the name of the font by simply double-clicking the font file in Windows, and the name of the font will be displayed at the top of the Font Viewer application, next to "Font name:". I'm not sure why this is necessary, but it's another requirement in order to get the fonts working properly.

Next, let's take a look at an example with a space in the font file and/or the font name:

<TextBlock FontFamily="LAUNCHBOX_ROOT_FOLDER/Startup Themes/ExampleTheme/Hearty Script.ttf#Hearty Script" />

Simply putting it in as expected with spaces does work, so that should not be a concern.

Let me know if anyone runs into any issues. I will say that I did find one font that just refused to work with WPF period, so if you can't seem to make it work, do try another font. Unfortunately it seems there are some fonts out there that are either just poorly made or incompatible with WPF for one reason or another.

Thanks again all. Calling you all out here so that everyone is aware of this new feature.

@faeran @Mr. RetroLust @RetroHumanoid @wallmachine @eatkinola @bbweiners @keltoigael @Jack. @y2guru @whoozwah @SNAK3ATER @Rincewind @CriticalCid @shro2016 @broskiplays @Grila @NJDave71 @Hexxxer @PhillsDoodles @Zombeaver @Omen @Cookz718 @viking @OrochiMishima @nosh @ea4492 @Maddoc1007 @vsilvalopes @damageinc86 @walter10h @skainlurmis @Scottad @Nyny77 @Sithel @Akezhar @Thanos Reigns

  • Like 5
  • Thanks 3

Share this post


Link to post
Share on other sites

Works like a charm Jason!!   one question though...

currently i generate the code in the same way as @wallmachine for example.. 

Value="LAUNCHBOX_ROOT_FOLDER/Themes/PASC/Fonts/Let_s_go_Digital.ttf#Let's go Digital"

and this works great when in BigBox, but when the Theme is ready for submission/review, should the code look like the following ?

Value="LAUNCHBOX_ROOT_FOLDER/Startup Themes/PASC/Let_s_go_Digital.ttf#Let's go Digital"

 

 

Share this post


Link to post
Share on other sites
On 3/19/2019 at 4:43 AM, wallmachine said:

This works for me only in PlatformWheel1FiltersView.xaml however not in the TextListView.xaml.

PlatformWheel1FiltersView.xaml:
image.thumb.png.74c6db48624bef3789409581303fe83c.png


<TextBlock Text="{Binding Path=ActivePlatform.TotalGameCount}" FontFamily="LAUNCHBOX_ROOT_FOLDER/Themes/Pandora/Fonts/Digital-Serial.ttf#Digital-Serial" />
<TextBlock Text=" GAMES AVAILABLE" FontFamily="LAUNCHBOX_ROOT_FOLDER/Themes/Pandora/Fonts/Digital-Serial.ttf#Digital-Serial" />

 

TextListView.xaml:
image.thumb.png.0b145b9ddf83e1e47faf8907ecff4f38.png


<Setter Property="FontFamily" Value="LAUNCHBOX_ROOT_FOLDER/Themes/Pandora/Fonts/Digital-Serial.ttf#Digital-Serial" />
<Setter Property="Typography.Capitals" Value="AllSmallCaps" />

 

I'm confused here as to what's wrong. First I tested putting the new font solution in a copy of the default theme, in the TextListView.xaml, and it shows up just fine with that font. Then I loaded up your theme and it appears to be working properly with the font and the new solution. What am I missing? As far as I can tell, everything is working properly.

Share this post


Link to post
Share on other sites
3 hours ago, y2guru said:

Works like a charm Jason!!   one question though...

currently i generate the code in the same way as @wallmachine for example.. 

Value="LAUNCHBOX_ROOT_FOLDER/Themes/PASC/Fonts/Let_s_go_Digital.ttf#Let's go Digital"

and this works great when in BigBox, but when the Theme is ready for submission/review, should the code look like the following ?

Value="LAUNCHBOX_ROOT_FOLDER/Startup Themes/PASC/Let_s_go_Digital.ttf#Let's go Digital"

 

 

@y2guru It depends on whether you're creating a Startup Theme or a Big Box Theme. The different types of themes go into different folders.

Share this post


Link to post
Share on other sites
Posted (edited)
On 3/21/2019 at 5:32 AM, Jason Carr said:

I'm confused here as to what's wrong. First I tested putting the new font solution in a copy of the default theme, in the TextListView.xaml, and it shows up just fine with that font. Then I loaded up your theme and it appears to be working properly with the font and the new solution. What am I missing? As far as I can tell, everything is working properly.

In the TextListView.xaml it never lets me put it as uppercase font for the game names however the A-Z search is uppercase and text in Platform views.

What it should look like.

 

 

Edited by wallmachine

Share this post


Link to post
Share on other sites
3 minutes ago, wallmachine said:

In the TextListView.xaml it never lets me put it as uppercase font for the game names however the A-Z search is uppercase.

What it should look like.

image.thumb.png.15650daa30836ca925d7540b89f4e2d4.png

 

I see. So the uppercase thing is a separate issue than the font not loading. I was under the impression that the fonts were not loading as expected. At least we can cross that issue off the list.

I'll do some quick research to see what might be going on with the uppercase thing.

Share this post


Link to post
Share on other sites

Just to clarify here for everyone in this thread, the new font solution above is working properly everywhere. @wallmachine's issue is an unrelated thing.

@wallmachine After looking at your code, I'm guessing you'll probably need to set the all caps thing inside the ListBoxItemStyle instead of the ListBoxStyle, and you might need to put it deeper down into the template as well.

Share this post


Link to post
Share on other sites
10 hours ago, Jason Carr said:

@wallmachine After looking at your code, I'm guessing you'll probably need to set the all caps thing inside the ListBoxItemStyle instead of the ListBoxStyle, and you might need to put it deeper down into the template as well.

already tried that

Share this post


Link to post
Share on other sites

heck to the yes, this is way better than wrapping things in a .dll. I will go ahead and start making changes and get it ready for release.

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, keltoigael said:

heck to the yes, this is way better than wrapping things in a .dll. I will go ahead and start making changes and get it ready for release.

Thank you keltoi! I'm also excited to get all your themes up in the themes manager. The uploader is now available as well. :)

Share this post


Link to post
Share on other sites
12 hours ago, wallmachine said:

already tried that

Unfortunately I can't tinker with it for the moment; I just have too much stuff going on. If anyone's willing to help out wallmachine with a XAML styling issue, please speak up. :)

Share this post


Link to post
Share on other sites
9 minutes ago, keltoigael said:

heck to the yes, this is way better than wrapping things in a .dll. I will go ahead and start making changes and get it ready for release.

I second that! a very elegant solution!

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for this feature! Does it work with a plugin? I tried this but doesn't work

 

        <lbsc:GameList Name="Items" FontSize="15" FontFamily="LAUNCHBOX_ROOT_FOLDER/Startup Themes/CityHunter 2/Fonts/Blazed.ttf#Blazed">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <cal:ActionMessage MethodName="OnEnter" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </lbsc:GameList>

 

Share this post


Link to post
Share on other sites
25 minutes ago, Artik said:

Thanks for this feature! Does it work with a plugin? I tried this but doesn't work

 


        <lbsc:GameList Name="Items" FontSize="15" FontFamily="LAUNCHBOX_ROOT_FOLDER/Startup Themes/CityHunter 2/Fonts/Blazed.ttf#Blazed">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <cal:ActionMessage MethodName="OnEnter" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </lbsc:GameList>

 

I'm guessing that setting the FontFamily on that control just doesn't work, as it specified somewhere further up the XAML tree.

Share this post


Link to post
Share on other sites

But I'm also trying in a classic bloc, couldn't get it working. Here is my FilterDetailsView.xaml bloc:

			<TextBlock Text="Details" FontFamily="LAUNCHBOX_ROOT_FOLDER/Startup Themes/CityHunter 2/Blazed.ttf#Blazed" FontSize="40" TextWrapping="Wrap" DockPanel.Dock="Top"  >
				<TextBlock.Foreground>
					<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
						<GradientStop Color="#FFFE1C1C" Offset="1"/>
						<GradientStop Color="#FFFF3737"/>
					</LinearGradientBrush>
				</TextBlock.Foreground>
			</TextBlock>

Font "Blazed.ttf" is at the root of my "CityHunter 2" folder in "Themes", and new font is not applied

ulWUQMF.png

 

And latest 9.6 version.

Don't know what am I doing wrong

Share this post


Link to post
Share on other sites

@Artik We have it confirmed working for several people, so there has to be some kind of discrepancy somewhere. Where did you get that Blazed font? Did you rename the font file from something else?

Hold up, nevermind. You have the file path wrong.

Share this post


Link to post
Share on other sites
Posted (edited)

Checked again and again, but I don't see where the path is wrong :S

(Font downloaded from Dafont, and I checked the name. "#Blazed" is correct)

Edited by Artik

Share this post


Link to post
Share on other sites
1 minute ago, Artik said:

Checked again and again, but I don't see where the path is wrong :S

(Font downloaded from Dafont, and name #Blazed" is correct)

Startup Themes vs. Themes.

Share this post


Link to post
Share on other sites

I can't believe ..... Tought was part of the synthax! It works now, thanks for help.

I continue my work, and here another question I have. Still in the gamelisting, Can I change the font and size using the same .ttf ?

(it's temporary small on purpose, and I'm using the "ListBox Scroll Center for BigBox" plugin to manage the fontsize. Is there a way to combine both for this listing? Custom font and small font size? Spent hours without success)

apXDdmx.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...