FontSettings Class

Specifies font settings for a document.

Inheritance Hierarchy

SystemObject
  Aspose.Words.FontsFontSettings

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

Syntax

public class FontSettings

The FontSettings type exposes the following members.

Constructors

  NameDescription
Public methodFontSettings
Initializes a new instance of the FontSettings class

Properties

  NameDescription
Public propertyStatic memberCode exampleDefaultInstance
Static default font settings.
Public propertyCode exampleFallbackSettings
Settings related to font fallback mechanism.
Public propertyCode exampleSubstitutionSettings
Settings related to font substitution mechanism.

Methods

  NameDescription
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetFontsSources
Gets a copy of the array that contains the list of sources where Aspose.Words looks for TrueType fonts.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleResetFontSources
Resets the fonts sources to the system default.
Public methodCode exampleSetFontsFolder
Sets the folder where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts. This is a shortcut to SetFontsFolders(String, Boolean) for setting only one font directory.
Public methodCode exampleSetFontsFolders
Sets the folders where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
Public methodCode exampleSetFontsSources
Sets the sources where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
Public methodToString (Inherited from Object.)

Remarks

Aspose.Words uses font settings to resolve the fonts in the document. Fonts are resolved mostly when building document layout or rendering to fixed page formats. But when loading some formats, Aspose.Words also may require to resolve the fonts. For example, when loading HTML documents Aspose.Words may resolve the fonts to perform font fallback. So it is recommended that you set the font settings in LoadOptions when loading the document. Or at least before building the layout or rendering the document to the fixed-page format.

By default all documents uses single static font settings instance. It could be accessed by DefaultInstance property.

Changing font settings is safe at any time from any thread. But it is recommended that you do not change the font settings while processing some documents which uses this settings. This can lead to the fact that the same font will be resolved differently in different parts of the document.

Examples

Demonstrates how to set the folder Aspose.Words uses to look for TrueType fonts during rendering or embedding of fonts.
Document doc = new Document(MyDir + "Rendering.docx");

// Note that this setting will override any default font sources that are being searched by default
// Now only these folders will be searched for fonts when rendering or embedding fonts
// To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and 
// FontSettings.SetFontSources instead
FontSettings.DefaultInstance.SetFontsFolder(@"C:\MyFonts\", false);

doc.Save(ArtifactsDir + "Rendering.SetTrueTypeFontsFolder.pdf");
Demonstrates how to set Aspose.Words to look in multiple folders for TrueType fonts when rendering or embedding fonts.
Document doc = new Document(MyDir + "Rendering.docx");

// Note that this setting will override any default font sources that are being searched by default
// Now only these folders will be searched for fonts when rendering or embedding fonts
// To add an extra font source while keeping system font sources then use both FontSettings.GetFontSources and 
// FontSettings.SetFontSources instead
FontSettings.DefaultInstance.SetFontsFolders(new string[] { @"C:\MyFonts\", @"D:\Misc\Fonts\" }, true);

doc.Save(ArtifactsDir + "Rendering.SetFontsFoldersMultipleFolders.pdf");
Demonstrates how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.
Document doc = new Document(MyDir + "Rendering.docx");

// Retrieve the array of environment-dependent font sources that are searched by default
// For example this will contain a "Windows\Fonts\" source on a Windows machines
// We add this array to a new ArrayList to make adding or removing font entries much easier
ArrayList fontSources = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());

// Add a new folder source which will instruct Aspose.Words to search the following folder for fonts
FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

// Add the custom folder which contains our fonts to the list of existing font sources
fontSources.Add(folderFontSource);

// Convert the ArrayList of source back into a primitive array of FontSource objects
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.ToArray(typeof(FontSourceBase));

// Apply the new set of font sources to use
FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);

doc.Save(ArtifactsDir + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");

See Also