start passing the pdf scanner in to read the type 1 files

This commit is contained in:
Eliot Jones
2018-01-14 15:33:22 +00:00
parent 1fb6ec41d1
commit 615ee88a46
10 changed files with 148 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
namespace UglyToad.PdfPig.Tokenization.Scanner
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -9,7 +10,12 @@
using Parser.Parts;
using Tokens;
internal class PdfTokenScanner : ISeekableTokenScanner
internal interface IPdfObjectScanner : ISeekableTokenScanner
{
ObjectToken Get(IndirectReference reference);
}
internal class PdfTokenScanner : IPdfObjectScanner
{
private readonly IInputBytes inputBytes;
private readonly IObjectLocationProvider objectLocationProvider;
@@ -449,5 +455,22 @@
{
coreTokenScanner.DeregisterCustomTokenizer(tokenizer);
}
public ObjectToken Get(IndirectReference reference)
{
if (!objectLocationProvider.TryGetOffset(reference, out var offset))
{
throw new InvalidOperationException($"Could not find the object with reference: {reference}.");
}
Seek(offset);
if (!MoveNext())
{
throw new InvalidOperationException($"Could not parse the object with reference: {reference}.");
}
return (ObjectToken)CurrentToken;
}
}
}