Aspose::Words::Fonts::StreamFontSource class

StreamFontSource class

Base class for user-defined stream font source. To learn more, visit the Working with Fonts documentation article.

class StreamFontSource : public Aspose::Words::Fonts::FontSourceBase,
                         public Aspose::Fonts::IFontData


get_CacheKey() constThe key of this source in the cache.
get_Priority() constReturns the font source priority.
get_Type() overrideReturns the type of the font source.
get_WarningCallback() constCalled during processing of font source when an issue is detected that might result in formatting fidelity loss.
GetAvailableFonts()Returns list of fonts available via this source.
GetType() const override
Is(const System::TypeInfo&) const override
virtual OpenFontDataStream()This method should open the stream with font data on demand.
set_WarningCallback(const System::SharedPtr<Aspose::Words::IWarningCallback>&)Setter for Aspose::Words::Fonts::FontSourceBase::get_WarningCallback.
static Type()


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.

void StreamFontSourceFileRendering()
    auto fontSettings = MakeObject<FontSettings>();

    auto builder = MakeObject<DocumentBuilder>();
    builder->Writeln(u"Test aspose text when saving to PDF.");

    builder->get_Document()->Save(ArtifactsDir + u"FontSettings.StreamFontSourceFileRendering.pdf");

class StreamFontSourceFile : public StreamFontSource
    SharedPtr<System::IO::Stream> OpenFontDataStream() override
        return System::IO::File::OpenRead(FontsDir + u"Kreon-Regular.ttf");

    virtual ~StreamFontSourceFile()

See Also