Aspose::Words::Fonts::FontSourceBase Class Referenceabstract

Detailed Description

This is an abstract base class for the classes that allow the user to specify various font sources.

Examples

Shows how to use a font file in the local file system as a font source.

auto fileFontSource = MakeObject<FileFontSource>(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", 0);
auto doc = MakeObject<Document>();
doc->set_FontSettings(MakeObject<FontSettings>());
doc->get_FontSettings()->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({fileFontSource}));
ASSERT_EQ(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", fileFontSource->get_FilePath());
ASSERT_EQ(FontSourceType::FontFile, fileFontSource->get_Type());
ASSERT_EQ(0, fileFontSource->get_Priority());

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

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

Public Member Functions

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 ()
 

Member Function Documentation

◆ get_Priority()

int32_t Aspose::Words::Fonts::FontSourceBase::get_Priority ( ) const

Returns the font source priority.

This value is used when there are fonts with the same family name and style in different font sources. In this case Aspose.Words selects the font from the source with the higher priority value.

The default value is 0.

Examples

Shows how to use a font file in the local file system as a font source.

auto fileFontSource = MakeObject<FileFontSource>(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", 0);
auto doc = MakeObject<Document>();
doc->set_FontSettings(MakeObject<FontSettings>());
doc->get_FontSettings()->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({fileFontSource}));
ASSERT_EQ(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", fileFontSource->get_FilePath());
ASSERT_EQ(FontSourceType::FontFile, fileFontSource->get_Type());
ASSERT_EQ(0, fileFontSource->get_Priority());

◆ get_Type()

virtual Aspose::Words::Fonts::FontSourceType Aspose::Words::Fonts::FontSourceBase::get_Type ( )
pure virtual

Returns the type of the font source.

Examples

Shows how to use a font file in the local file system as a font source.

auto fileFontSource = MakeObject<FileFontSource>(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", 0);
auto doc = MakeObject<Document>();
doc->set_FontSettings(MakeObject<FontSettings>());
doc->get_FontSettings()->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({fileFontSource}));
ASSERT_EQ(MyDir + u"Alte DIN 1451 Mittelschrift.ttf", fileFontSource->get_FilePath());
ASSERT_EQ(FontSourceType::FontFile, fileFontSource->get_Type());
ASSERT_EQ(0, fileFontSource->get_Priority());

Implemented in Aspose::Words::Fonts::FileFontSource, Aspose::Words::Fonts::FolderFontSource, Aspose::Words::Fonts::MemoryFontSource, Aspose::Words::Fonts::StreamFontSource, and Aspose::Words::Fonts::SystemFontSource.

◆ get_WarningCallback()

System::SharedPtr< Aspose::Words::IWarningCallback > Aspose::Words::Fonts::FontSourceBase::get_WarningCallback ( ) const

Called during processing of font source when an issue is detected that might result in formatting fidelity loss.

Examples

Shows how to call warning callback when the font sources working with.

void FontSourceWarning()
{
auto settings = MakeObject<FontSettings>();
settings->SetFontsFolder(u"bad folder?", false);
SharedPtr<FontSourceBase> source = settings->GetFontsSources()->idx_get(0);
auto callback = MakeObject<ExFontSettings::FontSourceWarningCollector>();
source->set_WarningCallback(callback);
// Get the list of fonts to call warning callback.
SharedPtr<System::Collections::Generic::IList<SharedPtr<PhysicalFontInfo>>> fontInfos = source->GetAvailableFonts();
ASSERT_TRUE(callback->FontSubstitutionWarnings->idx_get(0)->get_Description().Contains(u"Error loading font from the folder \"bad folder?\""));
}
class FontSourceWarningCollector : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontSubstitutionWarnings;
void Warning(SharedPtr<WarningInfo> info) override
{
FontSubstitutionWarnings->Warning(info);
}
FontSourceWarningCollector() : FontSubstitutionWarnings(MakeObject<WarningInfoCollection>())
{
}
};

◆ GetAvailableFonts()

System::SharedPtr< System::Collections::Generic::IList< System::SharedPtr< Aspose::Words::Fonts::PhysicalFontInfo > > > Aspose::Words::Fonts::FontSourceBase::GetAvailableFonts ( )

Returns list of fonts available via this source.

Examples

Shows how to list available fonts.

// Configure Aspose.Words to source fonts from a custom folder, and then print every available font.
ArrayPtr<SharedPtr<FontSourceBase>> folderFontSource = MakeArray<SharedPtr<FontSourceBase>>({MakeObject<FolderFontSource>(FontsDir, true)});
for (const auto& fontInfo : System::IterateOver(folderFontSource[0]->GetAvailableFonts()))
{
std::cout << "FontFamilyName : " << fontInfo->get_FontFamilyName() << std::endl;
std::cout << "FullFontName : " << fontInfo->get_FullFontName() << std::endl;
std::cout << "Version : " << fontInfo->get_Version() << std::endl;
std::cout << "FilePath : " << fontInfo->get_FilePath() << "\n" << std::endl;
}

◆ GetType()

◆ Is()

◆ set_WarningCallback()

void Aspose::Words::Fonts::FontSourceBase::set_WarningCallback ( const System::SharedPtr< Aspose::Words::IWarningCallback > &  value)

◆ Type()

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