start adding colorspace path operations to the operation context

This commit is contained in:
Eliot Jones
2019-07-10 21:31:23 +01:00
parent 283e1d38fa
commit 453faf50af
15 changed files with 175 additions and 2 deletions

View File

@@ -18,6 +18,8 @@
public PdfPath CurrentPath { get; set; }
public IColorspaceContext ColorspaceContext { get; } = new ColorspaceContext();
public PdfPoint CurrentPosition { get; set; }
public TestOperationContext()
@@ -69,4 +71,39 @@
{
}
}
public class TestColorspaceContext : IColorspaceContext
{
public void SetStrokingColorspace(NameToken colorspace)
{
}
public void SetNonStrokingColorspace(NameToken colorspace)
{
}
public void SetStrokingColorGray(decimal gray)
{
}
public void SetStrokingColorRgb(decimal r, decimal g, decimal b)
{
}
public void SetStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k)
{
}
public void SetNonStrokingColorGray(decimal gray)
{
}
public void SetNonStrokingColorRgb(decimal r, decimal g, decimal b)
{
}
public void SetNonStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k)
{
}
}
}

View File

@@ -84,6 +84,7 @@
"UglyToad.PdfPig.Graphics.Core.TextRenderingMode",
"UglyToad.PdfPig.Graphics.CurrentFontState",
"UglyToad.PdfPig.Graphics.CurrentGraphicsState",
"UglyToad.PdfPig.Graphics.IColorspaceContext",
"UglyToad.PdfPig.Graphics.IOperationContext",
"UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByEvenOddIntersect",
"UglyToad.PdfPig.Graphics.Operations.ClippingPaths.ModifyClippingByNonZeroWindingIntersect",

View File

@@ -0,0 +1,39 @@
namespace UglyToad.PdfPig.Graphics
{
using Tokens;
internal class ColorspaceContext : IColorspaceContext
{
public void SetStrokingColorspace(NameToken colorspace)
{
}
public void SetNonStrokingColorspace(NameToken colorspace)
{
}
public void SetStrokingColorGray(decimal gray)
{
}
public void SetStrokingColorRgb(decimal r, decimal g, decimal b)
{
}
public void SetStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k)
{
}
public void SetNonStrokingColorGray(decimal gray)
{
}
public void SetNonStrokingColorRgb(decimal r, decimal g, decimal b)
{
}
public void SetNonStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k)
{
}
}
}

View File

@@ -33,6 +33,9 @@
public TextMatrices TextMatrices { get; } = new TextMatrices();
public PdfPath CurrentPath { get; private set; }
public IColorspaceContext ColorspaceContext { get; } = new ColorspaceContext();
public PdfPoint CurrentPosition { get; set; }
public int StackSize => graphicsStack.Count;

View File

@@ -0,0 +1,66 @@
namespace UglyToad.PdfPig.Graphics
{
using Tokens;
/// <summary>
/// Methods for manipulating and retrieving the current color state for a PDF content stream.
/// </summary>
public interface IColorspaceContext
{
/// <summary>
/// Set the current color space to use for stroking operations.
/// </summary>
void SetStrokingColorspace(NameToken colorspace);
/// <summary>
/// Set the current color space to use for nonstroking operations.
/// </summary>
void SetNonStrokingColorspace(NameToken colorspace);
/// <summary>
/// Set the stroking color space to DeviceGray and set the gray level to use for stroking operations.
/// </summary>
/// <param name="gray">A number between 0.0 (black) and 1.0 (white).</param>
void SetStrokingColorGray(decimal gray);
/// <summary>
/// Set the stroking color space to DeviceRGB and set the color to use for stroking operations.
/// </summary>
/// <param name="r">Red - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
/// <param name="g">Green - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
/// <param name="b">Blue - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
void SetStrokingColorRgb(decimal r, decimal g, decimal b);
/// <summary>
/// Set the stroking color space to DeviceCMYK and set the color to use for stroking operations.
/// </summary>
/// <param name="c">Cyan - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="m">Magenta - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="y">Yellow - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="k">Black - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
void SetStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k);
/// <summary>
/// Set the nonstroking color space to DeviceGray and set the gray level to use for nonstroking operations.
/// </summary>
/// <param name="gray">A number between 0.0 (black) and 1.0 (white).</param>
void SetNonStrokingColorGray(decimal gray);
/// <summary>
/// Set the nonstroking color space to DeviceRGB and set the color to use for nonstroking operations.
/// </summary>
/// <param name="r">Red - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
/// <param name="g">Green - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
/// <param name="b">Blue - A number between 0 (minimum intensity) and 1 (maximum intensity).</param>
void SetNonStrokingColorRgb(decimal r, decimal g, decimal b);
/// <summary>
/// Set the nonstroking color space to DeviceCMYK and set the color to use for nonstroking operations.
/// </summary>
/// <param name="c">Cyan - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="m">Magenta - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="y">Yellow - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
/// <param name="k">Black - A number between 0 (minimum concentration) and 1 (maximum concentration).</param>
void SetNonStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k);
}
}

View File

@@ -18,7 +18,12 @@
PdfPath CurrentPath { get; }
/// <summary>
/// The current p
/// The active colorspaces for this content stream.
/// </summary>
IColorspaceContext ColorspaceContext { get; }
/// <summary>
/// The current position.
/// </summary>
PdfPoint CurrentPosition { get; set; }

View File

@@ -54,6 +54,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetNonStrokingColorCmyk(C, M, Y, K);
}
/// <inheritdoc />

View File

@@ -33,6 +33,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetNonStrokingColorGray(Gray);
}
/// <inheritdoc />

View File

@@ -47,6 +47,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetNonStrokingColorRgb(R, G, B);
}
/// <inheritdoc />

View File

@@ -36,6 +36,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetNonStrokingColorspace(Name);
}
/// <inheritdoc />

View File

@@ -14,7 +14,7 @@
/// The symbol for this operation in a stream.
/// </summary>
public const string Symbol = "SC";
/// <inheritdoc />
public string Operator => Symbol;
@@ -35,6 +35,20 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
switch (Operands.Count)
{
case 1:
operationContext.ColorspaceContext.SetStrokingColorGray(Operands[0]);
break;
case 3:
operationContext.ColorspaceContext.SetStrokingColorRgb(Operands[0], Operands[1], Operands[2]);
break;
case 4:
operationContext.ColorspaceContext.SetStrokingColorCmyk(Operands[0], Operands[1], Operands[2], Operands[3]);
break;
default:
return;
}
}
/// <inheritdoc />

View File

@@ -54,6 +54,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetStrokingColorCmyk(C, M, Y, K);
}
/// <inheritdoc />

View File

@@ -33,6 +33,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetStrokingColorGray(Gray);
}
/// <inheritdoc />

View File

@@ -47,6 +47,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetStrokingColorRgb(R, G, B);
}
/// <inheritdoc />

View File

@@ -36,6 +36,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ColorspaceContext.SetStrokingColorspace(Name);
}
/// <inheritdoc />