Refactor PDF canvas transform to use Save/Restore state
Move Y-axis flip transform inside signature drawing block and wrap with SaveState/RestoreState to prevent side effects on other drawing operations and pages. Removes redundant page-level transformation for better encapsulation.
This commit is contained in:
@@ -105,17 +105,13 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
public Pdf<TInputStream, TOutputStream> Background<TSignature>(IEnumerable<TSignature> signatures, double widthPx = 1.9500000000000002, double heightPx = 2.52)
|
||||
where TSignature : ISignature
|
||||
{
|
||||
// once per page
|
||||
Page(page =>
|
||||
{
|
||||
var canvas = new PdfCanvas(page);
|
||||
canvas.ConcatMatrix(1, 0, 0, -1, 0, page.GetPageSize().GetHeight());
|
||||
});
|
||||
|
||||
foreach (var signature in signatures)
|
||||
Page(signature.Page, page =>
|
||||
{
|
||||
var canvas = new PdfCanvas(page);
|
||||
canvas.SaveState();
|
||||
canvas.ConcatMatrix(1, 0, 0, -1, 0, page.GetPageSize().GetHeight());
|
||||
|
||||
double inchFactor = 72;
|
||||
double magin = .2;
|
||||
double x = (signature.X - .7 - magin) * inchFactor;
|
||||
@@ -134,6 +130,8 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
canvas.SetFillColor(new DeviceRgb(204, 202, 198))
|
||||
.Rectangle(x, y + height - bottomLineLength, width, bottomLineLength)
|
||||
.Fill();
|
||||
|
||||
canvas.RestoreState();
|
||||
});
|
||||
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user