Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Started using the official System.Drawing.Common assembly instead o…
Browse files Browse the repository at this point in the history
…f `CoreCompat.System.Drawing.v2`.
  • Loading branch information
VahidN committed Nov 28, 2017
1 parent 4428ad1 commit 99af3ef
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 67 deletions.
55 changes: 0 additions & 55 deletions src/EPPlus.Core/CoreFx/ColorTranslator.cs

This file was deleted.

85 changes: 85 additions & 0 deletions src/EPPlus.Core/CoreFx/ImageConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#if NETSTANDARD2_0

using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Drawing;

namespace OfficeOpenXml
{
/// <summary>
/// Summary description for ImageConverter.
/// </summary>
public class ImageConverter : TypeConverter
{
public ImageConverter()
{
}

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(System.Byte[]))
return true;
else
return false;
}

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if ((destinationType == typeof(System.Byte[])) || (destinationType == typeof(System.String)))
return true;
else
return false;
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
byte[] bytes = value as byte[];
if (bytes == null)
return base.ConvertFrom(context, culture, value);

MemoryStream ms = new MemoryStream(bytes);

return Image.FromStream(ms);
}

public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value == null)
return "(none)";

if (value is System.Drawing.Image)
{
if (destinationType == typeof(string))
{
return value.ToString();
}
else if (CanConvertTo(null, destinationType))
{
//came here means destinationType is byte array ;
using (MemoryStream ms = new MemoryStream())
{
((Image)value).Save(ms, ((Image)value).RawFormat);
return ms.ToArray();
}
}
}

string msg = string.Format("ImageConverter can not convert from type '{0}'.", value.GetType());
throw new NotSupportedException(msg);
}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
return TypeDescriptor.GetProperties(typeof(Image), attributes);
}

public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}

#endif
4 changes: 2 additions & 2 deletions src/EPPlus.Core/EPPlus.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>EPPlus.Core is an unofficial port of the EPPlus library to .NET Core.</Description>
<VersionPrefix>1.5.2</VersionPrefix>
<VersionPrefix>1.5.3</VersionPrefix>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>net40;net45;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);1591</NoWarn>
Expand Down Expand Up @@ -80,7 +80,7 @@
<DefineConstants>COREFX;NO_SFX</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="CoreCompat.System.Drawing.v2" Version="5.2.0-preview1-r131" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0-preview1-25914-04" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Reflection" Version="4.3.0" />
Expand Down
20 changes: 10 additions & 10 deletions src/EPPlus.Core/Packaging/DotNetZip/Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ namespace OfficeOpenXml.Packaging.Ionic.Zip
/// </summary>
internal static class SharedUtilities
{
#if NETSTANDARD2_0 || COREFX
#if NETSTANDARD2_0 || COREFX
static SharedUtilities()
{
// Adds missing code pages
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
}
#endif
#endif
/// private null constructor
//private SharedUtilities() { }

Expand Down Expand Up @@ -156,8 +156,8 @@ public static string NormalizePathForUseInZipFile(string pathName)
if (String.IsNullOrEmpty(pathName)) return pathName;

// trim volume if necessary
if ((pathName.Length >= 2) && ((pathName[1] == ':') && (pathName[2] == '\\')))
pathName = pathName.Substring(3);
if ((pathName.Length >= 2) && ((pathName[1] == ':') && (pathName[2] == '\\')))
pathName = pathName.Substring(3);

// swap slashes
pathName = pathName.Replace('\\', '/');
Expand Down Expand Up @@ -435,11 +435,11 @@ internal static DateTime PackedToDateTime(Int32 packedDateTime)
if (hour >= 24) { day++; hour = 0; }

DateTime d = System.DateTime.Now;
bool success= false;
bool success = false;
try
{
d = new System.DateTime(year, month, day, hour, minute, second, 0);
success= true;
success = true;
}
catch (System.ArgumentOutOfRangeException)
{
Expand All @@ -448,14 +448,14 @@ internal static DateTime PackedToDateTime(Int32 packedDateTime)
try
{
d = new System.DateTime(1980, 1, 1, hour, minute, second, 0);
success= true;
success = true;
}
catch (System.ArgumentOutOfRangeException)
{
try
{
d = new System.DateTime(1980, 1, 1, 0, 0, 0, 0);
success= true;
success = true;
}
catch (System.ArgumentOutOfRangeException) { }

Expand All @@ -479,7 +479,7 @@ internal static DateTime PackedToDateTime(Int32 packedDateTime)
while (second < 0) second++;
while (second > 59) second--;
d = new System.DateTime(year, month, day, hour, minute, second, 0);
success= true;
success = true;
}
catch (System.ArgumentOutOfRangeException) { }
}
Expand Down Expand Up @@ -612,7 +612,7 @@ internal static int ReadWithRetry(System.IO.Stream s, byte[] buffer, int offset,
n = s.Read(buffer, offset, count);
done = true;
}
#if NETCF || SILVERLIGHT || COREFX
#if NETCF || SILVERLIGHT || COREFX || NETSTANDARD2_0
catch (System.IO.IOException)
{
throw;
Expand Down
2 changes: 2 additions & 0 deletions src/EPPlus.Core/_0-restore.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet restore
pause
2 changes: 2 additions & 0 deletions src/EPPlus.Core/_1-dotnet_pack.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet pack -c release
paue

0 comments on commit 99af3ef

Please sign in to comment.