[]
        
(Showing Draft Content)

GrapeCity.ActiveReports.Document.SectionDocument.FontResolver

FontResolver Property

FontResolver

Gets or sets a value representing the implementation of the resolution of the font resources required to render a document in the CrossPlatform compatibility mode.

Declaration
[Browsable(false)]
public IFontResolver FontResolver { get; set; }
Property Value
Type Description
IFontResolver

An object that implements IFontResolver.

Remarks

A value of null indicates that the default resolver is used.

Examples

Custom font resolver implementation

public sealed class CustomFontResolver : GrapeCity.ActiveReports.IFontResolver
{
    static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection();
    static CustomFontResolver()
    {
        _fonts.RegisterDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts));
        _fonts.RegisterDirectory(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Microsoft/Windows/Fonts"));
        // required reference to DS.Documents.Imaging.Windows
        GrapeCity.Documents.Text.Windows.FontLinkHelper.UpdateFontLinks(_fonts, true);
        _fonts.DefaultFont = _fonts.FindFamilyName("Arial");
    }
    public static readonly GrapeCity.ActiveReports.IFontResolver Instance = new CustomFontResolver();
    private CustomFontResolver() { }
    GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic)
    {
        // suggested to cache values
        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;
    }
}

Set font resolver

var sectionDocument = new GrapeCity.ActiveReports.Document.SectionDocument();
sectionDocument.Load("Document.rdf");
sectionDocument.CompatibilityMode = GrapeCity.ActiveReports.Document.CompatibilityModes.CrossPlatform;
sectionDocument.FontResolver = CustomFontResolver.Instance;