FontSettings Class |
Namespace: Aspose.Words.Fonts
The FontSettings type exposes the following members.
Name | Description | |
---|---|---|
![]() | FontSettings | Initializes a new instance of the FontSettings class |
Name | Description | |
---|---|---|
![]() ![]() ![]() | DefaultInstance |
Static default font settings.
|
![]() ![]() | FallbackSettings |
Settings related to font fallback mechanism.
|
![]() ![]() | SubstitutionSettings |
Settings related to font substitution mechanism.
|
Name | Description | |
---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() ![]() | GetFontsSources |
Gets a copy of the array that contains the list of sources where Aspose.Words looks for TrueType fonts.
|
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() ![]() | ResetFontSources |
Resets the fonts sources to the system default.
|
![]() ![]() | SetFontsFolder |
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.
|
![]() ![]() | SetFontsFolders |
Sets the folders where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
|
![]() ![]() | SetFontsSources |
Sets the sources where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.
|
![]() | ToString | (Inherited from Object.) |
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.
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");
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");
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");