#26 prepare more content stream operations for public api

This commit is contained in:
Eliot Jones
2019-01-02 23:14:13 +00:00
parent 21aa964e0b
commit 29daeb5806
16 changed files with 312 additions and 19 deletions

View File

@@ -3,29 +3,42 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Close and stroke the path.
/// </summary>
internal class CloseAndStrokePath : IGraphicsStateOperation internal class CloseAndStrokePath : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "s"; public const string Symbol = "s";
/// <summary>
/// The instance of the <see cref="CloseAndStrokePath"/> operation.
/// </summary>
public static readonly CloseAndStrokePath Value = new CloseAndStrokePath(); public static readonly CloseAndStrokePath Value = new CloseAndStrokePath();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private CloseAndStrokePath() private CloseAndStrokePath()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
operationContext.StrokePath(true); operationContext.StrokePath(true);
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
stream.WriteText(Symbol); stream.WriteText(Symbol);
stream.WriteNewLine(); stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Close, fill, and then stroke the path, using the even-odd rule to determine the region to fill.
/// </summary>
internal class CloseFillPathEvenOddRuleAndStroke : IGraphicsStateOperation internal class CloseFillPathEvenOddRuleAndStroke : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "b*"; public const string Symbol = "b*";
/// <summary>
/// The instance of the <see cref="CloseFillPathEvenOddRuleAndStroke"/> operation.
/// </summary>
public static readonly CloseFillPathEvenOddRuleAndStroke Value = new CloseFillPathEvenOddRuleAndStroke(); public static readonly CloseFillPathEvenOddRuleAndStroke Value = new CloseFillPathEvenOddRuleAndStroke();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private CloseFillPathEvenOddRuleAndStroke() private CloseFillPathEvenOddRuleAndStroke()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Close, fill, and then stroke the path, using the nonzero winding number rule to determine the region to fill.
/// </summary>
internal class CloseFillPathNonZeroWindingAndStroke : IGraphicsStateOperation internal class CloseFillPathNonZeroWindingAndStroke : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "b"; public const string Symbol = "b";
/// <summary>
/// The instance of the <see cref="CloseFillPathNonZeroWindingAndStroke"/> operation.
/// </summary>
public static readonly CloseFillPathNonZeroWindingAndStroke Value = new CloseFillPathNonZeroWindingAndStroke(); public static readonly CloseFillPathNonZeroWindingAndStroke Value = new CloseFillPathNonZeroWindingAndStroke();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private CloseFillPathNonZeroWindingAndStroke() private CloseFillPathNonZeroWindingAndStroke()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Fill the path, using the even-odd rule to determine the region to fill.
/// </summary>
internal class FillPathEvenOddRule : IGraphicsStateOperation internal class FillPathEvenOddRule : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "f*"; public const string Symbol = "f*";
/// <summary>
/// The instance of the <see cref="FillPathEvenOddRule"/> operation.
/// </summary>
public static readonly FillPathEvenOddRule Value = new FillPathEvenOddRule(); public static readonly FillPathEvenOddRule Value = new FillPathEvenOddRule();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private FillPathEvenOddRule() private FillPathEvenOddRule()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Fill and then stroke the path, using the even-odd rule to determine the region to fill.
/// </summary>
internal class FillPathEvenOddRuleAndStroke : IGraphicsStateOperation internal class FillPathEvenOddRuleAndStroke : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "B*"; public const string Symbol = "B*";
/// <summary>
/// The instance of the <see cref="FillPathEvenOddRuleAndStroke"/> operation.
/// </summary>
public static readonly FillPathEvenOddRuleAndStroke Value = new FillPathEvenOddRuleAndStroke(); public static readonly FillPathEvenOddRuleAndStroke Value = new FillPathEvenOddRuleAndStroke();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private FillPathEvenOddRuleAndStroke() private FillPathEvenOddRuleAndStroke()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,42 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Fill the path, using the nonzero winding number rule to determine the region to fill.
/// Any subpaths that are open are implicitly closed before being filled.
/// </summary>
internal class FillPathNonZeroWinding : IGraphicsStateOperation internal class FillPathNonZeroWinding : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "f"; public const string Symbol = "f";
/// <summary>
/// The instance of the <see cref="FillPathNonZeroWinding"/> operation.
/// </summary>
public static readonly FillPathNonZeroWinding Value = new FillPathNonZeroWinding(); public static readonly FillPathNonZeroWinding Value = new FillPathNonZeroWinding();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private FillPathNonZeroWinding() private FillPathNonZeroWinding()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Fill and then stroke the path, using the nonzero winding number rule to determine the region to fill.
/// </summary>
internal class FillPathNonZeroWindingAndStroke : IGraphicsStateOperation internal class FillPathNonZeroWindingAndStroke : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "B"; public const string Symbol = "B";
/// <summary>
/// The instance of the <see cref="FillPathNonZeroWindingAndStroke"/> operation.
/// </summary>
public static readonly FillPathNonZeroWindingAndStroke Value = new FillPathNonZeroWindingAndStroke(); public static readonly FillPathNonZeroWindingAndStroke Value = new FillPathNonZeroWindingAndStroke();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private FillPathNonZeroWindingAndStroke() private FillPathNonZeroWindingAndStroke()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -3,27 +3,42 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Equivalent to <see cref="FillPathNonZeroWinding"/> included only for compatibility.
/// Although PDF consumer applications must be able to accept this operator, PDF producer applications should use <see cref="FillPathNonZeroWinding"/> instead.
/// </summary>
internal class FillPathNonZeroWindingCompatibility : IGraphicsStateOperation internal class FillPathNonZeroWindingCompatibility : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "F"; public const string Symbol = "F";
/// <summary>
/// The instance of the <see cref="FillPathEvenOddRuleAndStroke"/> operation.
/// </summary>
public static readonly FillPathNonZeroWindingCompatibility Value = new FillPathNonZeroWindingCompatibility(); public static readonly FillPathNonZeroWindingCompatibility Value = new FillPathNonZeroWindingCompatibility();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private FillPathNonZeroWindingCompatibility() private FillPathNonZeroWindingCompatibility()
{ {
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return Symbol; return Symbol;

View File

@@ -4,19 +4,37 @@
using Content; using Content;
using Tokens; using Tokens;
/// <summary>
/// Paint the specified XObject.
/// The operand name must appear as a key in the XObject subdictionary of the current resource dictionary.
/// The associated value must be a stream whose Type entry, if present, is XObject.
/// The effect of <see cref="InvokeNamedXObject"/> depends on the value of the XObject's Subtype entry, which may be Image, Form or PS.
/// </summary>
internal class InvokeNamedXObject : IGraphicsStateOperation internal class InvokeNamedXObject : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "Do"; public const string Symbol = "Do";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The name of the XObject which appears in the XObject subdictionary of the current resource dictionary.
/// </summary>
public NameToken Name { get; } public NameToken Name { get; }
/// <summary>
/// Create a new <see cref="InvokeNamedXObject"/>.
/// </summary>
/// <param name="name">The name of the XObject.</param>
public InvokeNamedXObject(NameToken name) public InvokeNamedXObject(NameToken name)
{ {
Name = name; Name = name;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
var xobject = resourceStore.GetXObject(Name); var xobject = resourceStore.GetXObject(Name);
@@ -24,11 +42,16 @@
operationContext.ApplyXObject(xobject); operationContext.ApplyXObject(xobject);
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteText($"/{Name}");
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Name} {Symbol}"; return $"{Name} {Symbol}";

View File

@@ -3,20 +3,46 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set the non-stroking color space to DeviceCMYK and set the color to use for stroking operations.
/// </summary>
internal class SetNonStrokeColorDeviceCmyk : IGraphicsStateOperation internal class SetNonStrokeColorDeviceCmyk : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "K"; public const string Symbol = "K";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The cyan level between 0 and 1.
/// </summary>
public decimal C { get; } public decimal C { get; }
/// <summary>
/// The magenta level between 0 and 1.
/// </summary>
public decimal M { get; } public decimal M { get; }
/// <summary>
/// The yellow level between 0 and 1.
/// </summary>
public decimal Y { get; } public decimal Y { get; }
/// <summary>
/// The key level between 0 and 1.
/// </summary>
public decimal K { get; } public decimal K { get; }
/// <summary>
/// Create a new <see cref="SetNonStrokeColorDeviceCmyk"/>.
/// </summary>
/// <param name="c">The cyan level.</param>
/// <param name="m">The magenta level.</param>
/// <param name="y">The yellow level.</param>
/// <param name="k">The key level.</param>
public SetNonStrokeColorDeviceCmyk(decimal c, decimal m, decimal y, decimal k) public SetNonStrokeColorDeviceCmyk(decimal c, decimal m, decimal y, decimal k)
{ {
C = c; C = c;
@@ -25,15 +51,27 @@
K = k; K = k;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteDecimal(C);
stream.WriteWhiteSpace();
stream.WriteDecimal(M);
stream.WriteWhiteSpace();
stream.WriteDecimal(Y);
stream.WriteWhiteSpace();
stream.WriteDecimal(K);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{C} {M} {Y} {K} {Symbol}"; return $"{C} {M} {Y} {K} {Symbol}";

View File

@@ -3,28 +3,45 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set the gray level for non-stroking operations.
/// </summary>
internal class SetNonStrokeColorDeviceGray : IGraphicsStateOperation internal class SetNonStrokeColorDeviceGray : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "g"; public const string Symbol = "g";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The gray level between 0 (black) and 1 (white).
/// </summary>
public decimal Gray { get; } public decimal Gray { get; }
/// <summary>
/// Create a new <see cref="SetNonStrokeColorDeviceGray"/>.
/// </summary>
/// <param name="gray">The gray level.</param>
public SetNonStrokeColorDeviceGray(decimal gray) public SetNonStrokeColorDeviceGray(decimal gray)
{ {
Gray = gray; Gray = gray;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteNumberText(Gray, Symbol);
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Gray} {Symbol}"; return $"{Gray} {Symbol}";

View File

@@ -3,18 +3,40 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set RGB color for non-stroking operations.
/// </summary>
internal class SetNonStrokeColorDeviceRgb : IGraphicsStateOperation internal class SetNonStrokeColorDeviceRgb : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "rg"; public const string Symbol = "rg";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The red level between 0 and 1.
/// </summary>
public decimal R { get; } public decimal R { get; }
/// <summary>
/// The green level between 0 and 1.
/// </summary>
public decimal G { get; } public decimal G { get; }
/// <summary>
/// The blue level between 0 and 1.
/// </summary>
public decimal B { get; } public decimal B { get; }
/// <summary>
/// Create a new <see cref="SetNonStrokeColorDeviceRgb"/>.
/// </summary>
/// <param name="r">The red level.</param>
/// <param name="g">The green level.</param>
/// <param name="b">The blue level.</param>
public SetNonStrokeColorDeviceRgb(decimal r, decimal g, decimal b) public SetNonStrokeColorDeviceRgb(decimal r, decimal g, decimal b)
{ {
R = r; R = r;
@@ -22,10 +44,12 @@
B = b; B = b;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
stream.WriteDecimal(R); stream.WriteDecimal(R);
@@ -38,6 +62,7 @@
stream.WriteNewLine(); stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{R} {G} {B} {Symbol}"; return $"{R} {G} {B} {Symbol}";

View File

@@ -3,20 +3,46 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set the stroking color space to DeviceCMYK and set the color to use for stroking operations.
/// </summary>
internal class SetStrokeColorDeviceCmyk : IGraphicsStateOperation internal class SetStrokeColorDeviceCmyk : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "K"; public const string Symbol = "K";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The cyan level between 0 and 1.
/// </summary>
public decimal C { get; } public decimal C { get; }
/// <summary>
/// The magenta level between 0 and 1.
/// </summary>
public decimal M { get; } public decimal M { get; }
/// <summary>
/// The yellow level between 0 and 1.
/// </summary>
public decimal Y { get; } public decimal Y { get; }
/// <summary>
/// The key level between 0 and 1.
/// </summary>
public decimal K { get; } public decimal K { get; }
/// <summary>
/// Create a new <see cref="SetStrokeColorDeviceCmyk"/>.
/// </summary>
/// <param name="c">The cyan level.</param>
/// <param name="m">The magenta level.</param>
/// <param name="y">The yellow level.</param>
/// <param name="k">The key level.</param>
public SetStrokeColorDeviceCmyk(decimal c, decimal m, decimal y, decimal k) public SetStrokeColorDeviceCmyk(decimal c, decimal m, decimal y, decimal k)
{ {
C = c; C = c;
@@ -25,15 +51,27 @@
K = k; K = k;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteDecimal(C);
stream.WriteWhiteSpace();
stream.WriteDecimal(M);
stream.WriteWhiteSpace();
stream.WriteDecimal(Y);
stream.WriteWhiteSpace();
stream.WriteDecimal(K);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{C} {M} {Y} {K} {Symbol}"; return $"{C} {M} {Y} {K} {Symbol}";

View File

@@ -8,6 +8,9 @@
/// </summary> /// </summary>
internal class SetStrokeColorDeviceGray : IGraphicsStateOperation internal class SetStrokeColorDeviceGray : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "G"; public const string Symbol = "G";
/// <inheritdoc /> /// <inheritdoc />
@@ -35,10 +38,7 @@
/// <inheritdoc /> /// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
stream.WriteDecimal(Gray); stream.WriteNumberText(Gray, Symbol);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -8,6 +8,9 @@
/// </summary> /// </summary>
internal class SetStrokeColorDeviceRgb : IGraphicsStateOperation internal class SetStrokeColorDeviceRgb : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "RG"; public const string Symbol = "RG";
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -1,32 +1,56 @@
namespace UglyToad.PdfPig.Graphics.Operations.TextShowing namespace UglyToad.PdfPig.Graphics.Operations.TextShowing
{ {
using System;
using System.IO; using System.IO;
using System.Linq;
using Content; using Content;
using TextPositioning; using TextPositioning;
using Util.JetBrains.Annotations; using Util.JetBrains.Annotations;
/// <summary>
/// Move to the next line and show a text string.
/// </summary>
internal class MoveToNextLineShowText : IGraphicsStateOperation internal class MoveToNextLineShowText : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "'"; public const string Symbol = "'";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The text to show as a <see cref="string"/>.
/// </summary>
[CanBeNull] [CanBeNull]
public string Text { get; } public string Text { get; }
/// <summary>
/// The text to show as hex bytes.
/// </summary>
[CanBeNull] [CanBeNull]
public byte[] Bytes { get; } public byte[] Bytes { get; }
/// <summary>
/// Create a new <see cref="MoveToNextLineShowText"/>.
/// </summary>
/// <param name="text">The text to show.</param>
public MoveToNextLineShowText(string text) public MoveToNextLineShowText(string text)
{ {
Text = text; Text = text;
} }
/// <summary>
/// Create a new <see cref="MoveToNextLineShowText"/>.
/// </summary>
/// <param name="hexBytes">The bytes of the text to show.</param>
public MoveToNextLineShowText(byte[] hexBytes) public MoveToNextLineShowText(byte[] hexBytes)
{ {
Bytes = hexBytes; Bytes = hexBytes;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
var move = MoveToNextLine.Value; var move = MoveToNextLine.Value;
@@ -37,11 +61,23 @@
showText.Run(operationContext, resourceStore); showText.Run(operationContext, resourceStore);
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); if (Bytes == null)
{
stream.WriteText($"({Text}) {Symbol}");
stream.WriteNewLine();
}
else
{
var hex = BitConverter.ToString(Bytes.ToArray()).Replace("-", string.Empty);
stream.WriteText($"<{hex}> {Symbol}");
stream.WriteNewLine();
}
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Text} {Symbol}"; return $"{Text} {Symbol}";