Skip to content

Commit f4190d0

Browse files
committed
Make classes related to page content parsing public
1 parent d1d79b0 commit f4190d0

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

src/UglyToad.PdfPig.Tests/Parser/PageContentParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public class PageContentParserTests
1717
{
18-
private readonly PageContentParser parser = new PageContentParser(new ReflectionGraphicsStateOperationFactory());
18+
private readonly PageContentParser parser = new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance);
1919
private readonly ILog log = new NoOpLog();
2020

2121
[Fact]

src/UglyToad.PdfPig.Tests/PublicApiScannerTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public void OnlyExposedApiIsPublic()
125125
"UglyToad.PdfPig.Geometry.GeometryExtensions",
126126
"UglyToad.PdfPig.Geometry.UserSpaceUnit",
127127
"UglyToad.PdfPig.Graphics.BaseStreamProcessor`1",
128+
"UglyToad.PdfPig.Graphics.IGraphicsStateOperationFactory",
129+
"UglyToad.PdfPig.Graphics.ReflectionGraphicsStateOperationFactory",
128130
"UglyToad.PdfPig.Graphics.Colors.CMYKColor",
129131
"UglyToad.PdfPig.Graphics.Colors.ColorSpace",
130132
"UglyToad.PdfPig.Graphics.PdfPath",
@@ -265,6 +267,7 @@ public void OnlyExposedApiIsPublic()
265267
"UglyToad.PdfPig.Outline.Destinations.NamedDestinations",
266268
"UglyToad.PdfPig.ParsingOptions",
267269
"UglyToad.PdfPig.Parser.IPageContentParser",
270+
"UglyToad.PdfPig.Parser.PageContentParser",
268271
"UglyToad.PdfPig.Parser.Parts.DirectObjectFinder",
269272
"UglyToad.PdfPig.PdfDocument",
270273
"UglyToad.PdfPig.PdfExtensions",

src/UglyToad.PdfPig/Graphics/IGraphicsStateOperationFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
using Operations;
55
using Tokens;
66

7-
internal interface IGraphicsStateOperationFactory
7+
/// <summary>
8+
/// Graphics state operation factory interface.
9+
/// </summary>
10+
public interface IGraphicsStateOperationFactory
811
{
12+
/// <summary>
13+
/// Create a graphics state operation.
14+
/// </summary>
15+
/// <param name="op">The operator token to build from.</param>
16+
/// <param name="operands"></param>
917
IGraphicsStateOperation? Create(OperatorToken op, IReadOnlyList<IToken> operands);
1018
}
1119
}

src/UglyToad.PdfPig/Graphics/ReflectionGraphicsStateOperationFactory.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,21 @@ namespace UglyToad.PdfPig.Graphics
2323
using System.Reflection;
2424
using Tokens;
2525

26-
internal sealed class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
26+
/// <summary>
27+
/// Reflection based graphics state operation factory.
28+
/// </summary>
29+
public sealed class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
2730
{
31+
/// <summary>
32+
/// The single instance of the <see cref="ReflectionGraphicsStateOperationFactory"/>.
33+
/// </summary>
34+
public static readonly ReflectionGraphicsStateOperationFactory Instance = new ReflectionGraphicsStateOperationFactory();
35+
36+
private ReflectionGraphicsStateOperationFactory()
37+
{
38+
// private
39+
}
40+
2841
private static readonly IReadOnlyDictionary<string, Type> operations =
2942
new Dictionary<string, Type>
3043
{
@@ -161,6 +174,7 @@ private static double OperandToDouble(IToken token)
161174
return numeric.Data;
162175
}
163176

177+
/// <inheritdoc/>
164178
public IGraphicsStateOperation? Create(OperatorToken op, IReadOnlyList<IToken> operands)
165179
{
166180
switch (op.Data)

src/UglyToad.PdfPig/Parser/PageContentParser.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,44 @@
1212
using Tokenization.Scanner;
1313
using Tokens;
1414

15-
internal sealed class PageContentParser : IPageContentParser
15+
/// <summary>
16+
/// Provides functionality to parse the content of a PDF page, extracting graphics state operations
17+
/// from the input data. This class is responsible for interpreting the PDF content stream and
18+
/// converting it into a collection of operations.
19+
/// </summary>
20+
public sealed class PageContentParser : IPageContentParser
1621
{
1722
private readonly IGraphicsStateOperationFactory operationFactory;
1823
private readonly bool useLenientParsing;
1924

25+
/// <summary>
26+
/// Initialises a new instance of the <see cref="PageContentParser"/> class.
27+
/// </summary>
28+
/// <param name="operationFactory">
29+
/// The factory responsible for creating graphics state operations.
30+
/// </param>
31+
/// <param name="useLenientParsing">
32+
/// A value indicating whether lenient parsing should be used. Defaults to <c>false</c>.
33+
/// </param>
2034
public PageContentParser(IGraphicsStateOperationFactory operationFactory, bool useLenientParsing = false)
2135
{
2236
this.operationFactory = operationFactory;
2337
this.useLenientParsing = useLenientParsing;
2438
}
2539

40+
/// <summary>
41+
/// Parses the content of a PDF page and extracts a collection of graphics state operations.
42+
/// </summary>
43+
/// <param name="pageNumber">The number of the page being parsed.</param>
44+
/// <param name="inputBytes">The input bytes representing the content of the page.</param>
45+
/// <param name="log">The logger instance for recording parsing-related information.</param>
46+
/// <returns>A read-only list of graphics state operations extracted from the page content.</returns>
47+
/// <exception cref="ArgumentNullException">
48+
/// Thrown if <paramref name="inputBytes"/> or <paramref name="log"/> is <c>null</c>.
49+
/// </exception>
50+
/// <exception cref="InvalidOperationException">
51+
/// Thrown if the parsing process encounters an invalid or unsupported token.
52+
/// </exception>
2653
public IReadOnlyList<IGraphicsStateOperation> Parse(
2754
int pageNumber,
2855
IInputBytes inputBytes,

src/UglyToad.PdfPig/Parser/PdfDocumentFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private static PdfDocument OpenDocument(
192192
parsingOptions.UseLenientParsing);
193193

194194
var pageFactory = new PageFactory(pdfScanner, resourceContainer, filterProvider,
195-
new PageContentParser(new ReflectionGraphicsStateOperationFactory(), parsingOptions.UseLenientParsing), parsingOptions);
195+
new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance, parsingOptions.UseLenientParsing), parsingOptions);
196196

197197
var catalog = CatalogFactory.Create(
198198
rootReference,

src/UglyToad.PdfPig/Writer/NoTextTokenWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private bool TryGetStreamWithoutText(StreamToken streamToken, [NotNullWhen(true)
7474
return false;
7575
}
7676

77-
var pageContentParser = new PageContentParser(new ReflectionGraphicsStateOperationFactory());
77+
var pageContentParser = new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance);
7878
IReadOnlyList<IGraphicsStateOperation> operations;
7979
try
8080
{

0 commit comments

Comments
 (0)