-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathFontFamilyKey.cs
113 lines (96 loc) · 3.14 KB
/
FontFamilyKey.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
namespace Avalonia.Media.Fonts
{
/// <summary>
/// Represents an identifier for a <see cref="FontFamily"/>
/// </summary>
public class FontFamilyKey
{
/// <summary>
/// Creates a new instance of <see cref="FontFamilyKey"/>
/// </summary>
/// <param name="source"></param>
/// <param name="baseUri"></param>
public FontFamilyKey(Uri source, Uri? baseUri = null)
{
Source = source ?? throw new ArgumentNullException(nameof(source));
BaseUri = baseUri;
}
/// <summary>
/// Source of stored font asset that belongs to a <see cref="FontFamily"/>
/// </summary>
public Uri Source { get; }
/// <summary>
/// A base URI to use if <see cref="Source"/> is relative
/// </summary>
public Uri? BaseUri { get; }
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
unchecked
{
var hash = (int)2166136261;
hash = (hash * 16777619) ^ Source.GetHashCode();
if (BaseUri != null)
{
hash = (hash * 16777619) ^ BaseUri.GetHashCode();
}
return hash;
}
}
public static bool operator !=(FontFamilyKey? a, FontFamilyKey? b)
{
return !(a == b);
}
public static bool operator ==(FontFamilyKey? a, FontFamilyKey? b)
{
if (ReferenceEquals(a, b))
{
return true;
}
return !(a is null) && a.Equals(b);
}
/// <summary>
/// Determines whether the specified <see cref="object" />, is equal to this instance.
/// </summary>
/// <param name="obj">The <see cref="object" /> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="object" /> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object? obj)
{
if (!(obj is FontFamilyKey other))
{
return false;
}
if (Source != other.Source)
{
return false;
}
if (BaseUri != other.BaseUri)
{
return false;
}
return true;
}
/// <summary>
/// Returns a <see cref="string" /> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="string" /> that represents this instance.
/// </returns>
public override string ToString()
{
if (!Source.IsAbsoluteUri && BaseUri != null)
{
return BaseUri.AbsoluteUri + Source.OriginalString;
}
return Source.ToString();
}
}
}