// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
namespace SixLabors.Fonts.Rendering {
///
/// Base type for normalized paint definitions that can be used by any renderer.
/// Glyph sources must pre-apply all relevant transforms and resolve any palette
/// or format-specific constructs before creating a paint instance.
///
public abstract class Paint
{
///
/// Gets the per-layer opacity multiplier in the range [0, 1].
/// Renderers should multiply this value into the alpha channel of the final brush.
///
public float Opacity { get; init; } = 1f;
///
/// Gets or sets an optional transform to apply to the paint.
/// Used to pre-apply gradientTransform in SVG or equivalent.
///
internal Matrix3x2 Transform { get; set; }
///
/// Gets the composite mode to use when applying this paint over existing content.
///
public CompositeMode CompositeMode { get; init; } = CompositeMode.SrcOver;
}
///
/// Solid color paint (direct RGBA). Interpreters must resolve palettes to RGBA.
/// Compatible with OT-SVG solid fills and COLR v1 PaintSolid after CPAL resolution.
///
public sealed class SolidPaint : Paint
{
///
/// Gets the color to use for the fill. Alpha is respected and further multiplied by .
///
public GlyphColor Color { get; init; }
}
///
/// Linear gradient paint.
///
public sealed class LinearGradientPaint : Paint
{
///
/// Gets the coordinate system for and .
///
internal GradientUnits Units { get; init; }
///
/// Gets the gradient start point. Normalized if is .
///
public Vector2 P0 { get; init; }
///
/// Gets the gradient end point. Normalized if is .
///
public Vector2 P1 { get; init; }
///
/// Gets the rotation point for the gradient. Normalized if is .
///
public Vector2? P2 { get; init; }
///
/// Gets the spread method applied when sampling outside the [0, 1] range.
///
public SpreadMethod Spread { get; init; } = SpreadMethod.Pad;
///
/// Gets the ordered gradient stops (ascending by ).
///
public GradientStop[] Stops { get; init; } = [];
}
///
/// Represents a radial gradient paint defined by two circles.
/// The first circle is centered at with radius .
/// The second circle is centered at with radius .
/// The color transition is computed between these two circles.
/// Compatible with two-circle radial gradients used by HTML Canvas and OpenType COLR v1.
///
public sealed class RadialGradientPaint : Paint
{
///
/// Gets the coordinate system for , ,
/// , and .
///
internal GradientUnits Units { get; init; }
///
/// Gets the center of the starting circle of the gradient.
///
public Vector2 Center0 { get; init; }
///
/// Gets the radius of the starting circle of the gradient.
/// If is ,
/// the radius is normalized to the bounds.
///
public float Radius0 { get; init; }
///
/// Gets the center of the ending circle of the gradient.
///
public Vector2 Center1 { get; init; }
///
/// Gets the radius of the ending circle of the gradient.
/// If is ,
/// the radius is normalized to the bounds.
///
public float Radius1 { get; init; }
///
/// Gets the spread method applied when sampling outside the [0, 1] range.
///
public SpreadMethod Spread { get; init; } = SpreadMethod.Pad;
///
/// Gets the ordered gradient stops, ascending by .
///
public GradientStop[] Stops { get; init; } = [];
}
///
/// Sweep (conic) gradient paint. Angles are expressed in degrees in the renderer's y-down space.
///
public sealed class SweepGradientPaint : Paint
{
///
/// Gets the coordinate system for . Sweep gradients are typically user-space.
///
internal GradientUnits Units { get; init; } = GradientUnits.UserSpaceOnUse;
///
/// Gets the center of the sweep gradient.
///
public Vector2 Center { get; init; }
///
/// Gets the start angle in degrees.
///
public float StartAngle { get; init; }
///
/// Gets the end angle in degrees.
///
public float EndAngle { get; init; }
///
/// Gets the spread method applied when sampling outside the [0, 1] range.
///
public SpreadMethod Spread { get; init; } = SpreadMethod.Pad;
///
/// Gets the ordered gradient stops (ascending by ).
///
public GradientStop[] Stops { get; init; } = [];
}
}