ResetFontSources
Contenuti
[
Nascondere
]FontSettings.ResetFontSources method
Reimposta le sorgenti dei font ai valori predefiniti del sistema.
public void ResetFontSources()
Esempi
Mostra come accedere alla sorgente dei font di sistema di un documento e impostare i font sostitutivi.
Document doc = new Document();
doc.FontSettings = new FontSettings();
// Per impostazione predefinita, un documento vuoto contiene sempre una sorgente font di sistema.
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);
}
// Imposta un font presente nella directory Fonts di Windows come sostituto di uno che non esiste.
doc.FontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;
doc.FontSettings.SubstitutionSettings.TableSubstitution.AddSubstitutes("Kreon-Regular", new[] {"Calibri"});
Assert.AreEqual(1,
doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").Count());
Assert.Contains("Calibri",
doc.FontSettings.SubstitutionSettings.TableSubstitution.GetSubstitutes("Kreon-Regular").ToArray());
// In alternativa, potremmo aggiungere una cartella font source in cui la cartella corrispondente contiene il font.
FolderFontSource folderFontSource = new FolderFontSource(FontsDir, false);
doc.FontSettings.SetFontsSources(new FontSourceBase[] {systemFontSource, folderFontSource});
Assert.AreEqual(2, doc.FontSettings.GetFontsSources().Length);
// Reimpostando le sorgenti dei font rimarranno comunque le sorgenti dei font di sistema e i nostri sostituti.
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());
Assert.True(doc.FontSettings.SubstitutionSettings.FontNameSubstitution.Enabled);
Guarda anche
- class FontSettings
- spazio dei nomi Aspose.Words.Fonts
- assemblea Aspose.Words