-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Font.cs
133 lines (108 loc) · 4.69 KB
/
Font.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#nullable enable
using System;
namespace Microsoft.Maui
{
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="Type[@FullName='Microsoft.Maui.Font']/Docs/*" />
public readonly struct Font : IEquatable<Font>
{
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='Family']/Docs/*" />
public string? Family { get; }
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='Size']/Docs/*" />
public double Size { get; }
public FontSlant Slant { get; }
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='IsDefault']/Docs/*" />
public bool IsDefault => Family == null && (Size <= 0 || double.IsNaN(Size)) && Slant == FontSlant.Default && Weight == FontWeight.Regular;
static Font _default = default(Font).WithWeight(FontWeight.Regular);
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='Default']/Docs/*" />
public static Font Default => _default;
readonly FontWeight _weight;
public FontWeight Weight
{
get => _weight <= 0 ? FontWeight.Regular : _weight;
}
private Font(string? family, double size, FontSlant slant, FontWeight weight, bool enableScaling) : this()
{
Family = family;
Size = size;
Slant = slant;
_weight = weight;
_disableScaling = !enableScaling;
}
readonly bool _disableScaling;
public bool AutoScalingEnabled
{
get => !_disableScaling;
}
public Font WithAutoScaling(bool enabled)
{
return new Font(Family, Size, Slant, Weight, enabled);
}
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='WithSize'][1]/Docs/*" />
public Font WithSize(double size)
{
return new Font(Family, size, Slant, Weight, AutoScalingEnabled);
}
public Font WithSlant(FontSlant fontSlant)
{
return new Font(Family, Size, fontSlant, Weight, AutoScalingEnabled);
}
public Font WithWeight(FontWeight weight)
{
return new Font(Family, Size, Slant, weight, AutoScalingEnabled);
}
public Font WithWeight(FontWeight weight, FontSlant fontSlant)
{
return new Font(Family, Size, fontSlant, weight, AutoScalingEnabled);
}
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='OfSize'][1]/Docs/*" />
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
public static Font OfSize(string? name, double size, FontWeight weight = FontWeight.Regular, FontSlant fontSlant = FontSlant.Default, bool enableScaling = true) =>
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
new(name, size, fontSlant, weight, enableScaling);
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='SystemFontOfSize'][1]/Docs/*" />
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
public static Font SystemFontOfSize(double size, FontWeight weight = FontWeight.Regular, FontSlant fontSlant = FontSlant.Default, bool enableScaling = true) =>
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
new(null, size, fontSlant, weight, enableScaling);
public static Font SystemFontOfWeight(FontWeight weight, FontSlant fontSlant = FontSlant.Default, bool enableScaling = true) =>
new(null, default(double), fontSlant, weight, enableScaling);
bool Equals(Font other)
{
return string.Equals(Family, other.Family, StringComparison.Ordinal)
&& Size.Equals(other.Size)
&& Weight == other.Weight
&& Slant == other.Slant
&& AutoScalingEnabled == other.AutoScalingEnabled;
}
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='Equals']/Docs/*" />
public override bool Equals(object? obj)
{
if (obj is null)
{
return false;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((Font)obj);
}
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='GetHashCode']/Docs/*" />
public override int GetHashCode() => (Family, Size, Weight, Slant, AutoScalingEnabled).GetHashCode();
public static bool operator ==(Font left, Font right)
{
return left.Equals(right);
}
public static bool operator !=(Font left, Font right)
{
return !left.Equals(right);
}
/// <include file="../../docs/Microsoft.Maui/Font.xml" path="//Member[@MemberName='ToString']/Docs/*" />
public override string ToString()
=> $"Family: {Family}, Size: {Size}, Weight: {Weight}, Slant: {Slant}, AutoScalingEnabled: {AutoScalingEnabled}";
bool IEquatable<Font>.Equals(Font other)
{
return Equals(other);
}
}
}