#26 add writing logic and comments to more graphics state operations

This commit is contained in:
Eliot Jones
2019-01-01 18:00:04 +00:00
parent 20e843f5ae
commit ea9ac795ff
6 changed files with 103 additions and 6 deletions

View File

@@ -3,27 +3,41 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// End path without filling or stroking.
/// </summary>
internal class EndPath : IGraphicsStateOperation internal class EndPath : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "n"; public const string Symbol = "n";
/// <summary>
/// The instance of the <see cref="EndPath"/> operation.
/// </summary>
public static readonly EndPath Value = new EndPath(); public static readonly EndPath Value = new EndPath();
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
private EndPath() private EndPath()
{ {
} }
/// <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

@@ -28,5 +28,13 @@
{ {
stream.WriteText(value.ToString("G")); stream.WriteText(value.ToString("G"));
} }
public static void WriteNumberText(this Stream stream, decimal number, string text)
{
stream.WriteDecimal(number);
stream.WriteWhiteSpace();
stream.WriteText(text);
stream.WriteNewLine();
}
} }
} }

View File

@@ -3,28 +3,45 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set the gray level for stroking operations.
/// </summary>
internal class SetStrokeColorDeviceGray : IGraphicsStateOperation internal class SetStrokeColorDeviceGray : IGraphicsStateOperation
{ {
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="SetStrokeColorDeviceGray"/>.
/// </summary>
/// <param name="gray">The gray level.</param>
public SetStrokeColorDeviceGray(decimal gray) public SetStrokeColorDeviceGray(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.WriteDecimal(Gray);
stream.WriteWhiteSpace();
stream.WriteText(Symbol);
stream.WriteNewLine();
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Gray} {Symbol}"; return $"{Gray} {Symbol}";

View File

@@ -3,18 +3,37 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set RGB color for stroking operations.
/// </summary>
internal class SetStrokeColorDeviceRgb : IGraphicsStateOperation internal class SetStrokeColorDeviceRgb : IGraphicsStateOperation
{ {
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="SetStrokeColorDeviceRgb"/>.
/// </summary>
/// <param name="r">The red level.</param>
/// <param name="g">The green level.</param>
/// <param name="b">The blue level.</param>
public SetStrokeColorDeviceRgb(decimal r, decimal g, decimal b) public SetStrokeColorDeviceRgb(decimal r, decimal g, decimal b)
{ {
R = r; R = r;
@@ -22,10 +41,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 +59,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,19 +3,34 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Set text rise.
/// </summary>
internal class SetTextRise : IGraphicsStateOperation internal class SetTextRise : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "Ts"; public const string Symbol = "Ts";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// The amount of text rise - how far to move the baseline up or down from its default location.
/// </summary>
public decimal Rise { get; } public decimal Rise { get; }
/// <summary>
/// Create a new <see cref="SetTextRise"/>.
/// </summary>
/// <param name="rise">The text rise.</param>
public SetTextRise(decimal rise) public SetTextRise(decimal rise)
{ {
Rise = rise; Rise = rise;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
var currentState = operationContext.GetCurrentState(); var currentState = operationContext.GetCurrentState();
@@ -23,11 +38,13 @@
currentState.FontState.Rise = Rise; currentState.FontState.Rise = Rise;
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteNumberText(Rise, Symbol);
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Rise} {Symbol}"; return $"{Rise} {Symbol}";

View File

@@ -3,19 +3,36 @@
using System.IO; using System.IO;
using Content; using Content;
/// <summary>
/// Sets the word spacing.
/// </summary>
internal class SetWordSpacing : IGraphicsStateOperation internal class SetWordSpacing : IGraphicsStateOperation
{ {
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "Tw"; public const string Symbol = "Tw";
/// <inheritdoc />
public string Operator => Symbol; public string Operator => Symbol;
/// <summary>
/// Sets the width of the space ' ' character. For horizontal
/// writing positive values increase the gap between words separated by space, for vertical writing
/// positive values decrease the gap.
/// </summary>
public decimal Spacing { get; } public decimal Spacing { get; }
/// <summary>
/// Create a new <see cref="SetWordSpacing"/>.
/// </summary>
/// <param name="spacing">The word spacing.</param>
public SetWordSpacing(decimal spacing) public SetWordSpacing(decimal spacing)
{ {
Spacing = spacing; Spacing = spacing;
} }
/// <inheritdoc />
public void Run(IOperationContext operationContext, IResourceStore resourceStore) public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{ {
var currentState = operationContext.GetCurrentState(); var currentState = operationContext.GetCurrentState();
@@ -23,11 +40,13 @@
currentState.FontState.WordSpacing = Spacing; currentState.FontState.WordSpacing = Spacing;
} }
/// <inheritdoc />
public void Write(Stream stream) public void Write(Stream stream)
{ {
throw new System.NotImplementedException(); stream.WriteNumberText(Spacing, Symbol);
} }
/// <inheritdoc />
public override string ToString() public override string ToString()
{ {
return $"{Spacing} {Symbol}"; return $"{Spacing} {Symbol}";