Removed ngen from the installer

Moved the SvgImage to GreenshotPlugin, so it's available everywhere
Upgraded Dapplo.Jira to a more modern version, but still far from current.
This commit is contained in:
Robin Krom 2020-02-19 22:01:56 +01:00
commit 7e99478b86
8 changed files with 172 additions and 190 deletions

View file

@ -19,7 +19,7 @@ Source: {#ReleaseDir}\Greenshot.exe; DestDir: {app}; Components: greenshot; Flag
Source: {#ReleaseDir}\GreenshotPlugin.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\GreenshotPlugin.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\Greenshot.exe.config; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\Greenshot.exe.config; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: {#ReleaseDir}\log4net.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\log4net.dll; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
Source: ..\..\log4net.xml; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion Source: ..\..\log4net.xml; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion
Source: {#ReleaseDir}\checksum.SHA256; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion Source: {#ReleaseDir}\checksum.SHA256; DestDir: {app}; Components: greenshot; Flags: overwritereadonly ignoreversion replacesameversion
;Source: ..\greenshot-defaults.ini; DestDir: {app}; Flags: overwritereadonly ignoreversion replacesameversion ;Source: ..\greenshot-defaults.ini; DestDir: {app}; Flags: overwritereadonly ignoreversion replacesameversion
Source: ..\additional_files\installer.txt; DestDir: {app}; Components: greenshot; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion Source: ..\additional_files\installer.txt; DestDir: {app}; Components: greenshot; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion
@ -240,7 +240,7 @@ es.ocr=Extensión para OCR (necesita Microsoft Office Document Imaging (MODI))
es.optimize=Optimizando rendimiento; por favor, espera. es.optimize=Optimizando rendimiento; por favor, espera.
es.startgreenshot=Lanzar {#ExeName} es.startgreenshot=Lanzar {#ExeName}
es.startup=Lanzar {#ExeName} al iniciarse Windows es.startup=Lanzar {#ExeName} al iniciarse Windows
es.win10=Extensión para Windows 10 es.win10=Extensión para Windows 10
fi.confluence=Confluence-liitännäinen fi.confluence=Confluence-liitännäinen
fi.default=${default} fi.default=${default}
@ -266,7 +266,7 @@ fr.ocr=Greffon OCR (nécessite Document Imaging de Microsoft Office [MODI])
fr.optimize=Optimisation des performances, Ceci peut prendre un certain temps. fr.optimize=Optimisation des performances, Ceci peut prendre un certain temps.
fr.startgreenshot=Démarrer {#ExeName} fr.startgreenshot=Démarrer {#ExeName}
fr.startup=Lancer {#ExeName} au démarrage de Windows fr.startup=Lancer {#ExeName} au démarrage de Windows
fr.win10=Greffon Windows 10 fr.win10=Greffon Windows 10
lt.confluence=Confluence spraudnis lt.confluence=Confluence spraudnis
lt.default=${default} lt.default=${default}
@ -295,7 +295,7 @@ nl.startup={#ExeName} automatisch starten met Windows
nl.win10=Windows 10 plug-in nl.win10=Windows 10 plug-in
nn.confluence=Confluence-tillegg nn.confluence=Confluence-tillegg
nn.default=Default installation nn.default=Default installation
nn.office=Microsoft Office Tillegg nn.office=Microsoft Office Tillegg
nn.externalcommand=Tillegg for å opne med ekstern kommando nn.externalcommand=Tillegg for å opne med ekstern kommando
nn.imgur=Imgur-tillegg (sjå http://imgur.com) nn.imgur=Imgur-tillegg (sjå http://imgur.com)
@ -362,19 +362,19 @@ Name: "custom"; Description: "{code:CustomInstall}"; Flags: iscustom
[Components] [Components]
Name: "greenshot"; Description: "Greenshot"; Types: default full compact custom; Flags: fixed Name: "greenshot"; Description: "Greenshot"; Types: default full compact custom; Flags: fixed
Name: "plugins\office"; Description: {cm:office}; Types: default full custom; Flags: disablenouninstallwarning Name: "plugins\office"; Description: {cm:office}; Types: default full custom; Flags: disablenouninstallwarning
Name: "plugins\ocr"; Description: {cm:ocr}; Types: default full custom; Flags: disablenouninstallwarning Name: "plugins\ocr"; Description: {cm:ocr}; Types: default full custom; Flags: disablenouninstallwarning
Name: "plugins\jira"; Description: {cm:jira}; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\jira"; Description: {cm:jira}; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\imgur"; Description: {cm:imgur}; Types: default full custom; Flags: disablenouninstallwarning Name: "plugins\imgur"; Description: {cm:imgur}; Types: default full custom; Flags: disablenouninstallwarning
Name: "plugins\confluence"; Description: {cm:confluence}; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\confluence"; Description: {cm:confluence}; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\externalcommand"; Description: {cm:externalcommand}; Types: default full custom; Flags: disablenouninstallwarning Name: "plugins\externalcommand"; Description: {cm:externalcommand}; Types: default full custom; Flags: disablenouninstallwarning
;Name: "plugins\networkimport"; Description: "Network Import Plugin"; Types: full ;Name: "plugins\networkimport"; Description: "Network Import Plugin"; Types: full
Name: "plugins\box"; Description: "Box Plugin"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\box"; Description: "Box Plugin"; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\dropbox"; Description: "Dropbox Plugin"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\dropbox"; Description: "Dropbox Plugin"; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\flickr"; Description: "Flickr Plugin"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\flickr"; Description: "Flickr Plugin"; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\picasa"; Description: "Picasa Plugin"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\picasa"; Description: "Picasa Plugin"; Types: full custom; Flags: disablenouninstallwarning
Name: "plugins\photobucket"; Description: "Photobucket Plugin"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\photobucket"; Description: "Photobucket Plugin"; Types: full custom; Flags: disablenouninstallwarning
;Name: "plugins\win10"; Description: "Windows 10 Plugin"; Types: default full custom; Flags: disablenouninstallwarning; Check: IsWindows10OrNewer() ;Name: "plugins\win10"; Description: "Windows 10 Plugin"; Types: default full custom; Flags: disablenouninstallwarning; Check: IsWindows10OrNewer()
Name: "languages"; Description: {cm:language}; Types: full custom; Flags: disablenouninstallwarning Name: "languages"; Description: {cm:language}; Types: full custom; Flags: disablenouninstallwarning
Name: "languages\arSY"; Description: "العربية"; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('d') Name: "languages\arSY"; Description: "العربية"; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('d')
Name: "languages\caCA"; Description: "Català"; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('1') Name: "languages\caCA"; Description: "Català"; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('1')
@ -427,7 +427,7 @@ begin
else else
Result := ExpandConstant('{pf}') Result := ExpandConstant('{pf}')
end; end;
function FullInstall(Param : String) : String; function FullInstall(Param : String) : String;
begin begin
@ -458,7 +458,7 @@ begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1'); sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := ''; sUnInstallString := '';
index := 0; index := 0;
// Retrieve uninstall string from HKLM32 or HKCU32 // Retrieve uninstall string from HKLM32 or HKCU32
if RegQueryStringValue(HKLM32, sUnInstPath, 'UninstallString', sUnInstallString) then if RegQueryStringValue(HKLM32, sUnInstPath, 'UninstallString', sUnInstallString) then
begin begin
@ -473,7 +473,7 @@ begin
asUninstallStrings[index] := sUnInstallString; asUninstallStrings[index] := sUnInstallString;
index := index +1; index := index +1;
end; end;
// Only for Windows with 64 bit support: Retrieve uninstall string from HKLM64 or HKCU64 // Only for Windows with 64 bit support: Retrieve uninstall string from HKLM64 or HKCU64
if IsWin64 then if IsWin64 then
begin begin
@ -544,7 +544,7 @@ begin
foundStart := false; foundStart := false;
for i:= 0 to ParamCount() do begin for i:= 0 to ParamCount() do begin
currentParameter := ParamStr(i); currentParameter := ParamStr(i);
// check if norun is supplied // check if norun is supplied
if Lowercase(currentParameter) = '/norun' then begin if Lowercase(currentParameter) = '/norun' then begin
foundNoRun := true; foundNoRun := true;
@ -595,19 +595,6 @@ begin
Result := netfxspversion(NetFx4x, '') >= 71; Result := netfxspversion(NetFx4x, '') >= 71;
end; end;
function getNGENPath(argument: String) : String;
var
installPath: string;
begin
if not RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'InstallPath', installPath) then begin
if not RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client', 'InstallPath', installPath) then begin
// 3.5 doesn't have NGEN and is using the .net 2.0 installation
installPath := ExpandConstant('{dotnet20}');
end;
end;
Result := installPath;
end;
// Initialize the setup // Initialize the setup
function InitializeSetup(): Boolean; function InitializeSetup(): Boolean;
begin begin
@ -617,7 +604,7 @@ begin
// Enhance installer, if needed, otherwise .NET installations won't work // Enhance installer, if needed, otherwise .NET installations won't work
msi20('2.0'); msi20('2.0');
msi31('3.0'); msi31('3.0');
//install .net 4.7.1 //install .net 4.7.1
dotnetfx47(71); dotnetfx47(71);
end; end;
@ -640,14 +627,8 @@ begin
end; end;
[Run] [Run]
Filename: "{code:getNGENPath}\ngen.exe"; Parameters: "install ""{app}\{#ExeName}.exe"""; StatusMsg: "{cm:optimize}"; Flags: runhidden runasoriginaluser
Filename: "{code:getNGENPath}\ngen.exe"; Parameters: "install ""{app}\GreenshotPlugin.dll"""; StatusMsg: "{cm:optimize}"; Flags: runhidden runasoriginaluser
Filename: "{app}\{#ExeName}.exe"; Description: "{cm:startgreenshot}"; Parameters: "{code:GetParamsForGS}"; WorkingDir: "{app}"; Flags: nowait postinstall runasoriginaluser Filename: "{app}\{#ExeName}.exe"; Description: "{cm:startgreenshot}"; Parameters: "{code:GetParamsForGS}"; WorkingDir: "{app}"; Flags: nowait postinstall runasoriginaluser
Filename: "http://getgreenshot.org/thank-you/?language={language}&version={#Version}"; Flags: shellexec runasoriginaluser Filename: "http://getgreenshot.org/thank-you/?language={language}&version={#Version}"; Flags: shellexec runasoriginaluser
[InstallDelete] [InstallDelete]
Name: {app}; Type: dirifempty; Name: {app}; Type: dirifempty;
[UninstallRun]
Filename: "{code:GetNGENPath}\ngen.exe"; Parameters: "uninstall ""{app}\{#ExeName}.exe"""; StatusMsg: "Cleanup"; Flags: runhidden
Filename: "{code:GetNGENPath}\ngen.exe"; Parameters: "uninstall ""{app}\GreenshotPlugin.dll"""; StatusMsg: "Cleanup"; Flags: runhidden

View file

@ -20,12 +20,12 @@
*/ */
using System; using System;
using System.Globalization;
using System.Windows.Forms; using System.Windows.Forms;
using Dapplo.Jira.Entities; using Dapplo.Jira.Entities;
using GreenshotPlugin.Controls; using GreenshotPlugin.Controls;
using GreenshotPlugin.Core; using GreenshotPlugin.Core;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using GreenshotPlugin.IniFile; using GreenshotPlugin.IniFile;
@ -176,8 +176,10 @@ namespace GreenshotJiraPlugin.Forms {
} }
item.SubItems.Add(issue.Key); item.SubItems.Add(issue.Key);
item.SubItems.Add(issue.Fields.Created.ToString("d", DateTimeFormatInfo.InvariantInfo)); item.SubItems.Add(issue.Fields.Created.HasValue
item.SubItems.Add(issue.Fields.Assignee?.DisplayName); ? issue.Fields.Created.Value.ToString("d", DateTimeFormatInfo.InvariantInfo)
: string.Empty);
item.SubItems.Add(issue.Fields.Assignee?.DisplayName);
item.SubItems.Add(issue.Fields.Reporter?.DisplayName); item.SubItems.Add(issue.Fields.Reporter?.DisplayName);
item.SubItems.Add(issue.Fields.Summary); item.SubItems.Add(issue.Fields.Summary);
jiraListView.Items.Add(item); jiraListView.Items.Add(item);

View file

@ -12,7 +12,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" /> <ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj" />
<PackageReference Include="Dapplo.Jira" version="0.5.12" /> <PackageReference Include="Dapplo.Jira" version="0.6.50" />
<PackageReference Include="Svg" version="2.3.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -90,22 +90,7 @@ namespace GreenshotJiraPlugin {
LogSettings.RegisterDefaultLogger<Log4NetLogger>(LogLevels.Fatal); LogSettings.RegisterDefaultLogger<Log4NetLogger>(LogLevels.Fatal);
} }
// Add a SVG converter, although it doesn't fit to the Jira plugin there is currently no other way return true;
ImageHelper.StreamConverters["svg"] = (stream, s) =>
{
stream.Position = 0;
try
{
return SvgImage.FromStream(stream).Image;
}
catch (Exception ex)
{
Log.Error("Can't load SVG", ex);
}
return null;
};
return true;
} }
public void Shutdown() { public void Shutdown() {

View file

@ -60,7 +60,22 @@ namespace GreenshotPlugin.Core {
return surface.GetImageForExport(); return surface.GetImageForExport();
}; };
static Image DefaultConverter(Stream stream, string s) // Add a SVG converter
StreamConverters["svg"] = (stream, s) =>
{
stream.Position = 0;
try
{
return SvgImage.FromStream(stream).Image;
}
catch (Exception ex)
{
Log.Error("Can't load SVG", ex);
}
return null;
};
static Image DefaultConverter(Stream stream, string s)
{ {
stream.Position = 0; stream.Position = 0;
using var tmpImage = Image.FromStream(stream, true, true); using var tmpImage = Image.FromStream(stream, true, true);

View file

@ -1,20 +1,20 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -71,7 +71,7 @@ namespace GreenshotPlugin.Core {
/// <param name="uri">An Uri to specify the download location</param> /// <param name="uri">An Uri to specify the download location</param>
/// <returns>string with the file content</returns> /// <returns>string with the file content</returns>
public static string GetAsString(Uri uri) { public static string GetAsString(Uri uri) {
return GetResponseAsString(CreateWebRequest(uri)); return GetResponseAsString(CreateWebRequest(uri));
} }
/// <summary> /// <summary>
@ -133,8 +133,8 @@ namespace GreenshotPlugin.Core {
extensions.AppendFormat(@"\.{0}|", extension); extensions.AppendFormat(@"\.{0}|", extension);
} }
extensions.Length--; extensions.Length--;
var imageUrlRegex = new Regex($@"(http|https)://.*(?<extension>{extensions})"); var imageUrlRegex = new Regex($@"(http|https)://.*(?<extension>{extensions})");
var match = imageUrlRegex.Match(url); var match = imageUrlRegex.Match(url);
try try
{ {
@ -190,7 +190,7 @@ namespace GreenshotPlugin.Core {
public static HttpWebRequest CreateWebRequest(string uri, HTTPMethod method) { public static HttpWebRequest CreateWebRequest(string uri, HTTPMethod method) {
return CreateWebRequest(new Uri(uri), method); return CreateWebRequest(new Uri(uri), method);
} }
/// <summary> /// <summary>
/// Helper method to create a web request with a lot of default settings /// Helper method to create a web request with a lot of default settings
/// </summary> /// </summary>
@ -254,7 +254,7 @@ namespace GreenshotPlugin.Core {
} }
return proxyToUse; return proxyToUse;
} }
/// <summary> /// <summary>
/// UrlEncodes a string without the requirement for System.Web /// UrlEncodes a string without the requirement for System.Web
/// </summary> /// </summary>
@ -324,7 +324,7 @@ namespace GreenshotPlugin.Core {
} }
return parameters; return parameters;
} }
/// <summary> /// <summary>
/// Generate the query paramters /// Generate the query paramters
/// </summary> /// </summary>
@ -462,7 +462,7 @@ namespace GreenshotPlugin.Core {
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="webRequest"></param> /// <param name="webRequest"></param>
/// <param name="alsoReturnContentOnError"></param> /// <param name="alsoReturnContentOnError"></param>
@ -615,7 +615,7 @@ namespace GreenshotPlugin.Core {
// Write the file data directly to the Stream, rather than serializing it to a string. // Write the file data directly to the Stream, rather than serializing it to a string.
dataStream.Write(_file, 0, _fileSize); dataStream.Write(_file, 0, _fileSize);
} }
/// <summary> /// <summary>
/// Upload the file to the webrequest /// Upload the file to the webrequest
/// </summary> /// </summary>
@ -754,7 +754,7 @@ namespace GreenshotPlugin.Core {
string header = $"--{boundary}\r\nContent-Disposition: form-data; name=\"{name}\"; filename=\"{Filename ?? name}\";\r\nContent-Type: {ContentType}\r\n\r\n"; string header = $"--{boundary}\r\nContent-Disposition: form-data; name=\"{name}\"; filename=\"{Filename ?? name}\";\r\nContent-Type: {ContentType}\r\n\r\n";
formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header)); formDataStream.Write(Encoding.UTF8.GetBytes(header), 0, Encoding.UTF8.GetByteCount(header));
ImageOutput.SaveToStream(_surface, formDataStream, _outputSettings); ImageOutput.SaveToStream(_surface, formDataStream, _outputSettings);
} }
/// <summary> /// <summary>
@ -765,7 +765,7 @@ namespace GreenshotPlugin.Core {
// Write the file data directly to the Stream, rather than serializing it to a string. // Write the file data directly to the Stream, rather than serializing it to a string.
ImageOutput.SaveToStream(_surface, dataStream, _outputSettings); ImageOutput.SaveToStream(_surface, dataStream, _outputSettings);
} }
/// <summary> /// <summary>
/// Upload the Surface as image to the webrequest /// Upload the Surface as image to the webrequest
/// </summary> /// </summary>

