Skip to content

Font Resolver is a cross-platform library to resolve font paths based on their font names

License

Notifications You must be signed in to change notification settings

eXpl0it3r/FontResolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Font Resolver

Font Resolver is a cross-platform library to resolve font paths based on their font names.

The library was originally developed to be used with PDFsharp. However, since resolving font files cross-platform can be useful in general, two separate packages have been created:

Goals

  • Resolve font files cross-platform
  • Keep the dependency graph minimal
  • Remain .NET Standard 2.0 compatible
  • Turn contributors into maintainers

Note: TrueType Collections (*.ttc) are not supported at the moment, as PDFsharp can't load them.

Install

Add the NuGet package to your project:

dotnet add package FontResolver

If you intend to use FontResolver with PDFsharp, use the FontResolver.PdfSharp package (which depends on FontResolver) instead:

dotnet add package FontResolver.PdfSharp

Usage

Standalone

using FontResolver;

// ...

var style = new FontStyle(bold: false, italic: false);
var font = FontResolver.Resolve("Arial", style with { Bold = true });

PDFsharp

using FontResolver.PdfSharp;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;

// ...

// Before rendering the PDF document call
FontResolverPdfSharp.Register();

// Or alternatively register the font resolver yourself
GlobalFontSettings.FontResolver = new FontResolverPdfSharp();

// ...

var migraDocDocument = new Document();
migraDocDocument.AddSection();
// ...

var renderer = new PdfDocumentRenderer
{
    Document = migraDocDocument
};
renderer.RenderDocument();

var pdfDocument = renderer.PdfDocument;
pdfDocument.Save("file.pdf");

Register Custom Font Directories

You can register custom font directories to be searched by the font resolver:

FontResolver.RegisterFontDirectory("path/to/custom/directory/with/fonts");

// Or for PDFsharp
FontResolverPdfSharp.RegisterFontDirectory("path/to/custom/directory/with/fonts");

Discover Font Families

Discover all the font families available on the system:

var fontFamilies = FontResolver.DiscoverFontFamilies();

License

FontResolver is licensed under the MIT license, see the LICENSE file.

About

Font Resolver is a cross-platform library to resolve font paths based on their font names

Resources

License

Stars

Watchers

Forks

Languages