// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.Fonts.Tables.AdvancedTypographic.Variations {
///
/// Represents a delta-set row in an subtable.
/// Each delta set contains per-region delta adjustment values.
///
///
internal class DeltaSet
{
///
/// Initializes a new instance of the class by reading delta values from the binary reader.
///
/// The big-endian binary reader positioned at the delta set data.
/// The number of deltas encoded using the larger (word) type.
/// Whether word deltas are 32-bit (int32) instead of 16-bit (int16).
/// The total number of region indices (and thus the total number of deltas).
public DeltaSet(BigEndianBinaryReader reader, int wordDeltas, bool longWords, ushort regionIndexCount)
{
this.ShortDeltas = new int[wordDeltas];
for (int i = 0; i < wordDeltas; i++)
{
this.ShortDeltas[i] = longWords ? reader.ReadInt32() : reader.ReadInt16();
}
int remaining = regionIndexCount - wordDeltas;
this.RegionDeltas = new short[remaining];
for (int i = 0; i < remaining; i++)
{
this.RegionDeltas[i] = longWords ? reader.ReadInt16() : reader.ReadSByte();
}
this.Deltas = new int[this.RegionDeltas.Length + this.ShortDeltas.Length];
int offset = 0;
for (int i = 0; i < this.ShortDeltas.Length; i++)
{
this.Deltas[offset++] = this.ShortDeltas[i];
}
for (int i = 0; i < this.RegionDeltas.Length; i++)
{
this.Deltas[offset++] = this.RegionDeltas[i];
}
}
///
/// Gets the remaining deltas encoded using the smaller (short) type.
///
public short[] RegionDeltas { get; }
///
/// Gets the initial deltas encoded using the larger (word) type.
///
public int[] ShortDeltas { get; }
///
/// Gets the combined array of all deltas (word deltas followed by region deltas), one per region.
///
public int[] Deltas { get; }
}
}