mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 17:47:12 +08:00
implement text positioning operations and general operations. as well as cm operation.
This commit is contained in:
@@ -85,7 +85,9 @@
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using Core;
|
||||
using Geometry;
|
||||
using Operations;
|
||||
using Operations.SpecialGraphicsState;
|
||||
|
||||
internal class CurrentGraphicsState : IDeepCloneable<CurrentGraphicsState>
|
||||
{
|
||||
@@ -13,6 +14,11 @@
|
||||
/// </summary>
|
||||
public CurrentFontState FontState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Map positions from user coordinates to device coordinates. Values set by <see cref="ModifyCurrentTransformationMatrix"/> (cm).
|
||||
/// </summary>
|
||||
public TransformationMatrix CurrentTransformationText { get; set; } = TransformationMatrix.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Thickness in user space units of path to be stroked.
|
||||
/// </summary>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace UglyToad.Pdf.Graphics.Operations.General
|
||||
{
|
||||
using Content;
|
||||
|
||||
internal class SetFlatnessTolerance : IGraphicsStateOperation
|
||||
{
|
||||
public const string Symbol = "i";
|
||||
@@ -13,6 +15,11 @@
|
||||
Tolerance = tolerance;
|
||||
}
|
||||
|
||||
public void Run(IOperationContext operationContext, IResourceStore resourceStore)
|
||||
{
|
||||
operationContext.GetCurrentState().Flatness = Tolerance;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Tolerance} {Symbol}";
|
||||
|
||||
@@ -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}";
|
||||
|
||||
@@ -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}";
|
||||
|
||||
@@ -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}";
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
public void Run(IOperationContext operationContext, IResourceStore resourceStore)
|
||||
{
|
||||
var currentState = operationContext.GetCurrentState();
|
||||
|
||||
currentState.LineWidth = Width;
|
||||
}
|
||||
|
||||
|
||||
@@ -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}";
|
||||
@@ -1,5 +1,13 @@
|
||||
namespace UglyToad.Pdf.Graphics.Operations.TextPositioning
|
||||
{
|
||||
using Content;
|
||||
|
||||
/// <summary>
|
||||
/// Move to the start of the next line.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This performs this operation: 0 Tl Td
|
||||
/// </remarks>
|
||||
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;
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
using Content;
|
||||
using Core;
|
||||
|
||||
/// <summary>
|
||||
/// Move to the start of the next line offset by Tx Ty.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Performs the following operation:
|
||||
/// 1 0 0<br/>
|
||||
/// Tm = Tlm = 0 1 0 * Tlm<br/>
|
||||
/// tx ty 1
|
||||
/// </remarks>
|
||||
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);
|
||||
|
||||
|
||||
@@ -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}";
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace UglyToad.Pdf.Graphics.Operations.TextPositioning
|
||||
{
|
||||
using System;
|
||||
using Content;
|
||||
using Core;
|
||||
|
||||
internal class SetTextMatrix : IGraphicsStateOperation
|
||||
{
|
||||
@@ -20,6 +22,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()
|
||||
{
|
||||
return $"{Value[0]} {Value[1]} {Value[2]} {Value[3]} {Value[4]} {Value[5]} {Symbol}";
|
||||
|
||||
Reference in New Issue
Block a user