1
0
mirror of https://github.com/greenshot/greenshot.git synced 2025-03-12 05:25:25 -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:
RKrom 2012-09-23 13:28:30 +00:00
parent 9553f840cb
commit fd91cc9107
18 changed files with 61 additions and 115 deletions

@ -4,7 +4,7 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# SharpDevelop 4.2.1.8805
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotPlugin", "..\GreenshotPlugin\GreenshotPlugin.csproj", "{5B924697-4DCD-4F98-85F1-105CB84B7341}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Greenshot-OCR-Plugin", "..\Greenshot-OCR-Plugin\Greenshot-OCR-Plugin.csproj", "{C6988EE8-2FEE-4349-9F09-F9628A0D8965}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotOCRPlugin", "..\GreenshotOCRPlugin\GreenshotOCRPlugin.csproj", "{C6988EE8-2FEE-4349-9F09-F9628A0D8965}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotJiraPlugin", "..\GreenshotJiraPlugin\GreenshotJiraPlugin.csproj", "{19FEEF09-313F-43C7-819D-F1BCA782B08B}"
EndProject

@ -51,8 +51,8 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\Greenshot-OCR-Plugin"</PostBuildEvent>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\GreenshotOCRPlugin"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\GreenshotOCRPlugin"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

@ -6,10 +6,9 @@
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>GreenshotOCR</RootNamespace>
<AssemblyName>Greenshot-OCR-Plugin</AssemblyName>
<AssemblyName>GreenshotOCRPlugin</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>
@ -52,9 +51,9 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="LanguageKeys.cs" />
<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">

@ -33,7 +33,5 @@ namespace GreenshotOCR {
public bool Orientimage;
[IniProperty("straightenImage", Description="Straighten image?", DefaultValue="true")]
public bool StraightenImage;
[IniProperty("hotkey", Description="OCR Hotkey", DefaultValue="Alt + Ctrl + PrintScreen")]
public string HotKey;
}
}

@ -37,7 +37,15 @@ namespace GreenshotOCR {
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 {
@ -50,13 +58,21 @@ namespace GreenshotOCR {
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) {
plugin.DoOCR(surface);
return new ExportInformation(this.Designation, this.Description, true);
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
exportInformation.ExportMade = plugin.DoOCR(surface) != null;
return exportInformation;
}
}
}

