diff --git a/src/UglyToad.Pdf/Core/TransformationMatrix.cs b/src/UglyToad.Pdf/Core/TransformationMatrix.cs index d0a44a73..7d7c49be 100644 --- a/src/UglyToad.Pdf/Core/TransformationMatrix.cs +++ b/src/UglyToad.Pdf/Core/TransformationMatrix.cs @@ -84,8 +84,10 @@ return new PdfPoint(x, y); } - - public static TransformationMatrix FromArray(params decimal[] values) + + public static TransformationMatrix FromValues(decimal a, decimal b, decimal c, decimal d, decimal e, decimal f) + => FromArray(new[] {a, b, c, d, e, f}); + public static TransformationMatrix FromArray(decimal[] values) { if (values.Length == 9) { diff --git a/src/UglyToad.Pdf/Graphics/CurrentGraphicsState.cs b/src/UglyToad.Pdf/Graphics/CurrentGraphicsState.cs index 0679ec04..bbdcaa98 100644 --- a/src/UglyToad.Pdf/Graphics/CurrentGraphicsState.cs +++ b/src/UglyToad.Pdf/Graphics/CurrentGraphicsState.cs @@ -5,6 +5,7 @@ using Core; using Geometry; using Operations; + using Operations.SpecialGraphicsState; internal class CurrentGraphicsState : IDeepCloneable { @@ -13,6 +14,11 @@ /// public CurrentFontState FontState { get; set; } + /// + /// Map positions from user coordinates to device coordinates. Values set by (cm). + /// + public TransformationMatrix CurrentTransformationText { get; set; } = TransformationMatrix.Identity; + /// /// Thickness in user space units of path to be stroked. /// diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetColorRenderingIntent.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetColorRenderingIntent.cs index 917380b7..c03d029d 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetColorRenderingIntent.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetColorRenderingIntent.cs @@ -1,9 +1,16 @@ namespace UglyToad.Pdf.Graphics.Operations.General { + using Content; + internal class SetColorRenderingIntent : IGraphicsStateOperation { public const string Symbol = "ri"; public string Operator => Symbol; + + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + + } } } \ No newline at end of file diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetFlatnessTolerance.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetFlatnessTolerance.cs index 9b035dfc..baa31f56 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetFlatnessTolerance.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetFlatnessTolerance.cs @@ -1,5 +1,7 @@ namespace UglyToad.Pdf.Graphics.Operations.General { + using Content; + internal class SetFlatnessTolerance : IGraphicsStateOperation { public const string Symbol = "i"; @@ -12,6 +14,11 @@ { Tolerance = tolerance; } + + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + operationContext.GetCurrentState().Flatness = Tolerance; + } public override string ToString() { diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineCap.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineCap.cs index 92554c39..9ade8d23 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineCap.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineCap.cs @@ -1,6 +1,7 @@ namespace UglyToad.Pdf.Graphics.Operations.General { using System; + using Content; internal class SetLineCap : IGraphicsStateOperation { @@ -21,6 +22,11 @@ Cap = cap; } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + operationContext.GetCurrentState().CapStyle = Cap; + } + public override string ToString() { return $"{(int) Cap} {Symbol}"; diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineDashPattern.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineDashPattern.cs index c1c04ecb..dc1d4584 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineDashPattern.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineDashPattern.cs @@ -1,5 +1,7 @@ namespace UglyToad.Pdf.Graphics.Operations.General { + using Content; + internal class SetLineDashPattern : IGraphicsStateOperation { public const string Symbol = "d"; @@ -8,12 +10,16 @@ public LineDashPattern Pattern { get; } - public SetLineDashPattern(decimal[] array, int phase) { Pattern = new LineDashPattern(phase, array); } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + operationContext.GetCurrentState().LineDashPattern = Pattern; + } + public override string ToString() { return $"{Pattern.Array} {Pattern.Phase} {Symbol}"; diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineJoin.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineJoin.cs index da7a5dc9..7fdc1884 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineJoin.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineJoin.cs @@ -1,6 +1,7 @@ namespace UglyToad.Pdf.Graphics.Operations.General { using System; + using Content; internal class SetLineJoin : IGraphicsStateOperation { @@ -21,6 +22,11 @@ Join = join; } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + operationContext.GetCurrentState().JoinStyle = Join; + } + public override string ToString() { return $"{(int)Join} {Symbol}"; diff --git a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineWidth.cs b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineWidth.cs index 049438af..d9beae52 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/General/SetLineWidth.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/General/SetLineWidth.cs @@ -18,6 +18,7 @@ public void Run(IOperationContext operationContext, IResourceStore resourceStore) { var currentState = operationContext.GetCurrentState(); + currentState.LineWidth = Width; } diff --git a/src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyTransformationMatrix.cs b/src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs similarity index 55% rename from src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyTransformationMatrix.cs rename to src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs index 726da53c..b01fda4d 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyTransformationMatrix.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/SpecialGraphicsState/ModifyCurrentTransformationMatrix.cs @@ -1,8 +1,10 @@ namespace UglyToad.Pdf.Graphics.Operations.SpecialGraphicsState { using System; + using Content; + using Core; - internal class ModifyTransformationMatrix : IGraphicsStateOperation + internal class ModifyCurrentTransformationMatrix : IGraphicsStateOperation { public const string Symbol = "cm"; @@ -10,7 +12,7 @@ public decimal[] Value { get; } - public ModifyTransformationMatrix(decimal[] value) + public ModifyCurrentTransformationMatrix(decimal[] value) { if (value == null) { @@ -24,6 +26,17 @@ Value = value; } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + var newMatrix = TransformationMatrix.FromArray(Value); + + var ctm = operationContext.GetCurrentState().CurrentTransformationMatrix; + + var newCtm = newMatrix.Multiply(ctm); + + operationContext.GetCurrentState().CurrentTransformationMatrix = newCtm; + } + public override string ToString() { return $"{Value[0]} {Value[1]} {Value[2]} {Value[3]} {Value[4]} {Value[5]} {Symbol}"; diff --git a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLine.cs b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLine.cs index 14ec97a6..96898fdf 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLine.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLine.cs @@ -1,5 +1,13 @@ namespace UglyToad.Pdf.Graphics.Operations.TextPositioning { + using Content; + + /// + /// Move to the start of the next line. + /// + /// + /// This performs this operation: 0 Tl Td + /// internal class MoveToNextLine : IGraphicsStateOperation { public const string Symbol = "T*"; @@ -11,6 +19,13 @@ { } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + var tdOperation = new MoveToNextLineWithOffset(0, operationContext.GetCurrentState().FontState.Leading); + + tdOperation.Run(operationContext, resourceStore); + } + public override string ToString() { return Symbol; diff --git a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs index ad86e6a0..899ca026 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffset.cs @@ -3,6 +3,15 @@ using Content; using Core; + /// + /// Move to the start of the next line offset by Tx Ty. + /// + /// + /// Performs the following operation: + /// 1 0 0
+ /// Tm = Tlm = 0 1 0 * Tlm
+ /// tx ty 1 + ///
internal class MoveToNextLineWithOffset : IGraphicsStateOperation { public const string Symbol = "Td"; @@ -23,7 +32,7 @@ { var currentTextLineMatrix = operationContext.TextMatrices.TextLineMatrix; - var matrix = TransformationMatrix.FromArray(1, 0, 0, 1, Tx, Ty); + var matrix = TransformationMatrix.FromValues(1, 0, 0, 1, Tx, Ty); var transformed = matrix.Multiply(currentTextLineMatrix); diff --git a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs index 7691252b..888457ae 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/MoveToNextLineWithOffsetSetLeading.cs @@ -1,5 +1,8 @@ namespace UglyToad.Pdf.Graphics.Operations.TextPositioning { + using Content; + using TextState; + internal class MoveToNextLineWithOffsetSetLeading : IGraphicsStateOperation { public const string Symbol = "TD"; @@ -16,6 +19,17 @@ Ty = ty; } + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + var tlOperation = new SetTextLeading(-Ty); + + tlOperation.Run(operationContext, resourceStore); + + var tdOperation = new MoveToNextLineWithOffset(Tx, Ty); + + tdOperation.Run(operationContext, resourceStore); + } + public override string ToString() { return $"{Tx} {Ty} {Symbol}"; diff --git a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/SetTextMatrix.cs b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/SetTextMatrix.cs index 32d5b364..c8c796c2 100644 --- a/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/SetTextMatrix.cs +++ b/src/UglyToad.Pdf/Graphics/Operations/TextPositioning/SetTextMatrix.cs @@ -1,6 +1,8 @@ namespace UglyToad.Pdf.Graphics.Operations.TextPositioning { using System; + using Content; + using Core; internal class SetTextMatrix : IGraphicsStateOperation { @@ -19,6 +21,14 @@ Value = value; } + + public void Run(IOperationContext operationContext, IResourceStore resourceStore) + { + var newMatrix = TransformationMatrix.FromArray(Value); + + operationContext.TextMatrices.TextMatrix = newMatrix; + operationContext.TextMatrices.TextLineMatrix = newMatrix; + } public override string ToString() {