mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Merge remote-tracking branch 'origin/release/1.3' into new-emoji-object-in-editor
This commit is contained in:
commit
2aa4da60f0
8 changed files with 592 additions and 420 deletions
|
@ -190,6 +190,8 @@ Root: HKCU; Subkey: Software\Classes\.greenshot; ValueType: string; ValueName: "
|
||||||
Root: HKCU; Subkey: Software\Classes\Greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot File"; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
Root: HKCU; Subkey: Software\Classes\Greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot File"; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
||||||
Root: HKCU; Subkey: Software\Classes\Greenshot\DefaultIcon; ValueType: string; ValueName: ""; ValueData: """{app}\Greenshot.EXE,0"""; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
Root: HKCU; Subkey: Software\Classes\Greenshot\DefaultIcon; ValueType: string; ValueName: ""; ValueData: """{app}\Greenshot.EXE,0"""; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
||||||
Root: HKCU; Subkey: Software\Classes\Greenshot\shell\open\command; ValueType: string; ValueName: ""; ValueData: """{app}\Greenshot.EXE"" --openfile ""%1"""; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
Root: HKCU; Subkey: Software\Classes\Greenshot\shell\open\command; ValueType: string; ValueName: ""; ValueData: """{app}\Greenshot.EXE"" --openfile ""%1"""; Permissions: users-modify; Flags: uninsdeletevalue noerror; Check: IsRegularUser
|
||||||
|
; Disable the default PRTSCR Snipping Tool in Windows 11
|
||||||
|
Root: HKCU; Subkey: Control Panel\Keyboard; ValueType: dword; ValueName: "PrintScreenKeyForSnippingEnabled"; ValueData: "0"; Flags: uninsdeletevalue; Check: ShouldDisableSnippingTool
|
||||||
; HKEY_LOCAL_MACHINE - for all users when admin
|
; HKEY_LOCAL_MACHINE - for all users when admin
|
||||||
Root: HKLM; Subkey: Software\Classes\.greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot"; Permissions: admins-modify; Flags: uninsdeletevalue noerror; Check: not IsRegularUser
|
Root: HKLM; Subkey: Software\Classes\.greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot"; Permissions: admins-modify; Flags: uninsdeletevalue noerror; Check: not IsRegularUser
|
||||||
Root: HKLM; Subkey: Software\Classes\Greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot File"; Permissions: admins-modify; Flags: uninsdeletevalue noerror; Check: not IsRegularUser
|
Root: HKLM; Subkey: Software\Classes\Greenshot; ValueType: string; ValueName: ""; ValueData: "Greenshot File"; Permissions: admins-modify; Flags: uninsdeletevalue noerror; Check: not IsRegularUser
|
||||||
|
@ -278,6 +280,7 @@ en.win10=Windows 10 plug-in
|
||||||
en.UninstallIconDescription=Uninstall
|
en.UninstallIconDescription=Uninstall
|
||||||
en.ShowLicense=Show license
|
en.ShowLicense=Show license
|
||||||
en.ShowReadme=Show Readme
|
en.ShowReadme=Show Readme
|
||||||
|
en.disablewin11snippingtool=Disable Win11 default PrtScr snipping tool
|
||||||
|
|
||||||
de.confluence=Confluence Plug-in
|
de.confluence=Confluence Plug-in
|
||||||
de.default=Standard installation
|
de.default=Standard installation
|
||||||
|
@ -290,6 +293,7 @@ de.optimize=Optimierung der Leistung, kann etwas dauern.
|
||||||
de.startgreenshot={#ExeName} starten
|
de.startgreenshot={#ExeName} starten
|
||||||
de.startup={#ExeName} starten wenn Windows hochfährt
|
de.startup={#ExeName} starten wenn Windows hochfährt
|
||||||
de.win10=Windows 10 Plug-in
|
de.win10=Windows 10 Plug-in
|
||||||
|
de.disablewin11snippingtool=Deaktiviere das Standard Windows 11 Snipping Tool auf "Druck"
|
||||||
|
|
||||||
es.confluence=Extensión para Confluence
|
es.confluence=Extensión para Confluence
|
||||||
es.default=${default}
|
es.default=${default}
|
||||||
|
@ -491,6 +495,7 @@ Name: "compact"; Description: "{code:CompactInstall}"
|
||||||
Name: "custom"; Description: "{code:CustomInstall}"; Flags: iscustom
|
Name: "custom"; Description: "{code:CustomInstall}"; Flags: iscustom
|
||||||
|
|
||||||
[Components]
|
[Components]
|
||||||
|
Name: "disablesnippingtool"; Description: {cm:disablewin11snippingtool}; Flags: disablenouninstallwarning; Types: default full custom; Check: IsWindows11OrNewer()
|
||||||
Name: "greenshot"; Description: "Greenshot"; Types: default full compact custom; Flags: fixed
|
Name: "greenshot"; Description: "Greenshot"; Types: default full compact custom; Flags: fixed
|
||||||
;Name: "plugins\networkimport"; Description: "Network Import Plugin"; Types: full
|
;Name: "plugins\networkimport"; Description: "Network Import Plugin"; Types: full
|
||||||
Name: "plugins\box"; Description: {cm:box}; Types: full custom; Flags: disablenouninstallwarning
|
Name: "plugins\box"; Description: {cm:box}; Types: full custom; Flags: disablenouninstallwarning
|
||||||
|
@ -540,6 +545,7 @@ Name: "languages\ukUA"; Description: {cm:ukUA}; Types: full custom; Flags: disab
|
||||||
Name: "languages\viVN"; Description: {cm:viVN}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('e')
|
Name: "languages\viVN"; Description: {cm:viVN}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('e')
|
||||||
Name: "languages\zhCN"; Description: {cm:zhCN}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('a')
|
Name: "languages\zhCN"; Description: {cm:zhCN}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('a')
|
||||||
Name: "languages\zhTW"; Description: {cm:zhTW}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('9')
|
Name: "languages\zhTW"; Description: {cm:zhTW}; Types: full custom; Flags: disablenouninstallwarning; Check: hasLanguageGroup('9')
|
||||||
|
|
||||||
[Code]
|
[Code]
|
||||||
// Do we have a regular user trying to install this?
|
// Do we have a regular user trying to install this?
|
||||||
function IsRegularUser(): Boolean;
|
function IsRegularUser(): Boolean;
|
||||||
|
@ -754,6 +760,19 @@ begin
|
||||||
Result := IsWindowsVersionOrNewer(10, 0);
|
Result := IsWindowsVersionOrNewer(10, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function IsWindows11OrNewer: Boolean;
|
||||||
|
var
|
||||||
|
WindowsVersion: TWindowsVersion;
|
||||||
|
begin
|
||||||
|
GetWindowsVersionEx(WindowsVersion);
|
||||||
|
Result := (WindowsVersion.Major >= 10) and (WindowsVersion.Build >= 22000);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ShouldDisableSnippingTool: Boolean;
|
||||||
|
begin
|
||||||
|
Result := IsComponentSelected('disablesnippingtool');
|
||||||
|
end;
|
||||||
|
|
||||||
[Run]
|
[Run]
|
||||||
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: "https://getgreenshot.org/thank-you/?language={language}&version={#Version}"; Flags: shellexec runasoriginaluser
|
Filename: "https://getgreenshot.org/thank-you/?language={language}&version={#Version}"; Flags: shellexec runasoriginaluser
|
||||||
|
|
|
@ -1,323 +1,325 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* Greenshot - a free and open source screenshot tool
|
||||||
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
*
|
*
|
||||||
* For more information see: https://getgreenshot.org/
|
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Dapplo.Windows.Common.Structs;
|
using Dapplo.Windows.Common.Structs;
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Editor.Drawing.Fields;
|
using Greenshot.Editor.Drawing.Fields;
|
||||||
using Greenshot.Editor.Helpers;
|
using Greenshot.Editor.Helpers;
|
||||||
|
|
||||||
namespace Greenshot.Editor.Drawing
|
namespace Greenshot.Editor.Drawing
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of PathContainer.
|
/// Description of PathContainer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class FreehandContainer : DrawableContainer
|
public class FreehandContainer : DrawableContainer
|
||||||
{
|
{
|
||||||
private static readonly float[] PointOffset =
|
private static readonly float[] PointOffset =
|
||||||
{
|
{
|
||||||
0.5f, 0.25f, 0.75f
|
0.5f, 0.25f, 0.75f
|
||||||
};
|
};
|
||||||
|
|
||||||
[NonSerialized] private GraphicsPath freehandPath = new GraphicsPath();
|
[NonSerialized]
|
||||||
private NativeRect myBounds = NativeRect.Empty;
|
private GraphicsPath freehandPath = new GraphicsPath();
|
||||||
private NativePoint lastMouse = NativePoint.Empty;
|
|
||||||
private readonly List<Point> capturePoints = new List<Point>();
|
private Rectangle myBounds = NativeRect.Empty;
|
||||||
private bool isRecalculated;
|
private Point lastMouse = NativePoint.Empty;
|
||||||
|
private List<Point> capturePoints = new List<Point>();
|
||||||
/// <summary>
|
private bool isRecalculated;
|
||||||
/// Constructor
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public FreehandContainer(ISurface parent) : base(parent)
|
/// Constructor
|
||||||
{
|
/// </summary>
|
||||||
Width = parent.Image.Width;
|
public FreehandContainer(ISurface parent) : base(parent)
|
||||||
Height = parent.Image.Height;
|
{
|
||||||
Top = 0;
|
Width = parent.Image.Width;
|
||||||
Left = 0;
|
Height = parent.Image.Height;
|
||||||
}
|
Top = 0;
|
||||||
|
Left = 0;
|
||||||
protected override void InitializeFields()
|
}
|
||||||
{
|
|
||||||
AddField(GetType(), FieldType.LINE_THICKNESS, 3);
|
protected override void InitializeFields()
|
||||||
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
|
{
|
||||||
}
|
AddField(GetType(), FieldType.LINE_THICKNESS, 3);
|
||||||
|
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
|
||||||
public override void Transform(Matrix matrix)
|
}
|
||||||
{
|
|
||||||
Point[] points = capturePoints.ToArray();
|
public override void Transform(Matrix matrix)
|
||||||
|
{
|
||||||
matrix.TransformPoints(points);
|
Point[] points = capturePoints.ToArray();
|
||||||
capturePoints.Clear();
|
|
||||||
capturePoints.AddRange(points);
|
matrix.TransformPoints(points);
|
||||||
RecalculatePath();
|
capturePoints.Clear();
|
||||||
}
|
capturePoints.AddRange(points);
|
||||||
|
RecalculatePath();
|
||||||
protected override void OnDeserialized(StreamingContext context)
|
}
|
||||||
{
|
|
||||||
RecalculatePath();
|
protected override void OnDeserialized(StreamingContext context)
|
||||||
}
|
{
|
||||||
|
RecalculatePath();
|
||||||
/// <summary>
|
}
|
||||||
/// This Dispose is called from the Dispose and the Destructor.
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="disposing">When disposing==true all non-managed resources should be freed too!</param>
|
/// This Dispose is called from the Dispose and the Destructor.
|
||||||
protected override void Dispose(bool disposing)
|
/// </summary>
|
||||||
{
|
/// <param name="disposing">When disposing==true all non-managed resources should be freed too!</param>
|
||||||
base.Dispose(disposing);
|
protected override void Dispose(bool disposing)
|
||||||
if (disposing)
|
{
|
||||||
{
|
base.Dispose(disposing);
|
||||||
freehandPath?.Dispose();
|
if (disposing)
|
||||||
}
|
{
|
||||||
|
freehandPath?.Dispose();
|
||||||
freehandPath = null;
|
}
|
||||||
}
|
|
||||||
|
freehandPath = null;
|
||||||
/// <summary>
|
}
|
||||||
/// Called from Surface (the parent) when the drawing begins (mouse-down)
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <returns>true if the surface doesn't need to handle the event</returns>
|
/// Called from Surface (the parent) when the drawing begins (mouse-down)
|
||||||
public override bool HandleMouseDown(int mouseX, int mouseY)
|
/// </summary>
|
||||||
{
|
/// <returns>true if the surface doesn't need to handle the event</returns>
|
||||||
lastMouse = new Point(mouseX, mouseY);
|
public override bool HandleMouseDown(int mouseX, int mouseY)
|
||||||
capturePoints.Add(lastMouse);
|
{
|
||||||
return true;
|
lastMouse = new Point(mouseX, mouseY);
|
||||||
}
|
capturePoints.Add(lastMouse);
|
||||||
|
return true;
|
||||||
/// <summary>
|
}
|
||||||
/// Called from Surface (the parent) if a mouse move is made while drawing
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <returns>true if the surface doesn't need to handle the event</returns>
|
/// Called from Surface (the parent) if a mouse move is made while drawing
|
||||||
public override bool HandleMouseMove(int mouseX, int mouseY)
|
/// </summary>
|
||||||
{
|
/// <returns>true if the surface doesn't need to handle the event</returns>
|
||||||
Point previousPoint = capturePoints[capturePoints.Count - 1];
|
public override bool HandleMouseMove(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= 2 * EditorConfig.FreehandSensitivity)
|
Point previousPoint = capturePoints[capturePoints.Count - 1];
|
||||||
{
|
|
||||||
capturePoints.Add(new Point(mouseX, mouseY));
|
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= 2 * EditorConfig.FreehandSensitivity)
|
||||||
}
|
{
|
||||||
|
capturePoints.Add(new Point(mouseX, mouseY));
|
||||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) < EditorConfig.FreehandSensitivity)
|
}
|
||||||
{
|
|
||||||
return true;
|
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) < EditorConfig.FreehandSensitivity)
|
||||||
}
|
{
|
||||||
|
return true;
|
||||||
//path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)});
|
}
|
||||||
lastMouse = new Point(mouseX, mouseY);
|
|
||||||
freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY));
|
//path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)});
|
||||||
// Only re-calculate the bounds & redraw when we added something to the path
|
lastMouse = new Point(mouseX, mouseY);
|
||||||
myBounds = Rectangle.Round(freehandPath.GetBounds());
|
freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY));
|
||||||
|
// Only re-calculate the bounds & redraw when we added something to the path
|
||||||
Invalidate();
|
myBounds = Rectangle.Round(freehandPath.GetBounds());
|
||||||
return true;
|
|
||||||
}
|
Invalidate();
|
||||||
|
return true;
|
||||||
/// <summary>
|
}
|
||||||
/// Called when the surface finishes drawing the element
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public override void HandleMouseUp(int mouseX, int mouseY)
|
/// Called when the surface finishes drawing the element
|
||||||
{
|
/// </summary>
|
||||||
// Make sure we don't loose the ending point
|
public override void HandleMouseUp(int mouseX, int mouseY)
|
||||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= EditorConfig.FreehandSensitivity)
|
{
|
||||||
{
|
// Make sure we don't loose the ending point
|
||||||
capturePoints.Add(new Point(mouseX, mouseY));
|
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= EditorConfig.FreehandSensitivity)
|
||||||
}
|
{
|
||||||
|
capturePoints.Add(new Point(mouseX, mouseY));
|
||||||
RecalculatePath();
|
}
|
||||||
}
|
|
||||||
|
RecalculatePath();
|
||||||
/// <summary>
|
}
|
||||||
/// Here we recalculate the freehand path by smoothing out the lines with Beziers.
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
private void RecalculatePath()
|
/// Here we recalculate the freehand path by smoothing out the lines with Beziers.
|
||||||
{
|
/// </summary>
|
||||||
// Store the previous path, to dispose it later when we are finished
|
private void RecalculatePath()
|
||||||
var previousFreehandPath = freehandPath;
|
{
|
||||||
var newFreehandPath = new GraphicsPath();
|
// Store the previous path, to dispose it later when we are finished
|
||||||
|
var previousFreehandPath = freehandPath;
|
||||||
// Here we can put some cleanup... like losing all the uninteresting points.
|
var newFreehandPath = new GraphicsPath();
|
||||||
if (capturePoints.Count >= 3)
|
|
||||||
{
|
// Here we can put some cleanup... like losing all the uninteresting points.
|
||||||
int index = 0;
|
if (capturePoints.Count >= 3)
|
||||||
while ((capturePoints.Count - 1) % 3 != 0)
|
{
|
||||||
{
|
int index = 0;
|
||||||
// duplicate points, first at 50% than 25% than 75%
|
while ((capturePoints.Count - 1) % 3 != 0)
|
||||||
capturePoints.Insert((int) (capturePoints.Count * PointOffset[index]), capturePoints[(int) (capturePoints.Count * PointOffset[index++])]);
|
{
|
||||||
}
|
// duplicate points, first at 50% than 25% than 75%
|
||||||
|
capturePoints.Insert((int) (capturePoints.Count * PointOffset[index]), capturePoints[(int) (capturePoints.Count * PointOffset[index++])]);
|
||||||
newFreehandPath.AddBeziers(capturePoints.ToArray());
|
}
|
||||||
}
|
|
||||||
else if (capturePoints.Count == 2)
|
newFreehandPath.AddBeziers(capturePoints.ToArray());
|
||||||
{
|
}
|
||||||
newFreehandPath.AddLine(capturePoints[0], capturePoints[1]);
|
else if (capturePoints.Count == 2)
|
||||||
}
|
{
|
||||||
|
newFreehandPath.AddLine(capturePoints[0], capturePoints[1]);
|
||||||
// Recalculate the bounds
|
}
|
||||||
myBounds = Rectangle.Round(newFreehandPath.GetBounds());
|
|
||||||
|
// Recalculate the bounds
|
||||||
// assign
|
myBounds = Rectangle.Round(newFreehandPath.GetBounds());
|
||||||
isRecalculated = true;
|
|
||||||
freehandPath = newFreehandPath;
|
// assign
|
||||||
|
isRecalculated = true;
|
||||||
// dispose previous
|
freehandPath = newFreehandPath;
|
||||||
previousFreehandPath?.Dispose();
|
|
||||||
}
|
// dispose previous
|
||||||
|
previousFreehandPath?.Dispose();
|
||||||
/// <summary>
|
}
|
||||||
/// Do the drawing of the freehand "stroke"
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="graphics"></param>
|
/// Do the drawing of the freehand "stroke"
|
||||||
/// <param name="renderMode"></param>
|
/// </summary>
|
||||||
public override void Draw(Graphics graphics, RenderMode renderMode)
|
/// <param name="graphics"></param>
|
||||||
{
|
/// <param name="renderMode"></param>
|
||||||
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
public override void Draw(Graphics graphics, RenderMode renderMode)
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
{
|
||||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
graphics.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
|
||||||
using var pen = new Pen(lineColor)
|
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||||
{
|
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||||
Width = lineThickness
|
using var pen = new Pen(lineColor)
|
||||||
};
|
{
|
||||||
if (!(pen.Width > 0))
|
Width = lineThickness
|
||||||
{
|
};
|
||||||
return;
|
if (!(pen.Width > 0))
|
||||||
}
|
{
|
||||||
|
return;
|
||||||
// Make sure the lines are nicely rounded
|
}
|
||||||
pen.EndCap = LineCap.Round;
|
|
||||||
pen.StartCap = LineCap.Round;
|
// Make sure the lines are nicely rounded
|
||||||
pen.LineJoin = LineJoin.Round;
|
pen.EndCap = LineCap.Round;
|
||||||
// Move to where we need to draw
|
pen.StartCap = LineCap.Round;
|
||||||
graphics.TranslateTransform(Left, Top);
|
pen.LineJoin = LineJoin.Round;
|
||||||
var currentFreehandPath = freehandPath;
|
// Move to where we need to draw
|
||||||
if (currentFreehandPath != null)
|
graphics.TranslateTransform(Left, Top);
|
||||||
{
|
var currentFreehandPath = freehandPath;
|
||||||
if (isRecalculated && Selected && renderMode == RenderMode.EDIT)
|
if (currentFreehandPath != null)
|
||||||
{
|
{
|
||||||
isRecalculated = false;
|
if (isRecalculated && Selected && renderMode == RenderMode.EDIT)
|
||||||
DrawSelectionBorder(graphics, pen, currentFreehandPath);
|
{
|
||||||
}
|
isRecalculated = false;
|
||||||
|
DrawSelectionBorder(graphics, pen, currentFreehandPath);
|
||||||
graphics.DrawPath(pen, currentFreehandPath);
|
}
|
||||||
}
|
|
||||||
|
graphics.DrawPath(pen, currentFreehandPath);
|
||||||
// Move back, otherwise everything is shifted
|
}
|
||||||
graphics.TranslateTransform(-Left, -Top);
|
|
||||||
}
|
// Move back, otherwise everything is shifted
|
||||||
|
graphics.TranslateTransform(-Left, -Top);
|
||||||
/// <summary>
|
}
|
||||||
/// Draw a selectionborder around the freehand path
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="graphics">Graphics</param>
|
/// Draw a selectionborder around the freehand path
|
||||||
/// <param name="linePen">Pen</param>
|
/// </summary>
|
||||||
/// <param name="path">GraphicsPath</param>
|
/// <param name="graphics">Graphics</param>
|
||||||
protected static void DrawSelectionBorder(Graphics graphics, Pen linePen, GraphicsPath path)
|
/// <param name="linePen">Pen</param>
|
||||||
{
|
/// <param name="path">GraphicsPath</param>
|
||||||
using var selectionPen = (Pen) linePen.Clone();
|
protected static void DrawSelectionBorder(Graphics graphics, Pen linePen, GraphicsPath path)
|
||||||
using var selectionPath = (GraphicsPath) path.Clone();
|
{
|
||||||
selectionPen.Width += 5;
|
using var selectionPen = (Pen) linePen.Clone();
|
||||||
selectionPen.Color = Color.FromArgb(120, Color.LightSeaGreen);
|
using var selectionPath = (GraphicsPath) path.Clone();
|
||||||
graphics.DrawPath(selectionPen, selectionPath);
|
selectionPen.Width += 5;
|
||||||
selectionPath.Widen(selectionPen);
|
selectionPen.Color = Color.FromArgb(120, Color.LightSeaGreen);
|
||||||
selectionPen.DashPattern = new float[]
|
graphics.DrawPath(selectionPen, selectionPath);
|
||||||
{
|
selectionPath.Widen(selectionPen);
|
||||||
2, 2
|
selectionPen.DashPattern = new float[]
|
||||||
};
|
{
|
||||||
selectionPen.Color = Color.LightSeaGreen;
|
2, 2
|
||||||
selectionPen.Width = 1;
|
};
|
||||||
graphics.DrawPath(selectionPen, selectionPath);
|
selectionPen.Color = Color.LightSeaGreen;
|
||||||
}
|
selectionPen.Width = 1;
|
||||||
|
graphics.DrawPath(selectionPen, selectionPath);
|
||||||
/// <summary>
|
}
|
||||||
/// Get the bounds in which we have something drawn, plus safety margin, these are not the normal bounds...
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
public override NativeRect DrawingBounds
|
/// Get the bounds in which we have something drawn, plus safety margin, these are not the normal bounds...
|
||||||
{
|
/// </summary>
|
||||||
get
|
public override NativeRect DrawingBounds
|
||||||
{
|
{
|
||||||
if (!myBounds.IsEmpty)
|
get
|
||||||
{
|
{
|
||||||
int lineThickness = Math.Max(10, GetFieldValueAsInt(FieldType.LINE_THICKNESS));
|
if (!myBounds.IsEmpty)
|
||||||
int safetyMargin = 10;
|
{
|
||||||
return new NativeRect(myBounds.Left + Left - (safetyMargin + lineThickness), myBounds.Top + Top - (safetyMargin + lineThickness),
|
int lineThickness = Math.Max(10, GetFieldValueAsInt(FieldType.LINE_THICKNESS));
|
||||||
myBounds.Width + 2 * (lineThickness + safetyMargin), myBounds.Height + 2 * (lineThickness + safetyMargin));
|
int safetyMargin = 10;
|
||||||
}
|
return new NativeRect(myBounds.Left + Left - (safetyMargin + lineThickness), myBounds.Top + Top - (safetyMargin + lineThickness),
|
||||||
|
myBounds.Width + 2 * (lineThickness + safetyMargin), myBounds.Height + 2 * (lineThickness + safetyMargin));
|
||||||
if (_parent?.Image is Image image)
|
}
|
||||||
{
|
|
||||||
return new NativeRect(0, 0, image.Width, image.Height);
|
if (_parent?.Image is Image image)
|
||||||
}
|
{
|
||||||
|
return new NativeRect(0, 0, image.Width, image.Height);
|
||||||
return NativeRect.Empty;
|
}
|
||||||
}
|
|
||||||
}
|
return NativeRect.Empty;
|
||||||
|
}
|
||||||
/// <summary>
|
}
|
||||||
/// FreehandContainer are regarded equal if they are of the same type and their paths are equal.
|
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="obj">object</param>
|
/// FreehandContainer are regarded equal if they are of the same type and their paths are equal.
|
||||||
/// <returns>bool</returns>
|
/// </summary>
|
||||||
public override bool Equals(object obj)
|
/// <param name="obj">object</param>
|
||||||
{
|
/// <returns>bool</returns>
|
||||||
bool ret = false;
|
public override bool Equals(object obj)
|
||||||
if (obj == null || GetType() != obj.GetType())
|
{
|
||||||
{
|
bool ret = false;
|
||||||
return false;
|
if (obj == null || GetType() != obj.GetType())
|
||||||
}
|
{
|
||||||
|
return false;
|
||||||
if (obj is FreehandContainer other && Equals(freehandPath, other.freehandPath))
|
}
|
||||||
{
|
|
||||||
ret = true;
|
if (obj is FreehandContainer other && Equals(freehandPath, other.freehandPath))
|
||||||
}
|
{
|
||||||
|
ret = true;
|
||||||
return ret;
|
}
|
||||||
}
|
|
||||||
|
return ret;
|
||||||
public override int GetHashCode()
|
}
|
||||||
{
|
|
||||||
return freehandPath?.GetHashCode() ?? 0;
|
public override int GetHashCode()
|
||||||
}
|
{
|
||||||
|
return freehandPath?.GetHashCode() ?? 0;
|
||||||
public override bool ClickableAt(int x, int y)
|
}
|
||||||
{
|
|
||||||
bool returnValue = base.ClickableAt(x, y);
|
public override bool ClickableAt(int x, int y)
|
||||||
if (returnValue)
|
{
|
||||||
{
|
bool returnValue = base.ClickableAt(x, y);
|
||||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
if (returnValue)
|
||||||
using var pen = new Pen(Color.White)
|
{
|
||||||
{
|
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
|
||||||
Width = lineThickness + 10
|
using var pen = new Pen(Color.White)
|
||||||
};
|
{
|
||||||
returnValue = freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
|
Width = lineThickness + 10
|
||||||
}
|
};
|
||||||
|
returnValue = freehandPath.IsOutlineVisible(x - Left, y - Top, pen);
|
||||||
return returnValue;
|
}
|
||||||
}
|
|
||||||
}
|
return returnValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -39,10 +39,10 @@ namespace Greenshot.Editor.Drawing
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SpeechbubbleContainer : TextContainer
|
public class SpeechbubbleContainer : TextContainer
|
||||||
{
|
{
|
||||||
private NativePoint _initialGripperPoint;
|
private Point _initialGripperPoint;
|
||||||
|
|
||||||
// Only used for serializing the TargetGripper location
|
// Only used for serializing the TargetGripper location
|
||||||
private NativePoint _storedTargetGripperLocation;
|
private Point _storedTargetGripperLocation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Store the current location of the target gripper
|
/// Store the current location of the target gripper
|
||||||
|
@ -120,7 +120,8 @@ namespace Greenshot.Editor.Drawing
|
||||||
int xOffset = leftAligned ? -20 : 20;
|
int xOffset = leftAligned ? -20 : 20;
|
||||||
int yOffset = topAligned ? -20 : 20;
|
int yOffset = topAligned ? -20 : 20;
|
||||||
|
|
||||||
NativePoint newGripperLocation = _initialGripperPoint.Offset(xOffset, yOffset);
|
NativePoint initialGripperPoint = _initialGripperPoint;
|
||||||
|
NativePoint newGripperLocation = initialGripperPoint.Offset(xOffset, yOffset);
|
||||||
|
|
||||||
if (TargetAdorner.Location != newGripperLocation)
|
if (TargetAdorner.Location != newGripperLocation)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@ using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.ServiceModel.Security;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Dapplo.Windows.Common.Extensions;
|
using Dapplo.Windows.Common.Extensions;
|
||||||
using Dapplo.Windows.Common.Structs;
|
using Dapplo.Windows.Common.Structs;
|
||||||
|
@ -41,6 +42,7 @@ using Greenshot.Base.Interfaces.Drawing.Adorners;
|
||||||
using Greenshot.Editor.Configuration;
|
using Greenshot.Editor.Configuration;
|
||||||
using Greenshot.Editor.Drawing.Emoji;
|
using Greenshot.Editor.Drawing.Emoji;
|
||||||
using Greenshot.Editor.Drawing.Fields;
|
using Greenshot.Editor.Drawing.Fields;
|
||||||
|
using Greenshot.Editor.Helpers;
|
||||||
using Greenshot.Editor.Memento;
|
using Greenshot.Editor.Memento;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
|
@ -723,6 +725,7 @@ namespace Greenshot.Editor.Drawing
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BinaryFormatter binaryRead = new BinaryFormatter();
|
BinaryFormatter binaryRead = new BinaryFormatter();
|
||||||
|
binaryRead.Binder = new BinaryFormatterHelper();
|
||||||
IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead);
|
IDrawableContainerList loadedElements = (IDrawableContainerList) binaryRead.Deserialize(streamRead);
|
||||||
loadedElements.Parent = this;
|
loadedElements.Parent = this;
|
||||||
// Make sure the steplabels are sorted according to their number
|
// Make sure the steplabels are sorted according to their number
|
||||||
|
@ -732,6 +735,10 @@ namespace Greenshot.Editor.Drawing
|
||||||
SelectElements(loadedElements);
|
SelectElements(loadedElements);
|
||||||
FieldAggregator.BindElements(loadedElements);
|
FieldAggregator.BindElements(loadedElements);
|
||||||
}
|
}
|
||||||
|
catch (SecurityAccessDeniedException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
LOG.Error("Error serializing elements from stream.", e);
|
LOG.Error("Error serializing elements from stream.", e);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using Dapplo.Windows.Common.Structs;
|
using Dapplo.Windows.Common.Structs;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
|
@ -34,14 +35,32 @@ namespace Greenshot.Editor.Drawing
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SvgContainer : VectorGraphicsContainer
|
public class SvgContainer : VectorGraphicsContainer
|
||||||
{
|
{
|
||||||
private readonly SvgDocument _svgDocument;
|
private MemoryStream _svgContent;
|
||||||
|
|
||||||
public SvgContainer(SvgDocument svgDocument, ISurface parent) : base(parent)
|
[NonSerialized]
|
||||||
|
private SvgDocument _svgDocument;
|
||||||
|
|
||||||
|
public SvgContainer(Stream stream, ISurface parent) : base(parent)
|
||||||
{
|
{
|
||||||
_svgDocument = svgDocument;
|
_svgContent = new MemoryStream();
|
||||||
Size = new Size((int)svgDocument.Width, (int)svgDocument.Height);
|
stream.CopyTo(_svgContent);
|
||||||
|
Init();
|
||||||
|
Size = new Size((int)_svgDocument.Width, (int)_svgDocument.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Init()
|
||||||
|
{
|
||||||
|
base.Init();
|
||||||
|
// Do nothing when there is no content
|
||||||
|
if (_svgContent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_svgContent.Position = 0;
|
||||||
|
|
||||||
|
_svgDocument = SvgDocument.Open<SvgDocument>(_svgContent);
|
||||||
|
}
|
||||||
|
|
||||||
protected override Image ComputeBitmap()
|
protected override Image ComputeBitmap()
|
||||||
{
|
{
|
||||||
//var image = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent);
|
//var image = ImageHelper.CreateEmpty(Width, Height, PixelFormat.Format32bppArgb, Color.Transparent);
|
||||||
|
|
|
@ -47,7 +47,8 @@ namespace Greenshot.Editor.Drawing
|
||||||
/// This is the cached version of the bitmap, pre-rendered to save performance
|
/// This is the cached version of the bitmap, pre-rendered to save performance
|
||||||
/// Do not serialized, it can be rebuild with other information.
|
/// Do not serialized, it can be rebuild with other information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized] private Image _cachedImage;
|
[NonSerialized]
|
||||||
|
private Image _cachedImage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor takes care of calling Init
|
/// Constructor takes care of calling Init
|
||||||
|
|
|
@ -1,89 +1,89 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* Greenshot - a free and open source screenshot tool
|
||||||
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
*
|
*
|
||||||
* For more information see: https://getgreenshot.org/
|
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Base.Interfaces.Plugin;
|
using Greenshot.Base.Interfaces.Plugin;
|
||||||
using Greenshot.Editor.Drawing;
|
using Greenshot.Editor.Drawing;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Svg;
|
using Svg;
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This handled the loading of SVG images to the editor
|
/// This handled the loading of SVG images to the editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SvgFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class SvgFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(SvgFileFormatHandler));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SvgFileFormatHandler));
|
||||||
private readonly IReadOnlyCollection<string> _ourExtensions = new[] { ".svg" };
|
private readonly IReadOnlyCollection<string> _ourExtensions = new[] { ".svg" };
|
||||||
|
|
||||||
public SvgFileFormatHandler()
|
public SvgFileFormatHandler()
|
||||||
{
|
{
|
||||||
SupportedExtensions[FileFormatHandlerActions.LoadDrawableFromStream] = _ourExtensions;
|
SupportedExtensions[FileFormatHandlerActions.LoadDrawableFromStream] = _ourExtensions;
|
||||||
SupportedExtensions[FileFormatHandlerActions.LoadFromStream] = _ourExtensions;
|
SupportedExtensions[FileFormatHandlerActions.LoadFromStream] = _ourExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bitmap = svgDocument.Draw();
|
bitmap = svgDocument.Draw();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error("Can't load SVG", ex);
|
Log.Error("Can't load SVG", ex);
|
||||||
}
|
}
|
||||||
bitmap = null;
|
bitmap = null;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension, ISurface surface = null, SurfaceOutputSettings surfaceOutputSettings = null)
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension, ISurface surface = null, SurfaceOutputSettings surfaceOutputSettings = null)
|
||||||
{
|
{
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<IDrawableContainer> LoadDrawablesFromStream(Stream stream, string extension, ISurface parent = null)
|
public override IEnumerable<IDrawableContainer> LoadDrawablesFromStream(Stream stream, string extension, ISurface parent = null)
|
||||||
{
|
{
|
||||||
SvgDocument svgDocument = null;
|
SvgContainer svgContainer = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
svgContainer = new SvgContainer(stream, parent);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error("Can't load SVG", ex);
|
Log.Error("Can't load SVG", ex);
|
||||||
}
|
}
|
||||||
if (svgDocument != null)
|
if (svgContainer != null)
|
||||||
{
|
{
|
||||||
yield return new SvgContainer(svgDocument, parent);
|
yield return svgContainer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
123
src/Greenshot.Editor/Helpers/BinaryFormatterHelper.cs
Normal file
123
src/Greenshot.Editor/Helpers/BinaryFormatterHelper.cs
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.ServiceModel.Security;
|
||||||
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
|
using Greenshot.Editor.Drawing;
|
||||||
|
using Greenshot.Editor.Drawing.Fields;
|
||||||
|
using Greenshot.Editor.Drawing.Filters;
|
||||||
|
using log4net;
|
||||||
|
using static Greenshot.Editor.Drawing.FilterContainer;
|
||||||
|
|
||||||
|
namespace Greenshot.Editor.Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This helps to map the serialization of the old .greenshot file to the newer.
|
||||||
|
/// It also prevents misuse.
|
||||||
|
/// </summary>
|
||||||
|
internal class BinaryFormatterHelper : SerializationBinder
|
||||||
|
{
|
||||||
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(BinaryFormatterHelper));
|
||||||
|
private static readonly IDictionary<string, Type> TypeMapper = new Dictionary<string, Type>
|
||||||
|
{
|
||||||
|
{"System.Guid",typeof(Guid) },
|
||||||
|
{"System.Drawing.Rectangle",typeof(System.Drawing.Rectangle) },
|
||||||
|
{"System.Drawing.Point",typeof(System.Drawing.Point) },
|
||||||
|
{"System.Drawing.Color",typeof(System.Drawing.Color) },
|
||||||
|
{"System.Drawing.Bitmap",typeof(System.Drawing.Bitmap) },
|
||||||
|
{"System.Drawing.Icon",typeof(System.Drawing.Icon) },
|
||||||
|
{"System.Drawing.Size",typeof(System.Drawing.Size) },
|
||||||
|
{"System.IO.MemoryStream",typeof(System.IO.MemoryStream) },
|
||||||
|
{"System.Drawing.StringAlignment",typeof(System.Drawing.StringAlignment) },
|
||||||
|
{"System.Collections.Generic.List`1[[Greenshot.Base.Interfaces.Drawing.IFieldHolder", typeof(List<IFieldHolder>)},
|
||||||
|
{"System.Collections.Generic.List`1[[Greenshot.Base.Interfaces.Drawing.IField", typeof(List<IField>)},
|
||||||
|
{"System.Collections.Generic.List`1[[System.Drawing.Point", typeof(List<System.Drawing.Point>)},
|
||||||
|
{"Greenshot.Editor.Drawing.ArrowContainer", typeof(ArrowContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.LineContainer", typeof(LineContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.TextContainer", typeof(TextContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.SpeechbubbleContainer", typeof(SpeechbubbleContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.RectangleContainer", typeof(RectangleContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.EllipseContainer", typeof(EllipseContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.FreehandContainer", typeof(FreehandContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.HighlightContainer", typeof(HighlightContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.IconContainer", typeof(IconContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.ObfuscateContainer", typeof(ObfuscateContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.StepLabelContainer", typeof(StepLabelContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.SvgContainer", typeof(SvgContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.VectorGraphicsContainer", typeof(VectorGraphicsContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.MetafileContainer", typeof(MetafileContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.ImageContainer", typeof(ImageContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.FilterContainer", typeof(FilterContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.DrawableContainer", typeof(DrawableContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.DrawableContainerList", typeof(DrawableContainerList) },
|
||||||
|
{"Greenshot.Editor.Drawing.CursorContainer", typeof(CursorContainer) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.HighlightFilter", typeof(HighlightFilter) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.GrayscaleFilter", typeof(GrayscaleFilter) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.MagnifierFilter", typeof(MagnifierFilter) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.BrightnessFilter", typeof(BrightnessFilter) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.BlurFilter", typeof(BlurFilter) },
|
||||||
|
{"Greenshot.Editor.Drawing.Filters.PixelizationFilter", typeof(PixelizationFilter) },
|
||||||
|
{"Greenshot.Base.Interfaces.Drawing.IDrawableContainer", typeof(IDrawableContainer) },
|
||||||
|
{"Greenshot.Base.Interfaces.Drawing.EditStatus", typeof(EditStatus) },
|
||||||
|
{"Greenshot.Base.Interfaces.Drawing.IFieldHolder", typeof(IFieldHolder) },
|
||||||
|
{"Greenshot.Base.Interfaces.Drawing.IField", typeof(IField) },
|
||||||
|
{"Greenshot.Base.Interfaces.Drawing.FieldFlag", typeof(FieldFlag) },
|
||||||
|
{"Greenshot.Editor.Drawing.Fields.Field", typeof(Field) },
|
||||||
|
{"Greenshot.Editor.Drawing.Fields.FieldType", typeof(FieldType) },
|
||||||
|
{"Greenshot.Editor.Drawing.FilterContainer+PreparedFilter", typeof(PreparedFilter) },
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Do the type mapping
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="assemblyName">Assembly for the type that was serialized</param>
|
||||||
|
/// <param name="typeName">Type that was serialized</param>
|
||||||
|
/// <returns>Type which was mapped</returns>
|
||||||
|
/// <exception cref="SecurityAccessDeniedException">If something smells fishy</exception>
|
||||||
|
public override Type BindToType(string assemblyName, string typeName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(typeName))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var typeNameCommaLocation = typeName.IndexOf(",");
|
||||||
|
var comparingTypeName = typeName.Substring(0, typeNameCommaLocation > 0 ? typeNameCommaLocation : typeName.Length);
|
||||||
|
|
||||||
|
// Correct wrong types
|
||||||
|
comparingTypeName = comparingTypeName.Replace("Greenshot.Drawing", "Greenshot.Editor.Drawing");
|
||||||
|
comparingTypeName = comparingTypeName.Replace("Greenshot.Plugin.Drawing", "Greenshot.Base.Interfaces.Drawing");
|
||||||
|
comparingTypeName = comparingTypeName.Replace("GreenshotPlugin.Interfaces.Drawing", "Greenshot.Base.Interfaces.Drawing");
|
||||||
|
comparingTypeName = comparingTypeName.Replace("Greenshot.Drawing.Fields", "Greenshot.Editor.Drawing.Fields");
|
||||||
|
comparingTypeName = comparingTypeName.Replace("Greenshot.Drawing.Filters", "Greenshot.Editor.Drawing.Filters");
|
||||||
|
|
||||||
|
if (TypeMapper.TryGetValue(comparingTypeName, out var returnType))
|
||||||
|
{
|
||||||
|
LOG.Info($"Mapped {assemblyName} - {typeName} to {returnType.FullName}");
|
||||||
|
return returnType;
|
||||||
|
}
|
||||||
|
LOG.Warn($"Unexpected Greenshot type in .greenshot file detected, maybe vulnerability attack created with ysoserial? Suspicious type: {assemblyName} - {typeName}");
|
||||||
|
throw new SecurityAccessDeniedException($"Suspicious type in .greenshot file: {assemblyName} - {typeName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue