diff --git a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs
index 30ba1f59..eb9178ac 100644
--- a/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs
+++ b/src/UglyToad.PdfPig.Tests/Graphics/TestOperationContext.cs
@@ -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)
+ {
+ }
+ }
}
diff --git a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs
index 22640787..1c3c5e96 100644
--- a/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs
+++ b/src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs
@@ -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",
diff --git a/src/UglyToad.PdfPig/Graphics/ColorspaceContext.cs b/src/UglyToad.PdfPig/Graphics/ColorspaceContext.cs
new file mode 100644
index 00000000..3ef2a7bc
--- /dev/null
+++ b/src/UglyToad.PdfPig/Graphics/ColorspaceContext.cs
@@ -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)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs
index 7568dc54..d71a5c71 100644
--- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs
+++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs
@@ -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;
diff --git a/src/UglyToad.PdfPig/Graphics/IColorspaceContext.cs b/src/UglyToad.PdfPig/Graphics/IColorspaceContext.cs
new file mode 100644
index 00000000..8d336038
--- /dev/null
+++ b/src/UglyToad.PdfPig/Graphics/IColorspaceContext.cs
@@ -0,0 +1,66 @@
+namespace UglyToad.PdfPig.Graphics
+{
+ using Tokens;
+
+ ///
+ /// Methods for manipulating and retrieving the current color state for a PDF content stream.
+ ///
+ public interface IColorspaceContext
+ {
+ ///
+ /// Set the current color space to use for stroking operations.
+ ///
+ void SetStrokingColorspace(NameToken colorspace);
+
+ ///
+ /// Set the current color space to use for nonstroking operations.
+ ///
+ void SetNonStrokingColorspace(NameToken colorspace);
+
+ ///
+ /// Set the stroking color space to DeviceGray and set the gray level to use for stroking operations.
+ ///
+ /// A number between 0.0 (black) and 1.0 (white).
+ void SetStrokingColorGray(decimal gray);
+
+ ///
+ /// Set the stroking color space to DeviceRGB and set the color to use for stroking operations.
+ ///
+ /// Red - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ /// Green - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ /// Blue - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ void SetStrokingColorRgb(decimal r, decimal g, decimal b);
+
+ ///
+ /// Set the stroking color space to DeviceCMYK and set the color to use for stroking operations.
+ ///
+ /// Cyan - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Magenta - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Yellow - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Black - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ void SetStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k);
+
+ ///
+ /// Set the nonstroking color space to DeviceGray and set the gray level to use for nonstroking operations.
+ ///
+ /// A number between 0.0 (black) and 1.0 (white).
+ void SetNonStrokingColorGray(decimal gray);
+
+ ///
+ /// Set the nonstroking color space to DeviceRGB and set the color to use for nonstroking operations.
+ ///
+ /// Red - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ /// Green - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ /// Blue - A number between 0 (minimum intensity) and 1 (maximum intensity).
+ void SetNonStrokingColorRgb(decimal r, decimal g, decimal b);
+
+ ///
+ /// Set the nonstroking color space to DeviceCMYK and set the color to use for nonstroking operations.
+ ///
+ /// Cyan - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Magenta - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Yellow - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ /// Black - A number between 0 (minimum concentration) and 1 (maximum concentration).
+ void SetNonStrokingColorCmyk(decimal c, decimal m, decimal y, decimal k);
+ }
+}
\ No newline at end of file
diff --git a/src/UglyToad.PdfPig/Graphics/IOperationContext.cs b/src/UglyToad.PdfPig/Graphics/IOperationContext.cs
index ad5e033b..3965165d 100644
--- a/src/UglyToad.PdfPig/Graphics/IOperationContext.cs
+++ b/src/UglyToad.PdfPig/Graphics/IOperationContext.cs
@@ -18,7 +18,12 @@
PdfPath CurrentPath { get; }
///
- /// The current p
+ /// The active colorspaces for this content stream.
+ ///
+ IColorspaceContext ColorspaceContext { get; }
+
+ ///
+ /// The current position.
///
PdfPoint CurrentPosition { get; set; }
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceCmyk.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceCmyk.cs
index dd39f974..8d0ae3be 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceCmyk.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceCmyk.cs
@@ -54,6 +54,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetNonStrokingColorCmyk(C, M, Y, K);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs
index 195f6f7d..3c256ceb 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceGray.cs
@@ -33,6 +33,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetNonStrokingColorGray(Gray);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceRgb.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceRgb.cs
index 95bcdfb7..cc063792 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceRgb.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorDeviceRgb.cs
@@ -47,6 +47,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetNonStrokingColorRgb(R, G, B);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorSpace.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorSpace.cs
index c0eca9d9..b057637b 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorSpace.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetNonStrokeColorSpace.cs
@@ -36,6 +36,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetNonStrokingColorspace(Name);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColor.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColor.cs
index 00fcb029..9e7b0fbb 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColor.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColor.cs
@@ -14,7 +14,7 @@
/// The symbol for this operation in a stream.
///
public const string Symbol = "SC";
-
+
///
public string Operator => Symbol;
@@ -35,6 +35,20 @@
///
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;
+ }
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs
index 10559b6f..f5ce5880 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceCmyk.cs
@@ -54,6 +54,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetStrokingColorCmyk(C, M, Y, K);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs
index e5d87545..397cab25 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceGray.cs
@@ -33,6 +33,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetStrokingColorGray(Gray);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs
index 6b5cf44c..fe9bd5f0 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorDeviceRgb.cs
@@ -47,6 +47,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetStrokingColorRgb(R, G, B);
}
///
diff --git a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorSpace.cs b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorSpace.cs
index 9ffaa7a5..a0369ecc 100644
--- a/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorSpace.cs
+++ b/src/UglyToad.PdfPig/Graphics/Operations/SetStrokeColorSpace.cs
@@ -36,6 +36,7 @@
///
public void Run(IOperationContext operationContext)
{
+ operationContext.ColorspaceContext.SetStrokingColorspace(Name);
}
///