aboutsummaryrefslogtreecommitdiffstatsci
path: root/Backends/VkvgBackend/src/FontExtents.cs
blob: f5614c2f15ba7a8e2794ee71c4dfed0fc1c9950b (plain)
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
// Copyright (c) 2018-2022  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Runtime.InteropServices;

namespace Crow.VkvgBackend
{
	[StructLayout (LayoutKind.Sequential)]
	internal struct FontExtents : IEquatable<FontExtents>
	{
		float ascent;
		float descent;
		float height;
		float maxXAdvance;
		float maxYAdvance;

		public float Ascent {
			get => ascent;
			set { ascent = value; }
		}

		public float Descent {
			get => descent;
			set { descent = value; }
		}

		public float Height {
			get => height;
			set { height = value; }
		}

		public float MaxXAdvance {
			get => maxXAdvance;
			set { maxXAdvance = value; }
		}

		public float MaxYAdvance {
			get => maxYAdvance;
			set { maxYAdvance = value; }
		}

		public FontExtents (float ascent, float descent, float height, float maxXAdvance, float maxYAdvance)
		{
			this.ascent = ascent;
			this.descent = descent;
			this.height = height;
			this.maxXAdvance = maxXAdvance;
			this.maxYAdvance = maxYAdvance;
		}

		public override int GetHashCode () => HashCode.Combine (ascent, descent, height, maxXAdvance, maxYAdvance);
		public override bool Equals (object obj) => obj is FontExtents fe ? Equals (fe) : false;

		public bool Equals(FontExtents other) =>
			ascent == other.ascent && descent == other.descent && height == other.height &&
			maxXAdvance == other.maxXAdvance && maxYAdvance == other.maxYAdvance;

		public static bool operator == (FontExtents extents, FontExtents other) => extents.Equals (other);
		public static bool operator != (FontExtents extents, FontExtents other) => !extents.Equals (other);
	}
}