mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
This commit breaks compiling for a short (!) period, need to sync my work to a different system
This commit is contained in:
parent
1751880581
commit
684a7615d7
38 changed files with 1845 additions and 1324 deletions
|
@ -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/>.
|
||||||
*/
|
*/
|
||||||
|
@ -65,15 +65,9 @@ namespace Greenshot.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid ID
|
public Guid ID
|
||||||
{
|
{
|
||||||
get
|
get => _uniqueId;
|
||||||
{
|
set => _uniqueId = value;
|
||||||
return _uniqueId;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_uniqueId = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event handlers (do not serialize!)
|
/// Event handlers (do not serialize!)
|
||||||
|
@ -82,69 +76,39 @@ namespace Greenshot.Drawing
|
||||||
private PropertyChangedEventHandler _propertyChanged;
|
private PropertyChangedEventHandler _propertyChanged;
|
||||||
public event PropertyChangedEventHandler PropertyChanged
|
public event PropertyChangedEventHandler PropertyChanged
|
||||||
{
|
{
|
||||||
add
|
add => _propertyChanged += value;
|
||||||
{
|
remove => _propertyChanged -= value;
|
||||||
_propertyChanged += value;
|
}
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_propertyChanged -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private SurfaceElementEventHandler _movingElementChanged;
|
private SurfaceElementEventHandler _movingElementChanged;
|
||||||
public event SurfaceElementEventHandler MovingElementChanged
|
public event SurfaceElementEventHandler MovingElementChanged
|
||||||
{
|
{
|
||||||
add
|
add => _movingElementChanged += value;
|
||||||
{
|
remove => _movingElementChanged -= value;
|
||||||
_movingElementChanged += value;
|
}
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_movingElementChanged -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private SurfaceDrawingModeEventHandler _drawingModeChanged;
|
private SurfaceDrawingModeEventHandler _drawingModeChanged;
|
||||||
public event SurfaceDrawingModeEventHandler DrawingModeChanged
|
public event SurfaceDrawingModeEventHandler DrawingModeChanged
|
||||||
{
|
{
|
||||||
add
|
add => _drawingModeChanged += value;
|
||||||
{
|
remove => _drawingModeChanged -= value;
|
||||||
_drawingModeChanged += value;
|
}
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_drawingModeChanged -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private SurfaceSizeChangeEventHandler _surfaceSizeChanged;
|
private SurfaceSizeChangeEventHandler _surfaceSizeChanged;
|
||||||
public event SurfaceSizeChangeEventHandler SurfaceSizeChanged
|
public event SurfaceSizeChangeEventHandler SurfaceSizeChanged
|
||||||
{
|
{
|
||||||
add
|
add => _surfaceSizeChanged += value;
|
||||||
{
|
remove => _surfaceSizeChanged -= value;
|
||||||
_surfaceSizeChanged += value;
|
}
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_surfaceSizeChanged -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private SurfaceMessageEventHandler _surfaceMessage;
|
private SurfaceMessageEventHandler _surfaceMessage;
|
||||||
public event SurfaceMessageEventHandler SurfaceMessage
|
public event SurfaceMessageEventHandler SurfaceMessage
|
||||||
{
|
{
|
||||||
add
|
add => _surfaceMessage += value;
|
||||||
{
|
remove => _surfaceMessage -= value;
|
||||||
_surfaceMessage += value;
|
}
|
||||||
}
|
|
||||||
remove
|
|
||||||
{
|
|
||||||
_surfaceMessage -= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// inUndoRedo makes sure we don't undo/redo while in a undo/redo action
|
/// inUndoRedo makes sure we don't undo/redo while in a undo/redo action
|
||||||
|
@ -153,7 +117,7 @@ namespace Greenshot.Drawing
|
||||||
private bool _inUndoRedo;
|
private bool _inUndoRedo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make only one surfacemove cycle undoable, see SurfaceMouseMove
|
/// Make only one surface move cycle undoable, see SurfaceMouseMove
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private bool _isSurfaceMoveMadeUndoable;
|
private bool _isSurfaceMoveMadeUndoable;
|
||||||
|
@ -179,7 +143,7 @@ namespace Greenshot.Drawing
|
||||||
private DrawingModes _drawingMode = DrawingModes.None;
|
private DrawingModes _drawingMode = DrawingModes.None;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// the keyslocked flag helps with focus issues
|
/// the keys-locked flag helps with focus issues
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
private bool _keysLocked;
|
private bool _keysLocked;
|
||||||
|
@ -265,8 +229,8 @@ namespace Greenshot.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CounterStart
|
public int CounterStart
|
||||||
{
|
{
|
||||||
get { return _counterStart; }
|
get => _counterStart;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_counterStart == value)
|
if (_counterStart == value)
|
||||||
{
|
{
|
||||||
|
@ -330,11 +294,8 @@ namespace Greenshot.Drawing
|
||||||
private Image _image;
|
private Image _image;
|
||||||
public Image Image
|
public Image Image
|
||||||
{
|
{
|
||||||
get
|
get => _image;
|
||||||
{
|
set
|
||||||
return _image;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
{
|
||||||
_image = value;
|
_image = value;
|
||||||
Size = _image.Size;
|
Size = _image.Size;
|
||||||
|
@ -347,15 +308,9 @@ namespace Greenshot.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FieldAggregator FieldAggregator
|
public FieldAggregator FieldAggregator
|
||||||
{
|
{
|
||||||
get
|
get => _fieldAggregator;
|
||||||
{
|
set => _fieldAggregator = value;
|
||||||
return _fieldAggregator;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_fieldAggregator = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The cursor container has it's own accessor so we can find and remove this (when needed)
|
/// The cursor container has it's own accessor so we can find and remove this (when needed)
|
||||||
|
@ -381,53 +336,35 @@ namespace Greenshot.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Brush TransparencyBackgroundBrush
|
public Brush TransparencyBackgroundBrush
|
||||||
{
|
{
|
||||||
get
|
get => _transparencyBackgroundBrush;
|
||||||
{
|
set => _transparencyBackgroundBrush = value;
|
||||||
return _transparencyBackgroundBrush;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_transparencyBackgroundBrush = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Are the keys on this surface locked?
|
/// Are the keys on this surface locked?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool KeysLocked
|
public bool KeysLocked
|
||||||
{
|
{
|
||||||
get
|
get => _keysLocked;
|
||||||
{
|
set => _keysLocked = value;
|
||||||
return _keysLocked;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_keysLocked = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is this surface modified? This is only true if the surface has not been exported.
|
/// Is this surface modified? This is only true if the surface has not been exported.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Modified
|
public bool Modified
|
||||||
{
|
{
|
||||||
get
|
get => _modified;
|
||||||
{
|
set => _modified = value;
|
||||||
return _modified;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_modified = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The DrawingMode property specifies the mode for drawing, more or less the element type.
|
/// The DrawingMode property specifies the mode for drawing, more or less the element type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DrawingModes DrawingMode
|
public DrawingModes DrawingMode
|
||||||
{
|
{
|
||||||
get { return _drawingMode; }
|
get => _drawingMode;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_drawingMode = value;
|
_drawingMode = value;
|
||||||
if (_drawingModeChanged != null)
|
if (_drawingModeChanged != null)
|
||||||
|
@ -448,15 +385,9 @@ namespace Greenshot.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string LastSaveFullPath
|
public string LastSaveFullPath
|
||||||
{
|
{
|
||||||
get
|
get => _lastSaveFullPath;
|
||||||
{
|
set => _lastSaveFullPath = value;
|
||||||
return _lastSaveFullPath;
|
}
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_lastSaveFullPath = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Property for accessing the URL to which the surface was recently uploaded
|
/// Property for accessing the URL to which the surface was recently uploaded
|
||||||
|
@ -1518,7 +1449,7 @@ namespace Greenshot.Drawing
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw a checkboard when capturing with transparency
|
/// Draw a checkboard when capturing with transparency
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="e">PaintEventArgs</param>
|
/// <param name="e">PaintEventArgs</param>
|
||||||
protected override void OnPaintBackground(PaintEventArgs e)
|
protected override void OnPaintBackground(PaintEventArgs e)
|
||||||
|
|
|
@ -39,6 +39,7 @@ using System.Windows.Forms;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using GreenshotPlugin.IniFile;
|
using GreenshotPlugin.IniFile;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using GreenshotPlugin.Interfaces.Ocr;
|
||||||
using ZXing;
|
using ZXing;
|
||||||
|
|
||||||
namespace Greenshot.Forms {
|
namespace Greenshot.Forms {
|
||||||
|
@ -308,7 +309,7 @@ namespace Greenshot.Forms {
|
||||||
TopMost = !TopMost;
|
TopMost = !TopMost;
|
||||||
break;
|
break;
|
||||||
case Keys.O:
|
case Keys.O:
|
||||||
if (_capture.OcrInformation is null)
|
if (_capture.CaptureDetails.OcrInformation is null)
|
||||||
{
|
{
|
||||||
var ocrProvider = SimpleServiceProvider.Current.GetInstance<IOcrProvider>();
|
var ocrProvider = SimpleServiceProvider.Current.GetInstance<IOcrProvider>();
|
||||||
if (ocrProvider is object)
|
if (ocrProvider is object)
|
||||||
|
@ -317,36 +318,12 @@ namespace Greenshot.Forms {
|
||||||
|
|
||||||
Task.Factory.StartNew(async () =>
|
Task.Factory.StartNew(async () =>
|
||||||
{
|
{
|
||||||
_capture.OcrInformation = await ocrProvider.DoOcrAsync(_capture.Image);
|
_capture.CaptureDetails.OcrInformation = await ocrProvider.DoOcrAsync(_capture.Image);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}, CancellationToken.None, TaskCreationOptions.None, uiTaskScheduler);
|
}, CancellationToken.None, TaskCreationOptions.None, uiTaskScheduler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Keys.Q:
|
|
||||||
// create a barcode reader instance
|
|
||||||
IBarcodeReader reader = new BarcodeReader();
|
|
||||||
// detect and decode the barcode inside the bitmap
|
|
||||||
var result = reader.Decode((Bitmap)_capture.Image);
|
|
||||||
// do something with the result
|
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
Log.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
|
|
||||||
using var graphics = Graphics.FromImage(_capture.Image);
|
|
||||||
var boundingBox = BoundingBox(result.ResultPoints.Select(p => new Point((int) p.X, (int) p.Y)));
|
|
||||||
|
|
||||||
using var pen = new Pen(Color.BlueViolet, 10);
|
|
||||||
using var solidBrush = new SolidBrush(Color.Green);
|
|
||||||
|
|
||||||
using var solidWhiteBrush = new SolidBrush(Color.White);
|
|
||||||
using var font = new Font(FontFamily.GenericSerif, 12, FontStyle.Regular);
|
|
||||||
graphics.FillRectangle(solidWhiteBrush, boundingBox);
|
|
||||||
graphics.DrawRectangle(pen, boundingBox);
|
|
||||||
graphics.DrawString(result.Text, font, solidBrush, boundingBox);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,7 +739,7 @@ namespace Greenshot.Forms {
|
||||||
//graphics.BitBlt((Bitmap)buffer, Point.Empty);
|
//graphics.BitBlt((Bitmap)buffer, Point.Empty);
|
||||||
graphics.DrawImageUnscaled(_capture.Image, Point.Empty);
|
graphics.DrawImageUnscaled(_capture.Image, Point.Empty);
|
||||||
|
|
||||||
var ocrInfo = _capture.OcrInformation;
|
var ocrInfo = _capture.CaptureDetails.OcrInformation;
|
||||||
if (ocrInfo != null)
|
if (ocrInfo != null)
|
||||||
{
|
{
|
||||||
using var pen = new Pen(Color.Red);
|
using var pen = new Pen(Color.Red);
|
||||||
|
@ -775,6 +752,25 @@ namespace Greenshot.Forms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_capture.CaptureDetails.QrResult != null)
|
||||||
|
{
|
||||||
|
var result = _capture.CaptureDetails.QrResult;
|
||||||
|
|
||||||
|
Log.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
|
||||||
|
var boundingBox = BoundingBox(result.ResultPoints.Select(p => new Point((int)p.X, (int)p.Y)));
|
||||||
|
|
||||||
|
using var pen = new Pen(Color.BlueViolet, 10);
|
||||||
|
using var solidBrush = new SolidBrush(Color.Green);
|
||||||
|
|
||||||
|
using var solidWhiteBrush = new SolidBrush(Color.White);
|
||||||
|
using var font = new Font(FontFamily.GenericSerif, 12, FontStyle.Regular);
|
||||||
|
graphics.FillRectangle(solidWhiteBrush, boundingBox);
|
||||||
|
graphics.DrawRectangle(pen, boundingBox);
|
||||||
|
graphics.DrawString(result.Text, font, solidBrush, boundingBox);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Only draw Cursor if it's (partly) visible
|
// Only draw Cursor if it's (partly) visible
|
||||||
if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(_capture.CursorLocation, _capture.Cursor.Size))) {
|
if (_capture.Cursor != null && _capture.CursorVisible && clipRectangle.IntersectsWith(new Rectangle(_capture.CursorLocation, _capture.Cursor.Size))) {
|
||||||
graphics.DrawIcon(_capture.Cursor, _capture.CursorLocation.X, _capture.CursorLocation.Y);
|
graphics.DrawIcon(_capture.Cursor, _capture.CursorLocation.X, _capture.CursorLocation.Y);
|
||||||
|
|
|
@ -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/>.
|
||||||
*/
|
*/
|
||||||
|
@ -33,8 +33,8 @@ namespace Greenshot.Processors {
|
||||||
public class TitleFixProcessor : AbstractProcessor {
|
public class TitleFixProcessor : AbstractProcessor {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
|
||||||
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
public TitleFixProcessor() {
|
public TitleFixProcessor() {
|
||||||
List<string> corruptKeys = new List<string>();
|
List<string> corruptKeys = new List<string>();
|
||||||
foreach(string key in config.ActiveTitleFixes) {
|
foreach(string key in config.ActiveTitleFixes) {
|
||||||
if (config.TitleFixMatcher.ContainsKey(key)) continue;
|
if (config.TitleFixMatcher.ContainsKey(key)) continue;
|
||||||
|
@ -42,8 +42,8 @@ namespace Greenshot.Processors {
|
||||||
LOG.WarnFormat("Key {0} not found, configuration is broken! Disabling this key!", key);
|
LOG.WarnFormat("Key {0} not found, configuration is broken! Disabling this key!", key);
|
||||||
corruptKeys.Add(key);
|
corruptKeys.Add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix configuration if needed
|
// Fix configuration if needed
|
||||||
if (corruptKeys.Count <= 0) return;
|
if (corruptKeys.Count <= 0) return;
|
||||||
|
|
||||||
foreach(string corruptKey in corruptKeys) {
|
foreach(string corruptKey in corruptKeys) {
|
||||||
|
@ -54,8 +54,8 @@ namespace Greenshot.Processors {
|
||||||
}
|
}
|
||||||
config.IsDirty = true;
|
config.IsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Designation => "TitleFix";
|
public override string Designation => "TitleFix";
|
||||||
|
|
||||||
public override string Description => Designation;
|
public override string Description => Designation;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ namespace Greenshot.Processors {
|
||||||
foreach(string titleIdentifier in config.ActiveTitleFixes) {
|
foreach(string titleIdentifier in config.ActiveTitleFixes) {
|
||||||
string regexpString = config.TitleFixMatcher[titleIdentifier];
|
string regexpString = config.TitleFixMatcher[titleIdentifier];
|
||||||
string replaceString = config.TitleFixReplacer[titleIdentifier] ?? string.Empty;
|
string replaceString = config.TitleFixReplacer[titleIdentifier] ?? string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(regexpString)) continue;
|
if (string.IsNullOrEmpty(regexpString)) continue;
|
||||||
|
|
||||||
var regex = new Regex(regexpString);
|
var regex = new Regex(regexpString);
|
||||||
|
|
63
Greenshot/Processors/ZXingQrProcessor.cs
Normal file
63
Greenshot/Processors/ZXingQrProcessor.cs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using GreenshotPlugin.IniFile;
|
||||||
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using log4net;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
|
namespace Greenshot.Processors {
|
||||||
|
/// <summary>
|
||||||
|
/// This processor processes a capture to see if there is a QR ode on it
|
||||||
|
/// </summary>
|
||||||
|
public class ZXingQrProcessor : AbstractProcessor {
|
||||||
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
|
||||||
|
private static readonly CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
|
public ZXingQrProcessor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Designation => "QRProcessor";
|
||||||
|
|
||||||
|
public override string Description => Designation;
|
||||||
|
|
||||||
|
public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails) {
|
||||||
|
// create a barcode reader instance
|
||||||
|
IBarcodeReader reader = new BarcodeReader();
|
||||||
|
// detect and decode the barcode inside the bitmap
|
||||||
|
var result = reader.Decode((Bitmap)surface.Image);
|
||||||
|
// do something with the result
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
LOG.InfoFormat("Found QR of type {0} - {1}", result.BarcodeFormat, result.Text);
|
||||||
|
captureDetails.QrResult = result;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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/>.
|
||||||
*/
|
*/
|
||||||
|
@ -26,8 +26,8 @@ namespace GreenshotPlugin.Core {
|
||||||
/// Description of AbstractProcessor.
|
/// Description of AbstractProcessor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractProcessor : IProcessor {
|
public abstract class AbstractProcessor : IProcessor {
|
||||||
|
|
||||||
public virtual int CompareTo(object obj) {
|
public virtual int CompareTo(object obj) {
|
||||||
if (!(obj is IProcessor other)) {
|
if (!(obj is IProcessor other)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,9 @@ namespace GreenshotPlugin.Core {
|
||||||
get;
|
get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual int Priority {
|
public virtual int Priority => 10;
|
||||||
get {
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
@ -60,12 +56,8 @@ namespace GreenshotPlugin.Core {
|
||||||
//if (disposing) {}
|
//if (disposing) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool isActive {
|
public virtual bool isActive => true;
|
||||||
get {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails);
|
public abstract bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
256
GreenshotPlugin/Core/Capture.cs
Normal file
256
GreenshotPlugin/Core/Capture.cs
Normal file
|
@ -0,0 +1,256 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using GreenshotPlugin.Interfaces.Ocr;
|
||||||
|
using log4net;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class is used to pass an instance of the "Capture" around
|
||||||
|
/// Having the Bitmap, eventually the Windows Title and cursor all together.
|
||||||
|
/// </summary>
|
||||||
|
public class Capture : ICapture {
|
||||||
|
private static readonly ILog Log = LogManager.GetLogger(typeof(Capture));
|
||||||
|
private List<ICaptureElement> _elements = new List<ICaptureElement>();
|
||||||
|
|
||||||
|
private Rectangle _screenBounds;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/Set the Screenbounds
|
||||||
|
/// </summary>
|
||||||
|
public Rectangle ScreenBounds {
|
||||||
|
get {
|
||||||
|
if (_screenBounds == Rectangle.Empty) {
|
||||||
|
_screenBounds = WindowCapture.GetScreenBounds();
|
||||||
|
}
|
||||||
|
return _screenBounds;
|
||||||
|
}
|
||||||
|
set => _screenBounds = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image _image;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/Set the Image
|
||||||
|
/// </summary>
|
||||||
|
public Image Image {
|
||||||
|
get => _image;
|
||||||
|
set {
|
||||||
|
_image?.Dispose();
|
||||||
|
_image = value;
|
||||||
|
if (value != null) {
|
||||||
|
if (value.PixelFormat.Equals(PixelFormat.Format8bppIndexed) || value.PixelFormat.Equals(PixelFormat.Format1bppIndexed) || value.PixelFormat.Equals(PixelFormat.Format4bppIndexed)) {
|
||||||
|
Log.Debug("Converting Bitmap to PixelFormat.Format32bppArgb as we don't support: " + value.PixelFormat);
|
||||||
|
try {
|
||||||
|
// Default Bitmap PixelFormat is Format32bppArgb
|
||||||
|
_image = new Bitmap(value);
|
||||||
|
} finally {
|
||||||
|
// Always dispose, even when a exception occured
|
||||||
|
value.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.DebugFormat("Image is set with the following specifications: {0} - {1}", _image.Size, _image.PixelFormat);
|
||||||
|
} else {
|
||||||
|
Log.Debug("Image is removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NullImage() {
|
||||||
|
_image = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Icon _cursor;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/Set the image for the Cursor
|
||||||
|
/// </summary>
|
||||||
|
public Icon Cursor {
|
||||||
|
get => _cursor;
|
||||||
|
set {
|
||||||
|
_cursor?.Dispose();
|
||||||
|
_cursor = (Icon)value.Clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The information which OCR brings
|
||||||
|
/// </summary>
|
||||||
|
public OcrInformation OcrInformation { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set if the cursor is visible
|
||||||
|
/// </summary>
|
||||||
|
public bool CursorVisible { get; set; }
|
||||||
|
|
||||||
|
private Point _cursorLocation = Point.Empty;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/Set the CursorLocation
|
||||||
|
/// </summary>
|
||||||
|
public Point CursorLocation {
|
||||||
|
get => _cursorLocation;
|
||||||
|
set => _cursorLocation = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point _location = Point.Empty;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/set the Location
|
||||||
|
/// </summary>
|
||||||
|
public Point Location {
|
||||||
|
get => _location;
|
||||||
|
set => _location = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CaptureDetails _captureDetails;
|
||||||
|
/// <summary>
|
||||||
|
/// Get/set the CaptureDetails
|
||||||
|
/// </summary>
|
||||||
|
public ICaptureDetails CaptureDetails {
|
||||||
|
get => _captureDetails;
|
||||||
|
set => _captureDetails = (CaptureDetails)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default Constructor
|
||||||
|
/// </summary>
|
||||||
|
public Capture() {
|
||||||
|
_screenBounds = WindowCapture.GetScreenBounds();
|
||||||
|
_captureDetails = new CaptureDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor with Image
|
||||||
|
/// Note: the supplied bitmap can be disposed immediately or when constructor is called.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newImage">Image</param>
|
||||||
|
public Capture(Image newImage) : this() {
|
||||||
|
Image = newImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Destructor
|
||||||
|
/// </summary>
|
||||||
|
~Capture() {
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The public accessible Dispose
|
||||||
|
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This Dispose is called from the Dispose and the Destructor.
|
||||||
|
/// When disposing==true all non-managed resources should be freed too!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing"></param>
|
||||||
|
protected virtual void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
_image?.Dispose();
|
||||||
|
_cursor?.Dispose();
|
||||||
|
}
|
||||||
|
_image = null;
|
||||||
|
_cursor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
||||||
|
public bool Crop(Rectangle cropRectangle) {
|
||||||
|
Log.Debug("Cropping to: " + cropRectangle);
|
||||||
|
if (!ImageHelper.Crop(ref _image, ref cropRectangle))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_location = cropRectangle.Location;
|
||||||
|
// Change mouse location according to the cropRectangle (including screenbounds) offset
|
||||||
|
MoveMouseLocation(-cropRectangle.Location.X, -cropRectangle.Location.Y);
|
||||||
|
// Move all the elements
|
||||||
|
// TODO: Enable when the elements are usable again.
|
||||||
|
// MoveElements(-cropRectangle.Location.X, -cropRectangle.Location.Y);
|
||||||
|
|
||||||
|
// Offset the OCR information
|
||||||
|
CaptureDetails.OcrInformation?.Offset(-cropRectangle.Location.X, -cropRectangle.Location.Y);
|
||||||
|
|
||||||
|
var offsetted
|
||||||
|
CaptureDetails.QrResult.ResultPoints[0];
|
||||||
|
var resultPoint = new ResultPoint();
|
||||||
|
|
||||||
|
// Remove invisible elements
|
||||||
|
var visibleElements = new List<ICaptureElement>();
|
||||||
|
foreach(var captureElement in _elements) {
|
||||||
|
if (captureElement.Bounds.IntersectsWith(cropRectangle)) {
|
||||||
|
visibleElements.Add(captureElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_elements = visibleElements;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply a translate to the mouse location.
|
||||||
|
/// e.g. needed for crop
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">x coordinates to move the mouse</param>
|
||||||
|
/// <param name="y">y coordinates to move the mouse</param>
|
||||||
|
public void MoveMouseLocation(int x, int y) {
|
||||||
|
_cursorLocation.Offset(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Enable when the elements are usable again.
|
||||||
|
///// <summary>
|
||||||
|
///// Apply a translate to the elements
|
||||||
|
///// e.g. needed for crop
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="x">x coordinates to move the elements</param>
|
||||||
|
///// <param name="y">y coordinates to move the elements</param>
|
||||||
|
//public void MoveElements(int x, int y) {
|
||||||
|
// MoveElements(elements, x, y);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//private void MoveElements(List<ICaptureElement> listOfElements, int x, int y) {
|
||||||
|
// foreach(ICaptureElement childElement in listOfElements) {
|
||||||
|
// Rectangle bounds = childElement.Bounds;
|
||||||
|
// bounds.Offset(x, y);
|
||||||
|
// childElement.Bounds = bounds;
|
||||||
|
// MoveElements(childElement.Children, x, y);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// Add a new element to the capture
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="element">CaptureElement</param>
|
||||||
|
//public void AddElement(ICaptureElement element) {
|
||||||
|
// int match = elements.IndexOf(element);
|
||||||
|
// if (match >= 0) {
|
||||||
|
// if (elements[match].Children.Count < element.Children.Count) {
|
||||||
|
// elements.RemoveAt(match);
|
||||||
|
// elements.Add(element);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// elements.Add(element);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// Returns a list of rectangles which represent object that are on the capture
|
||||||
|
///// </summary>
|
||||||
|
//public List<ICaptureElement> Elements {
|
||||||
|
// get {
|
||||||
|
// return elements;
|
||||||
|
// }
|
||||||
|
// set {
|
||||||
|
// elements = value;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
105
GreenshotPlugin/Core/CaptureDetails.cs
Normal file
105
GreenshotPlugin/Core/CaptureDetails.cs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using GreenshotPlugin.Interfaces.Ocr;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This Class is used to pass details about the capture around.
|
||||||
|
/// The time the Capture was taken and the Title of the window (or a region of) that is captured
|
||||||
|
/// </summary>
|
||||||
|
public class CaptureDetails : ICaptureDetails {
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Title {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public string Filename {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public DateTime DateTime {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public float DpiX {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public float DpiY {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public OcrInformation OcrInformation { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Result QrResult { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Dictionary<string, string> MetaData { get; } = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void AddMetaData(string key, string value) {
|
||||||
|
if (MetaData.ContainsKey(key)) {
|
||||||
|
MetaData[key] = value;
|
||||||
|
} else {
|
||||||
|
MetaData.Add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public CaptureMode CaptureMode {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public List<IDestination> CaptureDestinations { get; set; } = new List<IDestination>();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void ClearDestinations() {
|
||||||
|
CaptureDestinations.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void RemoveDestination(IDestination destination) {
|
||||||
|
if (CaptureDestinations.Contains(destination)) {
|
||||||
|
CaptureDestinations.Remove(destination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void AddDestination(IDestination captureDestination) {
|
||||||
|
if (!CaptureDestinations.Contains(captureDestination)) {
|
||||||
|
CaptureDestinations.Add(captureDestination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public bool HasDestination(string designation) {
|
||||||
|
foreach(IDestination destination in CaptureDestinations) {
|
||||||
|
if (designation.Equals(destination.Designation)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CaptureDetails() {
|
||||||
|
DateTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
GreenshotPlugin/Core/CaptureElement.cs
Normal file
48
GreenshotPlugin/Core/CaptureElement.cs
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using GreenshotPlugin.Interfaces;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A class representing an element in the capture
|
||||||
|
/// </summary>
|
||||||
|
public class CaptureElement : ICaptureElement {
|
||||||
|
public CaptureElement(Rectangle bounds) {
|
||||||
|
Bounds = bounds;
|
||||||
|
}
|
||||||
|
public CaptureElement(string name) {
|
||||||
|
Name = name;
|
||||||
|
}
|
||||||
|
public CaptureElement(string name, Rectangle bounds) {
|
||||||
|
Name = name;
|
||||||
|
Bounds = bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ICaptureElement> Children { get; set; } = new List<ICaptureElement>();
|
||||||
|
|
||||||
|
public string Name {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public Rectangle Bounds {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CaptureElements are regarded equal if their bounds are equal. this should be sufficient.
|
||||||
|
public override bool Equals(object obj) {
|
||||||
|
if (obj == null || GetType() != obj.GetType())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj is CaptureElement other && Bounds.Equals(other.Bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode() {
|
||||||
|
// TODO: Fix this, this is not right...
|
||||||
|
return Bounds.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -100,10 +100,10 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Download the uri into a memorystream, without catching exceptions
|
/// Download the uri into a memory stream, without catching exceptions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">Of an image</param>
|
/// <param name="url">Of an image</param>
|
||||||
/// <returns>MemoryStream which is already seeked to 0</returns>
|
/// <returns>MemoryStream which is already seek-ed to 0</returns>
|
||||||
public static MemoryStream GetAsMemoryStream(string url) {
|
public static MemoryStream GetAsMemoryStream(string url) {
|
||||||
HttpWebRequest request = CreateWebRequest(url);
|
HttpWebRequest request = CreateWebRequest(url);
|
||||||
using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||||
|
|
|
@ -33,363 +33,7 @@ using GreenshotPlugin.Interfaces;
|
||||||
using GreenshotPlugin.UnmanagedHelpers.Structs;
|
using GreenshotPlugin.UnmanagedHelpers.Structs;
|
||||||
|
|
||||||
namespace GreenshotPlugin.Core {
|
namespace GreenshotPlugin.Core {
|
||||||
/// <summary>
|
|
||||||
/// This Class is used to pass details about the capture around.
|
|
||||||
/// The time the Capture was taken and the Title of the window (or a region of) that is captured
|
|
||||||
/// </summary>
|
|
||||||
public class CaptureDetails : ICaptureDetails {
|
|
||||||
public string Title {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Filename {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTime DateTime {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float DpiX {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float DpiY {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<string, string> MetaData { get; } = new Dictionary<string, string>();
|
|
||||||
|
|
||||||
public void AddMetaData(string key, string value) {
|
|
||||||
if (MetaData.ContainsKey(key)) {
|
|
||||||
MetaData[key] = value;
|
|
||||||
} else {
|
|
||||||
MetaData.Add(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CaptureMode CaptureMode {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<IDestination> CaptureDestinations { get; set; } = new List<IDestination>();
|
|
||||||
|
|
||||||
public void ClearDestinations() {
|
|
||||||
CaptureDestinations.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveDestination(IDestination destination) {
|
|
||||||
if (CaptureDestinations.Contains(destination)) {
|
|
||||||
CaptureDestinations.Remove(destination);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddDestination(IDestination captureDestination) {
|
|
||||||
if (!CaptureDestinations.Contains(captureDestination)) {
|
|
||||||
CaptureDestinations.Add(captureDestination);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasDestination(string designation) {
|
|
||||||
foreach(IDestination destination in CaptureDestinations) {
|
|
||||||
if (designation.Equals(destination.Designation)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CaptureDetails() {
|
|
||||||
DateTime = DateTime.Now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This class is used to pass an instance of the "Capture" around
|
|
||||||
/// Having the Bitmap, eventually the Windows Title and cursor all together.
|
|
||||||
/// </summary>
|
|
||||||
public class Capture : ICapture {
|
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Capture));
|
|
||||||
private List<ICaptureElement> _elements = new List<ICaptureElement>();
|
|
||||||
|
|
||||||
private Rectangle _screenBounds;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the Screenbounds
|
|
||||||
/// </summary>
|
|
||||||
public Rectangle ScreenBounds {
|
|
||||||
get {
|
|
||||||
if (_screenBounds == Rectangle.Empty) {
|
|
||||||
_screenBounds = WindowCapture.GetScreenBounds();
|
|
||||||
}
|
|
||||||
return _screenBounds;
|
|
||||||
}
|
|
||||||
set {_screenBounds = value;}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Image _image;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the Image
|
|
||||||
/// </summary>
|
|
||||||
public Image Image {
|
|
||||||
get {return _image;}
|
|
||||||
set {
|
|
||||||
_image?.Dispose();
|
|
||||||
_image = value;
|
|
||||||
if (value != null) {
|
|
||||||
if (value.PixelFormat.Equals(PixelFormat.Format8bppIndexed) || value.PixelFormat.Equals(PixelFormat.Format1bppIndexed) || value.PixelFormat.Equals(PixelFormat.Format4bppIndexed)) {
|
|
||||||
Log.Debug("Converting Bitmap to PixelFormat.Format32bppArgb as we don't support: " + value.PixelFormat);
|
|
||||||
try {
|
|
||||||
// Default Bitmap PixelFormat is Format32bppArgb
|
|
||||||
_image = new Bitmap(value);
|
|
||||||
} finally {
|
|
||||||
// Always dispose, even when a exception occured
|
|
||||||
value.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Log.DebugFormat("Image is set with the following specifications: {0} - {1}", _image.Size, _image.PixelFormat);
|
|
||||||
} else {
|
|
||||||
Log.Debug("Image is removed.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NullImage() {
|
|
||||||
_image = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Icon _cursor;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the image for the Cursor
|
|
||||||
/// </summary>
|
|
||||||
public Icon Cursor {
|
|
||||||
get {return _cursor;}
|
|
||||||
set {
|
|
||||||
_cursor?.Dispose();
|
|
||||||
_cursor = (Icon)value.Clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The information which OCR brings
|
|
||||||
/// </summary>
|
|
||||||
public OcrInformation OcrInformation { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set if the cursor is visible
|
|
||||||
/// </summary>
|
|
||||||
public bool CursorVisible { get; set; }
|
|
||||||
|
|
||||||
private Point _cursorLocation = Point.Empty;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the CursorLocation
|
|
||||||
/// </summary>
|
|
||||||
public Point CursorLocation {
|
|
||||||
get {return _cursorLocation;}
|
|
||||||
set {_cursorLocation = value;}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Point _location = Point.Empty;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/set the Location
|
|
||||||
/// </summary>
|
|
||||||
public Point Location {
|
|
||||||
get {return _location;}
|
|
||||||
set {_location = value;}
|
|
||||||
}
|
|
||||||
|
|
||||||
private CaptureDetails _captureDetails;
|
|
||||||
/// <summary>
|
|
||||||
/// Get/set the CaptureDetails
|
|
||||||
/// </summary>
|
|
||||||
public ICaptureDetails CaptureDetails {
|
|
||||||
get {return _captureDetails;}
|
|
||||||
set {_captureDetails = (CaptureDetails)value;}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Default Constructor
|
|
||||||
/// </summary>
|
|
||||||
public Capture() {
|
|
||||||
_screenBounds = WindowCapture.GetScreenBounds();
|
|
||||||
_captureDetails = new CaptureDetails();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor with Image
|
|
||||||
/// Note: the supplied bitmap can be disposed immediately or when constructor is called.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="newImage">Image</param>
|
|
||||||
public Capture(Image newImage) : this() {
|
|
||||||
Image = newImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Destructor
|
|
||||||
/// </summary>
|
|
||||||
~Capture() {
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The public accessible Dispose
|
|
||||||
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
|
||||||
/// </summary>
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This Dispose is called from the Dispose and the Destructor.
|
|
||||||
/// When disposing==true all non-managed resources should be freed too!
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing"></param>
|
|
||||||
protected virtual void Dispose(bool disposing) {
|
|
||||||
if (disposing) {
|
|
||||||
_image?.Dispose();
|
|
||||||
_cursor?.Dispose();
|
|
||||||
}
|
|
||||||
_image = null;
|
|
||||||
_cursor = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
|
||||||
public bool Crop(Rectangle cropRectangle) {
|
|
||||||
Log.Debug("Cropping to: " + cropRectangle);
|
|
||||||
if (!ImageHelper.Crop(ref _image, ref cropRectangle))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_location = cropRectangle.Location;
|
|
||||||
// Change mouse location according to the cropRegtangle (including screenbounds) offset
|
|
||||||
MoveMouseLocation(-cropRectangle.Location.X, -cropRectangle.Location.Y);
|
|
||||||
// Move all the elements
|
|
||||||
// TODO: Enable when the elements are usable again.
|
|
||||||
// MoveElements(-cropRectangle.Location.X, -cropRectangle.Location.Y);
|
|
||||||
|
|
||||||
// Remove invisible elements
|
|
||||||
var newElements = new List<ICaptureElement>();
|
|
||||||
foreach(var captureElement in _elements) {
|
|
||||||
if (captureElement.Bounds.IntersectsWith(cropRectangle)) {
|
|
||||||
newElements.Add(captureElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_elements = newElements;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Apply a translate to the mouse location.
|
|
||||||
/// e.g. needed for crop
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">x coordinates to move the mouse</param>
|
|
||||||
/// <param name="y">y coordinates to move the mouse</param>
|
|
||||||
public void MoveMouseLocation(int x, int y) {
|
|
||||||
_cursorLocation.Offset(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Enable when the elements are usable again.
|
|
||||||
///// <summary>
|
|
||||||
///// Apply a translate to the elements
|
|
||||||
///// e.g. needed for crop
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="x">x coordinates to move the elements</param>
|
|
||||||
///// <param name="y">y coordinates to move the elements</param>
|
|
||||||
//public void MoveElements(int x, int y) {
|
|
||||||
// MoveElements(elements, x, y);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//private void MoveElements(List<ICaptureElement> listOfElements, int x, int y) {
|
|
||||||
// foreach(ICaptureElement childElement in listOfElements) {
|
|
||||||
// Rectangle bounds = childElement.Bounds;
|
|
||||||
// bounds.Offset(x, y);
|
|
||||||
// childElement.Bounds = bounds;
|
|
||||||
// MoveElements(childElement.Children, x, y);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// Add a new element to the capture
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="element">CaptureElement</param>
|
|
||||||
//public void AddElement(ICaptureElement element) {
|
|
||||||
// int match = elements.IndexOf(element);
|
|
||||||
// if (match >= 0) {
|
|
||||||
// if (elements[match].Children.Count < element.Children.Count) {
|
|
||||||
// elements.RemoveAt(match);
|
|
||||||
// elements.Add(element);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// elements.Add(element);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// Returns a list of rectangles which represent object that are on the capture
|
|
||||||
///// </summary>
|
|
||||||
//public List<ICaptureElement> Elements {
|
|
||||||
// get {
|
|
||||||
// return elements;
|
|
||||||
// }
|
|
||||||
// set {
|
|
||||||
// elements = value;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A class representing an element in the capture
|
|
||||||
/// </summary>
|
|
||||||
public class CaptureElement : ICaptureElement {
|
|
||||||
public CaptureElement(Rectangle bounds) {
|
|
||||||
Bounds = bounds;
|
|
||||||
}
|
|
||||||
public CaptureElement(string name) {
|
|
||||||
Name = name;
|
|
||||||
}
|
|
||||||
public CaptureElement(string name, Rectangle bounds) {
|
|
||||||
Name = name;
|
|
||||||
Bounds = bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ICaptureElement> Children { get; set; } = new List<ICaptureElement>();
|
|
||||||
|
|
||||||
public string Name {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
public Rectangle Bounds {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
// CaptureElements are regarded equal if their bounds are equal. this should be sufficient.
|
|
||||||
public override bool Equals(object obj) {
|
|
||||||
if (obj == null || GetType() != obj.GetType())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj is CaptureElement other && Bounds.Equals(other.Bounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode() {
|
|
||||||
// TODO: Fix this, this is not right...
|
|
||||||
return Bounds.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// The Window Capture code
|
/// The Window Capture code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WindowCapture {
|
public static class WindowCapture {
|
||||||
|
@ -397,7 +41,7 @@ namespace GreenshotPlugin.Core {
|
||||||
private static readonly CoreConfiguration Configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration Configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to cleanup the unmanged resource in the iconInfo for the CaptureCursor method
|
/// Used to cleanup the unmanaged resource in the iconInfo for the CaptureCursor method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hObject"></param>
|
/// <param name="hObject"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
@ -435,11 +79,11 @@ namespace GreenshotPlugin.Core {
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts locationRelativeToScreenOrigin to be relative to top left corner of all screen bounds, which might
|
/// Converts locationRelativeToScreenOrigin to be relative to top left corner of all screen bounds, which might
|
||||||
/// be different in multiscreen setups. This implementation
|
/// be different in multi-screen setups. This implementation
|
||||||
/// can conveniently be used when the cursor location is needed to deal with a fullscreen bitmap.
|
/// can conveniently be used when the cursor location is needed to deal with a fullscreen bitmap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="locationRelativeToScreenOrigin"></param>
|
/// <param name="locationRelativeToScreenOrigin"></param>
|
||||||
/// <returns></returns>
|
/// <returns>Point</returns>
|
||||||
public static Point GetLocationRelativeToScreenBounds(Point locationRelativeToScreenOrigin) {
|
public static Point GetLocationRelativeToScreenBounds(Point locationRelativeToScreenOrigin) {
|
||||||
Point ret = locationRelativeToScreenOrigin;
|
Point ret = locationRelativeToScreenOrigin;
|
||||||
Rectangle bounds = GetScreenBounds();
|
Rectangle bounds = GetScreenBounds();
|
||||||
|
@ -456,34 +100,32 @@ namespace GreenshotPlugin.Core {
|
||||||
if (capture == null) {
|
if (capture == null) {
|
||||||
capture = new Capture();
|
capture = new Capture();
|
||||||
}
|
}
|
||||||
CursorInfo cursorInfo = new CursorInfo();
|
var cursorInfo = new CursorInfo();
|
||||||
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
|
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
|
||||||
if (User32.GetCursorInfo(out cursorInfo)) {
|
if (!User32.GetCursorInfo(out cursorInfo)) return capture;
|
||||||
if (cursorInfo.flags == User32.CURSOR_SHOWING)
|
if (cursorInfo.flags != User32.CURSOR_SHOWING) return capture;
|
||||||
{
|
|
||||||
using SafeIconHandle safeIcon = User32.CopyIcon(cursorInfo.hCursor);
|
|
||||||
if (User32.GetIconInfo(safeIcon, out var iconInfo)) {
|
|
||||||
Point cursorLocation = User32.GetCursorLocation();
|
|
||||||
// Allign cursor location to Bitmap coordinates (instead of Screen coordinates)
|
|
||||||
var x = cursorLocation.X - iconInfo.xHotspot - capture.ScreenBounds.X;
|
|
||||||
var y = cursorLocation.Y - iconInfo.yHotspot - capture.ScreenBounds.Y;
|
|
||||||
// Set the location
|
|
||||||
capture.CursorLocation = new Point(x, y);
|
|
||||||
|
|
||||||
using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle())) {
|
using SafeIconHandle safeIcon = User32.CopyIcon(cursorInfo.hCursor);
|
||||||
capture.Cursor = icon;
|
if (!User32.GetIconInfo(safeIcon, out var iconInfo)) return capture;
|
||||||
}
|
|
||||||
|
|
||||||
if (iconInfo.hbmMask != IntPtr.Zero) {
|
Point cursorLocation = User32.GetCursorLocation();
|
||||||
DeleteObject(iconInfo.hbmMask);
|
// Align cursor location to Bitmap coordinates (instead of Screen coordinates)
|
||||||
}
|
var x = cursorLocation.X - iconInfo.xHotspot - capture.ScreenBounds.X;
|
||||||
if (iconInfo.hbmColor != IntPtr.Zero) {
|
var y = cursorLocation.Y - iconInfo.yHotspot - capture.ScreenBounds.Y;
|
||||||
DeleteObject(iconInfo.hbmColor);
|
// Set the location
|
||||||
}
|
capture.CursorLocation = new Point(x, y);
|
||||||
}
|
|
||||||
}
|
using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle())) {
|
||||||
}
|
capture.Cursor = icon;
|
||||||
return capture;
|
}
|
||||||
|
|
||||||
|
if (iconInfo.hbmMask != IntPtr.Zero) {
|
||||||
|
DeleteObject(iconInfo.hbmMask);
|
||||||
|
}
|
||||||
|
if (iconInfo.hbmColor != IntPtr.Zero) {
|
||||||
|
DeleteObject(iconInfo.hbmColor);
|
||||||
|
}
|
||||||
|
return capture;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -518,19 +160,19 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="process">Process owning the window</param>
|
/// <param name="process">Process owning the window</param>
|
||||||
/// <returns>true if it's allowed</returns>
|
/// <returns>true if it's allowed</returns>
|
||||||
public static bool IsDwmAllowed(Process process) {
|
public static bool IsDwmAllowed(Process process) {
|
||||||
if (process != null) {
|
if (process == null) return true;
|
||||||
if (Configuration.NoDWMCaptureForProduct != null && Configuration.NoDWMCaptureForProduct.Count > 0) {
|
if (Configuration.NoDWMCaptureForProduct == null ||
|
||||||
try {
|
Configuration.NoDWMCaptureForProduct.Count <= 0) return true;
|
||||||
string productName = process.MainModule.FileVersionInfo.ProductName;
|
|
||||||
if (productName != null && Configuration.NoDWMCaptureForProduct.Contains(productName.ToLower())) {
|
try {
|
||||||
return false;
|
string productName = process.MainModule?.FileVersionInfo.ProductName;
|
||||||
}
|
if (productName != null && Configuration.NoDWMCaptureForProduct.Contains(productName.ToLower())) {
|
||||||
} catch (Exception ex) {
|
return false;
|
||||||
Log.Warn(ex.Message);
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
}
|
Log.Warn(ex.Message);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -539,19 +181,19 @@ namespace GreenshotPlugin.Core {
|
||||||
/// <param name="process">Process owning the window</param>
|
/// <param name="process">Process owning the window</param>
|
||||||
/// <returns>true if it's allowed</returns>
|
/// <returns>true if it's allowed</returns>
|
||||||
public static bool IsGdiAllowed(Process process) {
|
public static bool IsGdiAllowed(Process process) {
|
||||||
if (process != null) {
|
if (process == null) return true;
|
||||||
if (Configuration.NoGDICaptureForProduct != null && Configuration.NoGDICaptureForProduct.Count > 0) {
|
if (Configuration.NoGDICaptureForProduct == null ||
|
||||||
try {
|
Configuration.NoGDICaptureForProduct.Count <= 0) return true;
|
||||||
string productName = process.MainModule.FileVersionInfo.ProductName;
|
|
||||||
if (productName != null && Configuration.NoGDICaptureForProduct.Contains(productName.ToLower())) {
|
try {
|
||||||
return false;
|
string productName = process.MainModule?.FileVersionInfo.ProductName;
|
||||||
}
|
if (productName != null && Configuration.NoGDICaptureForProduct.Contains(productName.ToLower())) {
|
||||||
} catch (Exception ex) {
|
return false;
|
||||||
Log.Warn(ex.Message);
|
}
|
||||||
}
|
} catch (Exception ex) {
|
||||||
}
|
Log.Warn(ex.Message);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -645,10 +287,10 @@ namespace GreenshotPlugin.Core {
|
||||||
Win32.SetLastError(0);
|
Win32.SetLastError(0);
|
||||||
|
|
||||||
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
||||||
using SafeDibSectionHandle safeDibSectionHandle = GDI32.CreateDIBSection(desktopDcHandle, ref bmi, BITMAPINFOHEADER.DIB_RGB_COLORS, out var bits0, IntPtr.Zero, 0);
|
using SafeDibSectionHandle safeDibSectionHandle = GDI32.CreateDIBSection(desktopDcHandle, ref bmi, BITMAPINFOHEADER.DIB_RGB_COLORS, out _, IntPtr.Zero, 0);
|
||||||
if (safeDibSectionHandle.IsInvalid) {
|
if (safeDibSectionHandle.IsInvalid) {
|
||||||
// Get Exception before the error is lost
|
// Get Exception before the error is lost
|
||||||
Exception exceptionToThrow = CreateCaptureException("CreateDIBSection", captureBounds);
|
var exceptionToThrow = CreateCaptureException("CreateDIBSection", captureBounds);
|
||||||
exceptionToThrow.Data.Add("hdcDest", safeCompatibleDcHandle.DangerousGetHandle().ToInt32());
|
exceptionToThrow.Data.Add("hdcDest", safeCompatibleDcHandle.DangerousGetHandle().ToInt32());
|
||||||
exceptionToThrow.Data.Add("hdcSrc", desktopDcHandle.DangerousGetHandle().ToInt32());
|
exceptionToThrow.Data.Add("hdcSrc", desktopDcHandle.DangerousGetHandle().ToInt32());
|
||||||
|
|
||||||
|
|
|
@ -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" />
|
<PackageReference Include="Svg" Version="3.0.102" />
|
||||||
|
<PackageReference Include="ZXing.Net" Version="0.16.5" />
|
||||||
<Reference Include="Accessibility" />
|
<Reference Include="Accessibility" />
|
||||||
<Reference Include="CustomMarshalers" />
|
<Reference Include="CustomMarshalers" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,187 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace GreenshotPlugin.Interfaces {
|
|
||||||
/// <summary>
|
|
||||||
/// The capture mode for Greenshot
|
|
||||||
/// </summary>
|
|
||||||
public enum CaptureMode { None, Region, FullScreen, ActiveWindow, Window, LastRegion, Clipboard, File, IE, Import}; //, Video };
|
|
||||||
public enum ScreenCaptureMode { Auto, FullScreen, Fixed};
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Details for the capture, like the window title and date/time etc.
|
|
||||||
/// </summary>
|
|
||||||
public interface ICaptureDetails {
|
|
||||||
string Filename {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
string Title {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
DateTime DateTime {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<IDestination> CaptureDestinations {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary<string, string> MetaData {
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Helper method to prevent complex code which needs to check every key
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">The key for the meta-data</param>
|
|
||||||
/// <param name="value">The value for the meta-data</param>
|
|
||||||
void AddMetaData(string key, string value);
|
|
||||||
|
|
||||||
void ClearDestinations();
|
|
||||||
void RemoveDestination(IDestination captureDestination);
|
|
||||||
void AddDestination(IDestination captureDestination);
|
|
||||||
bool HasDestination(string designation);
|
|
||||||
|
|
||||||
CaptureMode CaptureMode {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
float DpiX {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
float DpiY {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ICaptureElement {
|
|
||||||
List<ICaptureElement> Children {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
Rectangle Bounds {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
string Name {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The interface to the Capture object, so Plugins can use it.
|
|
||||||
/// </summary>
|
|
||||||
public interface ICapture : IDisposable {
|
|
||||||
// The Capture Details
|
|
||||||
ICaptureDetails CaptureDetails {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The captured Image
|
|
||||||
Image Image {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NullImage();
|
|
||||||
|
|
||||||
Rectangle ScreenBounds {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
Icon Cursor {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Boolean to specify if the cursor is available
|
|
||||||
bool CursorVisible {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point CursorLocation {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point Location {
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
|
||||||
bool Crop(Rectangle cropRectangle);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Apply a translate to the mouse location. e.g. needed for crop
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">x coordinates to move the mouse</param>
|
|
||||||
/// <param name="y">y coordinates to move the mouse</param>
|
|
||||||
void MoveMouseLocation(int x, int y);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Store the OCR information for this capture
|
|
||||||
/// </summary>
|
|
||||||
OcrInformation OcrInformation { get; set; }
|
|
||||||
|
|
||||||
// / TODO: Enable when the elements are usable again.
|
|
||||||
///// <summary>
|
|
||||||
///// Apply a translate to the elements e.g. needed for crop
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="x">x coordinates to move the elements</param>
|
|
||||||
///// <param name="y">y coordinates to move the elements</param>
|
|
||||||
//void MoveElements(int x, int y);
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// Add a new element to the capture
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="element">Rectangle</param>
|
|
||||||
//void AddElement(ICaptureElement element);
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// Returns a list of rectangles which represent objects that are "on" the capture
|
|
||||||
///// </summary>
|
|
||||||
//List<ICaptureElement> Elements {
|
|
||||||
// get;
|
|
||||||
// set;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
41
GreenshotPlugin/Interfaces/CaptureMode.cs
Normal file
41
GreenshotPlugin/Interfaces/CaptureMode.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The capture mode for Greenshot
|
||||||
|
/// </summary>
|
||||||
|
public enum CaptureMode
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Region,
|
||||||
|
FullScreen,
|
||||||
|
ActiveWindow,
|
||||||
|
Window,
|
||||||
|
LastRegion,
|
||||||
|
Clipboard,
|
||||||
|
File,
|
||||||
|
IE,
|
||||||
|
Import
|
||||||
|
// Video
|
||||||
|
};
|
||||||
|
}
|
40
GreenshotPlugin/Interfaces/DrawingModes.cs
Normal file
40
GreenshotPlugin/Interfaces/DrawingModes.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public enum DrawingModes
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Rect,
|
||||||
|
Ellipse,
|
||||||
|
Text,
|
||||||
|
Line,
|
||||||
|
Arrow,
|
||||||
|
Crop,
|
||||||
|
Highlight,
|
||||||
|
Obfuscate,
|
||||||
|
Bitmap,
|
||||||
|
Path,
|
||||||
|
SpeechBubble,
|
||||||
|
StepLabel
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,266 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using GreenshotPlugin.Effects;
|
|
||||||
using GreenshotPlugin.Interfaces.Drawing;
|
|
||||||
|
|
||||||
namespace GreenshotPlugin.Interfaces
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Alignment Enums for possitioning
|
|
||||||
/// </summary>
|
|
||||||
//public enum HorizontalAlignment {LEFT, CENTER, RIGHT};
|
|
||||||
public enum VerticalAlignment { TOP, CENTER, BOTTOM };
|
|
||||||
|
|
||||||
public enum SurfaceMessageTyp
|
|
||||||
{
|
|
||||||
FileSaved,
|
|
||||||
Error,
|
|
||||||
Info,
|
|
||||||
UploadedUri
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SurfaceMessageEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public SurfaceMessageTyp MessageType
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
public string Message
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
public ISurface Surface
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SurfaceElementEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public IDrawableContainerList Elements
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SurfaceDrawingModeEventArgs : EventArgs
|
|
||||||
{
|
|
||||||
public DrawingModes DrawingMode
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate void SurfaceSizeChangeEventHandler(object sender, EventArgs e);
|
|
||||||
public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs e);
|
|
||||||
public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs e);
|
|
||||||
public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs e);
|
|
||||||
public enum DrawingModes
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Rect,
|
|
||||||
Ellipse,
|
|
||||||
Text,
|
|
||||||
Line,
|
|
||||||
Arrow,
|
|
||||||
Crop,
|
|
||||||
Highlight,
|
|
||||||
Obfuscate,
|
|
||||||
Bitmap,
|
|
||||||
Path,
|
|
||||||
SpeechBubble,
|
|
||||||
StepLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The interface to the Surface object, so Plugins can use it.
|
|
||||||
/// </summary>
|
|
||||||
public interface ISurface : IDisposable
|
|
||||||
{
|
|
||||||
event SurfaceSizeChangeEventHandler SurfaceSizeChanged;
|
|
||||||
event SurfaceMessageEventHandler SurfaceMessage;
|
|
||||||
event SurfaceDrawingModeEventHandler DrawingModeChanged;
|
|
||||||
event SurfaceElementEventHandler MovingElementChanged;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Start valueof the step-labels (counts)
|
|
||||||
/// </summary>
|
|
||||||
int CounterStart { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Unique ID of the Surface
|
|
||||||
/// </summary>
|
|
||||||
Guid ID
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
IDrawableContainerList Elements
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get/Set the image to the Surface
|
|
||||||
/// get will give the image as is currently visible
|
|
||||||
/// set will overwrite both the visible image as the underlying image
|
|
||||||
///
|
|
||||||
/// important notice:
|
|
||||||
/// The setter will clone the passed bitmap and dispose it when the Surface is disposed
|
|
||||||
/// This means that the supplied image needs to be disposed by the calling code (if needed!)
|
|
||||||
/// </summary>
|
|
||||||
Image Image
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the current Image from the Editor for Exporting (save/upload etc)
|
|
||||||
/// Don't forget to call image.Dispose() when finished!!!
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Bitmap</returns>
|
|
||||||
Image GetImageForExport();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add a TextContainer, at the given location, to the Surface.
|
|
||||||
/// The TextContainer will be "re"sized to the text size.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="text">String to show</param>
|
|
||||||
/// <param name="horizontalAlignment">Left, Center, Right</param>
|
|
||||||
/// <param name="verticalAlignment">TOP, CENTER, BOTTOM</param>
|
|
||||||
/// <param name="family">FontFamily</param>
|
|
||||||
/// <param name="size">Font Size in float</param>
|
|
||||||
/// <param name="italic">bool true if italic</param>
|
|
||||||
/// <param name="bold">bool true if bold</param>
|
|
||||||
/// <param name="shadow">bool true if shadow</param>
|
|
||||||
/// <param name="borderSize">size of border (0 for none)</param>
|
|
||||||
/// <param name="color">Color of string</param>
|
|
||||||
/// <param name="fillColor">Color of background (e.g. Color.Transparent)</param>
|
|
||||||
ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor);
|
|
||||||
|
|
||||||
IImageContainer AddImageContainer(Image image, int x, int y);
|
|
||||||
ICursorContainer AddCursorContainer(Cursor cursor, int x, int y);
|
|
||||||
IIconContainer AddIconContainer(Icon icon, int x, int y);
|
|
||||||
IImageContainer AddImageContainer(string filename, int x, int y);
|
|
||||||
ICursorContainer AddCursorContainer(string filename, int x, int y);
|
|
||||||
IIconContainer AddIconContainer(string filename, int x, int y);
|
|
||||||
long SaveElementsToStream(Stream stream);
|
|
||||||
void LoadElementsFromStream(Stream stream);
|
|
||||||
|
|
||||||
bool HasSelectedElements
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
void RemoveSelectedElements();
|
|
||||||
void CutSelectedElements();
|
|
||||||
void CopySelectedElements();
|
|
||||||
void PasteElementFromClipboard();
|
|
||||||
void DuplicateSelectedElements();
|
|
||||||
void DeselectElement(IDrawableContainer container, bool generateEvents = true);
|
|
||||||
void DeselectAllElements();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add an element to the surface
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="elements">IDrawableContainerList</param>
|
|
||||||
/// <param name="makeUndoable">Should it be placed on the undo stack?</param>
|
|
||||||
void AddElements(IDrawableContainerList elements, bool makeUndoable = true);
|
|
||||||
void RemoveElements(IDrawableContainerList elements, bool makeUndoable = true);
|
|
||||||
void SelectElements(IDrawableContainerList elements);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Add an element to the surface
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="element">IDrawableContainer</param>
|
|
||||||
/// <param name="makeUndoable">Should it be placed on the undo stack?</param>
|
|
||||||
/// <param name="invalidate">Should it be invalidated (draw)</param>
|
|
||||||
void AddElement(IDrawableContainer element, bool makeUndoable = true, bool invalidate = true);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Select the supplied container
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="container">IDrawableContainer</param>
|
|
||||||
/// <param name="invalidate">false to skip invalidation</param>
|
|
||||||
/// <param name="generateEvents">false to skip event generation</param>
|
|
||||||
void SelectElement(IDrawableContainer container, bool invalidate = true, bool generateEvents = true);
|
|
||||||
/// <summary>
|
|
||||||
/// Is the supplied container "on" the surface?
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="container"></param>
|
|
||||||
/// <returns>This returns false if the container is deleted but still in the undo stack</returns>
|
|
||||||
bool IsOnSurface(IDrawableContainer container);
|
|
||||||
void Invalidate(Rectangle rectangleToInvalidate);
|
|
||||||
void Invalidate();
|
|
||||||
bool Modified
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
string LastSaveFullPath
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
string UploadUrl
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Remove an element of the elements list
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="elementToRemove">Element to remove</param>
|
|
||||||
/// <param name="makeUndoable">flag specifying if the remove needs to be undoable</param>
|
|
||||||
/// <param name="invalidate">flag specifying if an surface invalidate needs to be called</param>
|
|
||||||
/// <param name="generateEvents">flag specifying if the deselect needs to generate an event</param>
|
|
||||||
void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable = true, bool invalidate = true, bool generateEvents = true);
|
|
||||||
|
|
||||||
void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message);
|
|
||||||
void ApplyBitmapEffect(IEffect effect);
|
|
||||||
void RemoveCursor();
|
|
||||||
bool HasCursor
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
ICaptureDetails CaptureDetails
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
int Width { get; }
|
|
||||||
int Height { get; }
|
|
||||||
|
|
||||||
void MakeUndoable(IMemento memento, bool allowMerge);
|
|
||||||
}
|
|
||||||
}
|
|
105
GreenshotPlugin/Interfaces/ICapture.cs
Normal file
105
GreenshotPlugin/Interfaces/ICapture.cs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The interface to the Capture object, so Plugins can use it.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICapture : IDisposable {
|
||||||
|
/// <summary>
|
||||||
|
/// The Capture Details
|
||||||
|
/// </summary>
|
||||||
|
ICaptureDetails CaptureDetails {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The captured Image
|
||||||
|
/// </summary>
|
||||||
|
Image Image {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Null the image
|
||||||
|
/// </summary>
|
||||||
|
void NullImage();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Bounds on the screen from which the capture comes
|
||||||
|
/// </summary>
|
||||||
|
Rectangle ScreenBounds {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The cursor
|
||||||
|
/// </summary>
|
||||||
|
Icon Cursor {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Boolean to specify if the cursor is available
|
||||||
|
/// </summary>
|
||||||
|
bool CursorVisible {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Location of the cursor
|
||||||
|
/// </summary>
|
||||||
|
Point CursorLocation {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Location of the capture
|
||||||
|
/// </summary>
|
||||||
|
Point Location {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
||||||
|
bool Crop(Rectangle cropRectangle);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply a translate to the mouse location. e.g. needed for crop
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">x coordinates to move the mouse</param>
|
||||||
|
/// <param name="y">y coordinates to move the mouse</param>
|
||||||
|
void MoveMouseLocation(int x, int y);
|
||||||
|
}
|
||||||
|
}
|
109
GreenshotPlugin/Interfaces/ICaptureDetails.cs
Normal file
109
GreenshotPlugin/Interfaces/ICaptureDetails.cs
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using GreenshotPlugin.Interfaces.Ocr;
|
||||||
|
using ZXing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces {
|
||||||
|
/// <summary>
|
||||||
|
/// Details for the capture, like the window title and date/time etc.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICaptureDetails {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If the capture comes from a file, this contains the filename
|
||||||
|
/// </summary>
|
||||||
|
string Filename {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The title of the capture
|
||||||
|
/// </summary>
|
||||||
|
string Title {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When was the capture taken (or loaded)
|
||||||
|
/// </summary>
|
||||||
|
DateTime DateTime {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Destinations to where this capture goes or went
|
||||||
|
/// </summary>
|
||||||
|
List<IDestination> CaptureDestinations {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The meta data of the capture
|
||||||
|
/// </summary>
|
||||||
|
Dictionary<string, string> MetaData {
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method to prevent complex code which needs to check every key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The key for the meta-data</param>
|
||||||
|
/// <param name="value">The value for the meta-data</param>
|
||||||
|
void AddMetaData(string key, string value);
|
||||||
|
|
||||||
|
void ClearDestinations();
|
||||||
|
void RemoveDestination(IDestination captureDestination);
|
||||||
|
void AddDestination(IDestination captureDestination);
|
||||||
|
bool HasDestination(string designation);
|
||||||
|
|
||||||
|
CaptureMode CaptureMode {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
float DpiX {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
float DpiY {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Store the OCR information for this capture
|
||||||
|
/// </summary>
|
||||||
|
OcrInformation OcrInformation { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Store the QR information for this capture
|
||||||
|
/// </summary>
|
||||||
|
Result QrResult { get; set; }
|
||||||
|
}
|
||||||
|
}
|
41
GreenshotPlugin/Interfaces/ICaptureElement.cs
Normal file
41
GreenshotPlugin/Interfaces/ICaptureElement.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public interface ICaptureElement {
|
||||||
|
List<ICaptureElement> Children {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
Rectangle Bounds {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
string Name {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,127 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace GreenshotPlugin.Interfaces
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// This interface describes something that can do OCR of a bitmap
|
|
||||||
/// </summary>
|
|
||||||
public interface IOcrProvider
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Start the actual OCR
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="image">Image</param>
|
|
||||||
/// <returns>OcrInformation</returns>
|
|
||||||
Task<OcrInformation> DoOcrAsync(Image image);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Start the actual OCR
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="surface">ISurface</param>
|
|
||||||
/// <returns>OcrInformation</returns>
|
|
||||||
Task<OcrInformation> DoOcrAsync(ISurface surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains the information about a word
|
|
||||||
/// </summary>
|
|
||||||
public class Word
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The actual text for the word
|
|
||||||
/// </summary>
|
|
||||||
public string Text { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The location of the word
|
|
||||||
/// </summary>
|
|
||||||
public Rectangle Location { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Describes a line of words
|
|
||||||
/// </summary>
|
|
||||||
public class Line
|
|
||||||
{
|
|
||||||
private Rectangle? _calculatedBounds;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor will preallocate the number of words
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="wordCount">int</param>
|
|
||||||
public Line(int wordCount)
|
|
||||||
{
|
|
||||||
Words = new Word[wordCount];
|
|
||||||
for (int i = 0; i < wordCount; i++)
|
|
||||||
{
|
|
||||||
Words[i] = new Word();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// An array with words
|
|
||||||
/// </summary>
|
|
||||||
public Word[] Words { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculate the bounds of the words
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Rectangle</returns>
|
|
||||||
private Rectangle CalculateBounds()
|
|
||||||
{
|
|
||||||
if (Words.Length == 0)
|
|
||||||
{
|
|
||||||
return Rectangle.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = Words[0].Location;
|
|
||||||
for (var index = 0; index < Words.Length; index++)
|
|
||||||
{
|
|
||||||
result = Rectangle.Union(result, Words[index].Location);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Return the calculated bounds for the whole line
|
|
||||||
/// </summary>
|
|
||||||
public Rectangle CalculatedBounds
|
|
||||||
{
|
|
||||||
get { return _calculatedBounds ??= CalculateBounds(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains all the information on the OCR result
|
|
||||||
/// </summary>
|
|
||||||
public class OcrInformation
|
|
||||||
{
|
|
||||||
public string Text { get; set; }
|
|
||||||
|
|
||||||
public IList<Line> Lines { get; } = new List<Line>();
|
|
||||||
}
|
|
||||||
}
|
|
194
GreenshotPlugin/Interfaces/ISurface.cs
Normal file
194
GreenshotPlugin/Interfaces/ISurface.cs
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using GreenshotPlugin.Effects;
|
||||||
|
using GreenshotPlugin.Interfaces.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The interface to the Surface object, so Plugins can use it.
|
||||||
|
/// </summary>
|
||||||
|
public interface ISurface : IDisposable
|
||||||
|
{
|
||||||
|
event SurfaceSizeChangeEventHandler SurfaceSizeChanged;
|
||||||
|
event SurfaceMessageEventHandler SurfaceMessage;
|
||||||
|
event SurfaceDrawingModeEventHandler DrawingModeChanged;
|
||||||
|
event SurfaceElementEventHandler MovingElementChanged;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Start value of the step-labels (counts)
|
||||||
|
/// </summary>
|
||||||
|
int CounterStart { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unique ID of the Surface
|
||||||
|
/// </summary>
|
||||||
|
Guid ID
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDrawableContainerList Elements
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get/Set the image to the Surface
|
||||||
|
/// get will give the image as is currently visible
|
||||||
|
/// set will overwrite both the visible image as the underlying image
|
||||||
|
///
|
||||||
|
/// important notice:
|
||||||
|
/// The setter will clone the passed bitmap and dispose it when the Surface is disposed
|
||||||
|
/// This means that the supplied image needs to be disposed by the calling code (if needed!)
|
||||||
|
/// </summary>
|
||||||
|
Image Image
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the current Image from the Editor for Exporting (save/upload etc)
|
||||||
|
/// Don't forget to call image.Dispose() when finished!!!
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Bitmap</returns>
|
||||||
|
Image GetImageForExport();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add a TextContainer, at the given location, to the Surface.
|
||||||
|
/// The TextContainer will be "re"sized to the text size.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">String to show</param>
|
||||||
|
/// <param name="horizontalAlignment">Left, Center, Right</param>
|
||||||
|
/// <param name="verticalAlignment">TOP, CENTER, BOTTOM</param>
|
||||||
|
/// <param name="family">FontFamily</param>
|
||||||
|
/// <param name="size">Font Size in float</param>
|
||||||
|
/// <param name="italic">bool true if italic</param>
|
||||||
|
/// <param name="bold">bool true if bold</param>
|
||||||
|
/// <param name="shadow">bool true if shadow</param>
|
||||||
|
/// <param name="borderSize">size of border (0 for none)</param>
|
||||||
|
/// <param name="color">Color of string</param>
|
||||||
|
/// <param name="fillColor">Color of background (e.g. Color.Transparent)</param>
|
||||||
|
ITextContainer AddTextContainer(string text, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, FontFamily family, float size, bool italic, bool bold, bool shadow, int borderSize, Color color, Color fillColor);
|
||||||
|
|
||||||
|
IImageContainer AddImageContainer(Image image, int x, int y);
|
||||||
|
ICursorContainer AddCursorContainer(Cursor cursor, int x, int y);
|
||||||
|
IIconContainer AddIconContainer(Icon icon, int x, int y);
|
||||||
|
IImageContainer AddImageContainer(string filename, int x, int y);
|
||||||
|
ICursorContainer AddCursorContainer(string filename, int x, int y);
|
||||||
|
IIconContainer AddIconContainer(string filename, int x, int y);
|
||||||
|
long SaveElementsToStream(Stream stream);
|
||||||
|
void LoadElementsFromStream(Stream stream);
|
||||||
|
|
||||||
|
bool HasSelectedElements
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
void RemoveSelectedElements();
|
||||||
|
void CutSelectedElements();
|
||||||
|
void CopySelectedElements();
|
||||||
|
void PasteElementFromClipboard();
|
||||||
|
void DuplicateSelectedElements();
|
||||||
|
void DeselectElement(IDrawableContainer container, bool generateEvents = true);
|
||||||
|
void DeselectAllElements();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add an element to the surface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elements">IDrawableContainerList</param>
|
||||||
|
/// <param name="makeUndoable">Should it be placed on the undo stack?</param>
|
||||||
|
void AddElements(IDrawableContainerList elements, bool makeUndoable = true);
|
||||||
|
void RemoveElements(IDrawableContainerList elements, bool makeUndoable = true);
|
||||||
|
void SelectElements(IDrawableContainerList elements);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add an element to the surface
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="element">IDrawableContainer</param>
|
||||||
|
/// <param name="makeUndoable">Should it be placed on the undo stack?</param>
|
||||||
|
/// <param name="invalidate">Should it be invalidated (draw)</param>
|
||||||
|
void AddElement(IDrawableContainer element, bool makeUndoable = true, bool invalidate = true);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select the supplied container
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container">IDrawableContainer</param>
|
||||||
|
/// <param name="invalidate">false to skip invalidation</param>
|
||||||
|
/// <param name="generateEvents">false to skip event generation</param>
|
||||||
|
void SelectElement(IDrawableContainer container, bool invalidate = true, bool generateEvents = true);
|
||||||
|
/// <summary>
|
||||||
|
/// Is the supplied container "on" the surface?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="container"></param>
|
||||||
|
/// <returns>This returns false if the container is deleted but still in the undo stack</returns>
|
||||||
|
bool IsOnSurface(IDrawableContainer container);
|
||||||
|
void Invalidate(Rectangle rectangleToInvalidate);
|
||||||
|
void Invalidate();
|
||||||
|
bool Modified
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
string LastSaveFullPath
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
string UploadUrl
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Remove an element of the elements list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="elementToRemove">Element to remove</param>
|
||||||
|
/// <param name="makeUndoable">flag specifying if the remove needs to be undoable</param>
|
||||||
|
/// <param name="invalidate">flag specifying if an surface invalidate needs to be called</param>
|
||||||
|
/// <param name="generateEvents">flag specifying if the deselect needs to generate an event</param>
|
||||||
|
void RemoveElement(IDrawableContainer elementToRemove, bool makeUndoable = true, bool invalidate = true, bool generateEvents = true);
|
||||||
|
|
||||||
|
void SendMessageEvent(object source, SurfaceMessageTyp messageType, string message);
|
||||||
|
void ApplyBitmapEffect(IEffect effect);
|
||||||
|
void RemoveCursor();
|
||||||
|
bool HasCursor
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICaptureDetails CaptureDetails
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
int Width { get; }
|
||||||
|
int Height { get; }
|
||||||
|
|
||||||
|
void MakeUndoable(IMemento memento, bool allowMerge);
|
||||||
|
}
|
||||||
|
}
|
46
GreenshotPlugin/Interfaces/Ocr/IOcrProvider.cs
Normal file
46
GreenshotPlugin/Interfaces/Ocr/IOcrProvider.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces.Ocr
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This interface describes something that can do OCR of a bitmap
|
||||||
|
/// </summary>
|
||||||
|
public interface IOcrProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Start the actual OCR
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="image">Image</param>
|
||||||
|
/// <returns>OcrInformation</returns>
|
||||||
|
Task<OcrInformation> DoOcrAsync(Image image);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Start the actual OCR
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="surface">ISurface</param>
|
||||||
|
/// <returns>OcrInformation</returns>
|
||||||
|
Task<OcrInformation> DoOcrAsync(ISurface surface);
|
||||||
|
}
|
||||||
|
}
|
81
GreenshotPlugin/Interfaces/Ocr/Line.cs
Normal file
81
GreenshotPlugin/Interfaces/Ocr/Line.cs
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces.Ocr
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Describes a line of words
|
||||||
|
/// </summary>
|
||||||
|
public class Line
|
||||||
|
{
|
||||||
|
private Rectangle? _calculatedBounds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor will preallocate the number of words
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="wordCount">int</param>
|
||||||
|
public Line(int wordCount)
|
||||||
|
{
|
||||||
|
Words = new Word[wordCount];
|
||||||
|
for (int i = 0; i < wordCount; i++)
|
||||||
|
{
|
||||||
|
Words[i] = new Word();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The text of the line
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An array with words
|
||||||
|
/// </summary>
|
||||||
|
public Word[] Words { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculate the bounds of the words
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Rectangle</returns>
|
||||||
|
private Rectangle CalculateBounds()
|
||||||
|
{
|
||||||
|
if (Words.Length == 0)
|
||||||
|
{
|
||||||
|
return Rectangle.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = Words[0].Bounds;
|
||||||
|
for (var index = 0; index < Words.Length; index++)
|
||||||
|
{
|
||||||
|
result = Rectangle.Union(result, Words[index].Bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the calculated bounds for the whole line
|
||||||
|
/// </summary>
|
||||||
|
public Rectangle CalculatedBounds
|
||||||
|
{
|
||||||
|
get { return _calculatedBounds ??= CalculateBounds(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Offset the words with the specified x and y coordinates
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">int</param>
|
||||||
|
/// <param name="y">int</param>
|
||||||
|
public void Offset(int x, int y)
|
||||||
|
{
|
||||||
|
foreach (var word in Words)
|
||||||
|
{
|
||||||
|
var location = word.Bounds;
|
||||||
|
location.Offset(x,y);
|
||||||
|
word.Bounds = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
_calculatedBounds = null;
|
||||||
|
CalculateBounds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs
Normal file
46
GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces.Ocr
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all the information on the OCR result
|
||||||
|
/// </summary>
|
||||||
|
public class OcrInformation
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The complete text
|
||||||
|
/// </summary>
|
||||||
|
public string Text
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Build the text from the lines, otherwise it's just everything concatenated together
|
||||||
|
var text = new StringBuilder();
|
||||||
|
foreach (var line in Lines)
|
||||||
|
{
|
||||||
|
text.AppendLine(line.Text);
|
||||||
|
}
|
||||||
|
return text.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The lines of test which the OCR engine found
|
||||||
|
/// </summary>
|
||||||
|
public IList<Line> Lines { get; } = new List<Line>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Change the offset of the
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="x">int</param>
|
||||||
|
/// <param name="y">int</param>
|
||||||
|
public void Offset(int x, int y)
|
||||||
|
{
|
||||||
|
foreach (var line in Lines)
|
||||||
|
{
|
||||||
|
line.Offset(x,y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
GreenshotPlugin/Interfaces/Ocr/Word.cs
Normal file
20
GreenshotPlugin/Interfaces/Ocr/Word.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces.Ocr
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the information about a word
|
||||||
|
/// </summary>
|
||||||
|
public class Word
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The actual text for the word
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bounds of the word
|
||||||
|
/// </summary>
|
||||||
|
public Rectangle Bounds { get; set; }
|
||||||
|
}
|
||||||
|
}
|
30
GreenshotPlugin/Interfaces/ScreenCaptureMode.cs
Normal file
30
GreenshotPlugin/Interfaces/ScreenCaptureMode.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public enum ScreenCaptureMode
|
||||||
|
{
|
||||||
|
Auto,
|
||||||
|
FullScreen,
|
||||||
|
Fixed
|
||||||
|
};
|
||||||
|
}
|
34
GreenshotPlugin/Interfaces/SurfaceDrawingModeEventArgs.cs
Normal file
34
GreenshotPlugin/Interfaces/SurfaceDrawingModeEventArgs.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public class SurfaceDrawingModeEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public DrawingModes DrawingMode
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
GreenshotPlugin/Interfaces/SurfaceDrawingModeEventHandler.cs
Normal file
25
GreenshotPlugin/Interfaces/SurfaceDrawingModeEventHandler.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs e);
|
||||||
|
}
|
35
GreenshotPlugin/Interfaces/SurfaceElementEventArgs.cs
Normal file
35
GreenshotPlugin/Interfaces/SurfaceElementEventArgs.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using GreenshotPlugin.Interfaces.Drawing;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public class SurfaceElementEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public IDrawableContainerList Elements
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
GreenshotPlugin/Interfaces/SurfaceElementEventHandler.cs
Normal file
25
GreenshotPlugin/Interfaces/SurfaceElementEventHandler.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs e);
|
||||||
|
}
|
44
GreenshotPlugin/Interfaces/SurfaceMessageEventArgs.cs
Normal file
44
GreenshotPlugin/Interfaces/SurfaceMessageEventArgs.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public class SurfaceMessageEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public SurfaceMessageTyp MessageType
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public string Message
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
public ISurface Surface
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
GreenshotPlugin/Interfaces/SurfaceMessageEventHandler.cs
Normal file
25
GreenshotPlugin/Interfaces/SurfaceMessageEventHandler.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs e);
|
||||||
|
}
|
31
GreenshotPlugin/Interfaces/SurfaceMessageTyp.cs
Normal file
31
GreenshotPlugin/Interfaces/SurfaceMessageTyp.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public enum SurfaceMessageTyp
|
||||||
|
{
|
||||||
|
FileSaved,
|
||||||
|
Error,
|
||||||
|
Info,
|
||||||
|
UploadedUri
|
||||||
|
}
|
||||||
|
}
|
27
GreenshotPlugin/Interfaces/SurfaceSizeChangeEventHandler.cs
Normal file
27
GreenshotPlugin/Interfaces/SurfaceSizeChangeEventHandler.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
public delegate void SurfaceSizeChangeEventHandler(object sender, EventArgs e);
|
||||||
|
}
|
34
GreenshotPlugin/Interfaces/VerticalAlignment.cs
Normal file
34
GreenshotPlugin/Interfaces/VerticalAlignment.cs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace GreenshotPlugin.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Alignment Enums for positioning
|
||||||
|
/// </summary>
|
||||||
|
//public enum HorizontalAlignment {LEFT, CENTER, RIGHT};
|
||||||
|
public enum VerticalAlignment
|
||||||
|
{
|
||||||
|
TOP,
|
||||||
|
CENTER,
|
||||||
|
BOTTOM
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,109 +1,109 @@
|
||||||
/*
|
/*
|
||||||
* Greenshot - a free and open source screenshot tool
|
* Greenshot - a free and open source screenshot tool
|
||||||
* Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
|
* Copyright (C) 2007-2015 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 Sourceforge: http://sourceforge.net/projects/greenshot/
|
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/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.IO;
|
using System.IO;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
|
|
||||||
namespace GreenshotWin10Plugin
|
namespace GreenshotWin10Plugin.Internal
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is an IRandomAccessStream implementation which uses a MemoryStream
|
/// This is an IRandomAccessStream implementation which uses a MemoryStream
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MemoryRandomAccessStream : MemoryStream, IRandomAccessStream
|
internal sealed class MemoryRandomAccessStream : MemoryStream, IRandomAccessStream
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor
|
/// Default constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MemoryRandomAccessStream()
|
public MemoryRandomAccessStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor where also bytes are already passed
|
/// Constructor where also bytes are already passed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bytes">byte array</param>
|
/// <param name="bytes">byte array</param>
|
||||||
public MemoryRandomAccessStream(byte[] bytes)
|
public MemoryRandomAccessStream(byte[] bytes)
|
||||||
{
|
{
|
||||||
Write(bytes, 0, bytes.Length);
|
Write(bytes, 0, bytes.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IInputStream GetInputStreamAt(ulong position)
|
public IInputStream GetInputStreamAt(ulong position)
|
||||||
{
|
{
|
||||||
Seek((long)position, SeekOrigin.Begin);
|
Seek((long)position, SeekOrigin.Begin);
|
||||||
|
|
||||||
return this.AsInputStream();
|
return this.AsInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IOutputStream GetOutputStreamAt(ulong position)
|
public IOutputStream GetOutputStreamAt(ulong position)
|
||||||
{
|
{
|
||||||
Seek((long)position, SeekOrigin.Begin);
|
Seek((long)position, SeekOrigin.Begin);
|
||||||
|
|
||||||
return this.AsOutputStream();
|
return this.AsOutputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
ulong IRandomAccessStream.Position => (ulong)Position;
|
ulong IRandomAccessStream.Position => (ulong)Position;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public ulong Size
|
public ulong Size
|
||||||
{
|
{
|
||||||
get { return (ulong)Length; }
|
get { return (ulong)Length; }
|
||||||
set { SetLength((long)value); }
|
set { SetLength((long)value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRandomAccessStream CloneStream()
|
public IRandomAccessStream CloneStream()
|
||||||
{
|
{
|
||||||
var cloned = new MemoryRandomAccessStream();
|
var cloned = new MemoryRandomAccessStream();
|
||||||
CopyTo(cloned);
|
CopyTo(cloned);
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Seek(ulong position)
|
public void Seek(ulong position)
|
||||||
{
|
{
|
||||||
Seek((long)position, SeekOrigin.Begin);
|
Seek((long)position, SeekOrigin.Begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Windows.Foundation.IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
|
public Windows.Foundation.IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
|
||||||
{
|
{
|
||||||
var inputStream = GetInputStreamAt(0);
|
var inputStream = GetInputStreamAt(0);
|
||||||
return inputStream.ReadAsync(buffer, count, options);
|
return inputStream.ReadAsync(buffer, count, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
Windows.Foundation.IAsyncOperation<bool> IOutputStream.FlushAsync()
|
Windows.Foundation.IAsyncOperation<bool> IOutputStream.FlushAsync()
|
||||||
{
|
{
|
||||||
var outputStream = GetOutputStreamAt(0);
|
var outputStream = GetOutputStreamAt(0);
|
||||||
return outputStream.FlushAsync();
|
return outputStream.FlushAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Windows.Foundation.IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)
|
public Windows.Foundation.IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)
|
||||||
{
|
{
|
||||||
var outputStream = GetOutputStreamAt(0);
|
var outputStream = GetOutputStreamAt(0);
|
||||||
return outputStream.WriteAsync(buffer);
|
return outputStream.WriteAsync(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
43
GreenshotWin10Plugin/Internal/ShareInfo.cs
Normal file
43
GreenshotWin10Plugin/Internal/ShareInfo.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2020 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Windows.ApplicationModel.DataTransfer;
|
||||||
|
|
||||||
|
namespace GreenshotWin10Plugin.Internal
|
||||||
|
{
|
||||||
|
internal class ShareInfo
|
||||||
|
{
|
||||||
|
public string ApplicationName { get; set; }
|
||||||
|
public bool AreShareProvidersRequested { get; set; }
|
||||||
|
public bool IsDeferredFileCreated { get; set; }
|
||||||
|
public DataPackageOperation CompletedWithOperation { get; set; }
|
||||||
|
public string AcceptedFormat { get; set; }
|
||||||
|
public bool IsDestroyed { get; set; }
|
||||||
|
public bool IsShareCompleted { get; set; }
|
||||||
|
|
||||||
|
public TaskCompletionSource<bool> ShareTask { get; } = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
public bool IsDataRequested { get; set; }
|
||||||
|
|
||||||
|
public IntPtr SharingHwnd { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,9 +26,9 @@ using System.Threading.Tasks;
|
||||||
using Windows.Graphics.Imaging;
|
using Windows.Graphics.Imaging;
|
||||||
using Windows.Media.Ocr;
|
using Windows.Media.Ocr;
|
||||||
using GreenshotPlugin.Core;
|
using GreenshotPlugin.Core;
|
||||||
using System.Text;
|
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
|
using GreenshotPlugin.Interfaces.Ocr;
|
||||||
using GreenshotPlugin.Interfaces.Plugin;
|
using GreenshotPlugin.Interfaces.Plugin;
|
||||||
|
|
||||||
namespace GreenshotWin10Plugin
|
namespace GreenshotWin10Plugin
|
||||||
|
@ -112,33 +112,41 @@ namespace GreenshotWin10Plugin
|
||||||
|
|
||||||
var ocrResult = await ocrEngine.RecognizeAsync(softwareBitmap);
|
var ocrResult = await ocrEngine.RecognizeAsync(softwareBitmap);
|
||||||
|
|
||||||
var result = new OcrInformation();
|
return CreateOcrInformation(ocrResult);
|
||||||
// Build the text from the lines, otherwise it's just everything concatenated together
|
}
|
||||||
var text = new StringBuilder();
|
|
||||||
foreach (var line in ocrResult.Lines)
|
|
||||||
{
|
|
||||||
text.AppendLine(line.Text);
|
|
||||||
}
|
|
||||||
result.Text = text.ToString();
|
|
||||||
|
|
||||||
foreach (var ocrLine in ocrResult.Lines)
|
/// <summary>
|
||||||
{
|
/// Create the OcrInformation
|
||||||
var line = new Line(ocrLine.Words.Count);
|
/// </summary>
|
||||||
result.Lines.Add(line);
|
/// <param name="ocrResult">OcrResult</param>
|
||||||
|
/// <returns>OcrInformation</returns>
|
||||||
|
private OcrInformation CreateOcrInformation(OcrResult ocrResult)
|
||||||
|
{
|
||||||
|
var result = new OcrInformation();
|
||||||
|
|
||||||
|
foreach (var ocrLine in ocrResult.Lines)
|
||||||
|
{
|
||||||
|
var line = new Line(ocrLine.Words.Count)
|
||||||
|
{
|
||||||
|
Text = ocrLine.Text
|
||||||
|
};
|
||||||
|
|
||||||
|
result.Lines.Add(line);
|
||||||
|
|
||||||
for (var index = 0; index < ocrLine.Words.Count; index++)
|
for (var index = 0; index < ocrLine.Words.Count; index++)
|
||||||
{
|
{
|
||||||
var ocrWord = ocrLine.Words[index];
|
var ocrWord = ocrLine.Words[index];
|
||||||
var location = new Rectangle((int) ocrWord.BoundingRect.X, (int) ocrWord.BoundingRect.Y,
|
var location = new Rectangle((int)ocrWord.BoundingRect.X, (int)ocrWord.BoundingRect.Y,
|
||||||
(int) ocrWord.BoundingRect.Width, (int) ocrWord.BoundingRect.Height);
|
(int)ocrWord.BoundingRect.Width, (int)ocrWord.BoundingRect.Height);
|
||||||
|
|
||||||
var word = line.Words[index];
|
var word = line.Words[index];
|
||||||
word.Text = ocrWord.Text;
|
word.Text = ocrWord.Text;
|
||||||
word.Location = location;
|
word.Bounds = location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run the Windows 10 OCR engine to process the text on the captured image
|
/// Run the Windows 10 OCR engine to process the text on the captured image
|
||||||
|
|
|
@ -25,7 +25,6 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using Windows.ApplicationModel.DataTransfer;
|
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
using Color = Windows.UI.Color;
|
using Color = Windows.UI.Color;
|
||||||
|
@ -36,6 +35,7 @@ using System.Windows.Media;
|
||||||
using GreenshotPlugin.Hooking;
|
using GreenshotPlugin.Hooking;
|
||||||
using GreenshotPlugin.Interfaces;
|
using GreenshotPlugin.Interfaces;
|
||||||
using GreenshotPlugin.Interfaces.Plugin;
|
using GreenshotPlugin.Interfaces.Plugin;
|
||||||
|
using GreenshotWin10Plugin.Internal;
|
||||||
|
|
||||||
namespace GreenshotWin10Plugin
|
namespace GreenshotWin10Plugin
|
||||||
{
|
{
|
||||||
|
@ -54,22 +54,6 @@ namespace GreenshotWin10Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\shell32.dll"), 238);
|
public override Image DisplayIcon => PluginUtils.GetCachedExeIcon(FilenameHelper.FillCmdVariables(@"%windir%\system32\shell32.dll"), 238);
|
||||||
|
|
||||||
private class ShareInfo
|
|
||||||
{
|
|
||||||
public string ApplicationName { get; set; }
|
|
||||||
public bool AreShareProvidersRequested { get; set; }
|
|
||||||
public bool IsDeferredFileCreated { get; set; }
|
|
||||||
public DataPackageOperation CompletedWithOperation { get; set; }
|
|
||||||
public string AcceptedFormat { get; set; }
|
|
||||||
public bool IsDestroyed { get; set; }
|
|
||||||
public bool IsShareCompleted { get; set; }
|
|
||||||
|
|
||||||
public TaskCompletionSource<bool> ShareTask { get; } = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
||||||
public bool IsDataRequested { get; set; }
|
|
||||||
|
|
||||||
public IntPtr SharingHwnd { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Share the screenshot with a windows app
|
/// Share the screenshot with a windows app
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -102,7 +86,8 @@ namespace GreenshotWin10Plugin
|
||||||
|
|
||||||
// This is a bad trick, but don't know how else to do it.
|
// This is a bad trick, but don't know how else to do it.
|
||||||
// Wait for the focus to return, and depending on the state close the window!
|
// Wait for the focus to return, and depending on the state close the window!
|
||||||
focusMonitor.WindowOpenCloseChangeEvent += e => {
|
focusMonitor.WindowOpenCloseChangeEvent += e =>
|
||||||
|
{
|
||||||
|
|
||||||
if (e.IsOpen)
|
if (e.IsOpen)
|
||||||
{
|
{
|
||||||
|
@ -112,16 +97,14 @@ namespace GreenshotWin10Plugin
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (e.HWnd == shareInfo.SharingHwnd)
|
||||||
{
|
{
|
||||||
if (e.HWnd == shareInfo.SharingHwnd)
|
if (shareInfo.ApplicationName != null)
|
||||||
{
|
{
|
||||||
if (shareInfo.ApplicationName != null)
|
return;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
shareInfo.ShareTask.TrySetResult(false);
|
|
||||||
}
|
}
|
||||||
|
shareInfo.ShareTask.TrySetResult(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -217,10 +200,10 @@ namespace GreenshotWin10Plugin
|
||||||
await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
|
await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
|
||||||
await imageStream.FlushAsync().ConfigureAwait(false);
|
await imageStream.FlushAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
// Signal that the stream is ready
|
// Signal that the stream is ready
|
||||||
streamedFileDataRequest.Dispose();
|
streamedFileDataRequest.Dispose();
|
||||||
// Signal that the action is ready, bitmap was exported
|
// Signal that the action is ready, bitmap was exported
|
||||||
shareInfo.ShareTask.TrySetResult(true);
|
shareInfo.ShareTask.TrySetResult(true);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue