Compare commits
15 Commits
6c222ca9ad
...
eb024acfa7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb024acfa7 | ||
|
|
210ce072f8 | ||
|
|
036e1f68a8 | ||
|
|
0b87a3746a | ||
|
|
db84abf0e7 | ||
|
|
14be46d3d6 | ||
|
|
78b5e3f5cc | ||
|
|
093e64de81 | ||
|
|
43db4e275b | ||
|
|
353f7698f4 | ||
|
|
d5b4ea46d3 | ||
|
|
b6563d71b0 | ||
|
|
8a6a11c1bc | ||
|
|
cbd71aa2b9 | ||
|
|
df019a7243 |
23
EnvelopeGenerator.Web/Controllers/ConfigController.cs
Normal file
23
EnvelopeGenerator.Web/Controllers/ConfigController.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using EnvelopeGenerator.Web.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Web.Controllers;
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class ConfigController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly AnnotationParams _annotParams;
|
||||||
|
|
||||||
|
public ConfigController(IOptions<AnnotationParams> annotationParamsOptions)
|
||||||
|
{
|
||||||
|
_annotParams = annotationParamsOptions.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("Annotations")]
|
||||||
|
public IActionResult GetAnnotationParams()
|
||||||
|
{
|
||||||
|
return Ok(_annotParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,58 +1,106 @@
|
|||||||
namespace EnvelopeGenerator.Web.Models;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
public record Annotation(
|
namespace EnvelopeGenerator.Web.Models;
|
||||||
string Id,
|
|
||||||
string? HorBoundAnnotId = null, string? VerBoundAnnotId = null)
|
public record Annotation
|
||||||
{
|
{
|
||||||
#region Layout
|
public required string Name { get; init; }
|
||||||
internal double _marginX = default;
|
|
||||||
|
|
||||||
internal double _marginY = default;
|
#region Bound Annotation
|
||||||
|
[JsonIgnore]
|
||||||
|
public string? HorBoundAnnotName { get; init; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string? VerBoundAnnotName { get; init; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Layout
|
||||||
|
internal double _marginLeft = default;
|
||||||
|
|
||||||
|
internal double _marginTop = default;
|
||||||
|
|
||||||
internal double _width = default;
|
internal double _width = default;
|
||||||
|
|
||||||
internal double _height = default;
|
internal double _height = default;
|
||||||
|
|
||||||
public double MarginX
|
[JsonIgnore]
|
||||||
|
public double MarginLeft
|
||||||
{
|
{
|
||||||
get => _marginX;
|
get => _marginLeft;
|
||||||
init => _marginX = value;
|
init => _marginLeft = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double MarginY
|
[JsonIgnore]
|
||||||
|
public double MarginLeftRatio { get; init; } = 1;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public double MarginTop
|
||||||
{
|
{
|
||||||
get => _marginY;
|
get => _marginTop;
|
||||||
init => _marginY = value;
|
init => _marginTop = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public double MarginTopRatio { get; init; } = 1;
|
||||||
|
|
||||||
public double Width
|
public double Width
|
||||||
{
|
{
|
||||||
get => _width;
|
get => _width;
|
||||||
init => _width = value;
|
init => _width = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public double WidthRatio { get; init; } = 1;
|
||||||
|
|
||||||
public double Height
|
public double Height
|
||||||
{
|
{
|
||||||
get => _height;
|
get => _height;
|
||||||
init => _height = value;
|
init => _height = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public double HeightRatio { get; init; } = 1;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Pos
|
#region Position
|
||||||
public double PosX => MarginX + (HorBoundAnnot?.HorBoundary ?? 0);
|
public double Left => MarginLeft + (HorBoundAnnot?.HorBoundary ?? 0);
|
||||||
|
|
||||||
public double PosY => MarginY + (VerBoundAnnot?.VerBoundary ?? 0);
|
public double Top => MarginTop + (VerBoundAnnot?.VerBoundary ?? 0);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Boundary
|
#region Boundary
|
||||||
public double HorBoundary => MarginX + Width;
|
[JsonIgnore]
|
||||||
|
public double HorBoundary => Left + Width;
|
||||||
|
|
||||||
public double VerBoundary => MarginY + Height;
|
[JsonIgnore]
|
||||||
|
public double VerBoundary => Top + Height;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region BoundAnnot
|
#region BoundAnnot
|
||||||
public Annot? HorBoundAnnot { get; set; }
|
[JsonIgnore]
|
||||||
|
public Annotation? HorBoundAnnot { get; set; }
|
||||||
|
|
||||||
public Annot? VerBoundAnnot { get; set; }
|
[JsonIgnore]
|
||||||
|
public Annotation? VerBoundAnnot { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
internal Annotation Default
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// To set default value, annotation must have default (0) value but default must has non-default value
|
||||||
|
if (_marginLeft == default && value.MarginLeft != default)
|
||||||
|
_marginLeft = value.MarginLeft * MarginLeftRatio;
|
||||||
|
|
||||||
|
if (_marginTop == default && value.MarginTop != default)
|
||||||
|
_marginTop = value.MarginTop * MarginTopRatio;
|
||||||
|
|
||||||
|
if (_width == default && value.Width != default)
|
||||||
|
_width = value.Width * WidthRatio;
|
||||||
|
|
||||||
|
if (_height == default && value.Height != default)
|
||||||
|
_height = value.Height * HeightRatio;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
53
EnvelopeGenerator.Web/Models/AnnotationParams.cs
Normal file
53
EnvelopeGenerator.Web/Models/AnnotationParams.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Web.Models;
|
||||||
|
|
||||||
|
public class AnnotationParams
|
||||||
|
{
|
||||||
|
[JsonIgnore]
|
||||||
|
public Annotation? DefaultAnnotation { get; init; }
|
||||||
|
|
||||||
|
private readonly IEnumerable<Annotation> _annots = new List<Annotation>();
|
||||||
|
|
||||||
|
public Annotation this[string name] => _annots.First(a => a.Name == name);
|
||||||
|
|
||||||
|
public bool TryGet(string name, out Annotation annotation)
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||||
|
annotation = _annots.FirstOrDefault(a => a.Name == name);
|
||||||
|
#pragma warning restore CS8601 // Possible null reference assignment.
|
||||||
|
return annotation is not null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public required IEnumerable<Annotation> Annotations
|
||||||
|
{
|
||||||
|
get => _annots;
|
||||||
|
init
|
||||||
|
{
|
||||||
|
_annots = value;
|
||||||
|
|
||||||
|
if (DefaultAnnotation is not null)
|
||||||
|
foreach (var annot in _annots)
|
||||||
|
annot.Default = DefaultAnnotation;
|
||||||
|
|
||||||
|
foreach (var annot in _annots)
|
||||||
|
{
|
||||||
|
#region set bound annotations
|
||||||
|
// horizontal
|
||||||
|
if (annot.HorBoundAnnotName is string horBoundAnnotName)
|
||||||
|
if (TryGet(horBoundAnnotName, out var horBoundAnnot))
|
||||||
|
annot.HorBoundAnnot = horBoundAnnot;
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException($"{horBoundAnnotName} added as bound anotation. However, it is not defined.");
|
||||||
|
|
||||||
|
// vertical
|
||||||
|
if (annot.VerBoundAnnotName is string verBoundAnnotName)
|
||||||
|
if (TryGet(verBoundAnnotName, out var verBoundAnnot))
|
||||||
|
annot.VerBoundAnnot = verBoundAnnot;
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException($"{verBoundAnnotName} added as bound anotation. However, it is not defined.");
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -163,6 +163,8 @@ try
|
|||||||
|
|
||||||
builder.ConfigureBySection<CustomImages>();
|
builder.ConfigureBySection<CustomImages>();
|
||||||
|
|
||||||
|
builder.ConfigureBySection<AnnotationParams>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
@@ -149,5 +149,24 @@
|
|||||||
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
||||||
"Receiver": []
|
"Receiver": []
|
||||||
},
|
},
|
||||||
"MainPageTitle": null
|
"MainPageTitle": null,
|
||||||
|
"AnnotationParams": {
|
||||||
|
"DefaultAnnotation": {
|
||||||
|
"Width": 1,
|
||||||
|
"Height": 0.5
|
||||||
|
},
|
||||||
|
"Annotations": [
|
||||||
|
{
|
||||||
|
"Name": "Signature"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "City",
|
||||||
|
"VerBoundAnnotName": "Signature"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "Date",
|
||||||
|
"VerBoundAnnotName": "City"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user