// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.Fonts.Tables.AdvancedTypographic.Variations;
namespace SixLabors.Fonts.Tables.General.Colr {
///
/// Represents a COLR v1 ClipBox format 2 subtable with variation-aware int16 bounding box edges.
/// Each edge value is adjusted by a delta resolved from the ItemVariationStore.
///
///
internal sealed class ClipBoxFormat2 : ClipBox
{
///
/// The minimum x-coordinate of the clip box.
///
private readonly short xMin;
///
/// The minimum y-coordinate of the clip box.
///
private readonly short yMin;
///
/// The maximum x-coordinate of the clip box.
///
private readonly short xMax;
///
/// The maximum y-coordinate of the clip box.
///
private readonly short yMax;
///
/// The base index into the ItemVariationStore delta sets for the four edge values.
///
private readonly uint varIndexBase;
///
/// Initializes a new instance of the class.
///
/// The minimum x-coordinate.
/// The minimum y-coordinate.
/// The maximum x-coordinate.
/// The maximum y-coordinate.
/// The base index into the ItemVariationStore delta sets.
public ClipBoxFormat2(short xMin, short yMin, short xMax, short yMax, uint varIndexBase)
{
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
this.varIndexBase = varIndexBase;
}
///
public override Bounds GetBounds(ColrTable colr, GlyphVariationProcessor? processor)
{
float dx0 = colr.ResolveDelta(processor, this.varIndexBase + 0u);
float dy0 = colr.ResolveDelta(processor, this.varIndexBase + 1u);
float dx1 = colr.ResolveDelta(processor, this.varIndexBase + 2u);
float dy1 = colr.ResolveDelta(processor, this.varIndexBase + 3u);
float xMin = this.xMin + dx0;
float yMin = this.yMin + dy0;
float xMax = this.xMax + dx1;
float yMax = this.yMax + dy1;
return new Bounds(xMin, yMin, xMax, yMax);
}
}
}