Skip to content

Commit

Permalink
Merge pull request ststeiger#1 from startnow65/master
Browse files Browse the repository at this point in the history
Updates to Support Static Image Class from ImageSharp - Thanks & sorry, didn't see it until now.
  • Loading branch information
ststeiger authored Sep 27, 2017
2 parents 8ea343d + ca516ee commit ed9b8a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
25 changes: 13 additions & 12 deletions PdfSharpCore.ImageSharp/ImageSharpImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,44 @@
using MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes;
using static MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes.ImageSource;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;

namespace PdfSharpCore.ImageSharp
{
public class ImageSharpImageSource : ImageSource
public class ImageSharpImageSource<TPixel> : ImageSource where TPixel : struct, IPixel<TPixel>
{
protected override IImageSource FromBinaryImpl(string name, Func<byte[]> imageSource, int? quality = 75)
{
return new ImageSharpImageSourceImpl(name, () =>
return new ImageSharpImageSourceImpl<TPixel>(name, () =>
{
return new Image(imageSource.Invoke());
return Image.Load<TPixel>(imageSource.Invoke());
}, (int)quality);
}

protected override IImageSource FromFileImpl(string path, int? quality = 75)
{
return new ImageSharpImageSourceImpl(path, () =>
return new ImageSharpImageSourceImpl<TPixel>(path, () =>
{
return new Image(path);
return Image.Load<TPixel>(path);
}, (int)quality);
}

protected override IImageSource FromStreamImpl(string name, Func<Stream> imageStream, int? quality = 75)
{
return new ImageSharpImageSourceImpl(name, () =>
return new ImageSharpImageSourceImpl<TPixel>(name, () =>
{
using (var stream = imageStream.Invoke())
{
return new Image(stream);
return Image.Load<TPixel>(stream);
}
}, (int)quality);
}

private class ImageSharpImageSourceImpl : IImageSource
private class ImageSharpImageSourceImpl<TPixel2> : IImageSource where TPixel2 : struct, IPixel<TPixel2>
{

private Image _image;
private Image Image
private Image<TPixel2> _image;
private Image<TPixel2> Image
{
get
{
Expand All @@ -53,14 +54,14 @@ private Image Image
return _image;
}
}
private Func<Image> _getImage;
private Func<Image<TPixel2>> _getImage;
private readonly int _quality;

public int Width => Image.Width;
public int Height => Image.Height;
public string Name { get; }

public ImageSharpImageSourceImpl(string name, Func<Image> getImage, int quality)
public ImageSharpImageSourceImpl(string name, Func<Image<TPixel2>> getImage, int quality)
{
Name = name;
_getImage = getImage;
Expand Down
13 changes: 13 additions & 0 deletions PdfSharpCore/PdfSharpCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Stefan Steiger and Contributors</Authors>
<Description>PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Standard Additionally MigraDoc has been ported as well (from version 1.32). Images have been implemented with ImageSharp, which is still in Alpha. They State on their readme that it is still in Alpha status and shouldn't be used in productive environments. Since I didn't find any good alternatives it's still used.

ImageSharp beeing Alpha isn't a big issure either since this code isn't by far done yet. So please chime in ;)

PdfSharp.Xamarin is a partial port of PdfSharp for iOS and Android using Xamarin, it allows for creation and modification of PDF files.</Description>
<Copyright>Copyright (c) 2005-2007 empira Software GmbH, Cologne (Germany)</Copyright>
<PackageLicenseUrl>https://github.com/ststeiger/PdfSharpCore</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ststeiger/PdfSharpCore</PackageProjectUrl>
<RepositoryUrl>https://github.com/ststeiger/PdfSharpCore</RepositoryUrl>
<PackageReleaseNotes>PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Standard Additionally MigraDoc has been ported as well (from version 1.32)</PackageReleaseNotes>
<PackageTags>NuggetV1.0.0 (8ea343d5898342a563b9d4df2d67e27aaea9ac01)</PackageTags>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
3 changes: 2 additions & 1 deletion Stammbaum/Pdf/OldProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using ImageSharp;
using PdfSharpCore;
using PdfSharpCore.Pdf;

Expand All @@ -21,7 +22,7 @@ static void OldSimpleMain(string[] args)
PdfSharpCore.Fonts.GlobalFontSettings.FontResolver = new FontResolver();

MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
.ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource();
.ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource<Rgba32>();


using (PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument())
Expand Down
8 changes: 4 additions & 4 deletions Stammbaum/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using System.Linq;
using Stammbaum.DataStructures;

using ImageSharp;

namespace Stammbaum
{
Expand Down Expand Up @@ -119,7 +119,7 @@ static void Main(string[] args)
PdfSharpCore.Fonts.GlobalFontSettings.FontResolver = new FontResolver();

MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
.ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource();
.ImageSource.ImageSourceImpl = new PdfSharpCore.ImageSharp.ImageSharpImageSource<Rgba32>();


using (PdfSharpCore.Pdf.PdfDocument document = new PdfSharpCore.Pdf.PdfDocument())
Expand Down Expand Up @@ -231,7 +231,7 @@ from itemList in ti.ls[generationNumber]
where itemList.Id == dp1.Person.Child
select itemList
).FirstOrDefault(),
rect = new Rectangle(xNew, yNew, rect1.Width, rect1.Height)
rect = new DataStructures.Rectangle(xNew, yNew, rect1.Width, rect1.Height)
};

}
Expand Down Expand Up @@ -259,7 +259,7 @@ select itemList
dict[generationNumber][i] = new DataPoint()
{
Person = ti.ls[generationNumber][i],
rect = new Rectangle(rectX, rectY, textBoxWidth, textBoxHeight)
rect = new DataStructures.Rectangle(rectX, rectY, textBoxWidth, textBoxHeight)
};

}
Expand Down

0 comments on commit ed9b8a4

Please sign in to comment.