mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 02:44:58 +08:00
Implement FillStrokePath() operator and filling rule.
This commit is contained in:
@@ -69,8 +69,13 @@
|
|||||||
public void StrokePath(bool close)
|
public void StrokePath(bool close)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public void FillPath(bool close)
|
|
||||||
|
public void FillPath(FillingRule fillingRule, bool close)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
public void FillStrokePath(FillingRule fillingRule, bool close)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClosePath()
|
public void ClosePath()
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
using Tokenization.Scanner;
|
using Tokenization.Scanner;
|
||||||
using Tokens;
|
using Tokens;
|
||||||
using XObjects;
|
using XObjects;
|
||||||
|
using static UglyToad.PdfPig.Core.PdfSubpath;
|
||||||
|
|
||||||
internal class ContentStreamProcessor : IOperationContext
|
internal class ContentStreamProcessor : IOperationContext
|
||||||
{
|
{
|
||||||
@@ -94,7 +95,14 @@
|
|||||||
this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser));
|
this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser));
|
||||||
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
|
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
|
||||||
this.log = log;
|
this.log = log;
|
||||||
graphicsStack.Push(new CurrentGraphicsState());
|
|
||||||
|
// initiate CurrentClippingPath to cropBox
|
||||||
|
var clippingSubpath = new PdfSubpath();
|
||||||
|
clippingSubpath.Rectangle(cropBox.BottomLeft.X, cropBox.BottomLeft.Y, cropBox.Width, cropBox.Height);
|
||||||
|
var clippingPath = new PdfPath() { clippingSubpath };
|
||||||
|
clippingPath.SetClipping(FillingRule.NonZeroWinding);
|
||||||
|
|
||||||
|
graphicsStack.Push(new CurrentGraphicsState() { CurrentClippingPath = clippingPath });
|
||||||
ColorSpaceContext = new ColorSpaceContext(GetCurrentState, resourceStore);
|
ColorSpaceContext = new ColorSpaceContext(GetCurrentState, resourceStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +407,41 @@
|
|||||||
|
|
||||||
public void BeginSubpath()
|
public void BeginSubpath()
|
||||||
{
|
{
|
||||||
|
if (CurrentPath == null)
|
||||||
|
{
|
||||||
|
CurrentPath = new PdfPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
AddSubpath();
|
||||||
|
CurrentSubpath = new PdfSubpath();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfPoint CloseSubpath()
|
||||||
|
{
|
||||||
|
PdfPoint point;
|
||||||
|
if (CurrentSubpath.Commands[0] is Move move)
|
||||||
|
{
|
||||||
|
point = move.Location;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("CloseSubpath(): first command not Move.");
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentSubpath.ClosePath();
|
||||||
|
AddSubpath();
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSubpath()
|
||||||
|
{
|
||||||
|
if (CurrentSubpath == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentPath.Add(CurrentSubpath);
|
||||||
|
CurrentSubpath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StrokePath(bool close)
|
public void StrokePath(bool close)
|
||||||
@@ -407,11 +449,16 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FillPath(bool close)
|
public void FillPath(FillingRule fillingRule, bool close)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void FillStrokePath(FillingRule fillingRule, bool close)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void ClosePath()
|
public void ClosePath()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -95,8 +95,16 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fill the current path.
|
/// Fill the current path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="fillingRule">The filling rule to use.</param>
|
||||||
/// <param name="close">Whether to also close the path.</param>
|
/// <param name="close">Whether to also close the path.</param>
|
||||||
void FillPath(bool close);
|
void FillPath(FillingRule fillingRule, bool close);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fill and stroke the current path.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fillingRule">The filling rule to use.</param>
|
||||||
|
/// <param name="close">Whether to also close the path.</param>
|
||||||
|
void FillStrokePath(FillingRule fillingRule, bool close);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Close the current path.
|
/// Close the current path.
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(true);
|
operationContext.FillStrokePath(PdfPig.Core.FillingRule.EvenOdd, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(true);
|
operationContext.FillStrokePath(PdfPig.Core.FillingRule.NonZeroWinding, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(false);
|
operationContext.FillPath(PdfPig.Core.FillingRule.EvenOdd, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(false);
|
operationContext.FillStrokePath(PdfPig.Core.FillingRule.EvenOdd, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(false);
|
operationContext.FillPath(PdfPig.Core.FillingRule.NonZeroWinding, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(false);
|
operationContext.FillStrokePath(PdfPig.Core.FillingRule.NonZeroWinding, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
public const string Symbol = "F";
|
public const string Symbol = "F";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The instance of the <see cref="FillPathEvenOddRuleAndStroke"/> operation.
|
/// The instance of the <see cref="FillPathNonZeroWindingCompatibility"/> operation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly FillPathNonZeroWindingCompatibility Value = new FillPathNonZeroWindingCompatibility();
|
public static readonly FillPathNonZeroWindingCompatibility Value = new FillPathNonZeroWindingCompatibility();
|
||||||
|
|
||||||
@@ -29,13 +29,14 @@
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Run(IOperationContext operationContext)
|
public void Run(IOperationContext operationContext)
|
||||||
{
|
{
|
||||||
operationContext.FillPath(false);
|
operationContext.FillPath(PdfPig.Core.FillingRule.NonZeroWinding, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Write(Stream stream)
|
public void Write(Stream stream)
|
||||||
{
|
{
|
||||||
stream.WriteText(Symbol);
|
// Although PDF reader applications shall be able to accept this operator, PDF writer applications should use f instead.
|
||||||
|
stream.WriteText(FillPathNonZeroWinding.Symbol);
|
||||||
stream.WriteNewLine();
|
stream.WriteNewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user