Aspose::Words::Fonts::StreamFontSource Class Referenceabstract

Detailed Description

Base class for user-defined stream font source.

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.

Examples

Shows how to load fonts from stream.

void StreamFontSourceFileRendering()
{
auto fontSettings = MakeObject<FontSettings>();
fontSettings->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({MakeObject<ExFontSettings::StreamFontSourceFile>()}));
auto builder = MakeObject<DocumentBuilder>();
builder->get_Document()->set_FontSettings(fontSettings);
builder->get_Font()->set_Name(u"Kreon-Regular");
builder->Writeln(u"Test aspose text when saving to PDF.");
builder->get_Document()->Save(ArtifactsDir + u"FontSettings.StreamFontSourceFileRendering.pdf");
}
class StreamFontSourceFile : public StreamFontSource
{
public:
SharedPtr<System::IO::Stream> OpenFontDataStream() override
{
return System::IO::File::OpenRead(FontsDir + u"Kreon-Regular.ttf");
}
protected:
virtual ~StreamFontSourceFile()
{
}
};

#include <Aspose.Words.Cpp/Fonts/StreamFontSource.h>

+ Inheritance diagram for Aspose::Words::Fonts::StreamFontSource:

Public Member Functions

String get_CacheKey () const
 The key of this source in the cache. More...
 
FontSourceType get_Type () override
 Returns the type of the font source. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
virtual SharedPtr< StreamOpenFontDataStream ()=0
 This method should open the stream with font data on demand. More...
 
- Public Member Functions inherited from FontSourceBase
int32_t get_Priority () const
 Returns the font source priority. More...
 
virtual FontSourceType get_Type ()=0
 Returns the type of the font source. More...
 
SharedPtr< IWarningCallbackget_WarningCallback () const
 Called during processing of font source when an issue is detected that might result in formatting fidelity loss. More...
 
SharedPtr< IList< SharedPtr< PhysicalFontInfo > > > GetAvailableFonts ()
 Returns list of fonts available via this source. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_WarningCallback (const SharedPtr< IWarningCallback > &value)
 Setter for get_WarningCallback. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from FontSourceBase
static const TypeInfoType ()
 

Member Function Documentation

◆ get_CacheKey()

System::String Aspose::Words::Fonts::StreamFontSource::get_CacheKey ( ) const

The key of this source in the cache.

◆ get_Type()

Aspose::Words::Fonts::FontSourceType Aspose::Words::Fonts::StreamFontSource::get_Type ( )
overridevirtual

Returns the type of the font source.

Implements Aspose::Words::Fonts::FontSourceBase.

◆ GetType()

virtual const System::TypeInfo & Aspose::Words::Fonts::StreamFontSource::GetType ( ) const
overridevirtual

◆ Is()

virtual bool Aspose::Words::Fonts::StreamFontSource::Is ( const System::TypeInfo target) const
overridevirtual

◆ OpenFontDataStream()

virtual System::SharedPtr< System::IO::Stream > Aspose::Words::Fonts::StreamFontSource::OpenFontDataStream ( )
pure virtual

This method should open the stream with font data on demand.

Returns
Font data stream.
Examples

Shows how to load fonts from stream.

void StreamFontSourceFileRendering()
{
auto fontSettings = MakeObject<FontSettings>();
fontSettings->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({MakeObject<ExFontSettings::StreamFontSourceFile>()}));
auto builder = MakeObject<DocumentBuilder>();
builder->get_Document()->set_FontSettings(fontSettings);
builder->get_Font()->set_Name(u"Kreon-Regular");
builder->Writeln(u"Test aspose text when saving to PDF.");
builder->get_Document()->Save(ArtifactsDir + u"FontSettings.StreamFontSourceFileRendering.pdf");
}
class StreamFontSourceFile : public StreamFontSource
{
public:
SharedPtr<System::IO::Stream> OpenFontDataStream() override
{
return System::IO::File::OpenRead(FontsDir + u"Kreon-Regular.ttf");
}
protected:
virtual ~StreamFontSourceFile()
{
}
};

◆ Type()

static const System::TypeInfo & Aspose::Words::Fonts::StreamFontSource::Type ( )
static