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