diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs
index 57fa76974..3ec79db52 100644
--- a/Greenshot/Drawing/Surface.cs
+++ b/Greenshot/Drawing/Surface.cs
@@ -1,20 +1,20 @@
/*
* 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 .
*/
@@ -65,15 +65,9 @@ namespace Greenshot.Drawing
///
public Guid ID
{
- get
- {
- return _uniqueId;
- }
- set
- {
- _uniqueId = value;
- }
- }
+ get => _uniqueId;
+ set => _uniqueId = value;
+ }
///
/// Event handlers (do not serialize!)
@@ -82,69 +76,39 @@ namespace Greenshot.Drawing
private PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged
{
- add
- {
- _propertyChanged += value;
- }
- remove
- {
- _propertyChanged -= value;
- }
- }
+ add => _propertyChanged += value;
+ remove => _propertyChanged -= value;
+ }
[NonSerialized]
private SurfaceElementEventHandler _movingElementChanged;
public event SurfaceElementEventHandler MovingElementChanged
- {
- add
- {
- _movingElementChanged += value;
- }
- remove
- {
- _movingElementChanged -= value;
- }
- }
+ {
+ add => _movingElementChanged += value;
+ remove => _movingElementChanged -= value;
+ }
- [NonSerialized]
+ [NonSerialized]
private SurfaceDrawingModeEventHandler _drawingModeChanged;
public event SurfaceDrawingModeEventHandler DrawingModeChanged
{
- add
- {
- _drawingModeChanged += value;
- }
- remove
- {
- _drawingModeChanged -= value;
- }
- }
+ add => _drawingModeChanged += value;
+ remove => _drawingModeChanged -= value;
+ }
[NonSerialized]
private SurfaceSizeChangeEventHandler _surfaceSizeChanged;
public event SurfaceSizeChangeEventHandler SurfaceSizeChanged
{
- add
- {
- _surfaceSizeChanged += value;
- }
- remove
- {
- _surfaceSizeChanged -= value;
- }
- }
+ add => _surfaceSizeChanged += value;
+ remove => _surfaceSizeChanged -= value;
+ }
[NonSerialized]
private SurfaceMessageEventHandler _surfaceMessage;
public event SurfaceMessageEventHandler SurfaceMessage
{
- add
- {
- _surfaceMessage += value;
- }
- remove
- {
- _surfaceMessage -= value;
- }
- }
+ add => _surfaceMessage += value;
+ remove => _surfaceMessage -= value;
+ }
///
/// inUndoRedo makes sure we don't undo/redo while in a undo/redo action
@@ -153,7 +117,7 @@ namespace Greenshot.Drawing
private bool _inUndoRedo;
///
- /// Make only one surfacemove cycle undoable, see SurfaceMouseMove
+ /// Make only one surface move cycle undoable, see SurfaceMouseMove
///
[NonSerialized]
private bool _isSurfaceMoveMadeUndoable;
@@ -179,7 +143,7 @@ namespace Greenshot.Drawing
private DrawingModes _drawingMode = DrawingModes.None;
///
- /// the keyslocked flag helps with focus issues
+ /// the keys-locked flag helps with focus issues
///
[NonSerialized]
private bool _keysLocked;
@@ -265,8 +229,8 @@ namespace Greenshot.Drawing
///
public int CounterStart
{
- get { return _counterStart; }
- set
+ get => _counterStart;
+ set
{
if (_counterStart == value)
{
@@ -330,11 +294,8 @@ namespace Greenshot.Drawing
private Image _image;
public Image Image
{
- get
- {
- return _image;
- }
- set
+ get => _image;
+ set
{
_image = value;
Size = _image.Size;
@@ -347,15 +308,9 @@ namespace Greenshot.Drawing
///
public FieldAggregator FieldAggregator
{
- get
- {
- return _fieldAggregator;
- }
- set
- {
- _fieldAggregator = value;
- }
- }
+ get => _fieldAggregator;
+ set => _fieldAggregator = value;
+ }
///
/// The cursor container has it's own accessor so we can find and remove this (when needed)
@@ -381,53 +336,35 @@ namespace Greenshot.Drawing
///
public Brush TransparencyBackgroundBrush
{
- get
- {
- return _transparencyBackgroundBrush;
- }
- set
- {
- _transparencyBackgroundBrush = value;
- }
- }
+ get => _transparencyBackgroundBrush;
+ set => _transparencyBackgroundBrush = value;
+ }
///
/// Are the keys on this surface locked?
///
public bool KeysLocked
{
- get
- {
- return _keysLocked;
- }
- set
- {
- _keysLocked = value;
- }
- }
+ get => _keysLocked;
+ set => _keysLocked = value;
+ }
///
/// Is this surface modified? This is only true if the surface has not been exported.
///
public bool Modified
{
- get
- {
- return _modified;
- }
- set
- {
- _modified = value;
- }
- }
+ get => _modified;
+ set => _modified = value;
+ }
///
/// The DrawingMode property specifies the mode for drawing, more or less the element type.
///
public DrawingModes DrawingMode
{
- get { return _drawingMode; }
- set
+ get => _drawingMode;
+ set
{
_drawingMode = value;
if (_drawingModeChanged != null)
@@ -448,15 +385,9 @@ namespace Greenshot.Drawing
///
public string LastSaveFullPath
{
- get
- {
- return _lastSaveFullPath;
- }
- set
- {
- _lastSaveFullPath = value;
- }
- }
+ get => _lastSaveFullPath;
+ set => _lastSaveFullPath = value;
+ }
///
/// Property for accessing the URL to which the surface was recently uploaded
@@ -1518,7 +1449,7 @@ namespace Greenshot.Drawing
}
///
- /// Draw a checkboard when capturing with transparency
+ /// Draw a checkboard when capturing with transparency
///
/// PaintEventArgs
protected override void OnPaintBackground(PaintEventArgs e)
diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs
index 2798b2aa2..c6ca35666 100644
--- a/Greenshot/Forms/CaptureForm.cs
+++ b/Greenshot/Forms/CaptureForm.cs
@@ -39,6 +39,7 @@ using System.Windows.Forms;
using System.Windows.Threading;
using GreenshotPlugin.IniFile;
using GreenshotPlugin.Interfaces;
+using GreenshotPlugin.Interfaces.Ocr;
using ZXing;
namespace Greenshot.Forms {
@@ -308,7 +309,7 @@ namespace Greenshot.Forms {
TopMost = !TopMost;
break;
case Keys.O:
- if (_capture.OcrInformation is null)
+ if (_capture.CaptureDetails.OcrInformation is null)
{
var ocrProvider = SimpleServiceProvider.Current.GetInstance();
if (ocrProvider is object)
@@ -317,36 +318,12 @@ namespace Greenshot.Forms {
Task.Factory.StartNew(async () =>
{
- _capture.OcrInformation = await ocrProvider.DoOcrAsync(_capture.Image);
+ _capture.CaptureDetails.OcrInformation = await ocrProvider.DoOcrAsync(_capture.Image);
Invalidate();
}, CancellationToken.None, TaskCreationOptions.None, uiTaskScheduler);
}
}
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.DrawImageUnscaled(_capture.Image, Point.Empty);
- var ocrInfo = _capture.OcrInformation;
+ var ocrInfo = _capture.CaptureDetails.OcrInformation;
if (ocrInfo != null)
{
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
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);
diff --git a/Greenshot/Processors/TitleFixProcessor.cs b/Greenshot/Processors/TitleFixProcessor.cs
index 2940cad8d..7c44e218e 100644
--- a/Greenshot/Processors/TitleFixProcessor.cs
+++ b/Greenshot/Processors/TitleFixProcessor.cs
@@ -1,20 +1,20 @@
/*
* 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 .
*/
@@ -33,8 +33,8 @@ namespace Greenshot.Processors {
public class TitleFixProcessor : AbstractProcessor {
private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
private static readonly CoreConfiguration config = IniConfig.GetIniSection();
-
- public TitleFixProcessor() {
+
+ public TitleFixProcessor() {
List corruptKeys = new List();
foreach(string key in config.ActiveTitleFixes) {
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);
corruptKeys.Add(key);
}
-
- // Fix configuration if needed
+
+ // Fix configuration if needed
if (corruptKeys.Count <= 0) return;
foreach(string corruptKey in corruptKeys) {
@@ -54,8 +54,8 @@ namespace Greenshot.Processors {
}
config.IsDirty = true;
}
-
- public override string Designation => "TitleFix";
+
+ public override string Designation => "TitleFix";
public override string Description => Designation;
@@ -67,7 +67,7 @@ namespace Greenshot.Processors {
foreach(string titleIdentifier in config.ActiveTitleFixes) {
string regexpString = config.TitleFixMatcher[titleIdentifier];
string replaceString = config.TitleFixReplacer[titleIdentifier] ?? string.Empty;
-
+
if (string.IsNullOrEmpty(regexpString)) continue;
var regex = new Regex(regexpString);
diff --git a/Greenshot/Processors/ZXingQrProcessor.cs b/Greenshot/Processors/ZXingQrProcessor.cs
new file mode 100644
index 000000000..182344a4b
--- /dev/null
+++ b/Greenshot/Processors/ZXingQrProcessor.cs
@@ -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 .
+ */
+
+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 {
+ ///
+ /// This processor processes a capture to see if there is a QR ode on it
+ ///
+ public class ZXingQrProcessor : AbstractProcessor {
+ private static readonly ILog LOG = LogManager.GetLogger(typeof(TitleFixProcessor));
+ private static readonly CoreConfiguration config = IniConfig.GetIniSection();
+
+ 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;
+ }
+ }
+}
diff --git a/GreenshotPlugin/Core/AbstractProcessor.cs b/GreenshotPlugin/Core/AbstractProcessor.cs
index 5dd6c38ab..5e82b1d23 100644
--- a/GreenshotPlugin/Core/AbstractProcessor.cs
+++ b/GreenshotPlugin/Core/AbstractProcessor.cs
@@ -1,20 +1,20 @@
/*
* 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 .
*/
@@ -26,8 +26,8 @@ namespace GreenshotPlugin.Core {
/// Description of AbstractProcessor.
///
public abstract class AbstractProcessor : IProcessor {
-
- public virtual int CompareTo(object obj) {
+
+ public virtual int CompareTo(object obj) {
if (!(obj is IProcessor other)) {
return 1;
}
@@ -45,13 +45,9 @@ namespace GreenshotPlugin.Core {
get;
}
- public virtual int Priority {
- get {
- return 10;
- }
- }
+ public virtual int Priority => 10;
- public void Dispose() {
+ public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
@@ -60,12 +56,8 @@ namespace GreenshotPlugin.Core {
//if (disposing) {}
}
- public virtual bool isActive {
- get {
- return true;
- }
- }
+ public virtual bool isActive => true;
- public abstract bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails);
+ public abstract bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails);
}
}
diff --git a/GreenshotPlugin/Core/Capture.cs b/GreenshotPlugin/Core/Capture.cs
new file mode 100644
index 000000000..d4674ce70
--- /dev/null
+++ b/GreenshotPlugin/Core/Capture.cs
@@ -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
+{
+ ///
+ /// This class is used to pass an instance of the "Capture" around
+ /// Having the Bitmap, eventually the Windows Title and cursor all together.
+ ///
+ public class Capture : ICapture {
+ private static readonly ILog Log = LogManager.GetLogger(typeof(Capture));
+ private List _elements = new List();
+
+ private Rectangle _screenBounds;
+ ///
+ /// Get/Set the Screenbounds
+ ///
+ public Rectangle ScreenBounds {
+ get {
+ if (_screenBounds == Rectangle.Empty) {
+ _screenBounds = WindowCapture.GetScreenBounds();
+ }
+ return _screenBounds;
+ }
+ set => _screenBounds = value;
+ }
+
+ private Image _image;
+ ///
+ /// Get/Set the Image
+ ///
+ 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;
+ ///
+ /// Get/Set the image for the Cursor
+ ///
+ public Icon Cursor {
+ get => _cursor;
+ set {
+ _cursor?.Dispose();
+ _cursor = (Icon)value.Clone();
+ }
+ }
+
+ ///
+ /// The information which OCR brings
+ ///
+ public OcrInformation OcrInformation { get; set; }
+
+ ///
+ /// Set if the cursor is visible
+ ///
+ public bool CursorVisible { get; set; }
+
+ private Point _cursorLocation = Point.Empty;
+ ///
+ /// Get/Set the CursorLocation
+ ///
+ public Point CursorLocation {
+ get => _cursorLocation;
+ set => _cursorLocation = value;
+ }
+
+ private Point _location = Point.Empty;
+ ///
+ /// Get/set the Location
+ ///
+ public Point Location {
+ get => _location;
+ set => _location = value;
+ }
+
+ private CaptureDetails _captureDetails;
+ ///
+ /// Get/set the CaptureDetails
+ ///
+ public ICaptureDetails CaptureDetails {
+ get => _captureDetails;
+ set => _captureDetails = (CaptureDetails)value;
+ }
+
+ ///
+ /// Default Constructor
+ ///
+ public Capture() {
+ _screenBounds = WindowCapture.GetScreenBounds();
+ _captureDetails = new CaptureDetails();
+ }
+
+ ///
+ /// Constructor with Image
+ /// Note: the supplied bitmap can be disposed immediately or when constructor is called.
+ ///
+ /// Image
+ public Capture(Image newImage) : this() {
+ Image = newImage;
+ }
+
+ ///
+ /// Destructor
+ ///
+ ~Capture() {
+ Dispose(false);
+ }
+
+ ///
+ /// The public accessible Dispose
+ /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
+ ///
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// This Dispose is called from the Dispose and the Destructor.
+ /// When disposing==true all non-managed resources should be freed too!
+ ///
+ ///
+ protected virtual void Dispose(bool disposing) {
+ if (disposing) {
+ _image?.Dispose();
+ _cursor?.Dispose();
+ }
+ _image = null;
+ _cursor = null;
+ }
+
+ ///
+ /// Crops the capture to the specified rectangle (with Bitmap coordinates!)
+ ///
+ /// Rectangle with bitmap coordinates
+ 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();
+ foreach(var captureElement in _elements) {
+ if (captureElement.Bounds.IntersectsWith(cropRectangle)) {
+ visibleElements.Add(captureElement);
+ }
+ }
+ _elements = visibleElements;
+
+ return true;
+ }
+
+ ///
+ /// Apply a translate to the mouse location.
+ /// e.g. needed for crop
+ ///
+ /// x coordinates to move the mouse
+ /// y coordinates to move the mouse
+ public void MoveMouseLocation(int x, int y) {
+ _cursorLocation.Offset(x, y);
+ }
+
+ // TODO: Enable when the elements are usable again.
+ /////
+ ///// Apply a translate to the elements
+ ///// e.g. needed for crop
+ /////
+ ///// x coordinates to move the elements
+ ///// y coordinates to move the elements
+ //public void MoveElements(int x, int y) {
+ // MoveElements(elements, x, y);
+ //}
+
+ //private void MoveElements(List 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);
+ // }
+ //}
+
+ /////
+ ///// Add a new element to the capture
+ /////
+ ///// CaptureElement
+ //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);
+ // }
+ //}
+
+ /////
+ ///// Returns a list of rectangles which represent object that are on the capture
+ /////
+ //public List Elements {
+ // get {
+ // return elements;
+ // }
+ // set {
+ // elements = value;
+ // }
+ //}
+
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Core/CaptureDetails.cs b/GreenshotPlugin/Core/CaptureDetails.cs
new file mode 100644
index 000000000..9f7682d5a
--- /dev/null
+++ b/GreenshotPlugin/Core/CaptureDetails.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using GreenshotPlugin.Interfaces;
+using GreenshotPlugin.Interfaces.Ocr;
+using ZXing;
+
+namespace GreenshotPlugin.Core
+{
+ ///
+ /// 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
+ ///
+ 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 OcrInformation OcrInformation { get; set; }
+
+ ///
+ public Result QrResult { get; set; }
+
+ ///
+ public Dictionary MetaData { get; } = new Dictionary();
+
+ ///
+ 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 CaptureDestinations { get; set; } = new List();
+
+ ///
+ 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Core/CaptureElement.cs b/GreenshotPlugin/Core/CaptureElement.cs
new file mode 100644
index 000000000..6b0f3ab73
--- /dev/null
+++ b/GreenshotPlugin/Core/CaptureElement.cs
@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+using System.Drawing;
+using GreenshotPlugin.Interfaces;
+
+namespace GreenshotPlugin.Core
+{
+ ///
+ /// A class representing an element in the capture
+ ///
+ 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 Children { get; set; } = new List();
+
+ 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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Core/NetworkHelper.cs b/GreenshotPlugin/Core/NetworkHelper.cs
index 1b2378192..c3fcff8ab 100644
--- a/GreenshotPlugin/Core/NetworkHelper.cs
+++ b/GreenshotPlugin/Core/NetworkHelper.cs
@@ -100,10 +100,10 @@ namespace GreenshotPlugin.Core {
}
///
- /// Download the uri into a memorystream, without catching exceptions
+ /// Download the uri into a memory stream, without catching exceptions
///
/// Of an image
- /// MemoryStream which is already seeked to 0
+ /// MemoryStream which is already seek-ed to 0
public static MemoryStream GetAsMemoryStream(string url) {
HttpWebRequest request = CreateWebRequest(url);
using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
diff --git a/GreenshotPlugin/Core/WindowCapture.cs b/GreenshotPlugin/Core/WindowCapture.cs
index 494f62b77..7d2c9e4d3 100644
--- a/GreenshotPlugin/Core/WindowCapture.cs
+++ b/GreenshotPlugin/Core/WindowCapture.cs
@@ -33,363 +33,7 @@ using GreenshotPlugin.Interfaces;
using GreenshotPlugin.UnmanagedHelpers.Structs;
namespace GreenshotPlugin.Core {
- ///
- /// 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
- ///
- 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 MetaData { get; } = new Dictionary();
-
- 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 CaptureDestinations { get; set; } = new List();
-
- 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;
- }
- }
-
- ///
- /// This class is used to pass an instance of the "Capture" around
- /// Having the Bitmap, eventually the Windows Title and cursor all together.
- ///
- public class Capture : ICapture {
- private static readonly ILog Log = LogManager.GetLogger(typeof(Capture));
- private List _elements = new List();
-
- private Rectangle _screenBounds;
- ///
- /// Get/Set the Screenbounds
- ///
- public Rectangle ScreenBounds {
- get {
- if (_screenBounds == Rectangle.Empty) {
- _screenBounds = WindowCapture.GetScreenBounds();
- }
- return _screenBounds;
- }
- set {_screenBounds = value;}
- }
-
- private Image _image;
- ///
- /// Get/Set the Image
- ///
- 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;
- ///
- /// Get/Set the image for the Cursor
- ///
- public Icon Cursor {
- get {return _cursor;}
- set {
- _cursor?.Dispose();
- _cursor = (Icon)value.Clone();
- }
- }
-
- ///
- /// The information which OCR brings
- ///
- public OcrInformation OcrInformation { get; set; }
-
- ///
- /// Set if the cursor is visible
- ///
- public bool CursorVisible { get; set; }
-
- private Point _cursorLocation = Point.Empty;
- ///
- /// Get/Set the CursorLocation
- ///
- public Point CursorLocation {
- get {return _cursorLocation;}
- set {_cursorLocation = value;}
- }
-
- private Point _location = Point.Empty;
- ///
- /// Get/set the Location
- ///
- public Point Location {
- get {return _location;}
- set {_location = value;}
- }
-
- private CaptureDetails _captureDetails;
- ///
- /// Get/set the CaptureDetails
- ///
- public ICaptureDetails CaptureDetails {
- get {return _captureDetails;}
- set {_captureDetails = (CaptureDetails)value;}
- }
-
- ///
- /// Default Constructor
- ///
- public Capture() {
- _screenBounds = WindowCapture.GetScreenBounds();
- _captureDetails = new CaptureDetails();
- }
-
- ///
- /// Constructor with Image
- /// Note: the supplied bitmap can be disposed immediately or when constructor is called.
- ///
- /// Image
- public Capture(Image newImage) : this() {
- Image = newImage;
- }
-
- ///
- /// Destructor
- ///
- ~Capture() {
- Dispose(false);
- }
-
- ///
- /// The public accessible Dispose
- /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
- ///
- public void Dispose() {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// This Dispose is called from the Dispose and the Destructor.
- /// When disposing==true all non-managed resources should be freed too!
- ///
- ///
- protected virtual void Dispose(bool disposing) {
- if (disposing) {
- _image?.Dispose();
- _cursor?.Dispose();
- }
- _image = null;
- _cursor = null;
- }
-
- ///
- /// Crops the capture to the specified rectangle (with Bitmap coordinates!)
- ///
- /// Rectangle with bitmap coordinates
- 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();
- foreach(var captureElement in _elements) {
- if (captureElement.Bounds.IntersectsWith(cropRectangle)) {
- newElements.Add(captureElement);
- }
- }
- _elements = newElements;
-
- return true;
- }
-
- ///
- /// Apply a translate to the mouse location.
- /// e.g. needed for crop
- ///
- /// x coordinates to move the mouse
- /// y coordinates to move the mouse
- public void MoveMouseLocation(int x, int y) {
- _cursorLocation.Offset(x, y);
- }
-
- // TODO: Enable when the elements are usable again.
- /////
- ///// Apply a translate to the elements
- ///// e.g. needed for crop
- /////
- ///// x coordinates to move the elements
- ///// y coordinates to move the elements
- //public void MoveElements(int x, int y) {
- // MoveElements(elements, x, y);
- //}
-
- //private void MoveElements(List 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);
- // }
- //}
-
- /////
- ///// Add a new element to the capture
- /////
- ///// CaptureElement
- //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);
- // }
- //}
-
- /////
- ///// Returns a list of rectangles which represent object that are on the capture
- /////
- //public List Elements {
- // get {
- // return elements;
- // }
- // set {
- // elements = value;
- // }
- //}
-
- }
-
///
- /// A class representing an element in the capture
- ///
- 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 Children { get; set; } = new List();
-
- 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();
- }
- }
- ///
/// The Window Capture code
///
public static class WindowCapture {
@@ -397,7 +41,7 @@ namespace GreenshotPlugin.Core {
private static readonly CoreConfiguration Configuration = IniConfig.GetIniSection();
///
- /// 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
///
///
///
@@ -435,11 +79,11 @@ namespace GreenshotPlugin.Core {
///
/// 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.
///
///
- ///
+ /// Point
public static Point GetLocationRelativeToScreenBounds(Point locationRelativeToScreenOrigin) {
Point ret = locationRelativeToScreenOrigin;
Rectangle bounds = GetScreenBounds();
@@ -456,34 +100,32 @@ namespace GreenshotPlugin.Core {
if (capture == null) {
capture = new Capture();
}
- CursorInfo cursorInfo = new CursorInfo();
+ var cursorInfo = new CursorInfo();
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
- if (User32.GetCursorInfo(out cursorInfo)) {
- if (cursorInfo.flags == User32.CURSOR_SHOWING)
- {
- 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);
+ if (!User32.GetCursorInfo(out cursorInfo)) return capture;
+ if (cursorInfo.flags != User32.CURSOR_SHOWING) return capture;
- using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle())) {
- capture.Cursor = icon;
- }
+ using SafeIconHandle safeIcon = User32.CopyIcon(cursorInfo.hCursor);
+ if (!User32.GetIconInfo(safeIcon, out var iconInfo)) return capture;
- if (iconInfo.hbmMask != IntPtr.Zero) {
- DeleteObject(iconInfo.hbmMask);
- }
- if (iconInfo.hbmColor != IntPtr.Zero) {
- DeleteObject(iconInfo.hbmColor);
- }
- }
- }
- }
- return capture;
+ Point cursorLocation = User32.GetCursorLocation();
+ // Align 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())) {
+ capture.Cursor = icon;
+ }
+
+ if (iconInfo.hbmMask != IntPtr.Zero) {
+ DeleteObject(iconInfo.hbmMask);
+ }
+ if (iconInfo.hbmColor != IntPtr.Zero) {
+ DeleteObject(iconInfo.hbmColor);
+ }
+ return capture;
}
///
@@ -518,19 +160,19 @@ namespace GreenshotPlugin.Core {
/// Process owning the window
/// true if it's allowed
public static bool IsDwmAllowed(Process process) {
- if (process != null) {
- if (Configuration.NoDWMCaptureForProduct != null && Configuration.NoDWMCaptureForProduct.Count > 0) {
- try {
- string productName = process.MainModule.FileVersionInfo.ProductName;
- if (productName != null && Configuration.NoDWMCaptureForProduct.Contains(productName.ToLower())) {
- return false;
- }
- } catch (Exception ex) {
- Log.Warn(ex.Message);
- }
- }
- }
- return true;
+ if (process == null) return true;
+ if (Configuration.NoDWMCaptureForProduct == null ||
+ Configuration.NoDWMCaptureForProduct.Count <= 0) return true;
+
+ try {
+ string productName = process.MainModule?.FileVersionInfo.ProductName;
+ if (productName != null && Configuration.NoDWMCaptureForProduct.Contains(productName.ToLower())) {
+ return false;
+ }
+ } catch (Exception ex) {
+ Log.Warn(ex.Message);
+ }
+ return true;
}
///
@@ -539,19 +181,19 @@ namespace GreenshotPlugin.Core {
/// Process owning the window
/// true if it's allowed
public static bool IsGdiAllowed(Process process) {
- if (process != null) {
- if (Configuration.NoGDICaptureForProduct != null && Configuration.NoGDICaptureForProduct.Count > 0) {
- try {
- string productName = process.MainModule.FileVersionInfo.ProductName;
- if (productName != null && Configuration.NoGDICaptureForProduct.Contains(productName.ToLower())) {
- return false;
- }
- } catch (Exception ex) {
- Log.Warn(ex.Message);
- }
- }
- }
- return true;
+ if (process == null) return true;
+ if (Configuration.NoGDICaptureForProduct == null ||
+ Configuration.NoGDICaptureForProduct.Count <= 0) return true;
+
+ try {
+ string productName = process.MainModule?.FileVersionInfo.ProductName;
+ if (productName != null && Configuration.NoGDICaptureForProduct.Contains(productName.ToLower())) {
+ return false;
+ }
+ } catch (Exception ex) {
+ Log.Warn(ex.Message);
+ }
+ return true;
}
///
@@ -645,10 +287,10 @@ namespace GreenshotPlugin.Core {
Win32.SetLastError(0);
// 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) {
// 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("hdcSrc", desktopDcHandle.DangerousGetHandle().ToInt32());
diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj
index 4c2f3dd84..05c7ba595 100644
--- a/GreenshotPlugin/GreenshotPlugin.csproj
+++ b/GreenshotPlugin/GreenshotPlugin.csproj
@@ -15,6 +15,7 @@
+
diff --git a/GreenshotPlugin/Interfaces/Capture.cs b/GreenshotPlugin/Interfaces/Capture.cs
deleted file mode 100644
index 2ec761236..000000000
--- a/GreenshotPlugin/Interfaces/Capture.cs
+++ /dev/null
@@ -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 .
- */
-
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-
-namespace GreenshotPlugin.Interfaces {
- ///
- /// The capture mode for Greenshot
- ///
- public enum CaptureMode { None, Region, FullScreen, ActiveWindow, Window, LastRegion, Clipboard, File, IE, Import}; //, Video };
- public enum ScreenCaptureMode { Auto, FullScreen, Fixed};
-
- ///
- /// Details for the capture, like the window title and date/time etc.
- ///
- public interface ICaptureDetails {
- string Filename {
- get;
- set;
- }
- string Title {
- get;
- set;
- }
-
- DateTime DateTime {
- get;
- set;
- }
-
- List CaptureDestinations {
- get;
- set;
- }
-
- Dictionary MetaData {
- get;
- }
-
- ///
- /// Helper method to prevent complex code which needs to check every key
- ///
- /// The key for the meta-data
- /// The value for the meta-data
- 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 Children {
- get;
- set;
- }
- Rectangle Bounds {
- get;
- set;
- }
- string Name {
- get;
- set;
- }
- }
-
- ///
- /// The interface to the Capture object, so Plugins can use it.
- ///
- 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;
- }
-
- ///
- /// Crops the capture to the specified rectangle (with Bitmap coordinates!)
- ///
- /// Rectangle with bitmap coordinates
- bool Crop(Rectangle cropRectangle);
-
- ///
- /// Apply a translate to the mouse location. e.g. needed for crop
- ///
- /// x coordinates to move the mouse
- /// y coordinates to move the mouse
- void MoveMouseLocation(int x, int y);
-
- ///
- /// Store the OCR information for this capture
- ///
- OcrInformation OcrInformation { get; set; }
-
- // / TODO: Enable when the elements are usable again.
- /////
- ///// Apply a translate to the elements e.g. needed for crop
- /////
- ///// x coordinates to move the elements
- ///// y coordinates to move the elements
- //void MoveElements(int x, int y);
-
- /////
- ///// Add a new element to the capture
- /////
- ///// Rectangle
- //void AddElement(ICaptureElement element);
-
- /////
- ///// Returns a list of rectangles which represent objects that are "on" the capture
- /////
- //List Elements {
- // get;
- // set;
- //}
- }
-
-}
diff --git a/GreenshotPlugin/Interfaces/CaptureMode.cs b/GreenshotPlugin/Interfaces/CaptureMode.cs
new file mode 100644
index 000000000..70dae2f32
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/CaptureMode.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ ///
+ /// The capture mode for Greenshot
+ ///
+ public enum CaptureMode
+ {
+ None,
+ Region,
+ FullScreen,
+ ActiveWindow,
+ Window,
+ LastRegion,
+ Clipboard,
+ File,
+ IE,
+ Import
+ // Video
+ };
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/DrawingModes.cs b/GreenshotPlugin/Interfaces/DrawingModes.cs
new file mode 100644
index 000000000..9ada15b2d
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/DrawingModes.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public enum DrawingModes
+ {
+ None,
+ Rect,
+ Ellipse,
+ Text,
+ Line,
+ Arrow,
+ Crop,
+ Highlight,
+ Obfuscate,
+ Bitmap,
+ Path,
+ SpeechBubble,
+ StepLabel
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/Generic.cs b/GreenshotPlugin/Interfaces/Generic.cs
deleted file mode 100644
index 5ae2177ef..000000000
--- a/GreenshotPlugin/Interfaces/Generic.cs
+++ /dev/null
@@ -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 .
- */
-
-using System;
-using System.Drawing;
-using System.IO;
-using System.Windows.Forms;
-using GreenshotPlugin.Effects;
-using GreenshotPlugin.Interfaces.Drawing;
-
-namespace GreenshotPlugin.Interfaces
-{
- ///
- /// Alignment Enums for possitioning
- ///
- //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
- }
-
- ///
- /// The interface to the Surface object, so Plugins can use it.
- ///
- public interface ISurface : IDisposable
- {
- event SurfaceSizeChangeEventHandler SurfaceSizeChanged;
- event SurfaceMessageEventHandler SurfaceMessage;
- event SurfaceDrawingModeEventHandler DrawingModeChanged;
- event SurfaceElementEventHandler MovingElementChanged;
-
- ///
- /// Start valueof the step-labels (counts)
- ///
- int CounterStart { get; set; }
-
- ///
- /// Unique ID of the Surface
- ///
- Guid ID
- {
- get;
- set;
- }
-
- IDrawableContainerList Elements
- {
- get;
- }
-
- ///
- /// 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!)
- ///
- Image Image
- {
- get;
- set;
- }
-
- ///
- /// Get the current Image from the Editor for Exporting (save/upload etc)
- /// Don't forget to call image.Dispose() when finished!!!
- ///
- /// Bitmap
- Image GetImageForExport();
-
- ///
- /// Add a TextContainer, at the given location, to the Surface.
- /// The TextContainer will be "re"sized to the text size.
- ///
- /// String to show
- /// Left, Center, Right
- /// TOP, CENTER, BOTTOM
- /// FontFamily
- /// Font Size in float
- /// bool true if italic
- /// bool true if bold
- /// bool true if shadow
- /// size of border (0 for none)
- /// Color of string
- /// Color of background (e.g. Color.Transparent)
- 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();
-
- ///
- /// Add an element to the surface
- ///
- /// IDrawableContainerList
- /// Should it be placed on the undo stack?
- void AddElements(IDrawableContainerList elements, bool makeUndoable = true);
- void RemoveElements(IDrawableContainerList elements, bool makeUndoable = true);
- void SelectElements(IDrawableContainerList elements);
-
- ///
- /// Add an element to the surface
- ///
- /// IDrawableContainer
- /// Should it be placed on the undo stack?
- /// Should it be invalidated (draw)
- void AddElement(IDrawableContainer element, bool makeUndoable = true, bool invalidate = true);
-
- ///
- /// Select the supplied container
- ///
- /// IDrawableContainer
- /// false to skip invalidation
- /// false to skip event generation
- void SelectElement(IDrawableContainer container, bool invalidate = true, bool generateEvents = true);
- ///
- /// Is the supplied container "on" the surface?
- ///
- ///
- /// This returns false if the container is deleted but still in the undo stack
- bool IsOnSurface(IDrawableContainer container);
- void Invalidate(Rectangle rectangleToInvalidate);
- void Invalidate();
- bool Modified
- {
- get;
- set;
- }
- string LastSaveFullPath
- {
- get;
- set;
- }
- string UploadUrl
- {
- get;
- set;
- }
- ///
- /// Remove an element of the elements list
- ///
- /// Element to remove
- /// flag specifying if the remove needs to be undoable
- /// flag specifying if an surface invalidate needs to be called
- /// flag specifying if the deselect needs to generate an event
- 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);
- }
-}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/ICapture.cs b/GreenshotPlugin/Interfaces/ICapture.cs
new file mode 100644
index 000000000..231af2d08
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/ICapture.cs
@@ -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 .
+ */
+
+using System;
+using System.Drawing;
+
+namespace GreenshotPlugin.Interfaces
+{
+ ///
+ /// The interface to the Capture object, so Plugins can use it.
+ ///
+ public interface ICapture : IDisposable {
+ ///
+ /// The Capture Details
+ ///
+ ICaptureDetails CaptureDetails {
+ get;
+ set;
+ }
+
+ ///
+ /// The captured Image
+ ///
+ Image Image {
+ get;
+ set;
+ }
+
+ ///
+ /// Null the image
+ ///
+ void NullImage();
+
+ ///
+ /// Bounds on the screen from which the capture comes
+ ///
+ Rectangle ScreenBounds {
+ get;
+ set;
+ }
+
+ ///
+ /// The cursor
+ ///
+ Icon Cursor {
+ get;
+ set;
+ }
+
+ ///
+ /// Boolean to specify if the cursor is available
+ ///
+ bool CursorVisible {
+ get;
+ set;
+ }
+
+ ///
+ /// Location of the cursor
+ ///
+ Point CursorLocation {
+ get;
+ set;
+ }
+
+ ///
+ /// Location of the capture
+ ///
+ Point Location {
+ get;
+ set;
+ }
+
+ ///
+ /// Crops the capture to the specified rectangle (with Bitmap coordinates!)
+ ///
+ /// Rectangle with bitmap coordinates
+ bool Crop(Rectangle cropRectangle);
+
+ ///
+ /// Apply a translate to the mouse location. e.g. needed for crop
+ ///
+ /// x coordinates to move the mouse
+ /// y coordinates to move the mouse
+ void MoveMouseLocation(int x, int y);
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/ICaptureDetails.cs b/GreenshotPlugin/Interfaces/ICaptureDetails.cs
new file mode 100644
index 000000000..33df1a822
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/ICaptureDetails.cs
@@ -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 .
+ */
+
+using System;
+using System.Collections.Generic;
+using GreenshotPlugin.Interfaces.Ocr;
+using ZXing;
+
+namespace GreenshotPlugin.Interfaces {
+ ///
+ /// Details for the capture, like the window title and date/time etc.
+ ///
+ public interface ICaptureDetails {
+
+ ///
+ /// If the capture comes from a file, this contains the filename
+ ///
+ string Filename {
+ get;
+ set;
+ }
+
+ ///
+ /// The title of the capture
+ ///
+ string Title {
+ get;
+ set;
+ }
+
+ ///
+ /// When was the capture taken (or loaded)
+ ///
+ DateTime DateTime {
+ get;
+ set;
+ }
+
+ ///
+ /// Destinations to where this capture goes or went
+ ///
+ List CaptureDestinations {
+ get;
+ set;
+ }
+
+ ///
+ /// The meta data of the capture
+ ///
+ Dictionary MetaData {
+ get;
+ }
+
+ ///
+ /// Helper method to prevent complex code which needs to check every key
+ ///
+ /// The key for the meta-data
+ /// The value for the meta-data
+ 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;
+ }
+
+ ///
+ /// Store the OCR information for this capture
+ ///
+ OcrInformation OcrInformation { get; set; }
+
+ ///
+ /// Store the QR information for this capture
+ ///
+ Result QrResult { get; set; }
+ }
+}
diff --git a/GreenshotPlugin/Interfaces/ICaptureElement.cs b/GreenshotPlugin/Interfaces/ICaptureElement.cs
new file mode 100644
index 000000000..36c0bbc72
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/ICaptureElement.cs
@@ -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 .
+ */
+
+using System.Collections.Generic;
+using System.Drawing;
+
+namespace GreenshotPlugin.Interfaces
+{
+ public interface ICaptureElement {
+ List Children {
+ get;
+ set;
+ }
+ Rectangle Bounds {
+ get;
+ set;
+ }
+ string Name {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/IOcrProvider.cs b/GreenshotPlugin/Interfaces/IOcrProvider.cs
deleted file mode 100644
index 5d97f85a4..000000000
--- a/GreenshotPlugin/Interfaces/IOcrProvider.cs
+++ /dev/null
@@ -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 .
- */
-
-using System.Collections.Generic;
-using System.Drawing;
-using System.Threading.Tasks;
-
-namespace GreenshotPlugin.Interfaces
-{
- ///
- /// This interface describes something that can do OCR of a bitmap
- ///
- public interface IOcrProvider
- {
- ///
- /// Start the actual OCR
- ///
- /// Image
- /// OcrInformation
- Task DoOcrAsync(Image image);
-
- ///
- /// Start the actual OCR
- ///
- /// ISurface
- /// OcrInformation
- Task DoOcrAsync(ISurface surface);
- }
-
- ///
- /// Contains the information about a word
- ///
- public class Word
- {
- ///
- /// The actual text for the word
- ///
- public string Text { get; set; }
-
- ///
- /// The location of the word
- ///
- public Rectangle Location { get; set; }
- }
-
- ///
- /// Describes a line of words
- ///
- public class Line
- {
- private Rectangle? _calculatedBounds;
-
- ///
- /// Constructor will preallocate the number of words
- ///
- /// int
- public Line(int wordCount)
- {
- Words = new Word[wordCount];
- for (int i = 0; i < wordCount; i++)
- {
- Words[i] = new Word();
- }
- }
-
- ///
- /// An array with words
- ///
- public Word[] Words { get; }
-
- ///
- /// Calculate the bounds of the words
- ///
- /// Rectangle
- 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;
- }
-
- ///
- /// Return the calculated bounds for the whole line
- ///
- public Rectangle CalculatedBounds
- {
- get { return _calculatedBounds ??= CalculateBounds(); }
- }
- }
-
- ///
- /// Contains all the information on the OCR result
- ///
- public class OcrInformation
- {
- public string Text { get; set; }
-
- public IList Lines { get; } = new List();
- }
-}
diff --git a/GreenshotPlugin/Interfaces/ISurface.cs b/GreenshotPlugin/Interfaces/ISurface.cs
new file mode 100644
index 000000000..44a150364
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/ISurface.cs
@@ -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 .
+ */
+
+using System;
+using System.Drawing;
+using System.IO;
+using System.Windows.Forms;
+using GreenshotPlugin.Effects;
+using GreenshotPlugin.Interfaces.Drawing;
+
+namespace GreenshotPlugin.Interfaces
+{
+ ///
+ /// The interface to the Surface object, so Plugins can use it.
+ ///
+ public interface ISurface : IDisposable
+ {
+ event SurfaceSizeChangeEventHandler SurfaceSizeChanged;
+ event SurfaceMessageEventHandler SurfaceMessage;
+ event SurfaceDrawingModeEventHandler DrawingModeChanged;
+ event SurfaceElementEventHandler MovingElementChanged;
+
+ ///
+ /// Start value of the step-labels (counts)
+ ///
+ int CounterStart { get; set; }
+
+ ///
+ /// Unique ID of the Surface
+ ///
+ Guid ID
+ {
+ get;
+ set;
+ }
+
+ IDrawableContainerList Elements
+ {
+ get;
+ }
+
+ ///
+ /// 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!)
+ ///
+ Image Image
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Get the current Image from the Editor for Exporting (save/upload etc)
+ /// Don't forget to call image.Dispose() when finished!!!
+ ///
+ /// Bitmap
+ Image GetImageForExport();
+
+ ///
+ /// Add a TextContainer, at the given location, to the Surface.
+ /// The TextContainer will be "re"sized to the text size.
+ ///
+ /// String to show
+ /// Left, Center, Right
+ /// TOP, CENTER, BOTTOM
+ /// FontFamily
+ /// Font Size in float
+ /// bool true if italic
+ /// bool true if bold
+ /// bool true if shadow
+ /// size of border (0 for none)
+ /// Color of string
+ /// Color of background (e.g. Color.Transparent)
+ 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();
+
+ ///
+ /// Add an element to the surface
+ ///
+ /// IDrawableContainerList
+ /// Should it be placed on the undo stack?
+ void AddElements(IDrawableContainerList elements, bool makeUndoable = true);
+ void RemoveElements(IDrawableContainerList elements, bool makeUndoable = true);
+ void SelectElements(IDrawableContainerList elements);
+
+ ///
+ /// Add an element to the surface
+ ///
+ /// IDrawableContainer
+ /// Should it be placed on the undo stack?
+ /// Should it be invalidated (draw)
+ void AddElement(IDrawableContainer element, bool makeUndoable = true, bool invalidate = true);
+
+ ///
+ /// Select the supplied container
+ ///
+ /// IDrawableContainer
+ /// false to skip invalidation
+ /// false to skip event generation
+ void SelectElement(IDrawableContainer container, bool invalidate = true, bool generateEvents = true);
+ ///
+ /// Is the supplied container "on" the surface?
+ ///
+ ///
+ /// This returns false if the container is deleted but still in the undo stack
+ bool IsOnSurface(IDrawableContainer container);
+ void Invalidate(Rectangle rectangleToInvalidate);
+ void Invalidate();
+ bool Modified
+ {
+ get;
+ set;
+ }
+ string LastSaveFullPath
+ {
+ get;
+ set;
+ }
+ string UploadUrl
+ {
+ get;
+ set;
+ }
+ ///
+ /// Remove an element of the elements list
+ ///
+ /// Element to remove
+ /// flag specifying if the remove needs to be undoable
+ /// flag specifying if an surface invalidate needs to be called
+ /// flag specifying if the deselect needs to generate an event
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/Ocr/IOcrProvider.cs b/GreenshotPlugin/Interfaces/Ocr/IOcrProvider.cs
new file mode 100644
index 000000000..451ffb403
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/Ocr/IOcrProvider.cs
@@ -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 .
+ */
+
+using System.Drawing;
+using System.Threading.Tasks;
+
+namespace GreenshotPlugin.Interfaces.Ocr
+{
+ ///
+ /// This interface describes something that can do OCR of a bitmap
+ ///
+ public interface IOcrProvider
+ {
+ ///
+ /// Start the actual OCR
+ ///
+ /// Image
+ /// OcrInformation
+ Task DoOcrAsync(Image image);
+
+ ///
+ /// Start the actual OCR
+ ///
+ /// ISurface
+ /// OcrInformation
+ Task DoOcrAsync(ISurface surface);
+ }
+}
diff --git a/GreenshotPlugin/Interfaces/Ocr/Line.cs b/GreenshotPlugin/Interfaces/Ocr/Line.cs
new file mode 100644
index 000000000..c4f1dccb7
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/Ocr/Line.cs
@@ -0,0 +1,81 @@
+using System.Drawing;
+
+namespace GreenshotPlugin.Interfaces.Ocr
+{
+ ///
+ /// Describes a line of words
+ ///
+ public class Line
+ {
+ private Rectangle? _calculatedBounds;
+
+ ///
+ /// Constructor will preallocate the number of words
+ ///
+ /// int
+ public Line(int wordCount)
+ {
+ Words = new Word[wordCount];
+ for (int i = 0; i < wordCount; i++)
+ {
+ Words[i] = new Word();
+ }
+ }
+
+ ///
+ /// The text of the line
+ ///
+ public string Text { get; set; }
+
+ ///
+ /// An array with words
+ ///
+ public Word[] Words { get; }
+
+ ///
+ /// Calculate the bounds of the words
+ ///
+ /// Rectangle
+ 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;
+ }
+
+ ///
+ /// Return the calculated bounds for the whole line
+ ///
+ public Rectangle CalculatedBounds
+ {
+ get { return _calculatedBounds ??= CalculateBounds(); }
+ }
+
+ ///
+ /// Offset the words with the specified x and y coordinates
+ ///
+ /// int
+ /// int
+ 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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs b/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs
new file mode 100644
index 000000000..0e3b4f4c1
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/Ocr/OcrInformation.cs
@@ -0,0 +1,46 @@
+using System.Collections.Generic;
+using System.Text;
+
+namespace GreenshotPlugin.Interfaces.Ocr
+{
+ ///
+ /// Contains all the information on the OCR result
+ ///
+ public class OcrInformation
+ {
+ ///
+ /// The complete text
+ ///
+ 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();
+ }
+ }
+
+ ///
+ /// The lines of test which the OCR engine found
+ ///
+ public IList Lines { get; } = new List();
+
+ ///
+ /// Change the offset of the
+ ///
+ /// int
+ /// int
+ public void Offset(int x, int y)
+ {
+ foreach (var line in Lines)
+ {
+ line.Offset(x,y);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/Ocr/Word.cs b/GreenshotPlugin/Interfaces/Ocr/Word.cs
new file mode 100644
index 000000000..30982caa4
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/Ocr/Word.cs
@@ -0,0 +1,20 @@
+using System.Drawing;
+
+namespace GreenshotPlugin.Interfaces.Ocr
+{
+ ///
+ /// Contains the information about a word
+ ///
+ public class Word
+ {
+ ///
+ /// The actual text for the word
+ ///
+ public string Text { get; set; }
+
+ ///
+ /// The bounds of the word
+ ///
+ public Rectangle Bounds { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/ScreenCaptureMode.cs b/GreenshotPlugin/Interfaces/ScreenCaptureMode.cs
new file mode 100644
index 000000000..0a03f74c8
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/ScreenCaptureMode.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public enum ScreenCaptureMode
+ {
+ Auto,
+ FullScreen,
+ Fixed
+ };
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventArgs.cs b/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventArgs.cs
new file mode 100644
index 000000000..cfc4f040a
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventArgs.cs
@@ -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 .
+ */
+
+using System;
+
+namespace GreenshotPlugin.Interfaces
+{
+ public class SurfaceDrawingModeEventArgs : EventArgs
+ {
+ public DrawingModes DrawingMode
+ {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventHandler.cs b/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventHandler.cs
new file mode 100644
index 000000000..bada273cf
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceDrawingModeEventHandler.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public delegate void SurfaceDrawingModeEventHandler(object sender, SurfaceDrawingModeEventArgs e);
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceElementEventArgs.cs b/GreenshotPlugin/Interfaces/SurfaceElementEventArgs.cs
new file mode 100644
index 000000000..296ca1a08
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceElementEventArgs.cs
@@ -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 .
+ */
+
+using System;
+using GreenshotPlugin.Interfaces.Drawing;
+
+namespace GreenshotPlugin.Interfaces
+{
+ public class SurfaceElementEventArgs : EventArgs
+ {
+ public IDrawableContainerList Elements
+ {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceElementEventHandler.cs b/GreenshotPlugin/Interfaces/SurfaceElementEventHandler.cs
new file mode 100644
index 000000000..1ae41be70
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceElementEventHandler.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public delegate void SurfaceElementEventHandler(object sender, SurfaceElementEventArgs e);
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceMessageEventArgs.cs b/GreenshotPlugin/Interfaces/SurfaceMessageEventArgs.cs
new file mode 100644
index 000000000..44273f810
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceMessageEventArgs.cs
@@ -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 .
+ */
+
+using System;
+
+namespace GreenshotPlugin.Interfaces
+{
+ public class SurfaceMessageEventArgs : EventArgs
+ {
+ public SurfaceMessageTyp MessageType
+ {
+ get;
+ set;
+ }
+ public string Message
+ {
+ get;
+ set;
+ }
+ public ISurface Surface
+ {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceMessageEventHandler.cs b/GreenshotPlugin/Interfaces/SurfaceMessageEventHandler.cs
new file mode 100644
index 000000000..72ffa01a0
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceMessageEventHandler.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public delegate void SurfaceMessageEventHandler(object sender, SurfaceMessageEventArgs e);
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceMessageTyp.cs b/GreenshotPlugin/Interfaces/SurfaceMessageTyp.cs
new file mode 100644
index 000000000..abae0d6f1
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceMessageTyp.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ public enum SurfaceMessageTyp
+ {
+ FileSaved,
+ Error,
+ Info,
+ UploadedUri
+ }
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/SurfaceSizeChangeEventHandler.cs b/GreenshotPlugin/Interfaces/SurfaceSizeChangeEventHandler.cs
new file mode 100644
index 000000000..5f2dd1245
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/SurfaceSizeChangeEventHandler.cs
@@ -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 .
+ */
+
+using System;
+
+namespace GreenshotPlugin.Interfaces
+{
+ public delegate void SurfaceSizeChangeEventHandler(object sender, EventArgs e);
+}
\ No newline at end of file
diff --git a/GreenshotPlugin/Interfaces/VerticalAlignment.cs b/GreenshotPlugin/Interfaces/VerticalAlignment.cs
new file mode 100644
index 000000000..59e77f35e
--- /dev/null
+++ b/GreenshotPlugin/Interfaces/VerticalAlignment.cs
@@ -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 .
+ */
+
+namespace GreenshotPlugin.Interfaces
+{
+ ///
+ /// Alignment Enums for positioning
+ ///
+ //public enum HorizontalAlignment {LEFT, CENTER, RIGHT};
+ public enum VerticalAlignment
+ {
+ TOP,
+ CENTER,
+ BOTTOM
+ };
+}
\ No newline at end of file
diff --git a/GreenshotWin10Plugin/MemoryRandomAccessStream.cs b/GreenshotWin10Plugin/Internal/MemoryRandomAccessStream.cs
similarity index 92%
rename from GreenshotWin10Plugin/MemoryRandomAccessStream.cs
rename to GreenshotWin10Plugin/Internal/MemoryRandomAccessStream.cs
index 7b18328ca..fb48f4a5b 100644
--- a/GreenshotWin10Plugin/MemoryRandomAccessStream.cs
+++ b/GreenshotWin10Plugin/Internal/MemoryRandomAccessStream.cs
@@ -1,109 +1,109 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: http://getgreenshot.org/
- * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System.IO;
-using Windows.Storage.Streams;
-
-namespace GreenshotWin10Plugin
-{
- ///
- /// This is an IRandomAccessStream implementation which uses a MemoryStream
- ///
- public sealed class MemoryRandomAccessStream : MemoryStream, IRandomAccessStream
- {
- ///
- /// Default constructor
- ///
- public MemoryRandomAccessStream()
- {
- }
-
- ///
- /// Constructor where also bytes are already passed
- ///
- /// byte array
- public MemoryRandomAccessStream(byte[] bytes)
- {
- Write(bytes, 0, bytes.Length);
- }
-
- ///
- public IInputStream GetInputStreamAt(ulong position)
- {
- Seek((long)position, SeekOrigin.Begin);
-
- return this.AsInputStream();
- }
-
- ///
- public IOutputStream GetOutputStreamAt(ulong position)
- {
- Seek((long)position, SeekOrigin.Begin);
-
- return this.AsOutputStream();
- }
-
- ///
- ulong IRandomAccessStream.Position => (ulong)Position;
-
- ///
- public ulong Size
- {
- get { return (ulong)Length; }
- set { SetLength((long)value); }
- }
-
- ///
- public IRandomAccessStream CloneStream()
- {
- var cloned = new MemoryRandomAccessStream();
- CopyTo(cloned);
- return cloned;
- }
-
- ///
- public void Seek(ulong position)
- {
- Seek((long)position, SeekOrigin.Begin);
- }
-
- ///
- public Windows.Foundation.IAsyncOperationWithProgress ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
- {
- var inputStream = GetInputStreamAt(0);
- return inputStream.ReadAsync(buffer, count, options);
- }
-
- ///
- Windows.Foundation.IAsyncOperation IOutputStream.FlushAsync()
- {
- var outputStream = GetOutputStreamAt(0);
- return outputStream.FlushAsync();
- }
-
- ///
- public Windows.Foundation.IAsyncOperationWithProgress WriteAsync(IBuffer buffer)
- {
- var outputStream = GetOutputStreamAt(0);
- return outputStream.WriteAsync(buffer);
- }
- }
-}
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2015 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System.IO;
+using Windows.Storage.Streams;
+
+namespace GreenshotWin10Plugin.Internal
+{
+ ///
+ /// This is an IRandomAccessStream implementation which uses a MemoryStream
+ ///
+ internal sealed class MemoryRandomAccessStream : MemoryStream, IRandomAccessStream
+ {
+ ///
+ /// Default constructor
+ ///
+ public MemoryRandomAccessStream()
+ {
+ }
+
+ ///
+ /// Constructor where also bytes are already passed
+ ///
+ /// byte array
+ public MemoryRandomAccessStream(byte[] bytes)
+ {
+ Write(bytes, 0, bytes.Length);
+ }
+
+ ///
+ public IInputStream GetInputStreamAt(ulong position)
+ {
+ Seek((long)position, SeekOrigin.Begin);
+
+ return this.AsInputStream();
+ }
+
+ ///
+ public IOutputStream GetOutputStreamAt(ulong position)
+ {
+ Seek((long)position, SeekOrigin.Begin);
+
+ return this.AsOutputStream();
+ }
+
+ ///
+ ulong IRandomAccessStream.Position => (ulong)Position;
+
+ ///
+ public ulong Size
+ {
+ get { return (ulong)Length; }
+ set { SetLength((long)value); }
+ }
+
+ ///
+ public IRandomAccessStream CloneStream()
+ {
+ var cloned = new MemoryRandomAccessStream();
+ CopyTo(cloned);
+ return cloned;
+ }
+
+ ///
+ public void Seek(ulong position)
+ {
+ Seek((long)position, SeekOrigin.Begin);
+ }
+
+ ///
+ public Windows.Foundation.IAsyncOperationWithProgress ReadAsync(IBuffer buffer, uint count, InputStreamOptions options)
+ {
+ var inputStream = GetInputStreamAt(0);
+ return inputStream.ReadAsync(buffer, count, options);
+ }
+
+ ///
+ Windows.Foundation.IAsyncOperation IOutputStream.FlushAsync()
+ {
+ var outputStream = GetOutputStreamAt(0);
+ return outputStream.FlushAsync();
+ }
+
+ ///
+ public Windows.Foundation.IAsyncOperationWithProgress WriteAsync(IBuffer buffer)
+ {
+ var outputStream = GetOutputStreamAt(0);
+ return outputStream.WriteAsync(buffer);
+ }
+ }
+}
diff --git a/GreenshotWin10Plugin/Internal/ShareInfo.cs b/GreenshotWin10Plugin/Internal/ShareInfo.cs
new file mode 100644
index 000000000..9b06d0d47
--- /dev/null
+++ b/GreenshotWin10Plugin/Internal/ShareInfo.cs
@@ -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 .
+ */
+
+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 ShareTask { get; } = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+ public bool IsDataRequested { get; set; }
+
+ public IntPtr SharingHwnd { get; set; }
+ }
+}
diff --git a/GreenshotWin10Plugin/Win10OcrDestination.cs b/GreenshotWin10Plugin/Win10OcrDestination.cs
index b426e128d..96b22b96c 100644
--- a/GreenshotWin10Plugin/Win10OcrDestination.cs
+++ b/GreenshotWin10Plugin/Win10OcrDestination.cs
@@ -26,9 +26,9 @@ using System.Threading.Tasks;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;
using GreenshotPlugin.Core;
-using System.Text;
using Windows.Storage.Streams;
using GreenshotPlugin.Interfaces;
+using GreenshotPlugin.Interfaces.Ocr;
using GreenshotPlugin.Interfaces.Plugin;
namespace GreenshotWin10Plugin
@@ -112,33 +112,41 @@ namespace GreenshotWin10Plugin
var ocrResult = await ocrEngine.RecognizeAsync(softwareBitmap);
- var result = new OcrInformation();
- // 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();
+ return CreateOcrInformation(ocrResult);
+ }
- foreach (var ocrLine in ocrResult.Lines)
- {
- var line = new Line(ocrLine.Words.Count);
- result.Lines.Add(line);
+ ///
+ /// Create the OcrInformation
+ ///
+ /// OcrResult
+ /// OcrInformation
+ 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++)
{
var ocrWord = ocrLine.Words[index];
- var location = new Rectangle((int) ocrWord.BoundingRect.X, (int) ocrWord.BoundingRect.Y,
- (int) ocrWord.BoundingRect.Width, (int) ocrWord.BoundingRect.Height);
+ var location = new Rectangle((int)ocrWord.BoundingRect.X, (int)ocrWord.BoundingRect.Y,
+ (int)ocrWord.BoundingRect.Width, (int)ocrWord.BoundingRect.Height);
- var word = line.Words[index];
- word.Text = ocrWord.Text;
- word.Location = location;
+ var word = line.Words[index];
+ word.Text = ocrWord.Text;
+ word.Bounds = location;
}
}
+
return result;
- }
+ }
///
/// Run the Windows 10 OCR engine to process the text on the captured image
diff --git a/GreenshotWin10Plugin/Win10ShareDestination.cs b/GreenshotWin10Plugin/Win10ShareDestination.cs
index 541268a94..f7fd11370 100644
--- a/GreenshotWin10Plugin/Win10ShareDestination.cs
+++ b/GreenshotWin10Plugin/Win10ShareDestination.cs
@@ -25,7 +25,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
-using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
using Windows.Storage.Streams;
using Color = Windows.UI.Color;
@@ -36,6 +35,7 @@ using System.Windows.Media;
using GreenshotPlugin.Hooking;
using GreenshotPlugin.Interfaces;
using GreenshotPlugin.Interfaces.Plugin;
+using GreenshotWin10Plugin.Internal;
namespace GreenshotWin10Plugin
{
@@ -54,22 +54,6 @@ namespace GreenshotWin10Plugin
///
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 ShareTask { get; } = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
- public bool IsDataRequested { get; set; }
-
- public IntPtr SharingHwnd { get; set; }
- }
-
///
/// Share the screenshot with a windows app
///
@@ -102,7 +86,8 @@ namespace GreenshotWin10Plugin
// 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!
- focusMonitor.WindowOpenCloseChangeEvent += e => {
+ focusMonitor.WindowOpenCloseChangeEvent += e =>
+ {
if (e.IsOpen)
{
@@ -112,16 +97,14 @@ namespace GreenshotWin10Plugin
}
return;
}
- else
+
+ if (e.HWnd == shareInfo.SharingHwnd)
{
- if (e.HWnd == shareInfo.SharingHwnd)
+ if (shareInfo.ApplicationName != null)
{
- if (shareInfo.ApplicationName != null)
- {
- return;
- }
- shareInfo.ShareTask.TrySetResult(false);
+ return;
}
+ shareInfo.ShareTask.TrySetResult(false);
}
};
@@ -217,10 +200,10 @@ namespace GreenshotWin10Plugin
await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
await imageStream.FlushAsync().ConfigureAwait(false);
}
- // Signal that the stream is ready
- streamedFileDataRequest.Dispose();
- // Signal that the action is ready, bitmap was exported
- shareInfo.ShareTask.TrySetResult(true);
+ // Signal that the stream is ready
+ streamedFileDataRequest.Dispose();
+ // Signal that the action is ready, bitmap was exported
+ shareInfo.ShareTask.TrySetResult(true);
}
catch (Exception)
{