Implement FillStrokePath() operator and filling rule.

This commit is contained in:
BobLd
2020-04-02 16:55:09 +01:00
committed by Eliot Jones
parent 5eb2cc507e
commit 3ee9ac7915
10 changed files with 75 additions and 14 deletions

View File

@@ -69,8 +69,13 @@
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()

View File

@@ -17,6 +17,7 @@
using Tokenization.Scanner;
using Tokens;
using XObjects;
using static UglyToad.PdfPig.Core.PdfSubpath;
internal class ContentStreamProcessor : IOperationContext
{
@@ -94,7 +95,14 @@
this.pageContentParser = pageContentParser ?? throw new ArgumentNullException(nameof(pageContentParser));
this.filterProvider = filterProvider ?? throw new ArgumentNullException(nameof(filterProvider));
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);
}
@@ -399,7 +407,41 @@
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)
@@ -407,7 +449,12 @@
}
public void FillPath(bool close)
public void FillPath(FillingRule fillingRule, bool close)
{
}
public void FillStrokePath(FillingRule fillingRule, bool close)
{
}

View File

@@ -95,8 +95,16 @@
/// <summary>
/// Fill the current path.
/// </summary>
/// <param name="fillingRule">The filling rule to use.</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>
/// Close the current path.

View File

@@ -28,7 +28,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(true);
operationContext.FillStrokePath(PdfPig.Core.FillingRule.EvenOdd, true);
}
/// <inheritdoc />

View File

@@ -28,7 +28,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(true);
operationContext.FillStrokePath(PdfPig.Core.FillingRule.NonZeroWinding, true);
}
/// <inheritdoc />

View File

@@ -28,7 +28,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(false);
operationContext.FillPath(PdfPig.Core.FillingRule.EvenOdd, false);
}
/// <inheritdoc />

View File

@@ -28,7 +28,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(false);
operationContext.FillStrokePath(PdfPig.Core.FillingRule.EvenOdd, false);
}
/// <inheritdoc />

View File

@@ -29,7 +29,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(false);
operationContext.FillPath(PdfPig.Core.FillingRule.NonZeroWinding, false);
}
/// <inheritdoc />

View File

@@ -28,7 +28,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(false);
operationContext.FillStrokePath(PdfPig.Core.FillingRule.NonZeroWinding, false);
}
/// <inheritdoc />

View File

@@ -15,7 +15,7 @@
public const string Symbol = "F";
/// <summary>
/// The instance of the <see cref="FillPathEvenOddRuleAndStroke"/> operation.
/// The instance of the <see cref="FillPathNonZeroWindingCompatibility"/> operation.
/// </summary>
public static readonly FillPathNonZeroWindingCompatibility Value = new FillPathNonZeroWindingCompatibility();
@@ -29,13 +29,14 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.FillPath(false);
operationContext.FillPath(PdfPig.Core.FillingRule.NonZeroWinding, false);
}
/// <inheritdoc />
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();
}