// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.IO;
namespace SixLabors.Fonts.Tables.AdvancedTypographic {
///
/// A ClassSequenceRule table describes a context rule using glyph class values.
///
///
internal sealed class ClassSequenceRuleTable
{
///
/// Initializes a new instance of the class.
///
/// The array of input sequence classes, beginning with the second glyph position.
/// The array of sequence lookup records.
private ClassSequenceRuleTable(ushort[] inputSequence, SequenceLookupRecord[] seqLookupRecords)
{
this.InputSequence = inputSequence;
this.SequenceLookupRecords = seqLookupRecords;
}
///
/// Gets the array of input sequence classes, beginning with the second glyph position.
///
public ushort[] InputSequence { get; }
///
/// Gets the array of sequence lookup records specifying actions to be applied.
///
public SequenceLookupRecord[] SequenceLookupRecords { get; }
///
/// Loads the from the binary reader at the specified offset.
///
/// The big endian binary reader.
/// Offset from the beginning of the ClassSequenceRule table.
/// The .
public static ClassSequenceRuleTable Load(BigEndianBinaryReader reader, long offset)
{
// ClassSequenceRule
// +----------------------+----------------------------------+------------------------------------------+
// | Type | Name | Description |
// +======================+==================================+==========================================+
// | uint16 | glyphCount | Number of glyphs to be matched |
// +----------------------+----------------------------------+------------------------------------------+
// | uint16 | seqLookupCount | Number of SequenceLookupRecords |
// +----------------------+----------------------------------+------------------------------------------+
// | uint16 | inputSequence[glyphCount - 1] | Sequence of classes to be matched to the |
// | | | input glyph sequence, beginning with the |
// | | | second glyph position |
// +----------------------+----------------------------------+------------------------------------------+
// | SequenceLookupRecord | seqLookupRecords[seqLookupCount] | Array of SequenceLookupRecords |
// +----------------------+----------------------------------+------------------------------------------+
reader.Seek(offset, SeekOrigin.Begin);
ushort glyphCount = reader.ReadUInt16();
ushort seqLookupCount = reader.ReadUInt16();
ushort[] inputSequence = reader.ReadUInt16Array(glyphCount - 1);
SequenceLookupRecord[] seqLookupRecords = SequenceLookupRecord.LoadArray(reader, seqLookupCount);
return new ClassSequenceRuleTable(inputSequence, seqLookupRecords);
}
}
}