// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System;
using System.IO;
namespace SixLabors.Fonts.Tables.AdvancedTypographic {
///
/// A ChainedSequenceRuleSet table contains an array of ChainedSequenceRule tables that define
/// chained context rules for simple glyph contexts (glyph ID based).
///
///
internal sealed class ChainedSequenceRuleSetTable
{
///
/// Initializes a new instance of the class.
///
/// The array of chained sequence rule tables.
private ChainedSequenceRuleSetTable(ChainedSequenceRuleTable[] subRules) => this.SequenceRuleTables = subRules;
///
/// Gets the array of chained sequence rule tables.
///
public ChainedSequenceRuleTable[] SequenceRuleTables { get; }
///
/// Loads the from the binary reader at the specified offset.
///
/// The big endian binary reader.
/// Offset from the beginning of the ChainedSequenceRuleSet table.
/// The .
public static ChainedSequenceRuleSetTable Load(BigEndianBinaryReader reader, long offset)
{
// ChainedSequenceRuleSet
// +----------+--------------------------------------------+-----------------------------------------+
// | Type | Name | Description |
// +==========+============================================+=========================================+
// | uint16 | chainedSeqRuleCount | Number of ChainedSequenceRule tables |
// +----------+--------------------------------------------+-----------------------------------------+
// | Offset16 | chainedSeqRuleOffsets[chainedSeqRuleCount] | Array of offsets to ChainedSequenceRule |
// | | | tables, from beginning of |
// | | | ChainedSequenceRuleSet table |
// +----------+--------------------------------------------+-----------------------------------------+
reader.Seek(offset, SeekOrigin.Begin);
ushort chainedSeqRuleCount = reader.ReadUInt16();
using Buffer chainedSeqRuleOffsetsBuffer = new(chainedSeqRuleCount);
Span chainedSeqRuleOffsets = chainedSeqRuleOffsetsBuffer.GetSpan();
reader.ReadUInt16Array(chainedSeqRuleOffsets);
var chainedSequenceRules = new ChainedSequenceRuleTable[chainedSeqRuleCount];
for (int i = 0; i < chainedSequenceRules.Length; i++)
{
chainedSequenceRules[i] = ChainedSequenceRuleTable.Load(reader, offset + chainedSeqRuleOffsets[i]);
}
return new ChainedSequenceRuleSetTable(chainedSequenceRules);
}
}
}