mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-14 19:05:01 +08:00
add a more complicated type 2 font pdf and tests
This commit is contained in:
Binary file not shown.
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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>
|
||||
|
@@ -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)
|
||||
{
|
||||
|
32
src/UglyToad.Pdf/Parser/Parts/DirectObjectFinder.cs
Normal file
32
src/UglyToad.Pdf/Parser/Parts/DirectObjectFinder.cs
Normal 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}.");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user