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