mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-21 04:17:57 +08:00
#55 move support for images to page and add inline images
support both xobject and inline images. adds unsupported filters so that exceptions are only thrown when accessing lazily evaluated image.bytes property rather than when opening the page. treat all warnings as errors.
This commit is contained in:
@@ -44,7 +44,11 @@
|
||||
}
|
||||
else if (operationType == typeof(EndInlineImage))
|
||||
{
|
||||
operation = new EndInlineImage(new List<IToken>(), new List<byte>());
|
||||
operation = new EndInlineImage(new List<byte>());
|
||||
}
|
||||
else if (operationType == typeof(BeginInlineImageData))
|
||||
{
|
||||
operation = new BeginInlineImageData(new Dictionary<NameToken, IToken>());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -77,5 +77,17 @@
|
||||
public void SetNamedGraphicsState(NameToken stateName)
|
||||
{
|
||||
}
|
||||
|
||||
public void BeginInlineImage()
|
||||
{
|
||||
}
|
||||
|
||||
public void SetInlineImageProperties(IReadOnlyDictionary<NameToken, IToken> properties)
|
||||
{
|
||||
}
|
||||
|
||||
public void EndInlineImage(IReadOnlyList<byte> bytes)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,33 +0,0 @@
|
||||
namespace UglyToad.PdfPig.Tests.Graphics
|
||||
{
|
||||
using Content;
|
||||
using PdfPig.Fonts;
|
||||
using PdfPig.Tokens;
|
||||
|
||||
internal class TestResourceStore : IResourceStore
|
||||
{
|
||||
public void LoadResourceDictionary(DictionaryToken dictionary, bool isLenientParsing)
|
||||
{
|
||||
}
|
||||
|
||||
public IFont GetFont(NameToken name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public StreamToken GetXObject(NameToken name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public DictionaryToken GetExtendedGraphicsStateDictionary(NameToken name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IFont GetFontDirectly(IndirectReferenceToken fontReferenceToken, bool isLenientParsing)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -81,14 +81,14 @@
|
||||
{
|
||||
var page = document.GetPage(i + 1);
|
||||
|
||||
var images = page.ExperimentalAccess.GetRawImages();
|
||||
var images = page.GetImages();
|
||||
|
||||
Assert.NotNull(images);
|
||||
|
||||
foreach (var image in images)
|
||||
{
|
||||
Assert.True(image.Width > 0, $"Image had width of zero on page {i + 1}.");
|
||||
Assert.True(image.Height > 0, $"Image had height of zero on page {i + 1}.");
|
||||
Assert.True(image.WidthInSamples > 0, $"Image had width of zero on page {i + 1}.");
|
||||
Assert.True(image.HeightInSamples > 0, $"Image had height of zero on page {i + 1}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
var images = page.ExperimentalAccess.GetRawImages().ToList();
|
||||
var images = page.GetImages().ToList();
|
||||
Assert.Single(images);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,87 @@
|
||||
namespace UglyToad.PdfPig.Tests.Integration
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
public class SinglePageLibreOfficeImages
|
||||
{
|
||||
private static string GetFilePath() => IntegrationHelpers.GetDocumentPath(@"Single Page Images - from libre office.pdf");
|
||||
|
||||
[Fact]
|
||||
public void Has3Images()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
var images = page.GetImages().ToList();
|
||||
|
||||
Assert.Equal(3, images.Count);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ImagesHaveCorrectDimensionsAndLocations()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
var images = page.GetImages().OrderBy(x => x.Bounds.Width).ToList();
|
||||
|
||||
var pdfPigSquare = images[0];
|
||||
|
||||
Assert.Equal(148.3m, pdfPigSquare.Bounds.Width);
|
||||
Assert.Equal(148.3m, pdfPigSquare.Bounds.Height);
|
||||
Assert.Equal(60.1m, pdfPigSquare.Bounds.Left);
|
||||
Assert.Equal(765.8m, pdfPigSquare.Bounds.Top);
|
||||
|
||||
var pdfPigSquished = images[1];
|
||||
|
||||
Assert.Equal(206.8m, pdfPigSquished.Bounds.Width);
|
||||
Assert.Equal(83.2m, pdfPigSquished.Bounds.Height);
|
||||
Assert.Equal(309.8m, pdfPigSquished.Bounds.Left);
|
||||
Assert.Equal(552.1m, pdfPigSquished.Bounds.Top);
|
||||
|
||||
var birthdayPigs = images[2];
|
||||
|
||||
Assert.Equal(391m, birthdayPigs.Bounds.Width);
|
||||
Assert.Equal(267.1m, birthdayPigs.Bounds.Height);
|
||||
Assert.Equal(102.2m, birthdayPigs.Bounds.Left);
|
||||
Assert.Equal(426.3m, birthdayPigs.Bounds.Top);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasCorrectText()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
Assert.Equal("Oink oink", page.Text);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanAccessImageBytesExceptUnsupported()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilePath(), ParsingOptions.LenientParsingOff))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
foreach (var image in page.GetImages())
|
||||
{
|
||||
try
|
||||
{
|
||||
Assert.NotNull(image.Bytes);
|
||||
}
|
||||
catch (NotSupportedException )
|
||||
{
|
||||
// Should allow access to raw bytes.
|
||||
Assert.NotNull(image.RawBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -53,6 +53,8 @@
|
||||
"UglyToad.PdfPig.Annotations.AnnotationType",
|
||||
"UglyToad.PdfPig.Content.Catalog",
|
||||
"UglyToad.PdfPig.Content.DocumentInformation",
|
||||
"UglyToad.PdfPig.Content.InlineImage",
|
||||
"UglyToad.PdfPig.Content.IPdfImage",
|
||||
"UglyToad.PdfPig.Content.Letter",
|
||||
"UglyToad.PdfPig.Content.Page",
|
||||
"UglyToad.PdfPig.Content.PageRotationDegrees",
|
||||
|
@@ -11,6 +11,11 @@
|
||||
return new List<IFilter>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<IFilter> GetNamedFilters(IReadOnlyList<NameToken> names)
|
||||
{
|
||||
return new List<IFilter>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<IFilter> GetAllFilters()
|
||||
{
|
||||
return new List<IFilter>();
|
||||
|
@@ -42,5 +42,9 @@ namespace UglyToad.PdfPig.Tests.Tokens
|
||||
{
|
||||
return Objects[reference];
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user