View file

@ -1,118 +1,117 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
* For more information see: http://getgreenshot.org/ * For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or * the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using GreenshotPlugin.Core; using Svg;
using Svg;
namespace GreenshotPlugin.Core
namespace GreenshotJiraPlugin {
{ /// <summary>
/// <summary> /// Create an image look like of the SVG
/// Create an image look like of the SVG /// </summary>
/// </summary> public sealed class SvgImage : IImage
public class SvgImage : IImage {
{ private readonly SvgDocument _svgDocument;
private readonly SvgDocument _svgDocument;
private Image _imageClone;
private Image _imageClone;
/// <summary>
/// <summary> /// Factory to create via a stream
/// Factory to create via a stream /// </summary>
/// </summary> /// <param name="stream">Stream</param>
/// <param name="stream">Stream</param> /// <returns>IImage</returns>
/// <returns>IImage</returns> public static IImage FromStream(Stream stream)
public static IImage FromStream(Stream stream) {
{ return new SvgImage(stream);
return new SvgImage(stream); }
}
/// <summary>
/// <summary> /// Default constructor
/// Default constructor /// </summary>
/// </summary> /// <param name="stream"></param>
/// <param name="stream"></param> public SvgImage(Stream stream)
public SvgImage(Stream stream) {
{ _svgDocument = SvgDocument.Open<SvgDocument>(stream);
_svgDocument = SvgDocument.Open<SvgDocument>(stream); Height = (int)_svgDocument.ViewBox.Height;
Height = (int)_svgDocument.ViewBox.Height; Width = (int)_svgDocument.ViewBox.Width;
Width = (int)_svgDocument.ViewBox.Width; }
}
/// <summary>
/// <summary> /// Height of the image, can be set to change
/// Height of the image, can be set to change /// </summary>
/// </summary> public int Height { get; set; }
public int Height { get; set; }
/// <summary>
/// <summary> /// Width of the image, can be set to change.
/// Width of the image, can be set to change. /// </summary>
/// </summary> public int Width { get; set; }
public int Width { get; set; }
/// <summary>
/// <summary> /// Size of the image
/// Size of the image /// </summary>
/// </summary> public Size Size => new Size(Width, Height);
public Size Size => new Size(Width, Height);
/// <summary>
/// <summary> /// Pixelformat of the underlying image
/// Pixelformat of the underlying image /// </summary>
/// </summary> public PixelFormat PixelFormat => Image.PixelFormat;
public PixelFormat PixelFormat => Image.PixelFormat;
/// <summary>
/// <summary> /// Horizontal resolution of the underlying image
/// Horizontal resolution of the underlying image /// </summary>
/// </summary> public float HorizontalResolution => Image.HorizontalResolution;
public float HorizontalResolution => Image.HorizontalResolution;
/// <summary>
/// <summary> /// Vertical resolution of the underlying image
/// Vertical resolution of the underlying image /// </summary>
/// </summary> public float VerticalResolution => Image.VerticalResolution;
public float VerticalResolution => Image.VerticalResolution;
/// <summary>
/// <summary> /// Underlying image, or an on demand rendered version with different attributes as the original
/// Unterlying image, or an on demand rendered version with different attributes as the original /// </summary>
/// </summary> public Image Image
public Image Image {
{ get
get {
{ if (_imageClone?.Height == Height && _imageClone?.Width == Width)
if (_imageClone?.Height == Height && _imageClone?.Width == Width) {
{ return _imageClone;
return _imageClone; }
} // Calculate new image clone
// Calculate new image clone _imageClone?.Dispose();
_imageClone?.Dispose(); _imageClone = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
_imageClone = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96); _svgDocument.Draw((Bitmap)_imageClone);
_svgDocument.Draw((Bitmap)_imageClone); return _imageClone;
return _imageClone;
}
} }
}
/// <summary>
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary>
/// </summary> public void Dispose()
public void Dispose() {
{ _imageClone?.Dispose();
_imageClone?.Dispose(); }
} }
} }
}

View file

@ -15,6 +15,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="log4net" version="2.0.8" /> <PackageReference Include="log4net" version="2.0.8" />
<PackageReference Include="Svg" Version="3.0.102" />
<Reference Include="Accessibility" /> <Reference Include="Accessibility" />
<Reference Include="CustomMarshalers" /> <Reference Include="CustomMarshalers" />
</ItemGroup> </ItemGroup>