-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathKerningSubTable.cs
More file actions
78 lines (69 loc) · 2.71 KB
/
KerningSubTable.cs
File metadata and controls
78 lines (69 loc) · 2.71 KB
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
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
namespace SixLabors.Fonts.Tables.General.Kern;
internal abstract class KerningSubTable
{
private readonly KerningCoverage coverage;
public KerningSubTable(KerningCoverage coverage)
=> this.coverage = coverage;
public static KerningSubTable? Load(BigEndianBinaryReader reader)
{
// Kerning subtables will share the same header format.
// This header is used to identify the format of the subtable and the kind of information it contains:
// +--------+----------+----------------------------------------------------------+
// | Type | Field | Description |
// +========+==========+==========================================================+
// | uint16 | version | Kern subtable version number |
// +--------+----------+----------------------------------------------------------+
// | uint16 | length | Length of the subtable, in bytes(including this header). |
// +--------+----------+----------------------------------------------------------+
// | uint16 | coverage | What type of information is contained in this table. |
// +--------+----------+----------------------------------------------------------+
ushort subVersion = reader.ReadUInt16();
ushort length = reader.ReadUInt16();
KerningCoverage coverage = KerningCoverage.Read(reader);
if (coverage.Format == 0)
{
return Format0SubTable.Load(reader, coverage);
}
else
{
// we don't support versions other than 'Format 0' same as Windows
return null;
}
}
protected abstract bool TryGetOffset(ushort index1, ushort index2, out short offset);
public bool TryApplyOffset(ushort index1, ushort index2, ref Vector2 result)
{
if (this.TryGetOffset(index1, index2, out short offset))
{
if (this.coverage.Horizontal)
{
// apply to X
if (this.coverage.OverrideAccumulator)
{
result.X = offset;
}
else
{
result.X += offset;
}
}
else
{
// apply to Y
if (this.coverage.OverrideAccumulator)
{
result.Y = offset;
}
else
{
result.Y += offset;
}
}
return true;
}
return false;
}
}