search/mag_sel search/close
Aspose::Words::Fonts::StreamFontSource Class Referenceabstract

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

FontSourceType get_Type () override
 Returns the type of the font source. More...
 
String GetFilePath () override
 
int32_t GetSize () override
 
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...
 
SharedPtr< StreamOpenStream () override
 
- Public Member Functions inherited from FontSourceBase
int32_t get_Priority () const
 Returns the font source priority. 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...
 
void set_WarningCallback (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_Type()

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

Returns the type of the font source.

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

◆ GetFilePath()

System::String Aspose::Words::Fonts::StreamFontSource::GetFilePath ( )
override

◆ GetSize()

int32_t Aspose::Words::Fonts::StreamFontSource::GetSize ( )
override

◆ 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()
{
}
};

◆ OpenStream()

System::SharedPtr<System::IO::Stream> Aspose::Words::Fonts::StreamFontSource::OpenStream ( )
override

◆ Type()

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