SystemFontSource Class

Represents all TrueType fonts installed to the system.
Inheritance Hierarchy

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public class SystemFontSource : FontSourceBase

The SystemFontSource type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCode examplePriority
Returns the font source priority.
(Inherited from FontSourceBase.)
Public propertyCode exampleType
Returns the type of the font source.
(Overrides FontSourceBaseType.)
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Public methodCode exampleGetAvailableFonts
Returns list of fonts available via this source.
(Inherited from FontSourceBase.)
Public methodGetHashCode (Inherited from Object.)
Public methodStatic memberCode exampleGetSystemFontFolders
Returns system font folders or empty array if folders are not accessible.
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Examples
Shows how to access a document's system font source and set font substitutes.
Document doc = new Document();

// Create a font settings object for our document
doc.FontSettings = new FontSettings();

// By default we always start with a system font source
Assert.AreEqual(1, doc.FontSettings.GetFontsSources().Length);

SystemFontSource systemFontSource = (SystemFontSource)doc.FontSettings.GetFontsSources()[0];
Assert.AreEqual(FontSourceType.SystemFonts, systemFontSource.Type);
Assert.AreEqual(0, systemFontSource.Priority);

PlatformID pid = Environment.OSVersion.Platform;
bool isWindows = (pid == PlatformID.Win32NT) || (pid == PlatformID.Win32S) || (pid == PlatformID.Win32Windows) || (pid == PlatformID.WinCE);
if (isWindows)
{
    const string fontsPath = @"C:\WINDOWS\Fonts";
    Assert.AreEqual(fontsPath.ToLower(), SystemFontSource.GetSystemFontFolders().FirstOrDefault()?.ToLower());
}

foreach (string systemFontFolder in SystemFontSource.GetSystemFontFolders())
{
    Console.WriteLine(systemFontFolder);
}

// Set a font that exists in the windows fonts directory as a substitute for one that doesn't
doc.FontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;
doc.FontSettings.SubstitutionSettings.TableSubstitution.AddSubstitutes("Kreon-Regular", new string[] { "Calibri" });

Assert.AreEqual(1, doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").Count());
Assert.Contains("Calibri", doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").ToArray());

// Alternatively, we could add a folder font source in which the corresponding folder contains the font
FolderFontSource folderFontSource = new FolderFontSource(FontsDir, false);
doc.FontSettings.SetFontsSources(new FontSourceBase[] { systemFontSource, folderFontSource });
Assert.AreEqual(2, doc.FontSettings.GetFontsSources().Length);

// Resetting the font sources still leaves us with the system font source as well as our substitutes
doc.FontSettings.ResetFontSources();

Assert.AreEqual(1, doc.FontSettings.GetFontsSources().Length);
Assert.AreEqual(FontSourceType.SystemFonts, doc.FontSettings.GetFontsSources()[0].Type);
Assert.AreEqual(1, doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").Count());
See Also