2017-11-22 18:41:34 +00:00
|
|
|
|
namespace UglyToad.Pdf.Parser
|
|
|
|
|
|
{
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Graphics;
|
|
|
|
|
|
using Graphics.Operations;
|
|
|
|
|
|
using IO;
|
|
|
|
|
|
using Tokenization.Scanner;
|
|
|
|
|
|
using Tokenization.Tokens;
|
|
|
|
|
|
|
|
|
|
|
|
internal class PageContentParser : IPageContentParser
|
|
|
|
|
|
{
|
2017-12-02 14:57:44 +00:00
|
|
|
|
public IReadOnlyList<IGraphicsStateOperation> Parse(IGraphicsStateOperationFactory operationFactory, IInputBytes inputBytes)
|
2017-11-22 18:41:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
var scanner = new CoreTokenScanner(inputBytes);
|
|
|
|
|
|
|
|
|
|
|
|
var precedingTokens = new List<IToken>();
|
|
|
|
|
|
var graphicsStateOperations = new List<IGraphicsStateOperation>();
|
|
|
|
|
|
|
|
|
|
|
|
while (scanner.MoveNext())
|
|
|
|
|
|
{
|
|
|
|
|
|
var token = scanner.CurrentToken;
|
|
|
|
|
|
|
|
|
|
|
|
if (token is OperatorToken op)
|
|
|
|
|
|
{
|
|
|
|
|
|
var operation = operationFactory.Create(op, precedingTokens);
|
|
|
|
|
|
|
|
|
|
|
|
if (operation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
graphicsStateOperations.Add(operation);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
precedingTokens.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (token is CommentToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
precedingTokens.Add(token);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-02 14:57:44 +00:00
|
|
|
|
return graphicsStateOperations;
|
2017-11-22 18:41:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|