// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; namespace Avalonia.Media.TextFormatting { /// /// Unique text formatting properties that are used by the . /// public readonly struct TextFormat : IEquatable { public TextFormat(Typeface typeface, double fontRenderingEmSize) { Typeface = typeface; FontRenderingEmSize = fontRenderingEmSize; FontMetrics = new FontMetrics(typeface, fontRenderingEmSize); } /// /// Gets the typeface. /// /// /// The typeface. /// public Typeface Typeface { get; } /// /// Gets the font rendering em size. /// /// /// The em rendering size of the font. /// public double FontRenderingEmSize { get; } /// /// Gets the font metrics. /// /// /// The metrics of the font. /// public FontMetrics FontMetrics { get; } public static bool operator ==(TextFormat self, TextFormat other) { return self.Equals(other); } public static bool operator !=(TextFormat self, TextFormat other) { return !(self == other); } public bool Equals(TextFormat other) { return Typeface.Equals(other.Typeface) && FontRenderingEmSize.Equals(other.FontRenderingEmSize); } public override bool Equals(object obj) { return obj is TextFormat other && Equals(other); } public override int GetHashCode() { unchecked { var hashCode = (Typeface != null ? Typeface.GetHashCode() : 0); hashCode = (hashCode * 397) ^ FontRenderingEmSize.GetHashCode(); return hashCode; } } } }