49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace EnvelopeGenerator.Web.Models.Annotation;
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
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 void Locate(IEnumerable<IAnnotation> 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;
|
|
}
|
|
}
|