ActiveReports 15 .NET Edition
ActiveReports 15 User Guide / Concepts / Custom Font Resolver
In This Topic
    Custom Font Resolver
    In This Topic

    With the Custom Font Resolver, you can configure fonts for Page, RDL, and Section reports (in the CrossPlatform compatibility mode) on different platforms.

    Note: Custom font settings have higher priority over default font settings.

    You must specify the FontResolver property in the Windows Forms and the JavaScript Viewers as in the following code example. 

    Copy Code
    app.UseReporting(config => {
      config.FontResolver = ...
      config.UseFileStore(ResourcesRootDirectory)
    }); 
    

    You can configure fonts for preview and export on all platforms without installation as in the following examples. 

    Copy Code
    public sealed class WindowsFontResolver : GrapeCity.ActiveReports.IFontResolver
    {
       static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection();
       static WindowsFontResolver()
       {
            GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(_fonts, true);
            _fonts.DefaultFont = _fonts.FindFamilyName("Arial");
       }
       public static GrapeCity.ActiveReports.IFontResolver Instance = new WindowsFontResolver();
       private WindowsFontResolver() { }
       GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
       {
            var fonts = new GrapeCity.Documents.Text.FontCollection();
            fonts.Add(_fonts.FindFamilyName(familyName, isBold, isItalic) ?? _fonts.DefaultFont);
            GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateEudcLinks(fonts);
            return fonts;
       }
    }                        
    

     

    Copy Code
    public sealed class DirectoryFontResolver : GrapeCity.ActiveReports.IFontResolver
    {
       static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection();
       static DirectoryFontResolver()
       {
          // see https://developers.redhat.com/blog/2018/11/07/dotnet-special-folder-api-linux/
          _fonts.RegisterDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts));
          _fonts.DefaultFont = _fonts.FindFamilyName("Arial");
       }
       public static GrapeCity.ActiveReports.IFontResolver Instance = new DirectoryFontResolver();
       private DirectoryFontResolver() { }
       GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
       {
          var fonts = new GrapeCity.Documents.Text.FontCollection();
          var font = _fonts.FindFamilyName(familyName, isBold, isItalic);
          if (font != null) fonts.Add(font);
          fonts.Add(_fonts.DefaultFont);
          return fonts;
       }
    }                       
    

    To learn about how to configure custom fonts in the ActiveReports.config file, see ActiveReports Configuration File.

    If you need to link just one font to another (for example, link an EUDC font to an installed font), you can do it with just GcDocs API (GcImaging and GcPdf), using the following code.

    PASTE to the beginning of the Main function
    Copy Code
    GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(null, true);
    var fonts = new System.Collections.Generic.List();
    GrapeCity.Documents.Text.FontCollection.SystemFonts.SelectByFamilyName("MS UI Gothic", fonts);
    if (fonts.Count > 0)
     { 
    
        var eudcFonts = new GrapeCity.Documents.Text.FontCollection();
        using (var stream = new System.IO.FileStream(@"C:\EudcFonts\DFHSG3J.tte", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
        eudcFonts.LoadFonts(stream);
        foreach (var font in fonts)
          { 
    
            font.ClearEudcFontLinks();
            foreach (var eudcFont in eudcFonts) font.AddEudcFont(eudcFont); 
          }
      }