mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 18:57:28 -07:00
moved all sources to trunk directory
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@693 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
commit
a22b7578bd
392 changed files with 61489 additions and 0 deletions
94
Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj
Normal file
94
Greenshot-OCR-Plugin/Greenshot-OCR-Plugin.csproj
Normal file
|
@ -0,0 +1,94 @@
|
|||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{C6988EE8-2FEE-4349-9F09-F9628A0D8965}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>GreenshotOCR</RootNamespace>
|
||||
<AssemblyName>Greenshot-OCR-Plugin</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<SourceAnalysisOverrideSettingsFile>C:\Dokumente und Einstellungen\05018085\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
<Optimize>True</Optimize>
|
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MODI11">
|
||||
<HintPath>lib\MODI11.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MODI12">
|
||||
<HintPath>lib\MODI12.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Language.cs" />
|
||||
<Compile Include="LanguageKeys.cs" />
|
||||
<Compile Include="OCRPlugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsForm.cs" />
|
||||
<Compile Include="SettingsForm.Designer.cs">
|
||||
<DependentUpon>SettingsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="Languages\language_ocrplugin-de-DE.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Languages\language_ocrplugin-en-US.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Languages\language_ocrplugin-nl-NL.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="lib\MODI11.dll" />
|
||||
<None Include="lib\MODI12.dll" />
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
|
||||
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
|
||||
<Name>GreenshotPlugin</Name>
|
||||
</ProjectReference>
|
||||
<Folder Include="Languages" />
|
||||
<Folder Include="lib" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
|
||||
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\MODI*.dll" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*"
|
||||
mkdir "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\Languages\*.xml" "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)\"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
47
Greenshot-OCR-Plugin/Language.cs
Normal file
47
Greenshot-OCR-Plugin/Language.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Resources;
|
||||
using System.Threading;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// Wrapper for the language container for the Jira plugin.
|
||||
/// </summary>
|
||||
public class Language : LanguageContainer, ILanguage {
|
||||
private static ILanguage uniqueInstance;
|
||||
private const string LANGUAGE_FILENAME_PATTERN = @"language_ocrplugin-*.xml";
|
||||
|
||||
public static ILanguage GetInstance() {
|
||||
if(uniqueInstance == null) {
|
||||
uniqueInstance = new LanguageContainer();
|
||||
uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN;
|
||||
uniqueInstance.Load();
|
||||
uniqueInstance.SetLanguage(Thread.CurrentThread.CurrentUICulture.Name);
|
||||
}
|
||||
return uniqueInstance;
|
||||
}
|
||||
}
|
||||
}
|
29
Greenshot-OCR-Plugin/LanguageKeys.cs
Normal file
29
Greenshot-OCR-Plugin/LanguageKeys.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
public enum LangKey {
|
||||
language,
|
||||
orient_image,
|
||||
straighten_image
|
||||
}
|
||||
}
|
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-de-DE.xml
Normal file
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-de-DE.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Deutsch" ietf="de-DE" version="0.8.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Sprache für OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Bild Orientieren
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Bild Aufrichten
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-en-US.xml
Normal file
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-en-US.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="English" ietf="en-US" version="0.8.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Language for OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Orient image
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Straighten image
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-nl-NL.xml
Normal file
14
Greenshot-OCR-Plugin/Languages/language_ocrplugin-nl-NL.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Nederlands" ietf="nl-NL" version="0.8.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Taal voor OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Beeld richten
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Beeld vereffenen
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
322
Greenshot-OCR-Plugin/OCRPlugin.cs
Normal file
322
Greenshot-OCR-Plugin/OCRPlugin.cs
Normal file
|
@ -0,0 +1,322 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Core;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// OCR Plugin Greenshot
|
||||
/// </summary>
|
||||
public class OcrPlugin : IGreenshotPlugin {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OcrPlugin));
|
||||
private const string CONFIG_FILENAME = "ocr-config.properties";
|
||||
|
||||
private const string MODI_OFFICE11 = @"Software\Microsoft\Office\11.0\MODI";
|
||||
private const string MODI_OFFICE12 = @"Software\Microsoft\Office\12.0\MODI";
|
||||
|
||||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private Properties config = new Properties();
|
||||
|
||||
public OcrPlugin() { }
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IGreenshotPlugin.Initialize
|
||||
/// </summary>
|
||||
/// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
|
||||
/// <param name="captureHost">Use the ICaptureHost interface to register in the MainContextMenu</param>
|
||||
/// <param name="pluginAttribute">My own attributes</param>
|
||||
public void Initialize(IGreenshotPluginHost host, ICaptureHost captureHost, PluginAttribute myAttributes) {
|
||||
LOG.Debug("Initialize called of " + myAttributes.Name);
|
||||
this.host = (IGreenshotPluginHost)host;
|
||||
this.captureHost = captureHost;
|
||||
this.myAttributes = myAttributes;
|
||||
|
||||
// Make sure the MODI-DLLs are found by adding a resolver
|
||||
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyAssemblyResolver);
|
||||
|
||||
if (!HasMODI()) {
|
||||
LOG.Warn("No MODI found!");
|
||||
return;
|
||||
}
|
||||
LoadConfig();
|
||||
this.host.RegisterHotKey(3, 0x2C, new HotKeyHandler(MyHotkeyHandler));
|
||||
|
||||
// Here we can hang ourselves to the main context menu!
|
||||
ToolStripMenuItem item = new ToolStripMenuItem();
|
||||
item.Text = "Region OCR";
|
||||
item.ShortcutKeyDisplayString = "Ctrl + Alt + Print";
|
||||
item.Click += new System.EventHandler(MainMenuClick);
|
||||
|
||||
ContextMenuStrip contextMenu = host.MainMenu;
|
||||
bool addedItem = false;
|
||||
|
||||
for(int i=0; i < contextMenu.Items.Count; i++) {
|
||||
if (contextMenu.Items[i].GetType() == typeof(ToolStripSeparator)) {
|
||||
contextMenu.Items.Insert(i, item);
|
||||
addedItem = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!addedItem) {
|
||||
contextMenu.Items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IGreenshotPlugin.Shutdown
|
||||
/// </summary>
|
||||
public void Shutdown() {
|
||||
LOG.Debug("Shutdown of " + myAttributes.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the IPlugin.Configure
|
||||
/// </summary>
|
||||
public virtual void Configure() {
|
||||
if (!HasMODI()) {
|
||||
MessageBox.Show("Sorry, is seems that Microsoft Office Document Imaging (MODI) is not installed, therefor the OCR Plugin cannot work.");
|
||||
return;
|
||||
}
|
||||
SettingsForm settingsForm = new SettingsForm(GetLanguages(),config);
|
||||
DialogResult result = settingsForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
config.ChangeProperty("language", settingsForm.OCRLanguage);
|
||||
config.ChangeBoolProperty("orientImage", settingsForm.OrientImage);
|
||||
config.ChangeBoolProperty("straightenImage", settingsForm.StraightenImage);;
|
||||
SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method helps to resolve the MODI DLL files
|
||||
/// </summary>
|
||||
/// <param name="sender">object which is starting the resolve</param>
|
||||
/// <param name="args">ResolveEventArgs describing the Assembly that needs to be found</param>
|
||||
/// <returns></returns>
|
||||
private Assembly MyAssemblyResolver(object sender, ResolveEventArgs args) {
|
||||
string dllPath = Path.GetDirectoryName(myAttributes.DllFile);
|
||||
string dllFilename = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
|
||||
LOG.Debug("Resolving: " + dllFilename);
|
||||
if (dllFilename.StartsWith("MODI")) {
|
||||
return Assembly.LoadFile(Path.Combine(dllPath, dllFilename));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void LoadConfig() {
|
||||
string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME);
|
||||
if (File.Exists(filename)) {
|
||||
LOG.Debug("Loading configuration from: " + filename);
|
||||
config = Properties.read(filename);
|
||||
}
|
||||
bool changed = false;
|
||||
if (config == null) {
|
||||
config = new Properties();
|
||||
changed = true;
|
||||
}
|
||||
if (!config.ContainsKey("language")) {
|
||||
config.AddProperty("language", "miLANG_ENGLISH");
|
||||
changed = true;
|
||||
}
|
||||
if (!config.ContainsKey("straightenImage")) {
|
||||
config.AddBoolProperty("straightenImage", false);
|
||||
changed = true;
|
||||
}
|
||||
if (!config.ContainsKey("orientImage")) {
|
||||
config.AddBoolProperty("orientImage", false);
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SaveConfig() {
|
||||
string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME);
|
||||
LOG.Debug("Saving configuration to: " + filename);
|
||||
config.write(filename, "# The configuration file for the Greenshot OCR Plugin");
|
||||
}
|
||||
|
||||
private void StartOCRRegion() {
|
||||
LOG.Debug("Starting OCR!");
|
||||
captureHost.MakeCapture(CaptureMode.Region, false, new CaptureHandler(DoOCR));
|
||||
}
|
||||
|
||||
private void MyHotkeyHandler() {
|
||||
StartOCRRegion();
|
||||
}
|
||||
/// <summary>
|
||||
/// Is called when the OCR menu is selected
|
||||
/// </summary>
|
||||
/// <param name="sender">ContextMenu</param>
|
||||
/// <param name="e">EventArgs from ContextMenu</param>
|
||||
private void MainMenuClick(object sender, EventArgs e) {
|
||||
StartOCRRegion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handling of the CaptureTaken "event" from the ICaptureHost
|
||||
/// We do the OCR here!
|
||||
/// </summary>
|
||||
/// <param name="ImageOutputEventArgs">Has the Image and the capture details</param>
|
||||
private const int MIN_WIDTH = 130;
|
||||
private const int MIN_HEIGHT = 130;
|
||||
private void DoOCR(object sender, CaptureTakenEventArgs eventArgs) {
|
||||
if (eventArgs.Capture.Image == null) {
|
||||
return;
|
||||
}
|
||||
string file = host.GetFilename("bmp", eventArgs.Capture.CaptureDetails);
|
||||
string filePath = Path.Combine(Path.GetTempPath(),file);
|
||||
|
||||
using (FileStream stream = File.Create(filePath)) {
|
||||
Image capturedImage = eventArgs.Capture.Image;
|
||||
if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
|
||||
LOG.Debug("Image not big enough, copying to bigger image");
|
||||
int newWidth = Math.Max(capturedImage.Width, MIN_WIDTH);
|
||||
int newHeight = Math.Max(capturedImage.Height, MIN_HEIGHT);
|
||||
using (Image tmpImage = new Bitmap(newWidth, newHeight, capturedImage.PixelFormat)) {
|
||||
using (Graphics graphics = Graphics.FromImage(tmpImage)) {
|
||||
graphics.Clear(Color.White);
|
||||
graphics.DrawImage(capturedImage, Point.Empty);
|
||||
}
|
||||
host.SaveToStream(tmpImage, stream, "bmp", 100);
|
||||
}
|
||||
} else {
|
||||
host.SaveToStream(capturedImage, stream, "bmp", 100);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.Debug("Saved tmp file to: " + filePath);
|
||||
|
||||
string text = "";
|
||||
|
||||
try {
|
||||
|
||||
switch (CheckModiVersion()) {
|
||||
case ModiVersion.MODI11:
|
||||
// Instantiate the MODI.Document object
|
||||
MODI11.Document modi11Document = new MODI11.Document();
|
||||
// The Create method grabs the picture from disk snd prepares for OCR.
|
||||
modi11Document.Create(filePath);
|
||||
|
||||
// Add progress bar here:
|
||||
//md.OnOCRProgress += ;
|
||||
|
||||
// Do the OCR.
|
||||
modi11Document.OCR((MODI11.MiLANGUAGES)Enum.Parse(typeof(MODI11.MiLANGUAGES), config.GetProperty("language")), config.GetBoolProperty("orientImage"), config.GetBoolProperty("straightenImage"));
|
||||
// Get the first (and only image)
|
||||
MODI11.Image modi11Image = (MODI11.Image)modi11Document.Images[0];
|
||||
// Get the layout.
|
||||
MODI11.Layout modi11layout = modi11Image.Layout;
|
||||
text = modi11layout.Text;
|
||||
// Close the MODI.Document object.
|
||||
modi11Document.Close(false);
|
||||
break;
|
||||
case ModiVersion.MODI12:
|
||||
// Instantiate the MODI.Document object
|
||||
MODI12.Document modi12Document = new MODI12.Document();
|
||||
// The Create method grabs the picture from disk snd prepares for OCR.
|
||||
modi12Document.Create(filePath);
|
||||
|
||||
// Add progress bar here:
|
||||
//md.OnOCRProgress += ;
|
||||
|
||||
// Do the OCR.
|
||||
modi12Document.OCR((MODI12.MiLANGUAGES)Enum.Parse(typeof(MODI12.MiLANGUAGES), config.GetProperty("language")), config.GetBoolProperty("orientImage"), config.GetBoolProperty("straightenImage"));
|
||||
// Get the first (and only image)
|
||||
MODI12.Image modi12Image = (MODI12.Image)modi12Document.Images[0];
|
||||
// Get the layout.
|
||||
MODI12.Layout modi12layout = modi12Image.Layout;
|
||||
text = modi12layout.Text;
|
||||
// Close the MODI.Document object.
|
||||
modi12Document.Close(false);
|
||||
break;
|
||||
default:
|
||||
LOG.Error("Unknown MODI version!");
|
||||
break;
|
||||
}
|
||||
|
||||
// Paste to Clipboard (the Plugin currently doesn't have access to the ClipboardHelper from Greenshot
|
||||
IDataObject ido = new DataObject();
|
||||
ido.SetData(DataFormats.Text, true, text);
|
||||
Clipboard.SetDataObject(ido, true);
|
||||
} catch (Exception e) {
|
||||
string message = "A problem occured while trying to OCR the region, this plugin is still in a experimental stage!!";
|
||||
LOG.Error(message, e);
|
||||
MessageBox.Show(message);
|
||||
} finally {
|
||||
if (File.Exists(filePath)) {
|
||||
LOG.Debug("Cleaning up tmp file: " + filePath);
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string [] GetLanguages() {
|
||||
string [] languages = null;
|
||||
switch (CheckModiVersion()) {
|
||||
case ModiVersion.MODI11:
|
||||
languages = Enum.GetNames(typeof(MODI11.MiLANGUAGES));
|
||||
break;
|
||||
case ModiVersion.MODI12:
|
||||
languages =Enum.GetNames(typeof(MODI12.MiLANGUAGES));
|
||||
break;
|
||||
}
|
||||
return languages;
|
||||
}
|
||||
|
||||
private enum ModiVersion { None, MODI11, MODI12 };
|
||||
|
||||
private ModiVersion CheckModiVersion() {
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(MODI_OFFICE11, false)) {
|
||||
if (key != null) {
|
||||
LOG.Debug("Found Modi V11 in registry: " + key.Name);
|
||||
return ModiVersion.MODI11;
|
||||
}
|
||||
}
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(MODI_OFFICE12, false)) {
|
||||
if (key != null) {
|
||||
LOG.Debug("Found Modi V12 in registry: " + key.Name);
|
||||
return ModiVersion.MODI12;
|
||||
}
|
||||
}
|
||||
return ModiVersion.None;
|
||||
}
|
||||
|
||||
private bool HasMODI() {
|
||||
return CheckModiVersion() != ModiVersion.None;
|
||||
}
|
||||
}
|
||||
}
|
54
Greenshot-OCR-Plugin/Properties/AssemblyInfo.cs.template
Normal file
54
Greenshot-OCR-Plugin/Properties/AssemblyInfo.cs.template
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("GreenshotOCR")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("GreenshotOCR")]
|
||||
[assembly: AssemblyCopyright("Copyright 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
// The PluginAttribute describes the "entryType" and if the plugin is configurable
|
||||
[assembly: PluginAttribute("GreenshotOCR.OcrPlugin", true)]
|
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.$WCREV$")]
|
138
Greenshot-OCR-Plugin/SettingsForm.Designer.cs
generated
Normal file
138
Greenshot-OCR-Plugin/SettingsForm.Designer.cs
generated
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace GreenshotOCR
|
||||
{
|
||||
partial class SettingsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Designer variable used to keep track of non-visual components.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Disposes resources used by the form.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
if (components != null) {
|
||||
components.Dispose();
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method is required for Windows Forms designer support.
|
||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
||||
/// not be able to load this method if it was changed manually.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBox_languages = new System.Windows.Forms.ComboBox();
|
||||
this.checkBox_orientImage = new System.Windows.Forms.CheckBox();
|
||||
this.checkBox_straightenImage = new System.Windows.Forms.CheckBox();
|
||||
this.label_language = new System.Windows.Forms.Label();
|
||||
this.buttonOK = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// comboBox_languages
|
||||
//
|
||||
this.comboBox_languages.FormattingEnabled = true;
|
||||
this.comboBox_languages.Items.AddRange(new object[] {
|
||||
"English",
|
||||
"Deutsch"});
|
||||
this.comboBox_languages.Location = new System.Drawing.Point(74, 12);
|
||||
this.comboBox_languages.Name = "comboBox_languages";
|
||||
this.comboBox_languages.Size = new System.Drawing.Size(153, 21);
|
||||
this.comboBox_languages.TabIndex = 0;
|
||||
//
|
||||
// checkBox_orientImage
|
||||
//
|
||||
this.checkBox_orientImage.Location = new System.Drawing.Point(13, 41);
|
||||
this.checkBox_orientImage.Name = "checkBox_orientImage";
|
||||
this.checkBox_orientImage.Size = new System.Drawing.Size(104, 24);
|
||||
this.checkBox_orientImage.TabIndex = 1;
|
||||
this.checkBox_orientImage.Text = "Orient image";
|
||||
this.checkBox_orientImage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBox_straightenImage
|
||||
//
|
||||
this.checkBox_straightenImage.Location = new System.Drawing.Point(123, 41);
|
||||
this.checkBox_straightenImage.Name = "checkBox_straightenImage";
|
||||
this.checkBox_straightenImage.Size = new System.Drawing.Size(109, 24);
|
||||
this.checkBox_straightenImage.TabIndex = 2;
|
||||
this.checkBox_straightenImage.Text = "Straighten image";
|
||||
this.checkBox_straightenImage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label_language
|
||||
//
|
||||
this.label_language.Location = new System.Drawing.Point(13, 15);
|
||||
this.label_language.Name = "label_language";
|
||||
this.label_language.Size = new System.Drawing.Size(55, 23);
|
||||
this.label_language.TabIndex = 3;
|
||||
this.label_language.Text = "Language";
|
||||
//
|
||||
// buttonOK
|
||||
//
|
||||
this.buttonOK.Location = new System.Drawing.Point(13, 72);
|
||||
this.buttonOK.Name = "buttonOK";
|
||||
this.buttonOK.Size = new System.Drawing.Size(104, 23);
|
||||
this.buttonOK.TabIndex = 4;
|
||||
this.buttonOK.Text = "OK";
|
||||
this.buttonOK.UseVisualStyleBackColor = true;
|
||||
this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(123, 72);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(104, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.Text = "Cancel";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(244, 111);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonOK);
|
||||
this.Controls.Add(this.label_language);
|
||||
this.Controls.Add(this.checkBox_straightenImage);
|
||||
this.Controls.Add(this.checkBox_orientImage);
|
||||
this.Controls.Add(this.comboBox_languages);
|
||||
this.Name = "SettingsForm";
|
||||
this.Text = "SettingsForm";
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
private System.Windows.Forms.Label label_language;
|
||||
private System.Windows.Forms.Button buttonCancel;
|
||||
private System.Windows.Forms.Button buttonOK;
|
||||
private System.Windows.Forms.CheckBox checkBox_orientImage;
|
||||
private System.Windows.Forms.CheckBox checkBox_straightenImage;
|
||||
private System.Windows.Forms.ComboBox comboBox_languages;
|
||||
}
|
||||
}
|
99
Greenshot-OCR-Plugin/SettingsForm.cs
Normal file
99
Greenshot-OCR-Plugin/SettingsForm.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2010 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// Description of SettingsForm.
|
||||
/// </summary>
|
||||
public partial class SettingsForm : Form {
|
||||
private ILanguage language = Language.GetInstance();
|
||||
private string selectedLanguage;
|
||||
private bool orientImage;
|
||||
private bool straightenImage;
|
||||
|
||||
public SettingsForm(string [] languages, Properties config) {
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
InitializeComponent();
|
||||
language.SynchronizeLanguageToCulture();
|
||||
initializeComponentText();
|
||||
|
||||
comboBox_languages.Items.Clear();
|
||||
int index=0;
|
||||
foreach(string availableLanguage in languages) {
|
||||
string displayLanguage = cleanLanguage(availableLanguage);
|
||||
comboBox_languages.Items.Add(displayLanguage);
|
||||
if (availableLanguage.Equals(config["language"])) {
|
||||
comboBox_languages.SelectedIndex = index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
checkBox_orientImage.Checked = config.GetBoolProperty("orientImage");
|
||||
checkBox_straightenImage.Checked = config.GetBoolProperty("straightenImage");
|
||||
}
|
||||
private void initializeComponentText() {
|
||||
this.label_language.Text = language.GetString(LangKey.language);
|
||||
this.checkBox_orientImage.Text = language.GetString(LangKey.orient_image);
|
||||
}
|
||||
|
||||
private string cleanLanguage(string suppliedLanguage) {
|
||||
string displayLanguage = "";
|
||||
if (suppliedLanguage != null) {
|
||||
displayLanguage = suppliedLanguage.Replace("miLANG_","").Replace("_"," ");
|
||||
displayLanguage = displayLanguage.Substring(0, 1).ToUpper() + displayLanguage.Substring(1).ToLower();
|
||||
}
|
||||
return displayLanguage;
|
||||
}
|
||||
|
||||
public string OCRLanguage {
|
||||
get {return selectedLanguage;}
|
||||
}
|
||||
public bool OrientImage {
|
||||
get {return orientImage;}
|
||||
}
|
||||
public bool StraightenImage {
|
||||
get {return straightenImage;}
|
||||
}
|
||||
|
||||
void ButtonCancelClick(object sender, EventArgs e) {
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
void ButtonOKClick(object sender, EventArgs e) {
|
||||
string selectedString = (string) comboBox_languages.SelectedItem;
|
||||
if (selectedString != null) {
|
||||
selectedLanguage = "miLANG_" + selectedString.ToUpper().Replace(" ", "_");
|
||||
}
|
||||
orientImage = checkBox_orientImage.Checked;
|
||||
straightenImage = checkBox_straightenImage.Checked;
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
2
Greenshot-OCR-Plugin/lib/GEN.BAT
Normal file
2
Greenshot-OCR-Plugin/lib/GEN.BAT
Normal file
|
@ -0,0 +1,2 @@
|
|||
tlbimp Office12\MDIVWCTL.DLL /namespace:MODI12 /out:MODI12.dll
|
||||
tlbimp Office11\MDIVWCTL.DLL /namespace:MODI11 /out:MODI11.dll
|
BIN
Greenshot-OCR-Plugin/lib/MODI11.dll
Normal file
BIN
Greenshot-OCR-Plugin/lib/MODI11.dll
Normal file
Binary file not shown.
BIN
Greenshot-OCR-Plugin/lib/MODI12.dll
Normal file
BIN
Greenshot-OCR-Plugin/lib/MODI12.dll
Normal file
Binary file not shown.
BIN
Greenshot-OCR-Plugin/lib/Office11/MDIVWCTL.DLL
Normal file
BIN
Greenshot-OCR-Plugin/lib/Office11/MDIVWCTL.DLL
Normal file
Binary file not shown.
BIN
Greenshot-OCR-Plugin/lib/Office12/MDIVWCTL.DLL
Normal file
BIN
Greenshot-OCR-Plugin/lib/Office12/MDIVWCTL.DLL
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue