From 2a30631ab7055b21d10b142da714ae7947ac400b Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Fri, 4 Jan 2019 18:55:36 +0000 Subject: [PATCH] #26 make all operation classes public and test --- .../Operations/GraphicsStateOperationTests.cs | 23 +++++++++++++++++++ .../PublicApiScannerTests.cs | 12 +++++++++- .../CloseFillPathEvenOddRuleAndStroke.cs | 2 +- .../CloseFillPathNonZeroWindingAndStroke.cs | 2 +- .../FillPathEvenOddRuleAndStroke.cs | 2 +- .../Operations/SetNonStrokeColorDeviceGray.cs | 2 +- .../Operations/SetStrokeColorDeviceCmyk.cs | 2 +- .../Operations/SetStrokeColorDeviceGray.cs | 2 +- .../MoveToNextLineWithOffset.cs | 2 +- .../MoveToNextLineWithOffsetSetLeading.cs | 13 ++++++++++- .../TextPositioning/SetTextMatrix.cs | 9 +++++++- .../TextShowing/ShowTextsWithPositioning.cs | 18 +++++++++++++-- 12 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 src/UglyToad.PdfPig.Tests/Graphics/Operations/GraphicsStateOperationTests.cs diff --git a/src/UglyToad.PdfPig.Tests/Graphics/Operations/GraphicsStateOperationTests.cs b/src/UglyToad.PdfPig.Tests/Graphics/Operations/GraphicsStateOperationTests.cs new file mode 100644 index 00000000..e5be8e81 --- /dev/null +++ b/src/UglyToad.PdfPig.Tests/Graphics/Operations/GraphicsStateOperationTests.cs @@ -0,0 +1,23 @@ +namespace UglyToad.PdfPig.Tests.Graphics.Operations +{ + using System.Linq; + using System.Reflection; + using PdfPig.Graphics.Operations; + using Xunit; + + public class GraphicsStateOperationTests + { + [Fact] + public void AllOperationsArePublic() + { + var assembly = Assembly.GetAssembly(typeof(IGraphicsStateOperation)); + + var operationTypes = assembly.GetTypes().Where(x => typeof(IGraphicsStateOperation).IsAssignableFrom(x)); + + foreach (var operationType in operationTypes) + { + Assert.True(operationType.IsPublic, $"{operationType.Name} should be public."); + } + } + } +} diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs index eaeab994..3b0e1884 100644 --- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs +++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs @@ -59,8 +59,11 @@ "UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByEvenOddIntersect", "UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByNonZeroWindingIntersect", "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", @@ -81,7 +84,10 @@ "UglyToad.PdfPig.Graphics.Operations.PathConstruction.BeginNewSubpath", "UglyToad.PdfPig.Graphics.Operations.PathConstruction.CloseSubpath", "UglyToad.PdfPig.Graphics.Operations.SetNonStrokeColorDeviceCmyk", + "UglyToad.PdfPig.Graphics.Operations.SetNonStrokeColorDeviceGray", "UglyToad.PdfPig.Graphics.Operations.SetNonStrokeColorDeviceRgb", + "UglyToad.PdfPig.Graphics.Operations.SetStrokeColorDeviceCmyk", + "UglyToad.PdfPig.Graphics.Operations.SetStrokeColorDeviceGray", "UglyToad.PdfPig.Graphics.Operations.SetStrokeColorDeviceRgb", "UglyToad.PdfPig.Graphics.Operations.SpecialGraphicsState.ModifyCurrentTransformationMatrix", "UglyToad.PdfPig.Graphics.Operations.SpecialGraphicsState.Pop", @@ -90,9 +96,13 @@ "UglyToad.PdfPig.Graphics.Operations.TextObjects.BeginText", "UglyToad.PdfPig.Graphics.Operations.TextObjects.EndText", "UglyToad.PdfPig.Graphics.Operations.TextPositioning.MoveToNextLine", + "UglyToad.PdfPig.Graphics.Operations.TextPositioning.MoveToNextLineWithOffset", + "UglyToad.PdfPig.Graphics.Operations.TextPositioning.MoveToNextLineWithOffsetSetLeading", + "UglyToad.PdfPig.Graphics.Operations.TextPositioning.SetTextMatrix", "UglyToad.PdfPig.Graphics.Operations.TextShowing.MoveToNextLineShowText", "UglyToad.PdfPig.Graphics.Operations.TextShowing.MoveToNextLineShowTextWithSpacing", "UglyToad.PdfPig.Graphics.Operations.TextShowing.ShowText", + "UglyToad.PdfPig.Graphics.Operations.TextShowing.ShowTextsWithPositioning", "UglyToad.PdfPig.Graphics.Operations.TextState.SetCharacterSpacing", "UglyToad.PdfPig.Graphics.Operations.TextState.SetFontAndSize", "UglyToad.PdfPig.Graphics.Operations.TextState.SetHorizontalScaling", @@ -127,7 +137,7 @@ "UglyToad.PdfPig.Writer.TokenWriter", "UglyToad.PdfPig.XObjects.XObjectImage" }; - + foreach (var publicTypeName in publicTypeNames) { Assert.True(expected.Contains(publicTypeName), $"Type should not be public: {publicTypeName}."); diff --git a/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathEvenOddRuleAndStroke.cs b/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathEvenOddRuleAndStroke.cs index 7d7a292f..74528c5f 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathEvenOddRuleAndStroke.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathEvenOddRuleAndStroke.cs @@ -6,7 +6,7 @@ /// /// Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill. /// - internal class CloseFillPathEvenOddRuleAndStroke : IGraphicsStateOperation + public class CloseFillPathEvenOddRuleAndStroke : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathNonZeroWindingAndStroke.cs b/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathNonZeroWindingAndStroke.cs index b0abf77d..302f1130 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathNonZeroWindingAndStroke.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/CloseFillPathNonZeroWindingAndStroke.cs @@ -6,7 +6,7 @@ /// /// Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill. /// - internal class CloseFillPathNonZeroWindingAndStroke : IGraphicsStateOperation + public class CloseFillPathNonZeroWindingAndStroke : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/FillPathEvenOddRuleAndStroke.cs b/src/UglyToad.PdfPig/Graphics/Operations/FillPathEvenOddRuleAndStroke.cs index a4e1e7d2..95d6fb35 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/FillPathEvenOddRuleAndStroke.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/FillPathEvenOddRuleAndStroke.cs @@ -6,7 +6,7 @@ /// /// Fill and then stroke the path, using the even-odd rule to determine the region to fill. /// - internal class FillPathEvenOddRuleAndStroke : IGraphicsStateOperation + public class FillPathEvenOddRuleAndStroke : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs index e92cb399..195f6f7d 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs @@ -6,7 +6,7 @@ /// /// Set the gray level for non-stroking operations. /// - internal class SetNonStrokeColorDeviceGray : IGraphicsStateOperation + public class SetNonStrokeColorDeviceGray : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs index a459137f..10559b6f 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs @@ -6,7 +6,7 @@ /// /// Set the stroking color space to DeviceCMYK and set the color to use for stroking operations. /// - internal class SetStrokeColorDeviceCmyk : IGraphicsStateOperation + public class SetStrokeColorDeviceCmyk : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs index 38c5f437..e5d87545 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs @@ -6,7 +6,7 @@ /// /// Set the gray level for stroking operations. /// - internal class SetStrokeColorDeviceGray : IGraphicsStateOperation + public class SetStrokeColorDeviceGray : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs index d51e6d95..1e07c238 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs @@ -13,7 +13,7 @@ /// Tm = Tlm = 0 1 0 * Tlm
/// tx ty 1 /// - internal class MoveToNextLineWithOffset : IGraphicsStateOperation + public class MoveToNextLineWithOffset : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs index a113f8a0..e54218f5 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs @@ -8,7 +8,7 @@ /// Move to the start of the next line, offset from the start of the current line by (tx, ty). /// This operator also sets the leading parameter in the text state. /// - internal class MoveToNextLineWithOffsetSetLeading : IGraphicsStateOperation + public class MoveToNextLineWithOffsetSetLeading : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. @@ -18,10 +18,21 @@ /// public string Operator => Symbol; + /// + /// The x value of the offset. + /// public decimal Tx { get; } + /// + /// The y value of the offset and the inverse of the leading parameter. + /// public decimal Ty { get; } + /// + /// Create a new . + /// + /// The x value of the offset. + /// The y value of the offset and the inverse of the leading parameter. public MoveToNextLineWithOffsetSetLeading(decimal tx, decimal ty) { Tx = tx; diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/SetTextMatrix.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/SetTextMatrix.cs index a755a9c0..f98aea31 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/SetTextMatrix.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextPositioning/SetTextMatrix.cs @@ -8,7 +8,7 @@ /// /// Set the text matrix and the text line matrix. /// - internal class SetTextMatrix : IGraphicsStateOperation + public class SetTextMatrix : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. @@ -18,8 +18,15 @@ /// public string Operator => Symbol; + /// + /// The values of the text matrix. + /// public decimal[] Value { get; } + /// + /// Create a new . + /// + /// The values of the text matrix. public SetTextMatrix(decimal[] value) { if (value.Length != 6) diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs index 0d8ae41e..d598bd8d 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextShowing/ShowTextsWithPositioning.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using Tokens; + using Writer; /// /// @@ -12,7 +13,7 @@ /// If the element is a string, this operator shows the string. /// If it is a number, the operator adjusts the text position by that amount /// - internal class ShowTextsWithPositioning : IGraphicsStateOperation + public class ShowTextsWithPositioning : IGraphicsStateOperation { /// /// The symbol for this operation in a stream. @@ -59,7 +60,20 @@ /// public void Write(Stream stream) { - throw new NotImplementedException(); + stream.WriteText("["); + for (var i = 0; i < Array.Count; i++) + { + TokenWriter.WriteToken(Array[i], stream); + + if (i < Array.Count - 1) + { + stream.WriteWhiteSpace(); + } + } + stream.WriteText("]"); + stream.WriteWhiteSpace(); + stream.WriteText(Symbol); + stream.WriteNewLine(); } } } \ No newline at end of file