diff --git a/src/UglyToad.PdfPig.Tests/Core/PdfPathTests.cs b/src/UglyToad.PdfPig.Tests/Core/PdfSubpathTests.cs similarity index 99% rename from src/UglyToad.PdfPig.Tests/Core/PdfPathTests.cs rename to src/UglyToad.PdfPig.Tests/Core/PdfSubpathTests.cs index 83835b1b..cf717e65 100644 --- a/src/UglyToad.PdfPig.Tests/Core/PdfPathTests.cs +++ b/src/UglyToad.PdfPig.Tests/Core/PdfSubpathTests.cs @@ -4,7 +4,7 @@ using UglyToad.PdfPig.Core; using Xunit; - public class PdfPathTests + public class PdfSubpathTests { private static readonly DoubleComparer DoubleComparer = new DoubleComparer(3); private static readonly DoubleComparer PreciseDoubleComparer = new DoubleComparer(6); @@ -373,8 +373,11 @@ public void IsCounterClockwise(double[][] source, bool expected) { PdfSubpath pdfPath = new PdfSubpath(); - foreach (var point in source) + pdfPath.MoveTo(source[0][0], source[0][1]); + + for (int i = 1; i < source.Length; i++) { + var point = source[i]; pdfPath.LineTo(point[0], point[1]); } pdfPath.LineTo(source[0][0], source[0][1]); // close path diff --git a/src/UglyToad.PdfPig.Tests/Fonts/Type1/Type1FontParserTests.cs b/src/UglyToad.PdfPig.Tests/Fonts/Type1/Type1FontParserTests.cs index dee960b1..7a62be18 100644 --- a/src/UglyToad.PdfPig.Tests/Fonts/Type1/Type1FontParserTests.cs +++ b/src/UglyToad.PdfPig.Tests/Fonts/Type1/Type1FontParserTests.cs @@ -63,7 +63,7 @@ foreach (var charString in result.CharStrings.CharStrings) { Assert.True(result.CharStrings.TryGenerate(charString.Key, out var path)); - builder.AppendLine(path.ToFullSvg(double.NaN)); // TODO + builder.AppendLine(path.ToFullSvg(0)); } builder.Append(""); diff --git a/src/UglyToad.PdfPig.Tests/Geometry/PdfPathLineTests.cs b/src/UglyToad.PdfPig.Tests/Geometry/PdfSubpathLineTests.cs similarity index 99% rename from src/UglyToad.PdfPig.Tests/Geometry/PdfPathLineTests.cs rename to src/UglyToad.PdfPig.Tests/Geometry/PdfSubpathLineTests.cs index 28ca3a84..7f2dbe39 100644 --- a/src/UglyToad.PdfPig.Tests/Geometry/PdfPathLineTests.cs +++ b/src/UglyToad.PdfPig.Tests/Geometry/PdfSubpathLineTests.cs @@ -6,7 +6,7 @@ using Xunit; using static UglyToad.PdfPig.Core.PdfSubpath; - public class PdfPathLineTests + public class PdfSubpathLineTests { private static readonly DoubleComparer DoubleComparer = new DoubleComparer(3); private static readonly DoubleComparer PreciseDoubleComparer = new DoubleComparer(6); diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs index 00a8ff0f..650063c1 100644 --- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs +++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs @@ -92,6 +92,7 @@ "UglyToad.PdfPig.Geometry.GeometryExtensions", "UglyToad.PdfPig.Graphics.Colors.CMYKColor", "UglyToad.PdfPig.Graphics.Colors.ColorSpace", + "UglyToad.PdfPig.Graphics.PdfPath", "UglyToad.PdfPig.Graphics.Colors.ColorSpaceExtensions", "UglyToad.PdfPig.Graphics.Colors.ColorSpaceFamily", "UglyToad.PdfPig.Graphics.Colors.GrayColor", @@ -110,15 +111,16 @@ "UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByNonZeroWindingIntersect", "UglyToad.PdfPig.Graphics.Operations.Compatibility.BeginCompatibilitySection", "UglyToad.PdfPig.Graphics.Operations.Compatibility.EndCompatibilitySection", - "UglyToad.PdfPig.Graphics.Operations.CloseAndStrokePath", - "UglyToad.PdfPig.Graphics.Operations.CloseFillPathEvenOddRuleAndStroke", - "UglyToad.PdfPig.Graphics.Operations.CloseFillPathNonZeroWindingAndStroke", - "UglyToad.PdfPig.Graphics.Operations.EndPath", - "UglyToad.PdfPig.Graphics.Operations.FillPathEvenOddRule", - "UglyToad.PdfPig.Graphics.Operations.FillPathEvenOddRuleAndStroke", - "UglyToad.PdfPig.Graphics.Operations.FillPathNonZeroWinding", - "UglyToad.PdfPig.Graphics.Operations.FillPathNonZeroWindingAndStroke", - "UglyToad.PdfPig.Graphics.Operations.FillPathNonZeroWindingCompatibility", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.CloseAndStrokePath", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.CloseFillPathEvenOddRuleAndStroke", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.CloseFillPathNonZeroWindingAndStroke", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.EndPath", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.FillPathEvenOddRule", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.FillPathEvenOddRuleAndStroke", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.FillPathNonZeroWinding", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.FillPathNonZeroWindingAndStroke", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.FillPathNonZeroWindingCompatibility", + "UglyToad.PdfPig.Graphics.Operations.PathPainting.StrokePath", "UglyToad.PdfPig.Graphics.Operations.General.SetColorRenderingIntent", "UglyToad.PdfPig.Graphics.Operations.General.SetFlatnessTolerance", "UglyToad.PdfPig.Graphics.Operations.General.SetLineCap", @@ -160,7 +162,6 @@ "UglyToad.PdfPig.Graphics.Operations.SpecialGraphicsState.Pop", "UglyToad.PdfPig.Graphics.Operations.SpecialGraphicsState.Push", "UglyToad.PdfPig.Graphics.Operations.SpecialGraphicsState.SetGraphicsStateParametersFromDictionary", - "UglyToad.PdfPig.Graphics.Operations.StrokePath", "UglyToad.PdfPig.Graphics.Operations.TextObjects.BeginText", "UglyToad.PdfPig.Graphics.Operations.TextObjects.EndText", "UglyToad.PdfPig.Graphics.Operations.TextPositioning.MoveToNextLine", diff --git a/src/UglyToad.PdfPig/Geometry/Clipping.cs b/src/UglyToad.PdfPig/Geometry/Clipping.cs index 47606886..e1e89318 100644 --- a/src/UglyToad.PdfPig/Geometry/Clipping.cs +++ b/src/UglyToad.PdfPig/Geometry/Clipping.cs @@ -5,7 +5,7 @@ /// /// /// - public static class Clipping + internal static class Clipping { const double factor = 10_000.0; diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index 6fe31edb..391d8413 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -451,8 +451,7 @@ { if (CurrentPath == null) { - throw new ArgumentException("StrokePath(null)"); - //return; + return; } CurrentPath.SetStroked(); @@ -469,8 +468,7 @@ { if (CurrentPath == null) { - throw new ArgumentException("FillPath(null)"); - //return; + return; } CurrentPath.SetFilled(fillingRule); @@ -487,8 +485,7 @@ { if (CurrentPath == null) { - throw new ArgumentException("FillStrokePath(null)"); - //return; + return; } CurrentPath.SetFilled(fillingRule); @@ -514,7 +511,7 @@ { if (!clipPaths) { - // if we don't clip paths, add clipping paths + // if we don't clip paths, add clipping path to paths paths.Add(CurrentPath); markedContentStack.AddPath(CurrentPath); } @@ -573,24 +570,26 @@ { if (CurrentPath == null) { - throw new ArgumentException("ModifyClippingIntersect(null)"); + return; } AddCurrentSubpath(); - CurrentPath.SetClipping(clippingRule); - var currentClipping = GetCurrentState().CurrentClippingPath; - currentClipping.SetClipping(clippingRule); - var newClippings = CurrentPath.Clip(currentClipping); - if (newClippings == null) + if (clipPaths) { - Console.WriteLine("ContentStreamProcessor.ModifyClippingIntersect(): Warning, empty clipping path found... Clipping path not updated."); - log.Warn("ModifyClippingIntersect(): Warning, empty clipping path found... Clipping path not updated."); - } - else - { - GetCurrentState().CurrentClippingPath = newClippings; + var currentClipping = GetCurrentState().CurrentClippingPath; + currentClipping.SetClipping(clippingRule); + + var newClippings = CurrentPath.Clip(currentClipping); + if (newClippings == null) + { + log.Warn("Empty clipping path found. Clipping path not updated."); + } + else + { + GetCurrentState().CurrentClippingPath = newClippings; + } } }