start adding support for reading and applying XObjects

This commit is contained in:
Eliot Jones
2018-04-21 16:24:37 +01:00
parent 787bcd1cd2
commit b6585292fb
4 changed files with 60 additions and 1 deletions

View File

@@ -24,6 +24,18 @@
}
}
[Fact]
public void CanReadPage9()
{
using (var document = PdfDocument.Open(GetFilename()))
{
var page = document.GetPage(9);
// TODO: This page requires a CFF font parser for Type 1 fonts, see 5.5.1
Assert.Contains("BreedsNative breeds of pig can be found throughout the country. They are a small body size compared to other exotic and crosses pig types. There name varies from region to region, for example", page.Text);
}
}
[Fact]
public void HasCorrectNumberOfPages()
{

View File

@@ -30,6 +30,21 @@
LoadFontDictionary(fontDictionary, isLenientParsing);
}
if (resourceDictionary.TryGet(NameToken.Xobject, out var xobjectBase))
{
var xobjectDictionary = DirectObjectFinder.Get<DictionaryToken>(xobjectBase, scanner);
foreach (var pair in xobjectDictionary.Data)
{
if (!(pair.Value is IndirectReferenceToken reference))
{
throw new InvalidOperationException($"Expected the XObject dictionary value for key /{pair.Key} to be an indirect reference, instead got: {pair.Value}.");
}
currentResourceState[NameToken.Create(pair.Key)] = reference.Data;
}
}
}
private void LoadFontDictionary(DictionaryToken fontDictionary, bool isLenientParsing)

View File

@@ -0,0 +1,28 @@
namespace UglyToad.PdfPig.Graphics.Operations
{
using Content;
using Tokenization.Tokens;
internal class InvokeNamedXObject : IGraphicsStateOperation
{
public const string Symbol = "Do";
public string Operator => Symbol;
public NameToken Name { get; }
public InvokeNamedXObject(NameToken name)
{
Name = name;
}
public void Run(IOperationContext operationContext, IResourceStore resourceStore)
{
}
public override string ToString()
{
return $"{Name} {Symbol}";
}
}
}

View File

@@ -163,7 +163,11 @@ namespace UglyToad.PdfPig.Graphics
{
if (operands[offset] is NameToken name)
{
arguments.Add(name.Data);
arguments.Add(name);
}
else if (operands[offset] is StringToken s)
{
arguments.Add(NameToken.Create(s.Data));
}
else
{