FontFallbackSettings Class

Specifies font fallback mechanism settings.

Inheritance Hierarchy

SystemObject
  Aspose.Words.FontsFontFallbackSettings

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public class FontFallbackSettings

The FontFallbackSettings type exposes the following members.

Methods

  NameDescription
Public methodCode exampleBuildAutomatic
Automatically builds the fallback settings by scanning available fonts.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleLoad(Stream)
Loads fallback settings from XML stream.
Public methodCode exampleLoad(String)
Loads font fallback settings from XML file.
Public methodCode exampleLoadMsOfficeFallbackSettings
Loads predefined fallback settings which mimics the Microsoft Word fallback and uses Microsoft office fonts.
Public methodCode exampleLoadNotoFallbackSettings
Loads predefined fallback settings which uses Google Noto fonts.
Public methodCode exampleSave(Stream)
Saves the current fallback settings to stream.
Public methodCode exampleSave(String)
Saves the current fallback settings to file.
Public methodToString (Inherited from Object.)

Remarks

By default fallback settings are initialized with predefined settings which mimics the Microsoft Word fallback.

Examples

Shows how to distribute fallback fonts across unicode character code ranges.
Document doc = new Document();

// Create a FontSettings object for our document and get its FallbackSettings attribute
FontSettings fontSettings = new FontSettings();
doc.FontSettings = fontSettings;
FontFallbackSettings fontFallbackSettings = fontSettings.FallbackSettings;

// Set our fonts to be sourced exclusively from the "MyFonts" folder
FolderFontSource folderFontSource = new FolderFontSource(FontsDir, false);
fontSettings.SetFontsSources(new FontSourceBase[] { folderFontSource });

// Calling BuildAutomatic() 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 + "Font.FallbackSettingsCustom.BuildAutomatic.xml");

// We can also load a custom substitution scheme from a file like this
// This scheme applies the "Arvo" font across the "0000-00ff" unicode blocks, the "Squarish Sans CT" font across "0100-024f",
// and the "M+ 2m" font in every place that none of the other fonts cover
fontFallbackSettings.Load(MyDir + "Custom font fallback settings.xml");

// Create a document builder and set its font to one that doesn't exist in any of our sources
// In doing that we will rely completely on our font fallback scheme to render text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Missing Font";

// Type out 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("\n\n0x0021 - 0x00FF: \nBasic Latin/Latin-1 Supplement unicode blocks in \"Arvo\" font:");
            break;
        case 0x0100:
            builder.Writeln("\n\n0x0100 - 0x024F: \nLatin Extended A/B blocks, mostly in \"Squarish Sans CT\" font:");
            break;
        case 0x0250:
            builder.Writeln("\n\n0x0250 - 0x052F: \nIPA/Greek/Cyrillic blocks in \"M+ 2m\" font:");
            break;
    }

    builder.Write($"{Convert.ToChar(i)}");
}

doc.Save(ArtifactsDir + "Font.FallbackSettingsCustom.pdf");

See Also