diff --git a/Source/QuestPDF.Examples/ImageExamples.cs b/Source/QuestPDF.Examples/ImageExamples.cs index a44791a..363777c 100644 --- a/Source/QuestPDF.Examples/ImageExamples.cs +++ b/Source/QuestPDF.Examples/ImageExamples.cs @@ -5,6 +5,7 @@ using QuestPDF.Drawing.Exceptions; using QuestPDF.Examples.Engine; using QuestPDF.Fluent; using QuestPDF.Helpers; +using QuestPDF.Infrastructure; namespace QuestPDF.Examples { @@ -67,6 +68,46 @@ namespace QuestPDF.Examples }); }); } + + [Test] + public void DpiSetting() + { + RenderingTest + .Create() + .PageSize(400, 600) + .ProduceImages() + .ShowResults() + .Render(page => + { + page.Padding(10).Column(column => + { + column.Spacing(10); + + column.Item().Image("photo.jpg").WithRasterDpi(16); + column.Item().Image("photo.jpg").WithRasterDpi(72); + }); + }); + } + + [Test] + public void CompressionSetting() + { + RenderingTest + .Create() + .PageSize(400, 600) + .ProduceImages() + .ShowResults() + .Render(page => + { + page.Padding(10).Column(column => + { + column.Spacing(10); + + column.Item().Image("photo.jpg").WithCompressionQuality(ImageCompressionQuality.VeryLow); + column.Item().Image("photo.jpg").WithCompressionQuality(ImageCompressionQuality.High); + }); + }); + } [Test] public void Exception() diff --git a/Source/QuestPDF.Examples/QuestPDF.Examples.csproj b/Source/QuestPDF.Examples/QuestPDF.Examples.csproj index 56e2ce5..5f07fa7 100644 --- a/Source/QuestPDF.Examples/QuestPDF.Examples.csproj +++ b/Source/QuestPDF.Examples/QuestPDF.Examples.csproj @@ -35,6 +35,9 @@ PreserveNewest + + PreserveNewest + diff --git a/Source/QuestPDF.Examples/photo.jpg b/Source/QuestPDF.Examples/photo.jpg new file mode 100644 index 0000000..8691c99 Binary files /dev/null and b/Source/QuestPDF.Examples/photo.jpg differ diff --git a/Source/QuestPDF.UnitTests/ImageTests.cs b/Source/QuestPDF.UnitTests/ImageTests.cs index 5e1e700..d50902a 100644 --- a/Source/QuestPDF.UnitTests/ImageTests.cs +++ b/Source/QuestPDF.UnitTests/ImageTests.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Net.Mime; using FluentAssertions; @@ -62,19 +63,19 @@ namespace QuestPDF.UnitTests [Test] public void UsingSharedImageShouldNotDrasticallyIncreaseDocumentSize() { - var placeholderImage = Placeholders.Image(1000, 200); + var photo = File.ReadAllBytes("Resources/photo.jpg"); var documentWithSingleImageSize = GetDocumentSize(container => { - container.Image(placeholderImage); + container.Image(photo); }); var documentWithMultipleImagesSize = GetDocumentSize(container => { container.Column(column => { - foreach (var i in Enumerable.Range(0, 100)) - column.Item().Image(placeholderImage); + foreach (var i in Enumerable.Range(0, 10)) + column.Item().Image(photo); }); }); @@ -82,25 +83,17 @@ namespace QuestPDF.UnitTests { container.Column(column => { - var sharedImage = DocumentImage.FromBinaryData(placeholderImage).DisposeAfterDocumentGeneration(); + var sharedImage = DocumentImage.FromBinaryData(photo).DisposeAfterDocumentGeneration(); - foreach (var i in Enumerable.Range(0, 100)) + foreach (var i in Enumerable.Range(0, 10)) column.Item().Image(sharedImage); }); }); - (documentWithMultipleImagesSize / (float)documentWithSingleImageSize).Should().BeInRange(90, 100); - (documentWithSingleImageUsedMultipleTimesSize / (float)documentWithSingleImageSize).Should().BeInRange(1f, 1.5f); + (documentWithMultipleImagesSize / (float)documentWithSingleImageSize).Should().BeInRange(9.9f, 10); + (documentWithSingleImageUsedMultipleTimesSize / (float)documentWithSingleImageSize).Should().BeInRange(1f, 1.05f); } - - [Test] - public void ImageShouldNotBeScaledAboveItsNativeResolution() - { - var image = Placeholders.Image(200, 200); - // TODO - } - private static int GetDocumentSize(Action container) { return Document diff --git a/Source/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj b/Source/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj index 622e661..5d2d747 100644 --- a/Source/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj +++ b/Source/QuestPDF.UnitTests/QuestPDF.UnitTests.csproj @@ -27,4 +27,10 @@ + + + PreserveNewest + + + diff --git a/Source/QuestPDF.UnitTests/Resources/photo.jpg b/Source/QuestPDF.UnitTests/Resources/photo.jpg new file mode 100644 index 0000000..8691c99 Binary files /dev/null and b/Source/QuestPDF.UnitTests/Resources/photo.jpg differ