@ -1,4 +1,4 @@
/*
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
*
@ -21,9 +21,11 @@
using System;
namespace GreenshotOCR {
public enum LangKey {
language,
orient_image,
straighten_image
}
/// <summary>
/// This class is needed for design-time resolving of the language files
/// </summary>
public class OCRForm : GreenshotPlugin.Controls.GreenshotForm {
public OCRForm() : base() {
}
}
}

@ -70,12 +70,11 @@ namespace GreenshotOCR {
private static OCRConfiguration config;
private PluginAttribute myAttributes;
private ToolStripMenuItem ocrMenuItem = new ToolStripMenuItem();
private int hotkeyIdentifier = 0;
public OcrPlugin() { }
public IEnumerable<IDestination> Destinations() {
yield break;
yield return new OCRDestination(this);
}
public IEnumerable<IProcessor> Processors() {
yield break;
@ -105,13 +104,6 @@ namespace GreenshotOCR {
if (config.Language != null) {
config.Language = config.Language.Replace("miLANG_","").Replace("_"," ");
}
SetHotkeys();
// Here we can hang ourselves to the main context menu!
ocrMenuItem.Text = "Region OCR";
ocrMenuItem.Click += new System.EventHandler(MainMenuClick);
PluginUtils.AddToContextMenu(host, ocrMenuItem);
return true;
}
@ -120,23 +112,8 @@ namespace GreenshotOCR {
/// </summary>
public void Shutdown() {
LOG.Debug("Shutdown of " + myAttributes.Name);
HotkeyControl.UnregisterHotkey(hotkeyIdentifier);
hotkeyIdentifier = 0;
}
private void SetHotkeys() {
if (hotkeyIdentifier > 0) {
HotkeyControl.UnregisterHotkey(hotkeyIdentifier);
hotkeyIdentifier = 0;
}
hotkeyIdentifier = HotkeyControl.RegisterHotKey(config.HotKey, new HotKeyHandler(MyHotkeyHandler));
if (hotkeyIdentifier > 0) {
ocrMenuItem.ShortcutKeyDisplayString = HotkeyControl.GetLocalizedHotkeyStringFromString(config.HotKey);
} else {
ocrMenuItem.ShortcutKeyDisplayString = "";
}
}
/// <summary>
/// Implementation of the IPlugin.Configure
/// </summary>
@ -149,27 +126,10 @@ namespace GreenshotOCR {
DialogResult result = settingsForm.ShowDialog();
if (result == DialogResult.OK) {
// "Re"set hotkeys
SetHotkeys();
IniConfig.Save();
}
}
private void StartOCRRegion() {
LOG.Debug("Starting OCR!");
host.CaptureRegion(false, new OCRDestination(this));
}
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
@ -178,7 +138,7 @@ namespace GreenshotOCR {
/// <param name="ImageOutputEventArgs">Has the Image and the capture details</param>
private const int MIN_WIDTH = 130;
private const int MIN_HEIGHT = 130;
public void DoOCR(ISurface surface) {
public string DoOCR(ISurface surface) {
string filePath = null;
OutputSettings outputSettings = new OutputSettings(OutputFormat.bmp);
@ -222,7 +182,7 @@ namespace GreenshotOCR {
}
if (text == null || text.Trim().Length == 0) {
LOG.Info("No text returned");
return;
return null;
}
try {
@ -234,6 +194,7 @@ namespace GreenshotOCR {
} catch (Exception e) {
LOG.Error("Problem pasting text to clipboard: ", e);
}
return text;
}
private bool HasMODI() {

@ -49,13 +49,11 @@ namespace GreenshotOCR
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.ocr_hotkeyControl = new GreenshotPlugin.Controls.HotkeyControl();
this.label1 = new System.Windows.Forms.Label();
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
@ -75,17 +73,21 @@ namespace GreenshotOCR
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.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(118, 68);
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.Text = "Straighten image";
this.checkBox_straightenImage.LanguageKey = "straighten_image";
this.checkBox_straightenImage.UseVisualStyleBackColor = true;
this.checkBox_straightenImage.SectionName = "OCR";
this.checkBox_straightenImage.PropertyName = "straightenImage";
//
// label_language
//
@ -93,53 +95,35 @@ namespace GreenshotOCR
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";
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.Text = "OK";
this.buttonOK.LanguageKey = "OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(122, 98);
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.Text = "Cancel";
this.buttonCancel.LanguageKey = "CANCEL";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick);
//
// ocr_hotkeyControl
//
this.ocr_hotkeyControl.Hotkey = System.Windows.Forms.Keys.None;
this.ocr_hotkeyControl.HotkeyModifiers = System.Windows.Forms.Keys.None;
this.ocr_hotkeyControl.Location = new System.Drawing.Point(74, 39);
this.ocr_hotkeyControl.Name = "ocr_hotkeyControl";
this.ocr_hotkeyControl.Size = new System.Drawing.Size(153, 20);
this.ocr_hotkeyControl.TabIndex = 6;
//
// label1
//
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(13, 42);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(55, 23);
this.label1.TabIndex = 7;
this.label1.Text = "Hotkey";
//
// 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.label1);
this.Controls.Add(this.ocr_hotkeyControl);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.label_language);
@ -147,17 +131,14 @@ namespace GreenshotOCR
this.Controls.Add(this.checkBox_orientImage);
this.Controls.Add(this.comboBox_languages);
this.Name = "SettingsForm";
this.Text = "SettingsForm";
this.LanguageKey = "settings_title";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Label label1;
private GreenshotPlugin.Controls.HotkeyControl ocr_hotkeyControl;
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 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;
}
}

@ -26,7 +26,7 @@ namespace GreenshotOCR {
/// <summary>
/// Description of SettingsForm.
/// </summary>
public partial class SettingsForm : Form {
public partial class SettingsForm : OCRForm {
private OCRConfiguration config;
public SettingsForm(string [] languages, OCRConfiguration config) {
@ -36,7 +36,6 @@ namespace GreenshotOCR {
this.config = config;
InitializeComponent();
this.Icon = GreenshotResources.getGreenshotIcon();
initializeComponentText();
comboBox_languages.Items.Clear();
int index=0;
@ -54,16 +53,8 @@ namespace GreenshotOCR {
}
index++;
}
checkBox_orientImage.Checked = config.Orientimage;
checkBox_straightenImage.Checked = config.StraightenImage;
ocr_hotkeyControl.SetHotkey(config.HotKey);
}
private void initializeComponentText() {
this.label_language.Text = Language.GetString("ocr", LangKey.language);
this.checkBox_orientImage.Text = Language.GetString("ocr", LangKey.orient_image);
}
void ButtonCancelClick(object sender, EventArgs e) {
DialogResult = DialogResult.Cancel;
}
@ -73,8 +64,6 @@ namespace GreenshotOCR {
if (selectedString != null) {
config.Language = selectedString.ToUpper();
}
config.Orientimage = checkBox_orientImage.Checked;
config.StraightenImage = checkBox_straightenImage.Checked;
DialogResult = DialogResult.OK;
}