diff --git a/GreenshotOCRCommand/COMWrapper.cs b/GreenshotOCRCommand/COMWrapper.cs
index 67ef5fad9..4d9d7f11b 100644
--- a/GreenshotOCRCommand/COMWrapper.cs
+++ b/GreenshotOCRCommand/COMWrapper.cs
@@ -19,6 +19,7 @@
* along with this program. If not, see .
*/
using System;
+using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
@@ -79,13 +80,16 @@ namespace Greenshot.Interop {
try {
comObject = Marshal.GetActiveObject(progId);
} catch (COMException comE) {
- if (comE.ErrorCode == MK_E_UNAVAILABLE) {
- //LOG.DebugFormat("No current instance of {0} object available.", progId);
- } else if (comE.ErrorCode == CO_E_CLASSSTRING) {
- //LOG.WarnFormat("Unknown progId {0}", progId);
+ if (comE.ErrorCode == MK_E_UNAVAILABLE)
+ {
+ Debug.WriteLine($"No current instance of {progId} object available.");
}
- } catch (Exception) {
- //LOG.Warn("Error getting active object for " + progId, e);
+ else if (comE.ErrorCode == CO_E_CLASSSTRING)
+ {
+ Debug.WriteLine($"Unknown progId {progId}");
+ }
+ } catch (Exception ex) {
+ Debug.WriteLine($"Error getting active object for {progId} {ex.Message}");
}
if (comObject != null) {
@@ -123,30 +127,32 @@ namespace Greenshot.Interop {
try {
comObject = Marshal.GetActiveObject(progId);
} catch (COMException comE) {
- if (comE.ErrorCode == MK_E_UNAVAILABLE) {
- //LOG.DebugFormat("No current instance of {0} object available.", progId);
- } else if (comE.ErrorCode == CO_E_CLASSSTRING) {
- //LOG.WarnFormat("Unknown progId {0} (application not installed)", progId);
- return default(T);
+ if (comE.ErrorCode == MK_E_UNAVAILABLE)
+ {
+ Debug.WriteLine($"No current instance of {progId} object available.");
}
- } catch (Exception) {
- //LOG.Warn("Error getting active object for " + progId, e);
+ else if (comE.ErrorCode == CO_E_CLASSSTRING)
+ {
+ Debug.WriteLine($"Unknown progId {progId}");
+ }
+ } catch (Exception ex) {
+ Debug.WriteLine($"Error getting active object for {progId} {ex.Message}");
}
// Did we get the current instance? If not, try to create a new
if (comObject == null) {
try {
comType = Type.GetTypeFromProgID(progId, true);
} catch (Exception) {
- //LOG.Warn("Error type for " + progId, ex);
+ Debug.WriteLine($"Error getting type for {progId}");
}
if (comType != null) {
try {
comObject = Activator.CreateInstance(comType);
if (comObject != null) {
- //LOG.DebugFormat("Created new instance of {0} object.", progId);
+ Debug.WriteLine($"Created new instance of {progId} object.");
}
- } catch (Exception) {
- //LOG.Warn("Error creating object for " + progId, e);
+ } catch (Exception ex) {
+ Debug.WriteLine($"Error creating object for {progId} {ex.Message}");
}
}
}
@@ -225,9 +231,9 @@ namespace Greenshot.Interop {
while (Marshal.ReleaseComObject(_comObject) > 0)
{
}
- } catch (Exception) {
- //LOG.WarnFormat("Problem releasing {0}", _COMType);
- //LOG.Warn("Error: ", ex);
+ } catch (Exception ex) {
+ Debug.WriteLine($"Problem releasing {_comType}");
+ Debug.WriteLine("Error: " + ex);
}
}
}
@@ -318,8 +324,12 @@ namespace Greenshot.Interop {
IMethodCallMessage callMessage = myMessage as IMethodCallMessage;
MethodInfo method = callMessage?.MethodBase as MethodInfo;
- if (method == null) {
- //LOG.DebugFormat("Unrecognized Invoke call: {0}", callMessage.MethodBase.ToString());
+ if (method == null)
+ {
+ if (callMessage != null)
+ {
+ Debug.WriteLine($"Unrecognized Invoke call: {callMessage.MethodBase}");
+ }
return null;
}
diff --git a/GreenshotOCRCommand/ComProgIdAttribute.cs b/GreenshotOCRCommand/ComProgIdAttribute.cs
index 893db2fcb..05fd69237 100644
--- a/GreenshotOCRCommand/ComProgIdAttribute.cs
+++ b/GreenshotOCRCommand/ComProgIdAttribute.cs
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
using System;
namespace Greenshot.Interop {
diff --git a/GreenshotOCRCommand/GreenshotOCRCommand.csproj b/GreenshotOCRCommand/GreenshotOCRCommand.csproj
index bf34f8d0e..b9645113d 100644
--- a/GreenshotOCRCommand/GreenshotOCRCommand.csproj
+++ b/GreenshotOCRCommand/GreenshotOCRCommand.csproj
@@ -53,10 +53,21 @@
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/GreenshotOCRCommand/IDispatch.cs b/GreenshotOCRCommand/IDispatch.cs
deleted file mode 100644
index 8df4cc022..000000000
--- a/GreenshotOCRCommand/IDispatch.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.CustomMarshalers;
-
-namespace Greenshot.Interop {
- [ComImport, Guid("00020400-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- public interface IDispatch {
- void Reserved();
- [PreserveSig]
- int GetTypeInfo(uint nInfo, int lcid, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(TypeToTypeInfoMarshaler))] out Type typeInfo);
- }
-}
diff --git a/GreenshotOCRCommand/Modi/CompressionLevel.cs b/GreenshotOCRCommand/Modi/CompressionLevel.cs
new file mode 100644
index 000000000..a8bc9e34a
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/CompressionLevel.cs
@@ -0,0 +1,29 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCRCommand.Modi
+{
+ public enum CompressionLevel {
+ miCOMP_LEVEL_LOW = 0,
+ miCOMP_LEVEL_MEDIUM = 1,
+ miCOMP_LEVEL_HIGH = 2
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/FileFormat.cs b/GreenshotOCRCommand/Modi/FileFormat.cs
new file mode 100644
index 000000000..cbf061333
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/FileFormat.cs
@@ -0,0 +1,30 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCR
+{
+ public enum FileFormat {
+ miFILE_FORMAT_DEFAULTVALUE = -1,
+ miFILE_FORMAT_TIFF = 1,
+ miFILE_FORMAT_TIFF_LOSSLESS = 2,
+ miFILE_FORMAT_MDI = 4
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/ICommon.cs b/GreenshotOCRCommand/Modi/ICommon.cs
new file mode 100644
index 000000000..ecdf4052d
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/ICommon.cs
@@ -0,0 +1,32 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Base class for the common properties of the Modi interfaces
+ ///
+ public interface ICommon : IDisposable {
+ IDocument Application { get; }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/IDispatch.cs b/GreenshotOCRCommand/Modi/IDispatch.cs
new file mode 100644
index 000000000..22235153d
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IDispatch.cs
@@ -0,0 +1,33 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using System.Runtime.InteropServices.CustomMarshalers;
+
+namespace GreenshotOCRCommand.Modi {
+ [ComImport, Guid("00020400-0000-0000-C000-000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+ public interface IDispatch {
+ void Reserved();
+ [PreserveSig]
+ int GetTypeInfo(uint nInfo, int lcid, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(TypeToTypeInfoMarshaler))] out Type typeInfo);
+ }
+}
diff --git a/GreenshotOCRCommand/Modi/IDocument.cs b/GreenshotOCRCommand/Modi/IDocument.cs
new file mode 100644
index 000000000..7913ece5f
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IDocument.cs
@@ -0,0 +1,82 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using Greenshot.Interop;
+using GreenshotOCR;
+
+namespace GreenshotOCRCommand.Modi {
+ ///
+ /// The MODI Document object represents an ordered collection of document images saved as a single file.
+ /// You can use the Create method to load an existing MDI or TIF file, or to create an empty document that you can populate with images from other documents.
+ /// The OCR method performs OCR on all pages in the document, and the OnOCRProgress event reports the status of the operation and allows the user to cancel it.
+ /// The Dirty property lets you know whether your document has unsaved OCR results or changes.
+ /// The SaveAs method allows you to specify an image file format and a compression level.
+ /// You can also use the PrintOut method to print the document to a printer or a file.
+ ///
+ [ComProgId("MODI.Document")]
+ public interface IDocument : ICommon {
+ ///
+ /// Closes the document.
+ ///
+ ///
+ void Close(bool saveCall);
+
+ ///
+ /// The document's collection of pages.
+ ///
+ IImages Images
+ {
+ get;
+ }
+
+ ///
+ /// Occurs periodically during an optical character recognition (OCR) operation. Returns the estimated percentage of the OCR operation that is complete, and allows the user to cancel the operation.
+ ///
+ // event OnOCRProgress { get; }
+
+ ///
+ /// Indicates whether the active document has unsaved changes.
+ ///
+ bool Dirty { get; }
+
+ ///
+ /// Creates a new document.
+ ///
+ /// Optional String. The path and filename of the optional document file that is to be loaded into the new document.
+ void Create(string file);
+
+ ///
+ /// Performs optical character recognition (OCR) on the specified document or image.
+ ///
+ /// ModiLanguage
+ /// Optional Boolean. Specifies whether the OCR engine attempts to determine the orientation of the page. Default is true.
+ /// Optional Boolean. Specifies whether the OCR engine attempts to "de-skew" the page to correct for small angles of misalignment from the vertical. Default is true.
+ void OCR(ModiLanguage language, bool orientimage, bool straightenImage);
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ void SaveAs(string filename, FileFormat fileFormat, CompressionLevel compressionLevel);
+ }
+}
diff --git a/GreenshotOCRCommand/Modi/IImage.cs b/GreenshotOCRCommand/Modi/IImage.cs
new file mode 100644
index 000000000..fd7dd3c06
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IImage.cs
@@ -0,0 +1,41 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Describes the page in a scan
+ ///
+ public interface IImage : ICommon {
+ ILayout Layout {
+ get;
+ }
+
+ long BitsPerPixel { get; }
+ CompressionLevel Compression { get; }
+ //IPictureDisp Picture { get; }
+ int PixelHeight { get; }
+ int PixelWidth { get; }
+ //IPictureDisp Thumbnail { get; }
+ int XDPI { get; }
+ int YDPI { get; }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/IImages.cs b/GreenshotOCRCommand/Modi/IImages.cs
new file mode 100644
index 000000000..885dd1bba
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IImages.cs
@@ -0,0 +1,41 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System.Collections;
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Use the Images accessor property of the Document object to return an Images collection.
+ /// Use the Item property of the Images collection to return an Image object and gain access to its OCR Layout
+ /// (including recognized Text and Words), the properties that describe its dimensions and format (BitsPerPixel, Compression, PixelHeight, PixelWidth, XDPI, and YDPI),
+ /// and its Picture and Thumbnail images.
+ ///
+ public interface IImages : ICommon, IEnumerable {
+ int Count {
+ get;
+ }
+ IImage this [int index] {
+ get;
+ }
+ new IEnumerator GetEnumerator();
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/ILayout.cs b/GreenshotOCRCommand/Modi/ILayout.cs
new file mode 100644
index 000000000..ca7b43322
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/ILayout.cs
@@ -0,0 +1,55 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Layout of the IImage
+ ///
+ public interface ILayout : ICommon {
+ ///
+ /// Returns the recognized text as a Unicode string.
+ ///
+ string Text {
+ get;
+ }
+
+ ///
+ /// An accessor property that returns the Words collection recognized in the text during an optical character recognition (OCR) operation.
+ ///
+ IWords Words { get; }
+
+ ///
+ /// Returns the number of characters in the recognized text.
+ ///
+ int NumChars { get; }
+
+ ///
+ /// Returns the number of words in the recognized text.
+ ///
+ int NumWords { get; }
+
+ ///
+ /// Returns the language identifier for the recognized text. Read-only Long.
+ ///
+ ModiLanguage Language { get; }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/IMiRect.cs b/GreenshotOCRCommand/Modi/IMiRect.cs
new file mode 100644
index 000000000..18ac6b0e8
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IMiRect.cs
@@ -0,0 +1,48 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Represents a bounding rectangle in the optical character recognition (OCR) layout.
+ ///
+ public interface IMiRect : ICommon {
+ ///
+ /// The Bottom property represent the distance in pixels from the top edge of the containing image.
+ ///
+ int Bottom { get; }
+
+ ///
+ /// The Left property represent the distance in pixels from the left edge of the containing image.
+ ///
+ int Left { get; }
+
+ ///
+ /// The Right property represent the distance in pixels from the left edge of the containing image.
+ ///
+ int Right { get; }
+
+ ///
+ /// The Top property represent the distance in pixels from the top edge of the containing image.
+ ///
+ int Top { get; }
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/IMiRects.cs b/GreenshotOCRCommand/Modi/IMiRects.cs
new file mode 100644
index 000000000..9981bdd5f
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IMiRects.cs
@@ -0,0 +1,38 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System.Collections;
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Represents the collection of bounding rectangles in the optical character recognition (OCR) layout. A collection of MiRect objects.
+ ///
+ public interface IMiRects : ICommon, IEnumerable {
+ int Count {
+ get;
+ }
+ IMiRect this [int index] {
+ get;
+ }
+ new IEnumerator GetEnumerator();
+ }
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Modi/IWord.cs b/GreenshotOCRCommand/Modi/IWord.cs
new file mode 100644
index 000000000..8e7895f8c
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IWord.cs
@@ -0,0 +1,65 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// Represents a word recognized in the text during an optical character recognition (OCR) operation.
+ ///
+ public interface IWord : ICommon
+ {
+ ///
+ /// Returns the index of the specified word in the Words collection of the Layout or IMiSelectableItem object.
+ ///
+ long Id { get; }
+
+ ///
+ /// Returns the number of the region in the optical character recognition (OCR) layout where the word occurs.
+ ///
+ long RegionId { get; }
+
+ ///
+ /// Returns the number of the line in the optical character recognition (OCR) layout where the word occurs.
+ ///
+ long LineId { get; }
+
+ ///
+ /// Returns the recognized text as a Unicode string.
+ ///
+ string Text { get; }
+
+ ///
+ /// Returns the relative confidence factor reported by the optical character recognition (OCR) engine (on a scale of 0 to 999) after recognizing the specified word.
+ ///
+ short RecognitionConfidence { get; }
+
+ ///
+ /// Returns the index of the font used by the specified wordthis is the font that was recognized in the text during an optical character recognition (OCR) operation.
+ ///
+ long FontId { get; }
+
+ ///
+ /// Rectangles
+ ///
+ IMiRects Rects { get; }
+
+ }
+}
diff --git a/GreenshotOCRCommand/Modi/IWords.cs b/GreenshotOCRCommand/Modi/IWords.cs
new file mode 100644
index 000000000..b26b6f0c3
--- /dev/null
+++ b/GreenshotOCRCommand/Modi/IWords.cs
@@ -0,0 +1,43 @@
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System.Collections;
+
+namespace GreenshotOCRCommand.Modi
+{
+ ///
+ /// The Words collection recognized in the text during an optical character recognition (OCR) operation.
+ ///
+ public interface IWords : ICommon, IEnumerable
+ {
+ int Count
+ {
+ get;
+ }
+
+ IWord this[int index]
+ {
+ get;
+ }
+
+ new IEnumerator GetEnumerator();
+ }
+}
diff --git a/GreenshotOCRCommand/ModiInterop.cs b/GreenshotOCRCommand/Modi/ModiLanguage.cs
similarity index 53%
rename from GreenshotOCRCommand/ModiInterop.cs
rename to GreenshotOCRCommand/Modi/ModiLanguage.cs
index be861b808..d062a4cb9 100644
--- a/GreenshotOCRCommand/ModiInterop.cs
+++ b/GreenshotOCRCommand/Modi/ModiLanguage.cs
@@ -1,64 +1,26 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
- *
+ *
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-using System;
-using System.Collections;
-using Greenshot.Interop;
-
-namespace GreenshotOCR {
- [ComProgId("MODI.Document")]
- public interface ModiDocu : Common {
- void Close(bool SaveCall);
- IImages Images{
- get;
- }
- void Create(string file);
- void OCR(ModiLanguage language, bool Orientimage, bool StraightenImage);
- void SaveAs(string filename, FileFormat fileFormat, CompressionLevel compressionLevel);
- }
-
- public interface Common : IDisposable {
- ModiDocu Application { get; }
- }
-
- public interface ILayout : Common{
- string Text {
- get;
- }
- }
- public interface IImage : Common {
- ILayout Layout {
- get;
- }
- }
-
- public interface IImages : Common, IEnumerable{
- int Count {
- get;
- }
- IImage this [int index] {
- get;
- }
- new IEnumerator GetEnumerator();
- }
+namespace GreenshotOCRCommand.Modi
+{
public enum ModiLanguage {
CHINESE_SIMPLIFIED = 2052,
CHINESE_TRADITIONAL = 1028,
@@ -83,16 +45,4 @@ namespace GreenshotOCR {
TURKISH = 31,
SYSDEFAULT = 2048
}
-
- public enum CompressionLevel {
- miCOMP_LEVEL_LOW = 0,
- miCOMP_LEVEL_MEDIUM = 1,
- miCOMP_LEVEL_HIGH = 2
- }
- public enum FileFormat {
- miFILE_FORMAT_DEFAULTVALUE = -1,
- miFILE_FORMAT_TIFF = 1,
- miFILE_FORMAT_TIFF_LOSSLESS = 2,
- miFILE_FORMAT_MDI = 4
- }
-}
+}
\ No newline at end of file
diff --git a/GreenshotOCRCommand/Program.cs b/GreenshotOCRCommand/Program.cs
index eb8033856..6f7fe33a1 100644
--- a/GreenshotOCRCommand/Program.cs
+++ b/GreenshotOCRCommand/Program.cs
@@ -1,16 +1,37 @@
-using System;
+/*
+ * Greenshot - a free and open source screenshot tool
+ * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
+ *
+ * For more information see: http://getgreenshot.org/
+ * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using Greenshot.Interop;
-using GreenshotOCR;
+using GreenshotOCRCommand.Modi;
namespace GreenshotOCRCommand {
public class Program {
- private const string USAGE = "<-c> | [language] [orientimage] [straightenImage]";
+ private const string Usage = "<-c> | [language] [orientimage] [straightenImage]";
public static int Main(string[] args) {
- // to test
- //args = new string[] { @"C:\localdata\test.bmp"};
if (args.Length == 0) {
- Console.WriteLine(USAGE);
+ Console.WriteLine(Usage);
return -1;
}
string filename = args[0];
@@ -28,25 +49,43 @@ namespace GreenshotOCRCommand {
}
try {
if (File.Exists(filename) || "-c".Equals(filename)) {
- using (ModiDocu modiDocument = COMWrapper.GetOrCreateInstance()) {
- if (modiDocument == null) {
+ using (var document = COMWrapper.GetOrCreateInstance()) {
+ if (document == null) {
Console.WriteLine("MODI not installed");
return -2;
}
if ("-c".Equals(filename)) {
return 0;
}
- modiDocument.Create(filename);
- modiDocument.OCR(language, orientimage, straightenImage);
- IImage modiImage = modiDocument.Images[0];
- ILayout layout = modiImage.Layout;
- if (layout.Text != null)
+ document.Create(filename);
+ document.OCR(language, orientimage, straightenImage);
+ var modiImage = document.Images[0];
+ var layout = modiImage.Layout;
+ if (layout != null)
{
- // For for BUG-1884:
- // Although this is done in the OCR Plugin, it does make sense in the command too.
- Console.WriteLine(layout.Text.Trim());
+#if DEBUG
+ if (layout.Words != null)
+ {
+ foreach (var word in ToEnumerable(layout.Words))
+ {
+ if (word.Rects != null)
+ {
+ foreach (var rect in ToEnumerable(word.Rects))
+ {
+ Debug.WriteLine($"Rect {rect.Left},{rect.Top},{rect.Right},{rect.Bottom} - Word {word.Text} : Confidence: {word.RecognitionConfidence}");
+ }
+ }
+ }
+ }
+#endif
+ if (layout.Text != null)
+ {
+ // For for BUG-1884:
+ // Although trim is done in the OCR Plugin, it does make sense in the command too.
+ Console.WriteLine(layout.Text.Trim());
+ }
}
- modiDocument.Close(false);
+ document.Close(false);
return 0;
}
}
@@ -55,5 +94,29 @@ namespace GreenshotOCRCommand {
}
return -1;
}
+
+ ///
+ /// Helper method
+ ///
+ /// IEnumerable of IMiRect
+ private static IEnumerable ToEnumerable(IMiRects rects)
+ {
+ for (int i = 0; i < rects.Count; i++)
+ {
+ yield return rects[i];
+ }
+ }
+
+ ///
+ /// Helper method
+ ///
+ /// IEnumerable of IWord
+ private static IEnumerable ToEnumerable(IWords words)
+ {
+ for (int i = 0; i < words.Count; i++)
+ {
+ yield return words[i];
+ }
+ }
}
}
diff --git a/GreenshotWin10Plugin/Win10ShareDestination.cs b/GreenshotWin10Plugin/Win10ShareDestination.cs
index 758eab6da..ac790b50c 100644
--- a/GreenshotWin10Plugin/Win10ShareDestination.cs
+++ b/GreenshotWin10Plugin/Win10ShareDestination.cs
@@ -101,6 +101,7 @@ namespace GreenshotWin10Plugin
var filename = FilenameHelper.GetFilename(OutputFormat.png, captureDetails);
var storageFile = await StorageFile.CreateStreamedFileAsync(filename, async streamedFileDataRequest =>
{
+ // Information on how was found here: https://socialeboladev.wordpress.com/2013/03/15/how-to-use-createstreamedfileasync/
Log.DebugFormat("Creating deferred file {0}", filename);
try
{
@@ -116,7 +117,7 @@ namespace GreenshotWin10Plugin
{
streamedFileDataRequest.FailAndClose(StreamedFileFailureMode.Incomplete);
}
- // Signal transfer ready
+ // Signal transfer ready to the await down below
taskCompletionSource.TrySetResult(applicationName);
}, imageRandomAccessStreamReference);