Aspose::Words::Fonts::DefaultFontSubstitutionRule Class Reference

Detailed Description

Default font substitution rule.

Examples

Shows how to set the default font substitution rule.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
// Get the default substitution rule within FontSettings.
// This rule will substitute all missing fonts with "Times New Roman".
SharedPtr<DefaultFontSubstitutionRule> defaultFontSubstitutionRule = fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution();
ASSERT_TRUE(defaultFontSubstitutionRule->get_Enabled());
ASSERT_EQ(u"Times New Roman", defaultFontSubstitutionRule->get_DefaultFontName());
// Set the default font substitute to "Courier New".
defaultFontSubstitutionRule->set_DefaultFontName(u"Courier New");
// Using a document builder, add some text in a font that we do not have to see the substitution take place,
// and then render the result in a PDF.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Missing Font");
builder->Writeln(u"Line written in a missing font, which will be substituted with Courier New.");
doc->Save(ArtifactsDir + u"FontSettings.DefaultFontSubstitutionRule.pdf");

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

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

Public Member Functions

String get_DefaultFontName ()
 Gets or sets the default font name. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_DefaultFontName (const String &value)
 Setter for get_DefaultFontName. More...
 
- Public Member Functions inherited from FontSubstitutionRule
virtual bool get_Enabled ()
 Specifies whether the rule is enabled or not. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
virtual void set_Enabled (bool value)
 Setter for get_Enabled. More...
 

Static Public Member Functions

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

Member Function Documentation

◆ get_DefaultFontName()

System::String Aspose::Words::Fonts::DefaultFontSubstitutionRule::get_DefaultFontName ( )

Gets or sets the default font name.

The default value is 'Times New Roman'.

Examples

Shows how to specify a default font.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Arial");
builder->Writeln(u"Hello world!");
builder->get_Font()->set_Name(u"Arvo");
builder->Writeln(u"The quick brown fox jumps over the lazy dog.");
ArrayPtr<SharedPtr<FontSourceBase>> fontSources = FontSettings::get_DefaultInstance()->GetFontsSources();
// The font sources that the document uses contain the font "Arial", but not "Arvo".
ASSERT_EQ(1, fontSources->get_Length());
ASSERT_TRUE(fontSources[0]->GetAvailableFonts()->LINQ_Any([](SharedPtr<PhysicalFontInfo> f) { return f->get_FullFontName() == u"Arial"; }));
ASSERT_FALSE(fontSources[0]->GetAvailableFonts()->LINQ_Any([](SharedPtr<PhysicalFontInfo> f) { return f->get_FullFontName() == u"Arvo"; }));
// Set the "DefaultFontName" property to "Courier New" to,
// while rendering the document, apply that font in all cases when another font is not available.
FontSettings::get_DefaultInstance()->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Courier New");
ASSERT_TRUE(fontSources[0]->GetAvailableFonts()->LINQ_Any([](SharedPtr<PhysicalFontInfo> f) { return f->get_FullFontName() == u"Courier New"; }));
// Aspose.Words will now use the default font in place of any missing fonts during any rendering calls.
doc->Save(ArtifactsDir + u"FontSettings.DefaultFontName.pdf");

Shows how to set the default font substitution rule.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
// Get the default substitution rule within FontSettings.
// This rule will substitute all missing fonts with "Times New Roman".
SharedPtr<DefaultFontSubstitutionRule> defaultFontSubstitutionRule = fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution();
ASSERT_TRUE(defaultFontSubstitutionRule->get_Enabled());
ASSERT_EQ(u"Times New Roman", defaultFontSubstitutionRule->get_DefaultFontName());
// Set the default font substitute to "Courier New".
defaultFontSubstitutionRule->set_DefaultFontName(u"Courier New");
// Using a document builder, add some text in a font that we do not have to see the substitution take place,
// and then render the result in a PDF.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Missing Font");
builder->Writeln(u"Line written in a missing font, which will be substituted with Courier New.");
doc->Save(ArtifactsDir + u"FontSettings.DefaultFontSubstitutionRule.pdf");

◆ GetType()

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

◆ Is()

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

◆ set_DefaultFontName()

void Aspose::Words::Fonts::DefaultFontSubstitutionRule::set_DefaultFontName ( const System::String value)

◆ Type()

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