Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use a font that is an Avalonia resource? #56

Open
bmscodespace opened this issue Oct 7, 2024 · 4 comments
Open

How to use a font that is an Avalonia resource? #56

bmscodespace opened this issue Oct 7, 2024 · 4 comments

Comments

@bmscodespace
Copy link

Hi,

thank you all for the HtmlRenderer project. Is there a way to use as "font-family" a font that is registered in the Avalonia resources? F.e. I have added "Work Sans" to my resources and now want to do something like

<Style Selector="html|HtmlLabel">
            <Setter Property="BaseStylesheet" Value="* { font-family: 'Work Sans'; src: url(???)}" />
</Style>

where I at the moment don't know what to write in place of "???".
Thank you very much for any help ;)

@maxkatz6
Copy link
Member

maxkatz6 commented Oct 7, 2024

In HtmlContainer class, there is AddFontFamilyMapping method.
You can map your CSS font name to Avalonia font with this method.

@bmscodespace
Copy link
Author

bmscodespace commented Oct 8, 2024

"In HtmlContainer class, there is AddFontFamilyMapping method. You can map your CSS font name to Avalonia font with this method."

Oh, thank you, I will try that out ;)

Hm, it seems that the nuget package (i installed it using
dotnet add package Avalonia.HtmlRenderer --version 11.0.0
) seems to be not as up to date as the code in the repository. There seems to be no function AddFontFamilyMapping in the HtmlContainer class of the package. Is it possible to solve my problem above using the package?

@bmscodespace
Copy link
Author

bmscodespace commented Oct 8, 2024

ps .. using the package, I have tried the following:
I added the font using
HtmlRender.AddFontFamily(new FontFamily(new Uri("avares://..../Assets/Fonts#Work Sans"), "Work Sans"));
before the xaml is loaded and then tried to use the font
as follows:

<html:HtmlLabel
      Name = "SomeTestLabel"
      Margin="8,8,8,8"
      Text="Some Text"
      BaseStylesheet="* { font: 15.35px 'Work Sans'; color: #111; }"
 />

But somehow sadly it did not work, hm ....

@bmscodespace
Copy link
Author

Hi again.
Will the nuget package be updated to the current code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants