// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
using SixLabors.Fonts.Rendering;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Text {
///
/// Describes a single painted layer as a span within the glyph's path list.
///
public readonly struct GlyphLayerInfo
{
///
/// Initializes a new instance of the struct.
///
/// Start index (inclusive) of the layer's paths within the glyph's path list.
/// Number of paths in this layer.
/// The layer paint (null means use renderer default).
/// The fill rule to use for this layer.
/// Axis-aligned bounds of the layer geometry.
/// An optional semantic hint for the layer type.
internal GlyphLayerInfo(
int startIndex,
int count,
Paint? paint,
FillRule fillRule,
RectangleF bounds,
GlyphLayerKind kind)
{
this.StartIndex = startIndex;
this.Count = count;
this.Paint = paint;
this.IntersectionRule = TextUtilities.MapFillRule(fillRule);
CompositeMode compositeMode = paint?.CompositeMode ?? CompositeMode.SrcOver;
this.PixelAlphaCompositionMode = TextUtilities.MapCompositionMode(compositeMode);
this.PixelColorBlendingMode = TextUtilities.MapBlendingMode(compositeMode);
this.Bounds = bounds;
this.Kind = kind;
}
private GlyphLayerInfo(
int startIndex,
int count,
Paint? paint,
IntersectionRule intersectionRule,
PixelAlphaCompositionMode compositionMode,
PixelColorBlendingMode colorBlendingMode,
RectangleF bounds,
GlyphLayerKind kind)
{
this.StartIndex = startIndex;
this.Count = count;
this.Paint = paint;
this.IntersectionRule = intersectionRule;
this.PixelAlphaCompositionMode = compositionMode;
this.PixelColorBlendingMode = colorBlendingMode;
this.Bounds = bounds;
this.Kind = kind;
}
///
/// Gets the start index (inclusive) of the layer span within the glyph's path list.
///
public int StartIndex { get; }
///
/// Gets the number of paths in this layer.
///
public int Count { get; }
///
/// Gets the paint definition to use for this layer; may be .
///
public Paint? Paint { get; }
///
/// Gets the fill rule for rasterization of this layer.
///
public IntersectionRule IntersectionRule { get; }
///
/// Gets the pixel alpha composition mode to use for this layer.
///
public PixelAlphaCompositionMode PixelAlphaCompositionMode { get; }
///
/// Gets the pixel color blending mode to use for this layer.
///
public PixelColorBlendingMode PixelColorBlendingMode { get; }
///
/// Gets the bounds of the layer geometry (device space).
///
public RectangleF Bounds { get; }
///
/// Gets the semantic kind of the layer (for policy decisions).
///
public GlyphLayerKind Kind { get; }
internal static GlyphLayerInfo Transform(in GlyphLayerInfo info, Matrix4x4 matrix)
=> new(
info.StartIndex,
info.Count,
info.Paint,
info.IntersectionRule,
info.PixelAlphaCompositionMode,
info.PixelColorBlendingMode,
RectangleF.Transform(info.Bounds, matrix),
info.Kind);
}
}