diff --git a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs index 6f335aec..d1d718c4 100644 --- a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs +++ b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs @@ -66,7 +66,7 @@ { } - public PdfPoint CloseSubpath() + public PdfPoint? CloseSubpath() { return new PdfPoint(); } diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index eff2248c..1367fbb6 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -419,8 +419,13 @@ CurrentSubpath = new PdfSubpath(); } - public PdfPoint CloseSubpath() + public PdfPoint? CloseSubpath() { + if (CurrentSubpath == null) + { + return null; + } + PdfPoint point; if (CurrentSubpath.Commands[0] is Move move) { diff --git a/src/UglyToad.PdfPig/Graphics/IOperationContext.cs b/src/UglyToad.PdfPig/Graphics/IOperationContext.cs index 0b20e114..f08e16f3 100644 --- a/src/UglyToad.PdfPig/Graphics/IOperationContext.cs +++ b/src/UglyToad.PdfPig/Graphics/IOperationContext.cs @@ -89,7 +89,7 @@ /// /// Close the current subpath. /// - PdfPoint CloseSubpath(); + PdfPoint? CloseSubpath(); /// /// Add the current subpath to the path. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/PathConstruction/CloseSubpath.cs b/src/UglyToad.PdfPig/Graphics/Operations/PathConstruction/CloseSubpath.cs index a20f6543..595afdda 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/PathConstruction/CloseSubpath.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/PathConstruction/CloseSubpath.cs @@ -29,7 +29,11 @@ /// public void Run(IOperationContext operationContext) { - operationContext.CurrentPosition = operationContext.CloseSubpath(); + var point = operationContext.CloseSubpath(); + if (point.HasValue) + { + operationContext.CurrentPosition = point.Value; + } } ///