mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
start adding support for reading and applying XObjects
This commit is contained in:
@@ -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]
|
[Fact]
|
||||||
public void HasCorrectNumberOfPages()
|
public void HasCorrectNumberOfPages()
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,21 @@
|
|||||||
|
|
||||||
LoadFontDictionary(fontDictionary, isLenientParsing);
|
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)
|
private void LoadFontDictionary(DictionaryToken fontDictionary, bool isLenientParsing)
|
||||||
|
@@ -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}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -163,7 +163,11 @@ namespace UglyToad.PdfPig.Graphics
|
|||||||
{
|
{
|
||||||
if (operands[offset] is NameToken name)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user