Aspose::Words::Fonts::FontFallbackSettings Class Reference

Detailed Description

Specifies font fallback mechanism settings.

Examples

Shows how to distribute fallback fonts across Unicode character code ranges.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
SharedPtr<FontFallbackSettings> fontFallbackSettings = fontSettings->get_FallbackSettings();
// Configure our font settings to source fonts only from the "MyFonts" folder.
auto folderFontSource = MakeObject<FolderFontSource>(FontsDir, false);
fontSettings->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({folderFontSource}));
// Calling the "BuildAutomatic" method will generate a fallback scheme that
// distributes accessible fonts across as many Unicode character codes as possible.
// In our case, it only has access to the handful of fonts inside the "MyFonts" folder.
fontFallbackSettings->BuildAutomatic();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettingsCustom.BuildAutomatic.xml");
// We can also load a custom substitution scheme from a file like this.
// This scheme applies the "AllegroOpen" font across the "0000-00ff" Unicode blocks, the "AllegroOpen" font across "0100-024f",
// and the "M+ 2m" font in all other ranges that other fonts in the scheme do not cover.
fontFallbackSettings->Load(MyDir + u"Custom font fallback settings.xml");
// Create a document builder and set its font to one that does not exist in any of our sources.
// Our font settings will invoke the fallback scheme for characters that we type using the unavailable font.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Missing Font");
// Use the builder to print every Unicode character from 0x0021 to 0x052F,
// with descriptive lines dividing Unicode blocks we defined in our custom font fallback scheme.
for (int i = 0x0021; i < 0x0530; i++)
{
switch (i)
{
case 0x0021:
builder->Writeln(u"\n\n0x0021 - 0x00FF: \nBasic Latin/Latin-1 Supplement Unicode blocks in \"AllegroOpen\" font:");
break;
case 0x0100:
builder->Writeln(u"\n\n0x0100 - 0x024F: \nLatin Extended A/B blocks, mostly in \"AllegroOpen\" font:");
break;
case 0x0250:
builder->Writeln(u"\n\n0x0250 - 0x052F: \nIPA/Greek/Cyrillic blocks in \"M+ 2m\" font:");
break;
}
builder->Write(String::Format(u"{0}", System::Convert::ToChar(i)));
}
doc->Save(ArtifactsDir + u"FontSettings.FallbackSettingsCustom.pdf");

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

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

Public Member Functions

void BuildAutomatic ()
 Automatically builds the fallback settings by scanning available fonts. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void Load (const SharedPtr< Stream > &stream)
 Loads fallback settings from XML stream. More...
 
void Load (const String &fileName)
 Loads font fallback settings from XML file. More...
 
template<typename CharType , typename Traits >
void Load (std::basic_istream< CharType, Traits > &stream)
 
void LoadMsOfficeFallbackSettings ()
 Loads predefined fallback settings which mimics the Microsoft Word fallback and uses Microsoft office fonts. More...
 
void LoadNotoFallbackSettings ()
 Loads predefined fallback settings which uses Google Noto fonts. More...
 
void Save (const SharedPtr< Stream > &outputStream)
 Saves the current fallback settings to stream. More...
 
void Save (const String &fileName)
 Saves the current fallback settings to file. More...
 
template<typename CharType , typename Traits >
void Save (std::basic_ostream< CharType, Traits > &outputStream)
 

Static Public Member Functions

static const TypeInfoType ()
 

Member Function Documentation

◆ BuildAutomatic()

void Aspose::Words::Fonts::FontFallbackSettings::BuildAutomatic ( )

Automatically builds the fallback settings by scanning available fonts.

Examples

