// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.Fonts.Tables {
///
/// Represents a single entry in the WOFF2 triplet encoding table, which defines how
/// glyph coordinate triplets (flag, x, y) are packed into a compact binary representation.
///
///
internal readonly struct TripleEncodingRecord
{
/// The total number of bytes for this triplet (flag + x + y).
public readonly byte ByteCount;
/// The number of bits used to encode the X coordinate value.
public readonly byte XBits;
/// The number of bits used to encode the Y coordinate value.
public readonly byte YBits;
/// The delta offset added to the raw X coordinate value before applying the sign.
public readonly ushort DeltaX;
/// The delta offset added to the raw Y coordinate value before applying the sign.
public readonly ushort DeltaY;
/// The sign multiplier for the X coordinate (-1, 0, or 1).
public readonly sbyte Xsign;
/// The sign multiplier for the Y coordinate (-1, 0, or 1).
public readonly sbyte Ysign;
///
/// Initializes a new instance of the struct.
///
/// The total byte count for this triplet.
/// The number of bits for the X coordinate.
/// The number of bits for the Y coordinate.
/// The delta offset for X.
/// The delta offset for Y.
/// The sign multiplier for X.
/// The sign multiplier for Y.
public TripleEncodingRecord(
byte byteCount,
byte xbits,
byte ybits,
ushort deltaX,
ushort deltaY,
sbyte xsign,
sbyte ysign)
{
this.ByteCount = byteCount;
this.XBits = xbits;
this.YBits = ybits;
this.DeltaX = deltaX;
this.DeltaY = deltaY;
this.Xsign = xsign;
this.Ysign = ysign;
}
///
/// Transforms a raw X coordinate value using the delta and sign from this record.
///
/// The raw X coordinate value read from the stream.
/// The signed, delta-adjusted X coordinate.
public int Tx(int orgX) => (orgX + this.DeltaX) * this.Xsign;
///
/// Transforms a raw Y coordinate value using the delta and sign from this record.
///
/// The raw Y coordinate value read from the stream.
/// The signed, delta-adjusted Y coordinate.
public int Ty(int orgY) => (orgY + this.DeltaY) * this.Ysign;
}
}