StreamFontSource Class

Base class for user-defined stream font source.

ExpandedInheritance Hierarchy

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 21.10.0


public abstract class StreamFontSource : FontSourceBase

The StreamFontSource type exposes the following members.


Public propertyCode examplePriority
Returns the font source priority.
(Inherited from FontSourceBase.)
Public propertyType
Returns the type of the font source.
(Overrides FontSourceBaseType.)
Public propertyCode exampleWarningCallback
Called during processing of font source when an issue is detected that might result in formatting fidelity loss.
(Inherited from FontSourceBase.)


Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleGetAvailableFonts
Returns list of fonts available via this source.
(Inherited from FontSourceBase.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleOpenFontDataStream
This method should open the stream with font data on demand.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)


In order to use the stream font source you should create a derived class from the StreamFontSource and provide implementation of the OpenFontDataStream method.

OpenFontDataStream method could be called several times. For the first time it will be called when Aspose.Words scans the provided font sources to get the list of available fonts. Later it may be called if the font is used in the document to parse the font data and to embed the font data to some output formats.

StreamFontSource may be useful because it allows to load the font data only when it is required and not to store it in the memory for the FontSettings lifetime.


Shows how to load fonts from stream.
    FontSettings fontSettings = new FontSettings();
    fontSettings.SetFontsSources(new FontSourceBase[] { new StreamFontSourceFile() });

    DocumentBuilder builder = new DocumentBuilder();
    builder.Document.FontSettings = fontSettings;
    builder.Font.Name = "Kreon-Regular";
    builder.Writeln("Test aspose text when saving to PDF.");

    builder.Document.Save(ArtifactsDir + "FontSettings.StreamFontSourceFileRendering.pdf");

/// <summary>
/// Load the font data only when required instead of storing it in the memory for the entire lifetime of the "FontSettings" object.
/// </summary>
private class StreamFontSourceFile : StreamFontSource
    public override Stream OpenFontDataStream()
        return File.OpenRead(FontsDir + "Kreon-Regular.ttf");

ExpandedSee Also