Add IStringEncodable

This commit is contained in:
Yoshi Askharoun
2024-02-12 12:15:35 -06:00
parent a5b9b12908
commit 23d20873cf
8 changed files with 45 additions and 7 deletions
+3 -1
View File
@@ -12,7 +12,7 @@ using System.Text;
namespace Microsoft.Iris.Drawing
{
[Serializable]
public struct Color : ISerializable
public struct Color : ISerializable, IStringEncodable
{
private const int ARGBAlphaShift = 24;
private const int ARGBRedShift = 16;
@@ -230,6 +230,8 @@ namespace Microsoft.Iris.Drawing
info.AddValue(nameof(Value), Value);
}
public string EncodeString() => string.Join(", ", A, R, G, B);
internal static Color Transparent => new(0U);
internal static Color Black => new(0xFF00_0000U);
+17 -1
View File
@@ -6,7 +6,7 @@
namespace Microsoft.Iris.Drawing
{
internal sealed class Font
internal sealed class Font : IStringEncodable
{
private string _fontName;
private float _fontHeight;
@@ -70,6 +70,22 @@ namespace Microsoft.Iris.Drawing
set => _fontName = value;
}
public string EncodeString()
{
System.Collections.Generic.List<object> props = new(4)
{
FontName,
_fontHeight
};
if (_altFontHeight != default)
props.Add(_altFontHeight);
if (_fontStyle != default)
props.Add(_fontStyle);
return string.Join(", ", props);
}
public override bool Equals(object obj) => obj is Font font && _fontName == font._fontName && (_fontHeight == (double)font._fontHeight && _altFontHeight == (double)font._altFontHeight) && _fontStyle == font._fontStyle;
public override int GetHashCode() => _fontName.GetHashCode() ^ _fontHeight.GetHashCode() ^ _altFontHeight.GetHashCode() ^ _fontStyle.GetHashCode();