Shows how to distribute fallback fonts across Unicode character code ranges.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
SharedPtr<FontFallbackSettings> fontFallbackSettings = fontSettings->get_FallbackSettings();
// Configure our font settings to source fonts only from the "MyFonts" folder.
auto folderFontSource = MakeObject<FolderFontSource>(FontsDir, false);
fontSettings->SetFontsSources(MakeArray<SharedPtr<FontSourceBase>>({folderFontSource}));
// Calling the "BuildAutomatic" method will generate a fallback scheme that
// distributes accessible fonts across as many Unicode character codes as possible.
// In our case, it only has access to the handful of fonts inside the "MyFonts" folder.
fontFallbackSettings->BuildAutomatic();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettingsCustom.BuildAutomatic.xml");
// We can also load a custom substitution scheme from a file like this.
// This scheme applies the "AllegroOpen" font across the "0000-00ff" Unicode blocks, the "AllegroOpen" font across "0100-024f",
// and the "M+ 2m" font in all other ranges that other fonts in the scheme do not cover.
fontFallbackSettings->Load(MyDir + u"Custom font fallback settings.xml");
// Create a document builder and set its font to one that does not exist in any of our sources.
// Our font settings will invoke the fallback scheme for characters that we type using the unavailable font.
auto builder = MakeObject<DocumentBuilder>(doc);
builder->get_Font()->set_Name(u"Missing Font");
// Use the builder to print every Unicode character from 0x0021 to 0x052F,
// with descriptive lines dividing Unicode blocks we defined in our custom font fallback scheme.
for (int i = 0x0021; i < 0x0530; i++)
{
switch (i)
{
case 0x0021:
builder->Writeln(u"\n\n0x0021 - 0x00FF: \nBasic Latin/Latin-1 Supplement Unicode blocks in \"AllegroOpen\" font:");
break;
case 0x0100:
builder->Writeln(u"\n\n0x0100 - 0x024F: \nLatin Extended A/B blocks, mostly in \"AllegroOpen\" font:");
break;
case 0x0250:
builder->Writeln(u"\n\n0x0250 - 0x052F: \nIPA/Greek/Cyrillic blocks in \"M+ 2m\" font:");
break;
}
builder->Write(String::Format(u"{0}", System::Convert::ToChar(i)));
}
doc->Save(ArtifactsDir + u"FontSettings.FallbackSettingsCustom.pdf");

◆ GetType()

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

Reimplemented from System::Object.

◆ Is()

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

Reimplemented from System::Object.

◆ Load() [1/3]

void Aspose::Words::Fonts::FontFallbackSettings::Load ( const System::SharedPtr< System::IO::Stream > &  stream)

Loads fallback settings from XML stream.

Parameters
streamInput stream.
Examples

Shows how to load and save font fallback settings to/from a stream.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Load an XML document that defines a set of font fallback settings.
{
auto fontFallbackStream = MakeObject<System::IO::FileStream>(MyDir + u"Font fallback rules.xml", System::IO::FileMode::Open);
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_FallbackSettings()->Load(fontFallbackStream);
doc->set_FontSettings(fontSettings);
}
doc->Save(ArtifactsDir + u"FontSettings.LoadFontFallbackSettingsFromStream.pdf");
// Use a stream to save our document's current font fallback settings as an XML document.
{
auto fontFallbackStream = MakeObject<System::IO::FileStream>(ArtifactsDir + u"FallbackSettings.xml", System::IO::FileMode::Create);
doc->get_FontSettings()->get_FallbackSettings()->Save(fontFallbackStream);
}

◆ Load() [2/3]

void Aspose::Words::Fonts::FontFallbackSettings::Load ( const System::String fileName)

Loads font fallback settings from XML file.

Parameters
fileNameInput file name.
Examples

Shows how to load and save font fallback settings to/from an XML document in the local file system.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Load an XML document that defines a set of font fallback settings.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_FallbackSettings()->Load(MyDir + u"Font fallback rules.xml");
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.LoadFontFallbackSettingsFromFile.pdf");
// Save our document's current font fallback settings as an XML document.
doc->get_FontSettings()->get_FallbackSettings()->Save(ArtifactsDir + u"FallbackSettings.xml");

◆ Load() [3/3]

template<typename CharType , typename Traits >
void Aspose::Words::Fonts::FontFallbackSettings::Load ( std::basic_istream< CharType, Traits > &  stream)
inline

◆ LoadMsOfficeFallbackSettings()

void Aspose::Words::Fonts::FontFallbackSettings::LoadMsOfficeFallbackSettings ( )

Loads predefined fallback settings which mimics the Microsoft Word fallback and uses Microsoft office fonts.

Examples

Shows how to load pre-defined fallback font settings.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
SharedPtr<FontFallbackSettings> fontFallbackSettings = fontSettings->get_FallbackSettings();
// Save the default fallback font scheme to an XML document.
// For example, one of the elements has a value of "0C00-0C7F" for Range and a corresponding "Vani" value for FallbackFonts.
// This means that if the font some text is using does not have symbols for the 0x0C00-0x0C7F Unicode block,
// the fallback scheme will use symbols from the "Vani" font substitute.
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.Default.xml");
// Below are two pre-defined font fallback schemes we can choose from.
// 1 - Use the default Microsoft Office scheme, which is the same one as the default:
fontFallbackSettings->LoadMsOfficeFallbackSettings();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.LoadMsOfficeFallbackSettings.xml");
// 2 - Use the scheme built from Google Noto fonts:
fontFallbackSettings->LoadNotoFallbackSettings();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.LoadNotoFallbackSettings.xml");

