/// <summary> /// Create a new instance of the <see cref="Font" /> for the named font family. /// </summary> /// <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 Font CreateFont(float size, FontStyle style) { if (this == default) { FontsThrowHelper.ThrowDefaultInstance(); } return(new Font(this, size, style)); }
/// <summary> /// Gets the specified font metrics matching the given font style. /// </summary> /// <param name="style">The font style to use when searching for a match.</param> /// <param name="metrics"> /// When this method returns, contains the metrics associated with the specified name, /// if the name is found; otherwise, the default value for the type of the metrics parameter. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <see langword="true"/> if the <see cref="FontFamily"/> contains font metrics /// with the specified name; otherwise, <see langword="false"/>. /// </returns> internal bool TryGetMetrics(FontStyle style, [NotNullWhen(true)] out FontMetrics?metrics) { if (this == default) { FontsThrowHelper.ThrowDefaultInstance(); } return(this.collection.TryGetMetrics(this.Name, this.Culture, style, out metrics)); }
/// <summary> /// Gets the collection of <see cref="FontStyle" /> that are currently available. /// </summary> /// <returns>The <see cref="IEnumerable{T}" />.</returns> public IEnumerable <FontStyle> GetAvailableStyles() { if (this == default) { FontsThrowHelper.ThrowDefaultInstance(); } return(this.collection.GetAllStyles(this.Name, this.Culture)); }
/// <summary> /// Gets the filesystem path to the font family source. /// </summary> /// <param name="path"> /// When this method returns, contains the filesystem path to the font family source, /// if the path exists; otherwise, the default value for the type of the path parameter. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <see langword="true" /> if the <see cref="Font" /> was created via a filesystem path; otherwise, <see langword="false" />. /// </returns> public bool TryGetPath([NotNullWhen(true)] out string?path) { if (this == default) { FontsThrowHelper.ThrowDefaultInstance(); } if (this.FontMetrics is FileFontMetrics fileMetrics) { path = fileMetrics.Path; return(true); } path = null; return(false); }
/// <summary> /// Gets the collection of filesystem paths to the font family sources. /// </summary> /// <param name="paths"> /// When this method returns, contains the filesystem paths to the font family sources, /// if the path exists; otherwise, an empty value for the type of the paths parameter. /// This parameter is passed uninitialized. /// </param> /// <returns> /// <see langword="true" /> if the <see cref="FontFamily" /> was created via filesystem paths; otherwise, <see langword="false" />. /// </returns> public bool TryGetPaths(out IEnumerable <string> paths) { if (this == default) { FontsThrowHelper.ThrowDefaultInstance(); } var filePaths = new List <string>(); foreach (FontStyle style in this.GetAvailableStyles()) { if (this.collection.TryGetMetrics(this.Name, this.Culture, style, out FontMetrics? metrics) && metrics is FileFontMetrics fileMetrics) { filePaths.Add(fileMetrics.Path); } } paths = filePaths; return(filePaths.Count > 0); }