mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-24 08:47:01 +08:00
Make classes related to page content parsing public
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
public class PageContentParserTests
|
||||
{
|
||||
private readonly PageContentParser parser = new PageContentParser(new ReflectionGraphicsStateOperationFactory());
|
||||
private readonly PageContentParser parser = new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance);
|
||||
private readonly ILog log = new NoOpLog();
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -125,6 +125,8 @@
|
||||
"UglyToad.PdfPig.Geometry.GeometryExtensions",
|
||||
"UglyToad.PdfPig.Geometry.UserSpaceUnit",
|
||||
"UglyToad.PdfPig.Graphics.BaseStreamProcessor`1",
|
||||
"UglyToad.PdfPig.Graphics.IGraphicsStateOperationFactory",
|
||||
"UglyToad.PdfPig.Graphics.ReflectionGraphicsStateOperationFactory",
|
||||
"UglyToad.PdfPig.Graphics.Colors.CMYKColor",
|
||||
"UglyToad.PdfPig.Graphics.Colors.ColorSpace",
|
||||
"UglyToad.PdfPig.Graphics.PdfPath",
|
||||
@@ -265,6 +267,7 @@
|
||||
"UglyToad.PdfPig.Outline.Destinations.NamedDestinations",
|
||||
"UglyToad.PdfPig.ParsingOptions",
|
||||
"UglyToad.PdfPig.Parser.IPageContentParser",
|
||||
"UglyToad.PdfPig.Parser.PageContentParser",
|
||||
"UglyToad.PdfPig.Parser.Parts.DirectObjectFinder",
|
||||
"UglyToad.PdfPig.PdfDocument",
|
||||
"UglyToad.PdfPig.PdfExtensions",
|
||||
|
||||
@@ -4,8 +4,16 @@
|
||||
using Operations;
|
||||
using Tokens;
|
||||
|
||||
internal interface IGraphicsStateOperationFactory
|
||||
/// <summary>
|
||||
/// Graphics state operation factory interface.
|
||||
/// </summary>
|
||||
public interface IGraphicsStateOperationFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a graphics state operation.
|
||||
/// </summary>
|
||||
/// <param name="op">The operator token to build from.</param>
|
||||
/// <param name="operands"></param>
|
||||
IGraphicsStateOperation? Create(OperatorToken op, IReadOnlyList<IToken> operands);
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,21 @@ namespace UglyToad.PdfPig.Graphics
|
||||
using System.Reflection;
|
||||
using Tokens;
|
||||
|
||||
internal sealed class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
|
||||
/// <summary>
|
||||
/// Reflection based graphics state operation factory.
|
||||
/// </summary>
|
||||
public sealed class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// The single instance of the <see cref="ReflectionGraphicsStateOperationFactory"/>.
|
||||
/// </summary>
|
||||
public static readonly ReflectionGraphicsStateOperationFactory Instance = new ReflectionGraphicsStateOperationFactory();
|
||||
|
||||
private ReflectionGraphicsStateOperationFactory()
|
||||
{
|
||||
// private
|
||||
}
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, Type> operations =
|
||||
new Dictionary<string, Type>
|
||||
{
|
||||
@@ -161,6 +174,7 @@ namespace UglyToad.PdfPig.Graphics
|
||||
return numeric.Data;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGraphicsStateOperation? Create(OperatorToken op, IReadOnlyList<IToken> operands)
|
||||
{
|
||||
switch (op.Data)
|
||||
|
||||
@@ -12,17 +12,44 @@
|
||||
using Tokenization.Scanner;
|
||||
using Tokens;
|
||||
|
||||
internal sealed class PageContentParser : IPageContentParser
|
||||
/// <summary>
|
||||
/// Provides functionality to parse the content of a PDF page, extracting graphics state operations
|
||||
/// from the input data. This class is responsible for interpreting the PDF content stream and
|
||||
/// converting it into a collection of operations.
|
||||
/// </summary>
|
||||
public sealed class PageContentParser : IPageContentParser
|
||||
{
|
||||
private readonly IGraphicsStateOperationFactory operationFactory;
|
||||
private readonly bool useLenientParsing;
|
||||
|
||||
/// <summary>
|
||||
/// Initialises a new instance of the <see cref="PageContentParser"/> class.
|
||||
/// </summary>
|
||||
/// <param name="operationFactory">
|
||||
/// The factory responsible for creating graphics state operations.
|
||||
/// </param>
|
||||
/// <param name="useLenientParsing">
|
||||
/// A value indicating whether lenient parsing should be used. Defaults to <c>false</c>.
|
||||
/// </param>
|
||||
public PageContentParser(IGraphicsStateOperationFactory operationFactory, bool useLenientParsing = false)
|
||||
{
|
||||
this.operationFactory = operationFactory;
|
||||
this.useLenientParsing = useLenientParsing;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses the content of a PDF page and extracts a collection of graphics state operations.
|
||||
/// </summary>
|
||||
/// <param name="pageNumber">The number of the page being parsed.</param>
|
||||
/// <param name="inputBytes">The input bytes representing the content of the page.</param>
|
||||
/// <param name="log">The logger instance for recording parsing-related information.</param>
|
||||
/// <returns>A read-only list of graphics state operations extracted from the page content.</returns>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// Thrown if <paramref name="inputBytes"/> or <paramref name="log"/> is <c>null</c>.
|
||||
/// </exception>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if the parsing process encounters an invalid or unsupported token.
|
||||
/// </exception>
|
||||
public IReadOnlyList<IGraphicsStateOperation> Parse(
|
||||
int pageNumber,
|
||||
IInputBytes inputBytes,
|
||||
|
||||
@@ -192,7 +192,7 @@
|
||||
parsingOptions.UseLenientParsing);
|
||||
|
||||
var pageFactory = new PageFactory(pdfScanner, resourceContainer, filterProvider,
|
||||
new PageContentParser(new ReflectionGraphicsStateOperationFactory(), parsingOptions.UseLenientParsing), parsingOptions);
|
||||
new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance, parsingOptions.UseLenientParsing), parsingOptions);
|
||||
|
||||
var catalog = CatalogFactory.Create(
|
||||
rootReference,
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace UglyToad.PdfPig.Writer
|
||||
return false;
|
||||
}
|
||||
|
||||
var pageContentParser = new PageContentParser(new ReflectionGraphicsStateOperationFactory());
|
||||
var pageContentParser = new PageContentParser(ReflectionGraphicsStateOperationFactory.Instance);
|
||||
IReadOnlyList<IGraphicsStateOperation> operations;
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user