empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.27k stars 588 forks source link

[Feature request] Support for changing FontResolver #72

Closed LokiMidgard closed 5 years ago

LokiMidgard commented 5 years ago

If you once set GlobalFontSettings.FontResolver you can't change it.

I have a Project that gets inputs from different sources which can bring there own fonts. Because the different sources can use the same name for different fonts, the easiest way would be create a font resolver for any input and than switching the GlobalFontSettings.FontResolver. The library would then automatically invalidate all caches.

I currently see only two work arounds:

  1. Create an lookup for any font to an unique generated font name, so no font from any source will have the same name internally.
  2. Create a new AppDomain and tear it down.

Unfortunately I can't use 2 and using one will eventually run out of memory, because the internal cache will only grow and never shrinks until the process is terminated.

TH-Soft commented 5 years ago

It is by design that the FontResolver cannot be changed. Using AppDomains is the recommended solution if you cannot have it all in one FontResolver.
That's how the software architect wanted to have it.