mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
OCR Plugin refactoring, now should work as a real destination and have an icon.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2083 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
9553f840cb
commit
fd91cc9107
18 changed files with 61 additions and 115 deletions
95
GreenshotOCRPlugin/GreenshotOCRPlugin.csproj
Normal file
95
GreenshotOCRPlugin/GreenshotOCRPlugin.csproj
Normal file
|
@ -0,0 +1,95 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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>GreenshotOCRPlugin</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
|
||||
<NoStdLib>False</NoStdLib>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>Full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<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>
|
||||
<RegisterForComInterop>False</RegisterForComInterop>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
<BaseAddress>4194304</BaseAddress>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OCRConfiguration.cs" />
|
||||
<Compile Include="OCRDestination.cs" />
|
||||
<Compile Include="OCRForm.cs" />
|
||||
<Compile Include="OCRPlugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<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-fr-FR.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Languages\language_ocrplugin-nl-NL.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Languages\language_ocrplugin-zh-CN.xml" />
|
||||
<None Include="Properties\AssemblyInfo.cs.template" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
|
||||
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
|
||||
<Name>GreenshotPlugin</Name>
|
||||
</ProjectReference>
|
||||
</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)\$(ProjectName).pdb" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\"
|
||||
copy "$(ProjectDir)bin\$(Configuration)\MODI*.dll" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*"
|
||||
mkdir "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)"
|
||||
copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)\"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-de-DE.xml
Normal file
14
GreenshotOCRPlugin/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="1.0.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Sprache für OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Bild ausrichten
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Bild glätten
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-en-US.xml
Normal file
14
GreenshotOCRPlugin/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="1.0.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>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Français" ietf="fr-FR" version="1.0.0" languagegroup="">
|
||||
<resources>
|
||||
<resource name="language">Langage pour l'OCR</resource>
|
||||
<resource name="orient_image">Orienter l'image</resource>
|
||||
<resource name="straighten_image">Redresser l'image</resource>
|
||||
</resources>
|
||||
</language>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-it-IT.xml
Normal file
14
GreenshotOCRPlugin/Languages/language_ocrplugin-it-IT.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Italiano" ietf="it-IT" version="1.0.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Lingua OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Orienta
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Raddrizza
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-nl-NL.xml
Normal file
14
GreenshotOCRPlugin/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="1.0.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>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-ru-RU.xml
Normal file
14
GreenshotOCRPlugin/Languages/language_ocrplugin-ru-RU.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Русский" ietf="ru-RU" version="1.0.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
Язык для OCR
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
Ориентация изображения
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
Выпрямление изображения
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="Українська" ietf="uk-UA" version="1.0.0">
|
||||
<resources>
|
||||
<resource name="language">Мова для ОРТ</resource>
|
||||
<resource name="orient_image">Орієнтувати зображення</resource>
|
||||
<resource name="straighten_image">Випрямлення зображення</resource>
|
||||
</resources>
|
||||
</language>
|
14
GreenshotOCRPlugin/Languages/language_ocrplugin-zh-CN.xml
Normal file
14
GreenshotOCRPlugin/Languages/language_ocrplugin-zh-CN.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<language description="简体中文" ietf="zh-CN" version="1.0.0">
|
||||
<resources>
|
||||
<resource name="language">
|
||||
OCR语言
|
||||
</resource>
|
||||
<resource name="orient_image">
|
||||
图像定位
|
||||
</resource>
|
||||
<resource name="straighten_image">
|
||||
图像矫正
|
||||
</resource>
|
||||
</resources>
|
||||
</language>
|
37
GreenshotOCRPlugin/OCRConfiguration.cs
Normal file
37
GreenshotOCRPlugin/OCRConfiguration.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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 Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// Description of CoreConfiguration.
|
||||
/// </summary>
|
||||
[IniSection("OCR", Description="Greenshot OCR Plugin configuration")]
|
||||
public class OCRConfiguration : IniSection {
|
||||
[IniProperty("Language", Description="Language for OCR", DefaultValue="miLANG_ENGLISH")]
|
||||
public string Language;
|
||||
[IniProperty("orientimage", Description="Orient image?", DefaultValue="true")]
|
||||
public bool Orientimage;
|
||||
[IniProperty("straightenImage", Description="Straighten image?", DefaultValue="true")]
|
||||
public bool StraightenImage;
|
||||
}
|
||||
}
|
78
GreenshotOCRPlugin/OCRDestination.cs
Normal file
78
GreenshotOCRPlugin/OCRDestination.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Controls;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// Description of OCRDestination.
|
||||
/// </summary>
|
||||
public class OCRDestination : AbstractDestination {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OCRDestination));
|
||||
private static OCRConfiguration config = IniConfig.GetIniSection<OCRConfiguration>();
|
||||
private const int MIN_WIDTH = 130;
|
||||
private const int MIN_HEIGHT = 130;
|
||||
private static Image icon = null;
|
||||
private OcrPlugin plugin;
|
||||
|
||||
static OCRDestination() {
|
||||
string exePath = PluginUtils.GetExePath("MSPVIEW.EXE");
|
||||
if (exePath != null && File.Exists(exePath)) {
|
||||
icon = PluginUtils.GetExeIcon(exePath, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Designation {
|
||||
get {
|
||||
return "OCR";
|
||||
}
|
||||
}
|
||||
|
||||
public override string Description {
|
||||
get {
|
||||
return "OCR";
|
||||
}
|
||||
}
|
||||
|
||||
public override Image DisplayIcon {
|
||||
get {
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
public OCRDestination(OcrPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
|
||||
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
|
||||
exportInformation.ExportMade = plugin.DoOCR(surface) != null;
|
||||
return exportInformation;
|
||||
}
|
||||
}
|
||||
}
|
31
GreenshotOCRPlugin/OCRForm.cs
Normal file
31
GreenshotOCRPlugin/OCRForm.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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 {
|
||||
/// <summary>
|
||||
/// This class is needed for design-time resolving of the language files
|
||||
/// </summary>
|
||||
public class OCRForm : GreenshotPlugin.Controls.GreenshotForm {
|
||||
public OCRForm() : base() {
|
||||
}
|
||||
}
|
||||
}
|
213
GreenshotOCRPlugin/OCRPlugin.cs
Normal file
213
GreenshotOCRPlugin/OCRPlugin.cs
Normal file
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.Controls;
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Interop;
|
||||
using System.Diagnostics;
|
||||
|
||||
//using Microsoft.Win32;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
// Needed for the drop down, available languages for OCR
|
||||
public enum ModiLanguage {
|
||||
CHINESE_SIMPLIFIED = 2052,
|
||||
CHINESE_TRADITIONAL = 1028,
|
||||
CZECH = 5,
|
||||
DANISH = 6,
|
||||
DUTCH = 19,
|
||||
ENGLISH = 9,
|
||||
FINNISH = 11,
|
||||
FRENCH = 12,
|
||||
GERMAN = 7,
|
||||
GREEK = 8,
|
||||
HUNGARIAN = 14,
|
||||
ITALIAN = 16,
|
||||
JAPANESE = 17,
|
||||
KOREAN = 18,
|
||||
NORWEGIAN = 20,
|
||||
POLISH = 21,
|
||||
PORTUGUESE = 22,
|
||||
RUSSIAN = 25,
|
||||
SPANISH = 10,
|
||||
SWEDISH = 29,
|
||||
TURKISH = 31,
|
||||
SYSDEFAULT = 2048
|
||||
}
|
||||
/// <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 string OCR_COMMAND;
|
||||
private static IGreenshotHost host;
|
||||
private static OCRConfiguration config;
|
||||
private PluginAttribute myAttributes;
|
||||
private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem();
|
||||
|
||||
public OcrPlugin() { }
|
||||
|
||||
public IEnumerable<IDestination> Destinations() {
|
||||
yield return new OCRDestination(this);
|
||||
}
|
||||
public IEnumerable<IProcessor> Processors() {
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <returns>true if plugin is initialized, false if not (doesn't show)</returns>
|
||||
public virtual bool Initialize(IGreenshotHost greenshotHost, PluginAttribute myAttributes) {
|
||||
LOG.Debug("Initialize called of " + myAttributes.Name);
|
||||
host = greenshotHost;
|
||||
this.myAttributes = myAttributes;
|
||||
|
||||
OCR_COMMAND = Path.Combine(Path.GetDirectoryName(myAttributes.DllFile), "greenshotocrcommand.exe");
|
||||
|
||||
if (!HasMODI()) {
|
||||
LOG.Warn("No MODI found!");
|
||||
return false;
|
||||
}
|
||||
// Load configuration
|
||||
config = IniConfig.GetIniSection<OCRConfiguration>();
|
||||
|
||||
if (config.Language != null) {
|
||||
config.Language = config.Language.Replace("miLANG_","").Replace("_"," ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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(Enum.GetNames(typeof(ModiLanguage)), config);
|
||||
DialogResult result = settingsForm.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
// "Re"set hotkeys
|
||||
IniConfig.Save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <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;
|
||||
public string DoOCR(ISurface surface) {
|
||||
string filePath = null;
|
||||
OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp);
|
||||
|
||||
using (Image capturedImage = surface.GetImageForExport()) {
|
||||
if (capturedImage.Width < MIN_WIDTH || capturedImage.Height < MIN_HEIGHT) {
|
||||
LOG.Debug("Captured image is not big enough for OCR, growing 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);
|
||||
}
|
||||
filePath = host.SaveToTmpFile(tmpImage, outputSettings, null);
|
||||
}
|
||||
} else {
|
||||
filePath = host.SaveToTmpFile(capturedImage, outputSettings, null);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.Debug("Saved tmp file to: " + filePath);
|
||||
|
||||
string text = "";
|
||||
try {
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(OCR_COMMAND, "\"" + filePath + "\" " + config.Language + " " + config.Orientimage + " " + config.StraightenImage);
|
||||
processStartInfo.CreateNoWindow = true;
|
||||
processStartInfo.RedirectStandardOutput = true;
|
||||
processStartInfo.UseShellExecute = false;
|
||||
Process process = Process.Start(processStartInfo);
|
||||
process.WaitForExit(30*1000);
|
||||
if (process.ExitCode == 0) {
|
||||
text = process.StandardOutput.ReadToEnd();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.Error("Error while calling Microsoft Office Document Imaging (MODI) to OCR: ", e);
|
||||
} finally {
|
||||
if (File.Exists(filePath)) {
|
||||
LOG.Debug("Cleaning up tmp file: " + filePath);
|
||||
File.Delete(filePath);
|
||||
}
|
||||
}
|
||||
if (text == null || text.Trim().Length == 0) {
|
||||
LOG.Info("No text returned");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.DebugFormat("Pasting OCR Text to Clipboard: {0}", text);
|
||||
// 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) {
|
||||
LOG.Error("Problem pasting text to clipboard: ", e);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private bool HasMODI() {
|
||||
try {
|
||||
Process process = Process.Start(OCR_COMMAND, "-c");
|
||||
process.WaitForExit();
|
||||
int errorCode = process.ExitCode;
|
||||
return errorCode == 0;
|
||||
} catch(Exception e) {
|
||||
LOG.DebugFormat("Error trying to initiate MODI: {0}", e.Message);
|
||||
}
|
||||
LOG.InfoFormat("No Microsoft Office Document Imaging (MODI) found, disabling OCR");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
54
GreenshotOCRPlugin/Properties/AssemblyInfo.cs.template
Normal file
54
GreenshotOCRPlugin/Properties/AssemblyInfo.cs.template
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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("Greenshot")]
|
||||
[assembly: AssemblyProduct("OCR Plugin")]
|
||||
[assembly: AssemblyCopyright("Copyright (C) 2007-2012")]
|
||||
[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.3.$WCREV$")]
|
144
GreenshotOCRPlugin/SettingsForm.Designer.cs
generated
Normal file
144
GreenshotOCRPlugin/SettingsForm.Designer.cs
generated
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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 GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.checkBox_straightenImage = new GreenshotPlugin.Controls.GreenshotCheckBox();
|
||||
this.label_language = new GreenshotPlugin.Controls.GreenshotLabel();
|
||||
this.buttonOK = new GreenshotPlugin.Controls.GreenshotButton();
|
||||
this.buttonCancel = new GreenshotPlugin.Controls.GreenshotButton();
|
||||
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, 68);
|
||||
this.checkBox_orientImage.Name = "checkBox_orientImage";
|
||||
this.checkBox_orientImage.Size = new System.Drawing.Size(104, 24);
|
||||
this.checkBox_orientImage.TabIndex = 1;
|
||||
this.checkBox_orientImage.LanguageKey = "orient_image";
|
||||
this.checkBox_orientImage.UseVisualStyleBackColor = true;
|
||||
this.checkBox_orientImage.SectionName = "OCR";
|
||||
this.checkBox_orientImage.PropertyName = "orientimage";
|
||||
//
|
||||
// checkBox_straightenImage
|
||||
//
|
||||
this.checkBox_straightenImage.Location = new System.Drawing.Point(13, 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.LanguageKey = "straighten_image";
|
||||
this.checkBox_straightenImage.UseVisualStyleBackColor = true;
|
||||
this.checkBox_straightenImage.SectionName = "OCR";
|
||||
this.checkBox_straightenImage.PropertyName = "straightenImage";
|
||||
//
|
||||
// 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.LanguageKey = "ocr.language";
|
||||
//
|
||||
// buttonOK
|
||||
//
|
||||
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonOK.Location = new System.Drawing.Point(12, 98);
|
||||
this.buttonOK.Name = "buttonOK";
|
||||
this.buttonOK.Size = new System.Drawing.Size(104, 23);
|
||||
this.buttonOK.TabIndex = 4;
|
||||
this.buttonOK.LanguageKey = "OK";
|
||||
this.buttonOK.UseVisualStyleBackColor = true;
|
||||
this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonCancel.Location = new System.Drawing.Point(128, 98);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(104, 23);
|
||||
this.buttonCancel.TabIndex = 5;
|
||||
this.buttonCancel.LanguageKey = "CANCEL";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
|
||||
//
|
||||
// SettingsForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(244, 135);
|
||||
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.LanguageKey = "settings_title";
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
private GreenshotPlugin.Controls.GreenshotLabel label_language;
|
||||
private GreenshotPlugin.Controls.GreenshotButton buttonCancel;
|
||||
private GreenshotPlugin.Controls.GreenshotButton buttonOK;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkBox_orientImage;
|
||||
private GreenshotPlugin.Controls.GreenshotCheckBox checkBox_straightenImage;
|
||||
private System.Windows.Forms.ComboBox comboBox_languages;
|
||||
}
|
||||
}
|
71
GreenshotOCRPlugin/SettingsForm.cs
Normal file
71
GreenshotOCRPlugin/SettingsForm.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2012 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.Windows.Forms;
|
||||
using GreenshotPlugin.Core;
|
||||
|
||||
namespace GreenshotOCR {
|
||||
/// <summary>
|
||||
/// Description of SettingsForm.
|
||||
/// </summary>
|
||||
public partial class SettingsForm : OCRForm {
|
||||
private OCRConfiguration config;
|
||||
|
||||
public SettingsForm(string [] languages, OCRConfiguration config) {
|
||||
//
|
||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
||||
//
|
||||
this.config = config;
|
||||
InitializeComponent();
|
||||
this.Icon = GreenshotResources.getGreenshotIcon();
|
||||
|
||||
comboBox_languages.Items.Clear();
|
||||
int index=0;
|
||||
|
||||
// Preventing Tracker #3234560, although this should not happen...
|
||||
string languageFromConfig = "ENGLISH";
|
||||
if (config.Language != null) {
|
||||
languageFromConfig = config.Language;
|
||||
}
|
||||
foreach(string availableLanguage in languages) {
|
||||
string displayLanguage = availableLanguage.Substring(0, 1).ToUpper() + availableLanguage.Substring(1).ToLower();
|
||||
comboBox_languages.Items.Add(displayLanguage);
|
||||
if (availableLanguage.Equals(languageFromConfig, StringComparison.CurrentCultureIgnoreCase)) {
|
||||
comboBox_languages.SelectedIndex = index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonCancelClick(object sender, EventArgs e) {
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
|
||||
void ButtonOKClick(object sender, EventArgs e) {
|
||||
string selectedString = (string) comboBox_languages.SelectedItem;
|
||||
if (selectedString != null) {
|
||||
config.Language = selectedString.ToUpper();
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue