Implement Modify Clipping operations

This commit is contained in:
BobLd
2020-02-23 19:23:27 +00:00
committed by Eliot Jones
parent b0eaccf56f
commit 1d095af974
7 changed files with 67 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
namespace UglyToad.PdfPig.Core
{
/// <summary>
/// Rules for determining which points lie inside/outside a path.
/// </summary>
public enum ClippingRule
{
/// <summary>
/// No rule.
/// </summary>
None,
/// <summary>
/// This even-odd rule determines whether a point is inside a path by drawing a ray from that point in
/// any direction and simply counting the number of path segments that cross the ray, regardless of
/// direction. If this number is odd, the point is inside; if even, the point is outside. This yields
/// the same results as the nonzero winding number rule for paths with simple shapes, but produces
/// different results for more complex shapes.
/// </summary>
EvenOdd,
/// <summary>
/// The nonzero winding number rule determines whether a given point is inside a path by conceptually
/// drawing a ray from that point to infinity in any direction and then examining the places where a
/// segment of the path crosses the ray. Starting with a count of 0, the rule adds 1 each time a path
/// segment crosses the ray from left to right and subtracts 1 each time a segment crosses from right
/// to left. After counting all the crossings, if the result is 0, the point is outside the path;
/// otherwise, it is inside.
/// </summary>
NonZeroWinding
}
}

View File

@@ -22,6 +22,16 @@
/// </summary>
public bool IsDrawnAsRectangle { get; internal set; }
/// <summary>
/// Rules for determining which points lie inside/outside the path.
/// </summary>
public ClippingRule ClippingRule { get; private set; }
/// <summary>
/// Returns true if this is a clipping path.
/// </summary>
public bool IsClipping { get; private set; }
private PdfPoint? currentPosition;
private double shoeLaceSum;
@@ -78,6 +88,16 @@
return new PdfPoint(points.Average(p => p.X), points.Average(p => p.Y));
}
/// <summary>
///
/// </summary>
/// <param name="clippingRule"></param>
public void SetClipping(ClippingRule clippingRule)
{
IsClipping = true;
ClippingRule = clippingRule;
}
internal static PdfPoint GetStartPoint(IPathCommand command)
{
if (command is Line line)

View File

@@ -93,12 +93,14 @@
public void BeginMarkedContent(NameToken name, NameToken propertyDictionaryName, DictionaryToken properties)
{
}
public void EndMarkedContent()
{
}
public void ModifyClippingIntersect(ClippingRule clippingRule)
{
}
private class TestFontFactory : IFontFactory

View File

@@ -565,5 +565,10 @@
TextMatrices.TextMatrix = newMatrix;
}
public void ModifyClippingIntersect(ClippingRule clippingRule)
{
CurrentPath.SetClipping(clippingRule);
}
}
}

View File

@@ -127,5 +127,10 @@
/// Indicates that the current inline image is complete.
/// </summary>
void EndInlineImage(IReadOnlyList<byte> bytes);
/// <summary>
/// Modify the clipping rule of the current path.
/// </summary>
void ModifyClippingIntersect(ClippingRule clippingRule);
}
}

View File

@@ -29,6 +29,7 @@
/// <inheritdoc />
public void Run(IOperationContext operationContext)
{
operationContext.ModifyClippingIntersect(PdfPig.Core.ClippingRule.EvenOdd);
}
/// <inheritdoc />

View File

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