// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.IO;
namespace SixLabors.Fonts.Tables.General.Colr {
///
/// Represents the COLR v1 LayerList, which stores an array of offsets to paint tables.
/// PaintColrLayers references ranges within this list to compose multi-layer color glyphs.
///
///
internal sealed class LayerList
{
///
/// Initializes a new instance of the class.
///
/// The array of paint table offsets relative to the beginning of the COLR table.
public LayerList(uint[] paintOffsets)
=> this.PaintOffsets = paintOffsets;
///
/// Gets the array of paint table offsets relative to the beginning of the COLR table.
///
public uint[] PaintOffsets { get; }
///
/// Gets the number of paint offsets in the list.
///
public int Count => this.PaintOffsets.Length;
///
/// Loads a from the given reader at the specified offset.
///
/// The binary reader positioned within the COLR table.
/// The offset from the beginning of the COLR table to the LayerList.
/// The loaded , or if the offset is zero or the list is empty.
public static LayerList? Load(BigEndianBinaryReader reader, uint offset)
{
if (offset == 0)
{
return null;
}
reader.Seek(offset, SeekOrigin.Begin);
uint count = reader.ReadUInt32();
if (count == 0)
{
return null;
}
// Offsets are relative to the table start; convert to COLR-relative.
uint[] offsets = new uint[count];
for (int i = 0; i < count; i++)
{
offsets[i] = offset + reader.ReadOffset32();
}
return new LayerList(offsets);
}
}
}