add a more complicated type 2 font pdf and tests

This commit is contained in:
Eliot Jones
2018-01-04 21:25:49 +00:00
parent 6b4bd8689f
commit 2e7f9b8d76
5 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
namespace UglyToad.Pdf.Tests.Integration
{
using System;
using System.IO;
using Xunit;
public class MultiplePageMortalityStatistics
{
private static string GetFilename()
{
var documentFolder = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "Integration", "Documents"));
return Path.Combine(documentFolder, "Multiple Page - from Mortality Statistics.pdf");
}
[Fact]
public void HasCorrectNumberOfPages()
{
var file = GetFilename();
using (var document = PdfDocument.Open(File.ReadAllBytes(file)))
{
Assert.Equal(6, document.NumberOfPages);
}
}
[Fact]
public void HasCorrectVersion()
{
using (var document = PdfDocument.Open(GetFilename()))
{
Assert.Equal(1.7m, document.Version);
}
}
}
}

View File

@@ -12,6 +12,7 @@
<None Remove="Fonts\TrueType\Roboto-Regular.ttf" />
<None Remove="Integration\Documents\Font Size Test - from google chrome print pdf.pdf" />
<None Remove="Integration\Documents\Font Size Test - from libre office.pdf" />
<None Remove="Integration\Documents\Multiple Page - from Mortality Statistics.pdf" />
<None Remove="Integration\Documents\Single Page Form Content - from itext 1_1.pdf" />
<None Remove="Integration\Documents\Single Page Non Latin - from acrobat distiller.pdf" />
<None Remove="Integration\Documents\Single Page Simple - from google drive.pdf" />
@@ -32,6 +33,9 @@
<Content Include="Integration\Documents\Font Size Test - from google chrome print pdf.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Integration\Documents\Multiple Page - from Mortality Statistics.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Integration\Documents\Single Page Non Latin - from acrobat distiller.pdf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -11,6 +11,7 @@
using IO;
using Parts;
using Pdf.Parser;
using Pdf.Parser.Parts;
internal class Type0FontHandler : IFontHandler
{
@@ -37,7 +38,7 @@
if (TryGetFirstDescendant(dictionary, out var descendantObject))
{
var parsed = pdfObjectParser.Parse(descendantObject.ToIndirectReference(), reader, isLenientParsing);
var parsed = DirectObjectFinder.Find<PdfDictionary>(descendantObject, pdfObjectParser, reader, isLenientParsing);
if (parsed is PdfDictionary descendantFontDictionary)
{

View File

@@ -0,0 +1,32 @@
namespace UglyToad.Pdf.Parser.Parts
{
using System;
using Cos;
using IO;
internal static class DirectObjectFinder
{
public static CosBase Find<T>(CosObject baseObject, IPdfObjectParser parser, IRandomAccessRead reader,
bool isLenientParsing) where T : CosBase
{
var result = parser.Parse(baseObject.ToIndirectReference(), reader, isLenientParsing);
if (result is T resultT)
{
return resultT;
}
if (result is CosObject obj)
{
return Find<T>(obj, parser, reader, isLenientParsing);
}
if (result is COSArray arr && arr.Count == 1 && arr.get(0) is CosObject arrayObject)
{
return Find<T>(arrayObject, parser, reader, isLenientParsing);
}
throw new InvalidOperationException($"Could not find the object {baseObject.ToIndirectReference()} with type {typeof(T).Name}.");
}
}
}