86 lines
4.0 KiB
C#
86 lines
4.0 KiB
C#
// Copyright (c) Six Labors.
|
|
// Licensed under the Six Labors Split License.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
|
|
namespace SixLabors.Fonts {
|
|
/// <summary>
|
|
/// Provides a collection of fonts.
|
|
/// </summary>
|
|
public static class SystemFonts
|
|
{
|
|
private static readonly Lazy<SystemFontCollection> LazySystemFonts = new(() => new SystemFontCollection(), true);
|
|
|
|
/// <summary>
|
|
/// Gets the collection containing the globally installed system fonts.
|
|
/// </summary>
|
|
public static IReadOnlySystemFontCollection Collection => LazySystemFonts.Value;
|
|
|
|
/// <summary>
|
|
/// Gets the collection of <see cref="FontFamily"/>s installed on current system.
|
|
/// </summary>
|
|
public static IEnumerable<FontFamily> Families => Collection.Families;
|
|
|
|
/// <inheritdoc cref="IReadOnlyFontCollection.Get(string)"/>
|
|
public static FontFamily Get(string name) => GetByCulture(name, CultureInfo.InvariantCulture);
|
|
|
|
/// <inheritdoc cref="IReadOnlyFontCollection.TryGet(string, out FontFamily)" />
|
|
public static bool TryGet(string fontFamily, out FontFamily family)
|
|
=> Collection.TryGet(fontFamily, out family);
|
|
|
|
/// <summary>
|
|
/// Create a new instance of the <see cref="Font"/> for the named font family with regular styling.
|
|
/// </summary>
|
|
/// <param name="name">The font family name.</param>
|
|
/// <param name="size">The size of the font in PT units.</param>
|
|
/// <returns>The new <see cref="Font"/>.</returns>
|
|
public static Font CreateFont(string name, float size)
|
|
=> Collection.Get(name).CreateFont(size);
|
|
|
|
/// <summary>
|
|
/// Create a new instance of the <see cref="Font"/> for the named font family.
|
|
/// </summary>
|
|
/// <param name="name">The font family name.</param>
|
|
/// <param name="size">The size of the font in PT units.</param>
|
|
/// <param name="style">The font style.</param>
|
|
/// <returns>The new <see cref="Font"/>.</returns>
|
|
public static Font CreateFont(string name, float size, FontStyle style)
|
|
=> Collection.Get(name).CreateFont(size, style);
|
|
|
|
/// <inheritdoc cref="IReadOnlyFontCollection.GetByCulture(CultureInfo)"/>
|
|
public static IEnumerable<FontFamily> GetByCulture(CultureInfo culture)
|
|
=> Collection.GetByCulture(culture);
|
|
|
|
/// <inheritdoc cref="IReadOnlyFontCollection.GetByCulture(string, CultureInfo)" />
|
|
public static FontFamily GetByCulture(string fontFamily, CultureInfo culture)
|
|
=> Collection.GetByCulture(fontFamily, culture);
|
|
|
|
/// <inheritdoc cref="IReadOnlyFontCollection.TryGetByCulture(string, CultureInfo, out FontFamily)" />
|
|
public static bool TryGetByCulture(string fontFamily, CultureInfo culture, out FontFamily family)
|
|
=> Collection.TryGetByCulture(fontFamily, culture, out family);
|
|
|
|
/// <summary>
|
|
/// Create a new instance of the <see cref="Font"/> for the named font family with regular styling.
|
|
/// </summary>
|
|
/// <param name="name">The font family name.</param>
|
|
/// <param name="culture">The font culture.</param>
|
|
/// <param name="size">The size of the font in PT units.</param>
|
|
/// <returns>The new <see cref="Font"/>.</returns>
|
|
public static Font CreateFont(string name, CultureInfo culture, float size)
|
|
=> Collection.GetByCulture(name, culture).CreateFont(size);
|
|
|
|
/// <summary>
|
|
/// Create a new instance of the <see cref="Font"/> for the named font family.
|
|
/// </summary>
|
|
/// <param name="name">The font family name.</param>
|
|
/// <param name="culture">The font culture.</param>
|
|
/// <param name="size">The size of the font in PT units.</param>
|
|
/// <param name="style">The font style.</param>
|
|
/// <returns>The new <see cref="Font"/>.</returns>
|
|
public static Font CreateFont(string name, CultureInfo culture, float size, FontStyle style)
|
|
=> Collection.GetByCulture(name, culture).CreateFont(size, style);
|
|
}
|
|
}
|