Introduced the `UnitOfLength` enum to represent measurement units (Inch and Point) for signature positioning, with detailed documentation and conversion logic. Updated `SignatureDto` to use `init` accessors for immutability, added backing fields for `X` and `Y` with conversion support, and introduced the `Factor` property to handle unit conversions. Added a `Convert` method to enable switching between units of length and improved extensibility for future `SenderAppType` support. Enhanced code readability and maintainability with detailed comments and remarks.
68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using EnvelopeGenerator.ReceiverUI.Models.Constants;
|
|
|
|
namespace EnvelopeGenerator.ReceiverUI.Models;
|
|
|
|
/// <summary>
|
|
/// Represents a signature position on a PDF page.
|
|
/// Coordinates stored in INCHES (GdPicture14 native unit).
|
|
/// Origin: Top-left corner, X increases right, Y increases down.
|
|
/// </summary>
|
|
public class SignatureDto
|
|
{
|
|
/// <summary>Unique identifier.</summary>
|
|
public int Id { get; init; }
|
|
|
|
private double _x;
|
|
private double _y;
|
|
|
|
/// <summary>Horizontal position in INCHES from left edge.</summary>
|
|
public double X
|
|
{
|
|
get => _x * Factor;
|
|
init => _x = value;
|
|
}
|
|
|
|
/// <summary>Vertical position in INCHES from top edge.</summary>
|
|
public double Y
|
|
{
|
|
get => _y * Factor;
|
|
init => _y = value;
|
|
}
|
|
|
|
/// <summary>1-based page number.</summary>
|
|
public int Page { get; init; }
|
|
|
|
/// <summary>Sender application type that created this signature.</summary>
|
|
public SenderAppType SenderAppType { get; init; }
|
|
|
|
private UnitOfLength _unitOfLength;
|
|
|
|
public SignatureDto Convert(UnitOfLength unitOfLength)
|
|
{
|
|
_unitOfLength = unitOfLength;
|
|
return this;
|
|
}
|
|
|
|
public double Factor
|
|
{
|
|
get
|
|
{
|
|
if (SenderAppType != SenderAppType.LegacyFormApp)
|
|
{
|
|
throw new NotImplementedException(
|
|
$"SenderAppType '{SenderAppType}' is not yet implemented. " +
|
|
$"Currently, only '{nameof(SenderAppType.LegacyFormApp)}' is supported. " +
|
|
$"Future implementations will handle '{nameof(SenderAppType.ReceiverUIBlazorApp)}' and other types.");
|
|
}
|
|
|
|
// LegacyFormApp uses GdPicture14 with INCHES
|
|
return _unitOfLength switch
|
|
{
|
|
UnitOfLength.Inch => 1.0, // No conversion needed: INCHES → INCHES
|
|
UnitOfLength.Point => 72.0, // INCHES → PDF Points: 1 inch = 72 points (PDF standard, NOT pixels!)
|
|
_ => throw new InvalidOperationException(
|
|
$"Unknown UnitOfLength: {_unitOfLength}. Expected '{nameof(UnitOfLength.Inch)}' or '{nameof(UnitOfLength.Point)}'.")
|
|
};
|
|
}
|
|
}
|
|
} |