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

@@ -23,18 +23,24 @@
public ObjectLocationProvider(CrossReferenceTable crossReferenceTable, CosObjectPool pool, BruteForceSearcher searcher)
{
this.crossReferenceTable = crossReferenceTable;
foreach (var offset in crossReferenceTable.ObjectOffsets)
{
offsets[offset.Key] = offset.Value;
}
this.pool = pool;
this.searcher = searcher;
}
public bool TryGetOffset(IndirectReference reference, out long offset)
{
throw new System.NotImplementedException();
return offsets.TryGetValue(reference, out offset);
}
public void UpdateOffset(IndirectReference reference, long offset)
{
throw new System.NotImplementedException();
offsets[reference] = offset;
}
}
}

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;
}
}
}