PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 8:08 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue May 02, 2023 1:54 pm 
Offline

Joined: Tue May 02, 2023 1:46 pm
Posts: 3
Hello,

I'm asking for help to understand how the FailsafeFontResolver class works.
PDFsharp-MigraDoc 6.0.0-preview-2 on Windows is used.
Does this line of code
Code:
var result = PlatformFontResolver.ResolveTypeface(familyName, isBold, isItalic);

load the specified font if it is installed in the system?
In other words, if Arial is specified for the document and Arial is installed, can I use FailsafeFontResolver to load it?

Link to GItHub:
https://github.com/empira/PDFsharp/blob ... ver.cs#L24


Top
 Profile  
Reply with quote  
PostPosted: Tue May 02, 2023 2:21 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
Some background information: When your code is used under Windows only, you can use the GDI build or the WPF build and the default font resolver will load Arial from the Windows folder without any preparations in your code.

The Core build can run under Linux, Windows, Mac, you name it. To use Arial, you must provide the Arial files in some form.

The idea of the FailsafeFontResolver is that it will not throw exceptions. It will not load "Arial" or "Donald" or "Comic Sans", but it will return a font for any name you are asking.

See also:
viewtopic.php?f=8&t=3244
viewtopic.php?f=8&t=3073

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed May 03, 2023 6:32 am 
Offline

Joined: Tue May 02, 2023 1:46 pm
Posts: 3
So, if I understand the answer correctly, FailsafeFontResolver returns the built-in Segoe WP font for any requested font name.
My code have to work on Windows and Linux. For testing, Windows and Arial are used to ensure that the font is installed.

The desired resolver should behave as follows:
1. Work on Windows and Linux.
2. Load fonts used in a particular MigraDoc.DocumentObjectModel.Document, or according to the list of font names.
3. Provide the built-in default font if the requested fonts cannot be loaded.

If there currently a resolver that works like that or closely?
Is it a part of PDFsharp library on .NET6?


Top
 Profile  
Reply with quote  
PostPosted: Wed May 03, 2023 6:41 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
qurious wrote:
In other words, if Arial is specified for the document and Arial is installed, can I use FailsafeFontResolver to load it?
Maybe try NewFontResolver. Name and/or behaviour may change with future releases.

But note that the behaviour of NewFontResolver is platform-dependent.
If your app is for Windows only, then consider using the WPF or GDI build.
If your app is for all platforms, then NewFontResolver will lead to problems with Linux and Mac. So test everywhere and come up with a fallback strategy.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed May 03, 2023 7:19 am 
Offline

Joined: Tue May 02, 2023 1:46 pm
Posts: 3
Thank you!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Mcartwrite and 158 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group