Skip to content

Commit 306642a

Browse files
committed
Add SetStrokeDetails() and SetFillDetails() to PdfPath and tidy up ContentStreamProcessor
1 parent 204f488 commit 306642a

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace UglyToad.PdfPig.Graphics
44
{
55
using System;
66
using System.Collections.Generic;
7-
using Colors;
87
using Content;
98
using Filters;
109
using Geometry;
@@ -212,7 +211,7 @@ public override void BeginSubpath()
212211
return point;
213212
}
214213

215-
public void AddCurrentSubpath() // Not an override
214+
private void AddCurrentSubpath()
216215
{
217216
if (CurrentSubpath is null)
218217
{
@@ -385,16 +384,12 @@ public override void ClosePath()
385384
var currentState = GetCurrentState();
386385
if (CurrentPath.IsStroked)
387386
{
388-
CurrentPath.LineDashPattern = currentState.LineDashPattern;
389-
CurrentPath.StrokeColor = currentState.CurrentStrokingColor;
390-
CurrentPath.LineWidth = currentState.LineWidth;
391-
CurrentPath.LineCapStyle = currentState.CapStyle;
392-
CurrentPath.LineJoinStyle = currentState.JoinStyle;
387+
CurrentPath.SetStrokeDetails(currentState);
393388
}
394389

395390
if (CurrentPath.IsFilled)
396391
{
397-
CurrentPath.FillColor = currentState.CurrentNonStrokingColor;
392+
CurrentPath.SetFillDetails(currentState);
398393
}
399394

400395
if (ParsingOptions.ClipPaths)

src/UglyToad.PdfPig/Graphics/PdfPath.cs

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
using UglyToad.PdfPig.Graphics.Core;
77

88
/// <summary>
9-
/// A path is made up of one or more disconnected subpaths, each comprising a sequence of connected segments. The topology of the path is unrestricted: it may be concave or convex, may contain multiple subpaths representing disjoint areas, and may intersect itself in arbitrary ways.
9+
/// A path is made up of one or more disconnected subpaths, each comprising a sequence of connected segments.
10+
/// The topology of the path is unrestricted: it may be concave or convex, may contain multiple subpaths representing
11+
/// disjoint areas, and may intersect itself in arbitrary ways.
1012
/// <para>A path shall be composed of straight and curved line segments, which may connect to one another or may be disconnected.</para>
1113
/// </summary>
1214
public class PdfPath : List<PdfSubpath>
@@ -29,7 +31,7 @@ public class PdfPath : List<PdfSubpath>
2931
/// <summary>
3032
/// The fill color.
3133
/// </summary>
32-
public IColor? FillColor { get; internal set; }
34+
public IColor? FillColor { get; private set; }
3335

3436
/// <summary>
3537
/// Returns true if the path is stroked.
@@ -39,31 +41,31 @@ public class PdfPath : List<PdfSubpath>
3941
/// <summary>
4042
/// The stroke color.
4143
/// </summary>
42-
public IColor? StrokeColor { get; internal set; }
44+
public IColor? StrokeColor { get; private set; }
4345

4446
/// <summary>
4547
/// Thickness in user space units of path to be stroked.
4648
/// </summary>
47-
public double LineWidth { get; internal set; }
49+
public double LineWidth { get; private set; }
4850

4951
/// <summary>
5052
/// The pattern to be used for stroked lines.
5153
/// </summary>
52-
public LineDashPattern? LineDashPattern { get; internal set; }
54+
public LineDashPattern? LineDashPattern { get; private set; }
5355

5456
/// <summary>
5557
/// The cap style to be used for stroked lines.
5658
/// </summary>
57-
public LineCapStyle LineCapStyle { get; internal set; }
59+
public LineCapStyle LineCapStyle { get; private set; }
5860

5961
/// <summary>
6062
/// The join style to be used for stroked lines.
6163
/// </summary>
62-
public LineJoinStyle LineJoinStyle { get; internal set; }
64+
public LineJoinStyle LineJoinStyle { get; private set; }
6365

6466
/// <summary>
65-
/// Set the clipping mode for this path and IsClipping to true.
66-
/// <para>IsFilled and IsStroked flags will be set to false.</para>
67+
/// Set the clipping mode for this path and <c>IsClipping</c> to <c>true</c>.
68+
/// <para><c>IsFilled</c> and <c>IsStroked</c> flags will be set to <c>false</c>.</para>
6769
/// </summary>
6870
public void SetClipping(FillingRule fillingRule)
6971
{
@@ -74,7 +76,7 @@ public void SetClipping(FillingRule fillingRule)
7476
}
7577

7678
/// <summary>
77-
/// Set the filling rule for this path and IsFilled to true.
79+
/// Set the filling rule for this path and <c>IsFilled</c> to <c>true</c>.
7880
/// </summary>
7981
public void SetFilled(FillingRule fillingRule)
8082
{
@@ -83,13 +85,35 @@ public void SetFilled(FillingRule fillingRule)
8385
}
8486

8587
/// <summary>
86-
/// Set IsStroked to true.
88+
/// Set <c>IsStroked</c> to <c>true</c>.
8789
/// </summary>
8890
public void SetStroked()
8991
{
9092
IsStroked = true;
9193
}
9294

95+
/// <summary>
96+
/// Set the path stroke details, i.e. <c>LineDashPattern</c>, <c>StrokeColor</c>, <c>LineWidth</c>, <c>LineCapStyle</c> and <c>LineJoinStyle</c>.
97+
/// </summary>
98+
/// <param name="graphicsState">The current graphics state.</param>
99+
public void SetStrokeDetails(CurrentGraphicsState graphicsState)
100+
{
101+
LineDashPattern = graphicsState.LineDashPattern;
102+
StrokeColor = graphicsState.CurrentStrokingColor;
103+
LineWidth = graphicsState.LineWidth;
104+
LineCapStyle = graphicsState.CapStyle;
105+
LineJoinStyle = graphicsState.JoinStyle;
106+
}
107+
108+
/// <summary>
109+
/// Set the path fill details, i.e. <c>FillColor</c>.
110+
/// </summary>
111+
/// <param name="graphicsState">The current graphics state.</param>
112+
public void SetFillDetails(CurrentGraphicsState graphicsState)
113+
{
114+
FillColor = graphicsState.CurrentNonStrokingColor;
115+
}
116+
93117
/// <summary>
94118
/// Create a clone with no Subpaths.
95119
/// </summary>

0 commit comments

Comments
 (0)