using System.Text.Json.Serialization; namespace EnvelopeGenerator.Web.Models.Annotation; /// /// The Background is an annotation for the PSPDF Kit. However, it has no function. /// It is only the first annotation as a background for other annotations. /// public record Background : IAnnotation { [JsonIgnore] public double Margin { get; init; } public string Name { get; } = "Background"; public double? Width { get; set; } public double? Height { get; set; } public double Left { get; set; } public double Top { get; set; } public Color? BackgroundColor { get; init; } #region Border public Color? BorderColor { get; init; } public string? BorderStyle { get; init; } public int? BorderWidth { get; set; } #endregion public void Locate(IEnumerable annotations) { // set Top if (annotations.MinBy(a => a.Top)?.Top is double minTop) Top = minTop; // set Left if (annotations.MinBy(a => a.Left)?.Left is double minLeft) Left = minLeft; // set Width if(annotations.MaxBy(a => a.GetRight())?.GetRight() is double maxRight) Width = maxRight - Left; // set Height if (annotations.MaxBy(a => a.GetBottom())?.GetBottom() is double maxBottom) Height = maxBottom - Top; // add margins Top -= Margin; Left -= Margin; Width += Margin * 2; Height += Margin * 2; } }