◆ LoadNotoFallbackSettings()

void Aspose::Words::Fonts::FontFallbackSettings::LoadNotoFallbackSettings ( )

Loads predefined fallback settings which uses Google Noto fonts.

Examples

Shows how to add predefined font fallback settings for Google Noto fonts.

auto fontSettings = MakeObject<FontSettings>();
// These are free fonts licensed under the SIL Open Font License.
// We can download the fonts here:
// https://www.google.com/get/noto/#sans-lgc
fontSettings->SetFontsFolder(FontsDir + u"Noto", false);
// Note that the predefined settings only use Sans-style Noto fonts with regular weight.
// Some of the Noto fonts use advanced typography features.
// Fonts featuring advanced typography may not be rendered correctly as Aspose.Words currently do not support them.
fontSettings->get_FallbackSettings()->LoadNotoFallbackSettings();
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(false);
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Noto Sans");
auto doc = MakeObject<Document>();
doc->set_FontSettings(fontSettings);

Shows how to load pre-defined fallback font settings.

auto doc = MakeObject<Document>();
auto fontSettings = MakeObject<FontSettings>();
doc->set_FontSettings(fontSettings);
SharedPtr<FontFallbackSettings> fontFallbackSettings = fontSettings->get_FallbackSettings();
// Save the default fallback font scheme to an XML document.
// For example, one of the elements has a value of "0C00-0C7F" for Range and a corresponding "Vani" value for FallbackFonts.
// This means that if the font some text is using does not have symbols for the 0x0C00-0x0C7F Unicode block,
// the fallback scheme will use symbols from the "Vani" font substitute.
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.Default.xml");
// Below are two pre-defined font fallback schemes we can choose from.
// 1 - Use the default Microsoft Office scheme, which is the same one as the default:
fontFallbackSettings->LoadMsOfficeFallbackSettings();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.LoadMsOfficeFallbackSettings.xml");
// 2 - Use the scheme built from Google Noto fonts:
fontFallbackSettings->LoadNotoFallbackSettings();
fontFallbackSettings->Save(ArtifactsDir + u"FontSettings.FallbackSettings.LoadNotoFallbackSettings.xml");

◆ Save() [1/3]

void Aspose::Words::Fonts::FontFallbackSettings::Save ( const System::SharedPtr< System::IO::Stream > &  outputStream)

Saves the current fallback settings to stream.

Parameters
outputStreamOutput stream.
Examples

Shows how to load and save font fallback settings to/from a stream.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Load an XML document that defines a set of font fallback settings.
{
auto fontFallbackStream = MakeObject<System::IO::FileStream>(MyDir + u"Font fallback rules.xml", System::IO::FileMode::Open);
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_FallbackSettings()->Load(fontFallbackStream);
doc->set_FontSettings(fontSettings);
}
doc->Save(ArtifactsDir + u"FontSettings.LoadFontFallbackSettingsFromStream.pdf");
// Use a stream to save our document's current font fallback settings as an XML document.
{
auto fontFallbackStream = MakeObject<System::IO::FileStream>(ArtifactsDir + u"FallbackSettings.xml", System::IO::FileMode::Create);
doc->get_FontSettings()->get_FallbackSettings()->Save(fontFallbackStream);
}

◆ Save() [2/3]

void Aspose::Words::Fonts::FontFallbackSettings::Save ( const System::String fileName)

Saves the current fallback settings to file.

Parameters
fileNameOutput file name.
Examples

Shows how to load and save font fallback settings to/from an XML document in the local file system.

auto doc = MakeObject<Document>(MyDir + u"Rendering.docx");
// Load an XML document that defines a set of font fallback settings.
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_FallbackSettings()->Load(MyDir + u"Font fallback rules.xml");
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.LoadFontFallbackSettingsFromFile.pdf");
// Save our document's current font fallback settings as an XML document.
doc->get_FontSettings()->get_FallbackSettings()->Save(ArtifactsDir + u"FallbackSettings.xml");

◆ Save() [3/3]

template<typename CharType , typename Traits >
void Aspose::Words::Fonts::FontFallbackSettings::Save ( std::basic_ostream< CharType, Traits > &  outputStream)
inline

◆ Type()

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