Skip to content

Commit

Permalink
Merge branch 'release-7.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bovender committed Jul 11, 2016
2 parents 495bf1f + 6d16364 commit eea0f42
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.0.0.27")]
[assembly: AssemblyFileVersion("7.0.0.27")]
[assembly: AssemblyVersion("7.0.1.0")]
[assembly: AssemblyFileVersion("7.0.1.0")]
8 changes: 4 additions & 4 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug %28Bovender via NuGet%29'">
<Reference Include="Bovender, Version=0.11.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.11.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.11.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.11.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Reference Include="Bovender, Version=0.11.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.11.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.11.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.11.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
limitations under the License.
-->
<packages>
<package id="Bovender" version="0.11.0.0" targetFramework="net40" />
<package id="Bovender" version="0.11.1.0" targetFramework="net40" />
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
<package id="NLog" version="4.3.3" targetFramework="net40" />
<package id="NUnitTestAdapter" version="2.0.0" targetFramework="net40" />
Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
7.0.0
7.0.0.27
7.0.1
7.0.1.0
1 change: 1 addition & 0 deletions XLToolbox/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ static void ExportScreenshot()
{
vm.ChooseFileNameMessage.Sent += (sender, args) =>
{
Logger.Info("Choose file name message was received");
ChooseFileSaveAction a = new ChooseFileSaveAction();
a.Invoke(args);
};
Expand Down
197 changes: 197 additions & 0 deletions XLToolbox/Export/DibBitmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
using FreeImageAPI;
/* DibBitmap.cs
* part of Daniel's XL Toolbox NG
*
* Copyright 2014-2016 Daniel Kraus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace XLToolbox.Export
{
/// <summary>
/// Provides access to a System.Drawing.Bitmap that is created
/// from a DIB.
/// </summary>
/// <remarks>
/// Inspired by:
/// <list type="unordered">
/// <item>http://hecgeek.blogspot.de/2007/04/converting-from-dib-to.html</item>
/// <item>http://stackoverflow.com/questions/1054009/how-can-i-pass-memorystream-data-to-unmanaged-c-dll-using-p-invoke</item>
/// <item>http://snipplr.com/view/36593.44712/</item>
/// </list>
/// </remarks>
public class DibBitmap : IDisposable
{
#region Public properties

public Bitmap Bitmap
{
get
{
if (_bitmap == null)
{
_bitmap = new Bitmap(
Width, Height,
Width * 4,
// (Width * 24 + (32-1)) / 32 * 4,
PixelFormat.Format32bppRgb,
Scan0);
}
return _bitmap;
}
}

public int Width
{
get
{
return DibHeader.biWidth;
}
}

public int Height
{
get
{
return DibHeader.biHeight;
}
}

#endregion

#region Constructor

public DibBitmap(Stream dibStream)
{
if (dibStream == null)
{
throw new ArgumentNullException("dibStream", "Stream with DIB data is required");
}
_stream = dibStream;
}

#endregion

#region Dispose

~DibBitmap()
{
Dispose(false);
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected void Dispose(bool calledFromDispose)
{
if (!_disposed)
{
_disposed = true;
if (calledFromDispose)
{
if (_handle != null && _handle.IsAllocated)
{
_handle.Free();
}
if (_bitmap != null)
{
_bitmap.Dispose();
}
_stream.Dispose();
}
}
}

#endregion

#region Private properties

private byte[] DibBytes
{
get
{
if (_bytes == null)
{
_bytes = new byte[_stream.Length];
_stream.Read(_bytes, 0, Convert.ToInt32(_stream.Length));
}
return _bytes;
}
}

private GCHandle DibHandle
{
get
{
if (_handle == null || !_handle.IsAllocated)
{
_handle = GCHandle.Alloc(DibBytes, GCHandleType.Pinned);
}
return _handle;
}
}

private IntPtr Scan0
{
get
{
if (_scan0 == IntPtr.Zero)
{
IntPtr handlePtr = DibHandle.AddrOfPinnedObject();
_scan0 = new IntPtr(handlePtr.ToInt32() + 40);
}
return _scan0;
}
}

private BITMAPINFOHEADER DibHeader
{
get
{
if (!_headerInitialized)
{
_headerInitialized = true;
_dibHeader = (BITMAPINFOHEADER)Marshal.PtrToStructure(DibHandle.AddrOfPinnedObject(), _dibHeader.GetType());
}
return _dibHeader;
}
}

#endregion

#region Private fields

private bool _disposed;
private Bitmap _bitmap;
private Stream _stream;
private byte[] _bytes;
private IntPtr _scan0;
private BITMAPINFOHEADER _dibHeader;
private bool _headerInitialized;
private GCHandle _handle;

#endregion
}
}
62 changes: 54 additions & 8 deletions XLToolbox/Export/ScreenshotExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
using FreeImageAPI;
using XLToolbox.Excel.ViewModels;
using XLToolbox.Unmanaged;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace XLToolbox.Export
{
Expand All @@ -36,20 +38,64 @@ public class ScreenshotExporter

public void ExportSelection(string fileName)
{
Logger.Info("ExportSelection");
FreeImageBitmap fi;
if (Instance.Default.Application.Selection is Microsoft.Office.Interop.Excel.Range)
{
Logger.Info("ExportSelection: Exporting via DIB");
fi = CreateFreeImageViaDIB();
}
else
{
Logger.Info("ExportSelection: Exporting directly");
fi = CreateFreeImageDirectly();
}

Logger.Info("ExportSelection: Save to file");
fi.SetResolution(102.42f, 102.42f);
fi.Save(fileName,
FREE_IMAGE_FORMAT.FIF_PNG,
FREE_IMAGE_SAVE_FLAGS.PNG_Z_BEST_COMPRESSION | FREE_IMAGE_SAVE_FLAGS.PNG_INTERLACED);
}

#endregion

#region Private methods

private FreeImageBitmap CreateFreeImageDirectly()
{
FreeImageBitmap fi;
using (DllManager dllManager = new DllManager())
{
dllManager.LoadDll("FreeImage.DLL");
Instance.Default.Application.Selection.Copy();
MemoryStream data = Clipboard.GetData("PNG") as MemoryStream;
Logger.Info("Create FreeImage bitmap");
FreeImageBitmap fi = FreeImageBitmap.FromStream(data);
fi.SetResolution(102.42f, 102.42f);
Logger.Info("Save to file");
fi.Save(fileName,
FREE_IMAGE_FORMAT.FIF_PNG,
FREE_IMAGE_SAVE_FLAGS.PNG_Z_BEST_COMPRESSION);
Logger.Info("CreateFreeImageDirectly: Create FreeImage bitmap");
fi = FreeImageBitmap.FromStream(data);
}
return fi;
}

private FreeImageBitmap CreateFreeImageViaDIB()
{
FreeImageBitmap fi;
using (DllManager dllManager = new DllManager())
{
dllManager.LoadDll("FreeImage.DLL");
Logger.Info("CreateFreeImageViaDIB: Copy to clipboard and get data from it");
Instance.Default.Application.Selection.Copy();
MemoryStream stream = Clipboard.GetData(System.Windows.DataFormats.Dib) as MemoryStream;
using (DibBitmap dibBitmap = new DibBitmap(stream))
{
Logger.Info("CreateFreeImageViaDIB: Create FreeImage bitmap");
fi = new FreeImageBitmap(dibBitmap.Bitmap);
bool convertType = fi.ConvertType(FREE_IMAGE_TYPE.FIT_BITMAP, true);
Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertType returned {0}", convertType);
bool convertColorDepth = fi.ConvertColorDepth(FREE_IMAGE_COLOR_DEPTH.FICD_24_BPP); // won't work with 32 bpp!
Logger.Debug("CreateFreeImageViaDIB: FreeImageBitmap.ConvertColorDepth returned {0}", convertColorDepth);
fi.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
}
}
return fi;
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion XLToolbox/Export/ViewModels/ScreenshotExporterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void DoExportSelection(FileNameMessageContent messageContent)
private bool CanExportSelection()
{
Xl.Application app = Excel.ViewModels.Instance.Default.Application;
return !(app == null || app.Selection is Xl.Range);
return !(app == null || app.Selection == null);
}

#endregion
Expand Down
Binary file modified XLToolbox/Legacy/XLToolboxLegacyAddin.xlam
Binary file not shown.
4 changes: 2 additions & 2 deletions XLToolbox/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.0.0.27")]
[assembly: AssemblyFileVersion("7.0.0.27")]
[assembly: AssemblyVersion("7.0.1.0")]
[assembly: AssemblyFileVersion("7.0.1.0")]
9 changes: 5 additions & 4 deletions XLToolbox/XLToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug %28Bovender via NuGet%29|AnyCPU'">
<Reference Include="Bovender, Version=0.11.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.11.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.11.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.11.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Reference Include="Bovender, Version=0.11.0.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<Reference Include="Bovender, Version=0.11.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Bovender.0.11.0.0\lib\net40\Bovender.dll</HintPath>
<HintPath>..\packages\Bovender.0.11.1.0\lib\net40\Bovender.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -137,6 +137,7 @@
</Compile>
<Compile Include="ExceptionHandler\TestException.cs" />
<Compile Include="Export\BatchExporter.cs" />
<Compile Include="Export\DibBitmap.cs" />
<Compile Include="Export\Lcms\ColorSpaceSignature.cs" />
<Compile Include="Export\Lcms\FileExtension.cs" />
<Compile Include="Export\Lcms\Formatters.cs" />
Expand Down
2 changes: 1 addition & 1 deletion XLToolbox/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
limitations under the License.
-->
<packages>
<package id="Bovender" version="0.11.0.0" targetFramework="net40" />
<package id="Bovender" version="0.11.1.0" targetFramework="net40" />
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
<package id="NLog" version="4.3.3" targetFramework="net40" />
<package id="NUnit" version="2.6.4" targetFramework="net40" />
Expand Down
4 changes: 2 additions & 2 deletions XLToolboxForExcel/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.0.0.27")]
[assembly: AssemblyFileVersion("7.0.0.27")]
[assembly: AssemblyVersion("7.0.1.0")]
[assembly: AssemblyFileVersion("7.0.1.0")]

[assembly: NeutralResourcesLanguageAttribute("en-US")]
Loading

0 comments on commit eea0f42

Please sign in to comment.