diff --git a/Greenshot/Drawing/ImageContainer.cs b/Greenshot/Drawing/ImageContainer.cs
index b9f08c28f..172ac7e9a 100644
--- a/Greenshot/Drawing/ImageContainer.cs
+++ b/Greenshot/Drawing/ImageContainer.cs
@@ -36,7 +36,7 @@ namespace Greenshot.Drawing {
///
[Serializable]
public class ImageContainer : DrawableContainer, IImageContainer {
- private static readonly ILog LOG = LogManager.GetLogger(typeof(ImageContainer));
+ private static readonly ILog Log = LogManager.GetLogger(typeof(ImageContainer));
private Image image;
@@ -80,7 +80,7 @@ namespace Greenshot.Drawing {
protected void BitmapContainer_OnFieldChanged(object sender, FieldChangedEventArgs e) {
if (sender.Equals(this)) {
- if (e.Field.FieldType == FieldType.SHADOW) {
+ if (FieldType.SHADOW.Equals(e.Field.FieldType)) {
ChangeShadowField();
}
}
@@ -140,15 +140,11 @@ namespace Greenshot.Drawing {
}
private void DisposeImage() {
- if (image != null) {
- image.Dispose();
- }
+ image?.Dispose();
image = null;
}
private void DisposeShadow() {
- if (_shadowBitmap != null) {
- _shadowBitmap.Dispose();
- }
+ _shadowBitmap?.Dispose();
_shadowBitmap = null;
}
@@ -162,10 +158,11 @@ namespace Greenshot.Drawing {
int rotateAngle = CalculateAngle(matrix);
// we currently assume only one transformation has been made.
if (rotateAngle != 0) {
- LOG.DebugFormat("Rotating element with {0} degrees.", rotateAngle);
+ Log.DebugFormat("Rotating element with {0} degrees.", rotateAngle);
DisposeShadow();
using (var tmpMatrix = new Matrix()) {
- using (Image tmpImage = image) {
+ using (image)
+ {
image = ImageHelper.ApplyEffect(image, new RotateEffect(rotateAngle), tmpMatrix);
}
}
@@ -178,14 +175,16 @@ namespace Greenshot.Drawing {
///
///
public void Load(string filename) {
- if (File.Exists(filename)) {
- // Always make sure ImageHelper.LoadBitmap results are disposed some time,
- // as we close the bitmap internally, we need to do it afterwards
- using (Image tmpImage = ImageHelper.LoadImage(filename)) {
- Image = tmpImage;
- }
- LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
+ if (!File.Exists(filename))
+ {
+ return;
}
+ // Always make sure ImageHelper.LoadBitmap results are disposed some time,
+ // as we close the bitmap internally, we need to do it afterwards
+ using (var tmpImage = ImageHelper.LoadImage(filename)) {
+ Image = tmpImage;
+ }
+ Log.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
}
///
@@ -222,16 +221,8 @@ namespace Greenshot.Drawing {
}
}
- public override bool HasDefaultSize {
- get {
- return true;
- }
- }
+ public override bool HasDefaultSize => true;
- public override Size DefaultSize {
- get {
- return image.Size;
- }
- }
+ public override Size DefaultSize => image.Size;
}
}
diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs
index 7a4b368a9..12199733d 100644
--- a/Greenshot/Drawing/Surface.cs
+++ b/Greenshot/Drawing/Surface.cs
@@ -436,7 +436,7 @@ namespace Greenshot.Drawing
///
/// Property for accessing the URL to which the surface was recently uploaded
///
- public string UploadURL
+ public string UploadUrl
{
get;
set;
diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs
index 355fb4396..7beee15f5 100644
--- a/Greenshot/Forms/MainForm.cs
+++ b/Greenshot/Forms/MainForm.cs
@@ -41,6 +41,7 @@ using GreenshotPlugin.Controls;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
using Greenshot.Destinations;
+using Greenshot.Drawing;
using log4net;
using Timer = System.Timers.Timer;
@@ -320,6 +321,9 @@ namespace Greenshot {
public MainForm(CopyDataTransport dataTransport) {
_instance = this;
+ // Factory for surface objects
+ ImageHelper.SurfaceFactory = () => new Surface();
+
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs
index f31c1e81e..74975f82f 100644
--- a/Greenshot/Helpers/CaptureHelper.cs
+++ b/Greenshot/Helpers/CaptureHelper.cs
@@ -549,8 +549,8 @@ namespace Greenshot.Helpers {
MessageBox.Show(string.Format("{0}\r\nexplorer.exe {1}", errorMessage, surface.LastSaveFullPath), "explorer.exe", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
- } else if (surface != null && !string.IsNullOrEmpty(surface.UploadURL)) {
- Process.Start(surface.UploadURL);
+ } else if (surface != null && !string.IsNullOrEmpty(surface.UploadUrl)) {
+ Process.Start(surface.UploadUrl);
}
LOG.DebugFormat("Deregistering the BalloonTipClicked");
RemoveEventHandler(sender, e);
diff --git a/GreenshotConfluencePlugin/ConfluenceDestination.cs b/GreenshotConfluencePlugin/ConfluenceDestination.cs
index ea2594b29..fa9ccb7a1 100644
--- a/GreenshotConfluencePlugin/ConfluenceDestination.cs
+++ b/GreenshotConfluencePlugin/ConfluenceDestination.cs
@@ -36,11 +36,12 @@ namespace GreenshotConfluencePlugin {
/// Description of ConfluenceDestination.
///
public class ConfluenceDestination : AbstractDestination {
- private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ConfluenceDestination));
- private static readonly ConfluenceConfiguration config = IniConfig.GetIniSection();
- private static readonly CoreConfiguration coreConfig = IniConfig.GetIniSection();
- private static readonly Image confluenceIcon = null;
- private readonly Page page;
+ private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ConfluenceDestination));
+ private static readonly ConfluenceConfiguration ConfluenceConfig = IniConfig.GetIniSection();
+ private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection();
+ private static readonly Image ConfluenceIcon;
+ private readonly Page _page;
+
public static bool IsInitialized {
get;
private set;
@@ -49,14 +50,14 @@ namespace GreenshotConfluencePlugin {
IsInitialized = false;
try {
Uri confluenceIconUri = new Uri("/GreenshotConfluencePlugin;component/Images/Confluence.ico", UriKind.Relative);
- using (Stream iconStream = Application.GetResourceStream(confluenceIconUri).Stream) {
- using (Image tmpImage = Image.FromStream(iconStream)) {
- confluenceIcon = ImageHelper.Clone(tmpImage);
- }
+ using (Stream iconStream = Application.GetResourceStream(confluenceIconUri)?.Stream)
+ {
+ // TODO: Check what to do with the IImage
+ ConfluenceIcon = ImageHelper.FromStream(iconStream);
}
IsInitialized = true;
} catch (Exception ex) {
- LOG.ErrorFormat("Problem in the confluence static initializer: {0}", ex.Message);
+ Log.ErrorFormat("Problem in the confluence static initializer: {0}", ex.Message);
}
}
@@ -64,7 +65,7 @@ namespace GreenshotConfluencePlugin {
}
public ConfluenceDestination(Page page) {
- this.page = page;
+ _page = page;
}
public override string Designation {
@@ -75,10 +76,10 @@ namespace GreenshotConfluencePlugin {
public override string Description {
get {
- if (page == null) {
+ if (_page == null) {
return Language.GetString("confluence", LangKey.upload_menu_item);
} else {
- return Language.GetString("confluence", LangKey.upload_menu_item) + ": \"" + page.Title + "\"";
+ return Language.GetString("confluence", LangKey.upload_menu_item) + ": \"" + _page.Title + "\"";
}
}
}
@@ -91,13 +92,13 @@ namespace GreenshotConfluencePlugin {
public override bool isActive {
get {
- return base.isActive && !string.IsNullOrEmpty(config.Url);
+ return base.isActive && !string.IsNullOrEmpty(ConfluenceConfig.Url);
}
}
public override Image DisplayIcon {
get {
- return confluenceIcon;
+ return ConfluenceIcon;
}
}
@@ -121,9 +122,9 @@ namespace GreenshotConfluencePlugin {
return exportInformation;
}
- Page selectedPage = page;
- bool openPage = (page == null) && config.OpenPageAfterUpload;
- string filename = FilenameHelper.GetFilenameWithoutExtensionFromPattern(coreConfig.OutputFileFilenamePattern, captureDetails);
+ Page selectedPage = _page;
+ bool openPage = (_page == null) && ConfluenceConfig.OpenPageAfterUpload;
+ string filename = FilenameHelper.GetFilenameWithoutExtensionFromPattern(CoreConfig.OutputFileFilenamePattern, captureDetails);
if (selectedPage == null) {
ConfluenceUpload confluenceUpload = new ConfluenceUpload(filename);
Nullable dialogResult = confluenceUpload.ShowDialog();
@@ -135,18 +136,23 @@ namespace GreenshotConfluencePlugin {
filename = confluenceUpload.Filename;
}
}
- string extension = "." + config.UploadFormat;
+ string extension = "." + ConfluenceConfig.UploadFormat;
if (!filename.ToLower().EndsWith(extension)) {
filename = filename + extension;
}
if (selectedPage != null) {
string errorMessage;
- bool uploaded = upload(surface, selectedPage, filename, out errorMessage);
+ bool uploaded = Upload(surface, selectedPage, filename, out errorMessage);
if (uploaded) {
if (openPage) {
- try {
+ try
+ {
Process.Start(selectedPage.Url);
- } catch { }
+ }
+ catch
+ {
+ // Ignore
+ }
}
exportInformation.ExportMade = true;
exportInformation.Uri = selectedPage.Url;
@@ -158,31 +164,33 @@ namespace GreenshotConfluencePlugin {
return exportInformation;
}
- private bool upload(ISurface surfaceToUpload, Page page, string filename, out string errorMessage) {
- SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
+ private bool Upload(ISurface surfaceToUpload, Page page, string filename, out string errorMessage) {
+ SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(ConfluenceConfig.UploadFormat, ConfluenceConfig.UploadJpegQuality, ConfluenceConfig.UploadReduceColors);
errorMessage = null;
try {
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("confluence", LangKey.communication_wait),
- delegate() {
- ConfluencePlugin.ConfluenceConnector.AddAttachment(page.Id, "image/" + config.UploadFormat.ToString().ToLower(), null, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
+ delegate {
+ ConfluencePlugin.ConfluenceConnector.AddAttachment(page.Id, "image/" + ConfluenceConfig.UploadFormat.ToString().ToLower(), null, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
}
);
- LOG.Debug("Uploaded to Confluence.");
- if (config.CopyWikiMarkupForImageToClipboard) {
- int retryCount = 2;
- while (retryCount >= 0) {
- try {
- Clipboard.SetText("!" + filename + "!");
- break;
- } catch (Exception ee) {
- if (retryCount == 0) {
- LOG.Error(ee);
- } else {
- Thread.Sleep(100);
- }
- } finally {
- --retryCount;
+ Log.Debug("Uploaded to Confluence.");
+ if (!ConfluenceConfig.CopyWikiMarkupForImageToClipboard)
+ {
+ return true;
+ }
+ int retryCount = 2;
+ while (retryCount >= 0) {
+ try {
+ Clipboard.SetText("!" + filename + "!");
+ break;
+ } catch (Exception ee) {
+ if (retryCount == 0) {
+ Log.Error(ee);
+ } else {
+ Thread.Sleep(100);
}
+ } finally {
+ --retryCount;
}
}
return true;
diff --git a/GreenshotImgurPlugin/ImgurUtils.cs b/GreenshotImgurPlugin/ImgurUtils.cs
index ed430bb99..c32c0afba 100644
--- a/GreenshotImgurPlugin/ImgurUtils.cs
+++ b/GreenshotImgurPlugin/ImgurUtils.cs
@@ -32,7 +32,7 @@ namespace GreenshotImgurPlugin {
/// Description of ImgurUtils.
///
public static class ImgurUtils {
- private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImgurUtils));
+ private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(ImgurUtils));
private const string SmallUrlPattern = "http://i.imgur.com/{0}s.jpg";
private static readonly ImgurConfiguration Config = IniConfig.GetIniSection();
private const string AuthUrlPattern = "https://api.imgur.com/oauth2/authorize?response_type=code&client_id={ClientId}&redirect_uri={RedirectUrl}&state={State}";
@@ -64,7 +64,7 @@ namespace GreenshotImgurPlugin {
RetrieveImgurThumbnail(imgurInfo);
Config.runtimeImgurHistory.Add(hash, imgurInfo);
} else {
- LOG.DebugFormat("Deleting not found ImgUr {0} from config.", hash);
+ Log.DebugFormat("Deleting not found ImgUr {0} from config.", hash);
Config.ImgurUploadHistory.Remove(hash);
saveNeeded = true;
}
@@ -74,16 +74,16 @@ namespace GreenshotImgurPlugin {
HttpWebResponse response = ((HttpWebResponse)wE.Response);
// Image no longer available
if (response.StatusCode == HttpStatusCode.Redirect) {
- LOG.InfoFormat("ImgUr image for hash {0} is no longer available", hash);
+ Log.InfoFormat("ImgUr image for hash {0} is no longer available", hash);
Config.ImgurUploadHistory.Remove(hash);
redirected = true;
}
}
if (!redirected) {
- LOG.Error("Problem loading ImgUr history for hash " + hash, wE);
+ Log.Error("Problem loading ImgUr history for hash " + hash, wE);
}
} catch (Exception e) {
- LOG.Error("Problem loading ImgUr history for hash " + hash, e);
+ Log.Error("Problem loading ImgUr history for hash " + hash, e);
}
}
if (saveNeeded) {
@@ -146,7 +146,7 @@ namespace GreenshotImgurPlugin {
}
}
} catch (Exception ex) {
- LOG.Error("Upload to imgur gave an exeption: ", ex);
+ Log.Error("Upload to imgur gave an exeption: ", ex);
throw;
}
} else {
@@ -200,10 +200,10 @@ namespace GreenshotImgurPlugin {
///
public static void RetrieveImgurThumbnail(ImgurInfo imgurInfo) {
if (imgurInfo.SmallSquare == null) {
- LOG.Warn("Imgur URL was null, not retrieving thumbnail.");
+ Log.Warn("Imgur URL was null, not retrieving thumbnail.");
return;
}
- LOG.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo.SmallSquare);
+ Log.InfoFormat("Retrieving Imgur image for {0} with url {1}", imgurInfo.Hash, imgurInfo.SmallSquare);
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(string.Format(SmallUrlPattern, imgurInfo.Hash), HTTPMethod.GET);
webRequest.ServicePoint.Expect100Continue = false;
// Not for getting the thumbnail, in anonymous modus
@@ -213,7 +213,7 @@ namespace GreenshotImgurPlugin {
Stream responseStream = response.GetResponseStream();
if (responseStream != null)
{
- imgurInfo.Image = Image.FromStream(responseStream);
+ imgurInfo.Image = ImageHelper.FromStream(responseStream);
}
}
}
@@ -226,16 +226,21 @@ namespace GreenshotImgurPlugin {
/// ImgurInfo
public static ImgurInfo RetrieveImgurInfo(string hash, string deleteHash) {
string url = Config.ImgurApi3Url + "/image/" + hash + ".xml";
- LOG.InfoFormat("Retrieving Imgur info for {0} with url {1}", hash, url);
+ Log.InfoFormat("Retrieving Imgur info for {0} with url {1}", hash, url);
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url, HTTPMethod.GET);
webRequest.ServicePoint.Expect100Continue = false;
SetClientId(webRequest);
- string responseString;
+ string responseString = null;
try {
using (WebResponse response = webRequest.GetResponse()) {
LogRateLimitInfo(response);
- using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
- responseString = reader.ReadToEnd();
+ var responseStream = response.GetResponseStream();
+ if (responseStream != null)
+ {
+ using (StreamReader reader = new StreamReader(responseStream, true))
+ {
+ responseString = reader.ReadToEnd();
+ }
}
}
} catch (WebException wE) {
@@ -246,9 +251,13 @@ namespace GreenshotImgurPlugin {
}
throw;
}
- LOG.Debug(responseString);
- ImgurInfo imgurInfo = ImgurInfo.ParseResponse(responseString);
- imgurInfo.DeleteHash = deleteHash;
+ ImgurInfo imgurInfo = null;
+ if (responseString != null)
+ {
+ Log.Debug(responseString);
+ imgurInfo = ImgurInfo.ParseResponse(responseString);
+ imgurInfo.DeleteHash = deleteHash;
+ }
return imgurInfo;
}
@@ -257,21 +266,26 @@ namespace GreenshotImgurPlugin {
///
///
public static void DeleteImgurImage(ImgurInfo imgurInfo) {
- LOG.InfoFormat("Deleting Imgur image for {0}", imgurInfo.DeleteHash);
+ Log.InfoFormat("Deleting Imgur image for {0}", imgurInfo.DeleteHash);
try {
string url = Config.ImgurApi3Url + "/image/" + imgurInfo.DeleteHash + ".xml";
HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(url, HTTPMethod.DELETE);
webRequest.ServicePoint.Expect100Continue = false;
SetClientId(webRequest);
- string responseString;
+ string responseString = null;
using (WebResponse response = webRequest.GetResponse()) {
LogRateLimitInfo(response);
- using (StreamReader reader = new StreamReader(response.GetResponseStream(), true)) {
- responseString = reader.ReadToEnd();
+ var responseStream = response.GetResponseStream();
+ if (responseStream != null)
+ {
+ using (StreamReader reader = new StreamReader(responseStream, true))
+ {
+ responseString = reader.ReadToEnd();
+ }
}
}
- LOG.InfoFormat("Delete result: {0}", responseString);
+ Log.InfoFormat("Delete result: {0}", responseString);
} catch (WebException wE) {
// Allow "Bad request" this means we already deleted it
if (wE.Status == WebExceptionStatus.ProtocolError) {
@@ -293,7 +307,7 @@ namespace GreenshotImgurPlugin {
///
private static void LogHeader(IDictionary nameValues, string key) {
if (nameValues.ContainsKey(key)) {
- LOG.InfoFormat("key={0}", nameValues[key]);
+ Log.InfoFormat("key={0}", nameValues[key]);
}
}
diff --git a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
index 935db3188..cc52a7b68 100644
--- a/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
+++ b/GreenshotJiraPlugin/GreenshotJiraPlugin.csproj
@@ -95,6 +95,7 @@
+
Always
diff --git a/GreenshotJiraPlugin/JiraDestination.cs b/GreenshotJiraPlugin/JiraDestination.cs
index 455fcd061..f45859841 100644
--- a/GreenshotJiraPlugin/JiraDestination.cs
+++ b/GreenshotJiraPlugin/JiraDestination.cs
@@ -118,12 +118,12 @@ namespace GreenshotJiraPlugin {
{
var surfaceContainer = new SurfaceContainer(surfaceToUpload, outputSettings, filename);
await _jiraPlugin.JiraConnector.AttachAsync(_jiraIssue.Key, surfaceContainer);
- surfaceToUpload.UploadURL = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
+ surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", _jiraIssue.Key).AbsoluteUri;
}
);
Log.DebugFormat("Uploaded to Jira {0}", _jiraIssue.Key);
exportInformation.ExportMade = true;
- exportInformation.Uri = surfaceToUpload.UploadURL;
+ exportInformation.Uri = surfaceToUpload.UploadUrl;
} catch (Exception e) {
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
}
@@ -133,7 +133,7 @@ namespace GreenshotJiraPlugin {
var dialogResult = jiraForm.ShowDialog();
if (dialogResult == DialogResult.OK) {
try {
- surfaceToUpload.UploadURL = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri;
+ surfaceToUpload.UploadUrl = _jiraPlugin.JiraConnector.JiraBaseUri.AppendSegments("browse", jiraForm.GetJiraIssue().Key).AbsoluteUri;
// Run upload in the background
new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
async () =>
@@ -143,7 +143,7 @@ namespace GreenshotJiraPlugin {
);
Log.DebugFormat("Uploaded to Jira {0}", jiraForm.GetJiraIssue().Key);
exportInformation.ExportMade = true;
- exportInformation.Uri = surfaceToUpload.UploadURL;
+ exportInformation.Uri = surfaceToUpload.UploadUrl;
} catch(Exception e) {
MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
}
diff --git a/GreenshotJiraPlugin/JiraPlugin.cs b/GreenshotJiraPlugin/JiraPlugin.cs
index 009ac9ce3..b61bbe907 100644
--- a/GreenshotJiraPlugin/JiraPlugin.cs
+++ b/GreenshotJiraPlugin/JiraPlugin.cs
@@ -23,9 +23,13 @@ using System.Windows.Forms;
using Greenshot.IniFile;
using Greenshot.Plugin;
using System;
+using System.Drawing;
+using System.Drawing.Imaging;
using System.Threading.Tasks;
using Dapplo.Log.Facade;
using GreenshotJiraPlugin.Forms;
+using GreenshotPlugin.Core;
+using Svg;
namespace GreenshotJiraPlugin {
///
@@ -95,6 +99,21 @@ namespace GreenshotJiraPlugin {
_config = IniConfig.GetIniSection();
LogSettings.RegisterDefaultLogger();
+ // Add a SVG converter, although it doesn't fit to the Jira plugin there is currently no other way
+ 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;
}
diff --git a/GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs b/GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs
index f8d995d99..47b3a24d1 100644
--- a/GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs
+++ b/GreenshotJiraPlugin/SvgBitmapHttpContentConverter.cs
@@ -22,7 +22,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
-using System.Drawing.Imaging;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -33,8 +32,6 @@ using Dapplo.HttpExtensions.Support;
using Dapplo.Log.Facade;
using System.Net.Http;
using System.Net.Http.Headers;
-using GreenshotPlugin.Core;
-using Svg;
namespace GreenshotJiraPlugin
{
@@ -86,12 +83,12 @@ namespace GreenshotJiraPlugin
using (var memoryStream = (MemoryStream) await StreamHttpContentConverter.Instance.ConvertFromHttpContentAsync(typeof(MemoryStream), httpContent, cancellationToken).ConfigureAwait(false))
{
Log.Debug().WriteLine("Creating a Bitmap from the SVG.");
- var bitmap = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
- var svgDoc = SvgDocument.Open(memoryStream);
- svgDoc.Width = Width;
- svgDoc.Height = Height;
- svgDoc.Draw(bitmap);
- return bitmap;
+ var svgImage = new SvgImage(memoryStream)
+ {
+ Height = Height,
+ Width = Width
+ };
+ return svgImage.Image;
}
}
diff --git a/GreenshotJiraPlugin/SvgImage.cs b/GreenshotJiraPlugin/SvgImage.cs
new file mode 100644
index 000000000..bb86e3264
--- /dev/null
+++ b/GreenshotJiraPlugin/SvgImage.cs
@@ -0,0 +1,118 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * 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
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using GreenshotPlugin.Core;
+using Svg;
+
+namespace GreenshotJiraPlugin
+{
+ ///
+ /// Create an image look like of the SVG
+ ///
+ public class SvgImage : IImage
+ {
+ private readonly SvgDocument _svgDocument;
+
+ private Image _imageClone;
+
+ ///
+ /// Factory to create via a stream
+ ///
+ /// Stream
+ /// IImage
+ public static IImage FromStream(Stream stream)
+ {
+ return new SvgImage(stream);
+ }
+
+ ///
+ /// Default constructor
+ ///
+ ///
+ public SvgImage(Stream stream)
+ {
+ _svgDocument = SvgDocument.Open(stream);
+ Height = (int)_svgDocument.ViewBox.Height;
+ Width = (int)_svgDocument.ViewBox.Width;
+ }
+
+ ///
+ /// Height of the image, can be set to change
+ ///
+ public int Height { get; set; }
+
+ ///
+ /// Width of the image, can be set to change.
+ ///
+ public int Width { get; set; }
+
+ ///
+ /// Size of the image
+ ///
+ public Size Size => new Size(Width, Height);
+
+ ///
+ /// Pixelformat of the underlying image
+ ///
+ public PixelFormat PixelFormat => Image.PixelFormat;
+
+ ///
+ /// Horizontal resolution of the underlying image
+ ///
+ public float HorizontalResolution => Image.HorizontalResolution;
+
+ ///
+ /// Vertical resolution of the underlying image
+ ///
+ public float VerticalResolution => Image.VerticalResolution;
+
+ ///
+ /// Unterlying image, or an on demand rendered version with different attributes as the original
+ ///
+ public Image Image
+ {
+ get
+ {
+ if (_imageClone?.Height == Height && _imageClone?.Width == Width)
+ {
+ return _imageClone;
+ }
+ // Calculate new image clone
+ _imageClone?.Dispose();
+ _imageClone = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent, 96, 96);
+ _svgDocument.Draw((Bitmap)_imageClone);
+ return _imageClone;
+
+ }
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ _imageClone?.Dispose();
+ }
+ }
+}
diff --git a/GreenshotPlugin/Core/AbstractDestination.cs b/GreenshotPlugin/Core/AbstractDestination.cs
index 42dbf812c..b0a0bd965 100644
--- a/GreenshotPlugin/Core/AbstractDestination.cs
+++ b/GreenshotPlugin/Core/AbstractDestination.cs
@@ -123,7 +123,7 @@ namespace GreenshotPlugin.Core {
public void ProcessExport(ExportInformation exportInformation, ISurface surface) {
if (exportInformation != null && exportInformation.ExportMade) {
if (!string.IsNullOrEmpty(exportInformation.Uri)) {
- surface.UploadURL = exportInformation.Uri;
+ surface.UploadUrl = exportInformation.Uri;
surface.SendMessageEvent(this, SurfaceMessageTyp.UploadedUri, Language.GetFormattedString("exported_to", exportInformation.DestinationDescription));
} else if (!string.IsNullOrEmpty(exportInformation.Filepath)) {
surface.LastSaveFullPath = exportInformation.Filepath;
diff --git a/GreenshotPlugin/Core/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs
index ece141ab8..84950c05c 100644
--- a/GreenshotPlugin/Core/ClipboardHelper.cs
+++ b/GreenshotPlugin/Core/ClipboardHelper.cs
@@ -39,9 +39,9 @@ namespace GreenshotPlugin.Core {
/// Description of ClipboardHelper.
///
public static class ClipboardHelper {
- private static readonly ILog LOG = LogManager.GetLogger(typeof(ClipboardHelper));
- private static readonly object clipboardLockObject = new object();
- private static readonly CoreConfiguration config = IniConfig.GetIniSection();
+ private static readonly ILog Log = LogManager.GetLogger(typeof(ClipboardHelper));
+ private static readonly object ClipboardLockObject = new object();
+ private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection();
private static readonly string FORMAT_FILECONTENTS = "FileContents";
private static readonly string FORMAT_PNG = "PNG";
private static readonly string FORMAT_PNG_OFFICEART = "PNG+Office Art";
@@ -52,12 +52,11 @@ namespace GreenshotPlugin.Core {
private static readonly string FORMAT_GIF = "GIF";
private static readonly string FORMAT_BITMAP = "System.Drawing.Bitmap";
//private static readonly string FORMAT_HTML = "HTML Format";
-
- private static IntPtr nextClipboardViewer = IntPtr.Zero;
+
// Template for the HTML Text on the clipboard
// see: http://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
// or: http://msdn.microsoft.com/en-us/library/Aa767917.aspx
- private const string HTML_CLIPBOARD_STRING = @"Version:0.9
+ private const string HtmlClipboardString = @"Version:0.9
StartHTML:<<<<<<<1
EndHTML:<<<<<<<2
StartFragment:<<<<<<<3
@@ -75,7 +74,7 @@ EndSelection:<<<<<<<4