From ea9ac795ffc894f9b5443ab813d0f3cd2583ce9e Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Tue, 1 Jan 2019 18:00:04 +0000 Subject: [PATCH] #26 add writing logic and comments to more graphics state operations --- .../Graphics/Operations/EndPath.cs | 16 +++++++++++++- .../Operations/OperationWriteHelper.cs | 8 +++++++ .../Operations/SetStrokeColorDeviceGray.cs | 21 ++++++++++++++++-- .../Operations/SetStrokeColorDeviceRgb.cs | 22 +++++++++++++++++++ .../Operations/TextState/SetTextRise.cs | 21 ++++++++++++++++-- .../Operations/TextState/SetWordSpacing.cs | 21 +++++++++++++++++- 6 files changed, 103 insertions(+), 6 deletions(-) diff --git a/src/UglyToad.PdfPig/Graphics/Operations/EndPath.cs b/src/UglyToad.PdfPig/Graphics/Operations/EndPath.cs index 178bb53c..3d1c1c18 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/EndPath.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/EndPath.cs @@ -3,27 +3,41 @@ using System.IO; using Content; + /// + /// End path without filling or stroking. + /// internal class EndPath : IGraphicsStateOperation { + /// + /// The symbol for this operation in a stream. + /// public const string Symbol = "n"; + /// + /// The instance of the operation. + /// public static readonly EndPath Value = new EndPath(); + /// public string Operator => Symbol; private EndPath() { } + /// public void Run(IOperationContext operationContext, IResourceStore resourceStore) { } + /// public void Write(Stream stream) { - throw new System.NotImplementedException(); + stream.WriteText(Symbol); + stream.WriteNewLine(); } + /// public override string ToString() { return Symbol; diff --git a/src/UglyToad.PdfPig/Graphics/Operations/OperationWriteHelper.cs b/src/UglyToad.PdfPig/Graphics/Operations/OperationWriteHelper.cs index 6734dbe1..4def2d3f 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/OperationWriteHelper.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/OperationWriteHelper.cs @@ -28,5 +28,13 @@ { 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(); + } } } diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs index 1d0335c4..63e2c352 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs @@ -3,28 +3,45 @@ using System.IO; using Content; + /// + /// Set the gray level for stroking operations. + /// internal class SetStrokeColorDeviceGray : IGraphicsStateOperation { public const string Symbol = "G"; + /// public string Operator => Symbol; + /// + /// The gray level between 0 (black) and 1 (white). + /// public decimal Gray { get; } + /// + /// Create a new . + /// + /// The gray level. public SetStrokeColorDeviceGray(decimal gray) { Gray = gray; } + /// public void Run(IOperationContext operationContext, IResourceStore resourceStore) { } - + + /// public void Write(Stream stream) { - throw new System.NotImplementedException(); + stream.WriteDecimal(Gray); + stream.WriteWhiteSpace(); + stream.WriteText(Symbol); + stream.WriteNewLine(); } + /// public override string ToString() { return $"{Gray} {Symbol}"; diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs index de41c77e..e353d828 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs @@ -3,18 +3,37 @@ using System.IO; using Content; + /// + /// Set RGB color for stroking operations. + /// internal class SetStrokeColorDeviceRgb : IGraphicsStateOperation { public const string Symbol = "RG"; + /// public string Operator => Symbol; + /// + /// The red level between 0 and 1. + /// public decimal R { get; } + /// + /// The green level between 0 and 1. + /// public decimal G { get; } + /// + /// The blue level between 0 and 1. + /// public decimal B { get; } + /// + /// Create a new . + /// + /// The red level. + /// The green level. + /// The blue level. public SetStrokeColorDeviceRgb(decimal r, decimal g, decimal b) { R = r; @@ -22,10 +41,12 @@ B = b; } + /// public void Run(IOperationContext operationContext, IResourceStore resourceStore) { } + /// public void Write(Stream stream) { stream.WriteDecimal(R); @@ -38,6 +59,7 @@ stream.WriteNewLine(); } + /// public override string ToString() { return $"{R} {G} {B} {Symbol}"; diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetTextRise.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetTextRise.cs index 1d5cd506..094f9632 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetTextRise.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetTextRise.cs @@ -3,19 +3,34 @@ using System.IO; using Content; + /// + /// Set text rise. + /// internal class SetTextRise : IGraphicsStateOperation { + /// + /// The symbol for this operation in a stream. + /// public const string Symbol = "Ts"; + /// public string Operator => Symbol; + /// + /// The amount of text rise - how far to move the baseline up or down from its default location. + /// public decimal Rise { get; } + /// + /// Create a new . + /// + /// The text rise. public SetTextRise(decimal rise) { Rise = rise; } - + + /// public void Run(IOperationContext operationContext, IResourceStore resourceStore) { var currentState = operationContext.GetCurrentState(); @@ -23,11 +38,13 @@ currentState.FontState.Rise = Rise; } + /// public void Write(Stream stream) { - throw new System.NotImplementedException(); + stream.WriteNumberText(Rise, Symbol); } + /// public override string ToString() { return $"{Rise} {Symbol}"; diff --git a/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetWordSpacing.cs b/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetWordSpacing.cs index 91f2f02d..f40cc0fe 100644 --- a/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetWordSpacing.cs +++ b/src/UglyToad.PdfPig/Graphics/Operations/TextState/SetWordSpacing.cs @@ -3,19 +3,36 @@ using System.IO; using Content; + /// + /// Sets the word spacing. + /// internal class SetWordSpacing : IGraphicsStateOperation { + /// + /// The symbol for this operation in a stream. + /// public const string Symbol = "Tw"; + /// public string Operator => Symbol; + /// + /// 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. + /// public decimal Spacing { get; } + /// + /// Create a new . + /// + /// The word spacing. public SetWordSpacing(decimal spacing) { Spacing = spacing; } + /// public void Run(IOperationContext operationContext, IResourceStore resourceStore) { var currentState = operationContext.GetCurrentState(); @@ -23,11 +40,13 @@ currentState.FontState.WordSpacing = Spacing; } + /// public void Write(Stream stream) { - throw new System.NotImplementedException(); + stream.WriteNumberText(Spacing, Symbol); } + /// public override string ToString() { return $"{Spacing} {Symbol}";