2010-10-12 13:17:56 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Nikse.SubtitleEdit.Logic;
|
2011-06-26 19:01:23 +02:00
|
|
|
|
using System.Collections.Generic;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
|
|
|
|
namespace Nikse.SubtitleEdit.Forms
|
|
|
|
|
{
|
|
|
|
|
public sealed partial class VobSubOcrCharacter : Form
|
|
|
|
|
{
|
2011-06-18 08:20:32 +02:00
|
|
|
|
|
|
|
|
|
VobSubOcr _vobSubForm;
|
2011-06-26 19:01:23 +02:00
|
|
|
|
List<VobSubOcr.ImageCompareAddition> _additions;
|
2011-06-18 08:20:32 +02:00
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
public VobSubOcrCharacter()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
var language = Configuration.Settings.Language.VobSubOcrCharacter;
|
|
|
|
|
Text = language.Title;
|
|
|
|
|
labelSubtitleImage.Text = language.SubtitleImage;
|
|
|
|
|
buttonExpandSelection.Text = language.ExpandSelection;
|
|
|
|
|
buttonShrinkSelection.Text = language.ShrinkSelection;
|
|
|
|
|
labelCharacters.Text = language.Characters;
|
|
|
|
|
labelCharactersAsText.Text = language.CharactersAsText;
|
|
|
|
|
checkBoxItalic.Text = language.Italic;
|
|
|
|
|
buttonAbort.Text = language.Abort;
|
|
|
|
|
buttonOK.Text = Configuration.Settings.Language.General.OK;
|
2011-06-18 08:20:32 +02:00
|
|
|
|
buttonCancel.Text = language.Skip;
|
2011-06-18 23:34:07 +02:00
|
|
|
|
nordicToolStripMenuItem.Text = language.Nordic;
|
|
|
|
|
spanishToolStripMenuItem.Text = language.Spanish;
|
|
|
|
|
germanToolStripMenuItem.Text = language.German;
|
|
|
|
|
checkBoxAutoSubmitOfFirstChar.Text = language.AutoSubmitOnFirstChar;
|
|
|
|
|
|
2010-12-30 20:20:33 +01:00
|
|
|
|
FixLargeFonts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixLargeFonts()
|
|
|
|
|
{
|
|
|
|
|
Graphics graphics = this.CreateGraphics();
|
|
|
|
|
SizeF textSize = graphics.MeasureString(buttonCancel.Text, this.Font);
|
|
|
|
|
if (textSize.Height > buttonCancel.Height - 4)
|
|
|
|
|
{
|
|
|
|
|
int newButtonHeight = (int)(textSize.Height + 7 + 0.5);
|
|
|
|
|
Utilities.SetButtonHeight(this, newButtonHeight, 1);
|
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ManualRecognizedCharacters
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return textBoxCharacters.Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsItalic
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return checkBoxItalic.Checked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Point FormPosition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new Point(Left, Top);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExpandSelection { get; private set; }
|
|
|
|
|
|
|
|
|
|
public bool ShrinkSelection { get; private set; }
|
|
|
|
|
|
2011-07-03 09:27:20 +02:00
|
|
|
|
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool italicChecked, bool showShrink, VobSubOcr.CompareMatch bestGuess, List<VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
|
2010-10-12 13:17:56 +02:00
|
|
|
|
{
|
2011-06-20 19:26:24 +02:00
|
|
|
|
ShrinkSelection = false;
|
|
|
|
|
ExpandSelection = false;
|
|
|
|
|
|
2011-06-18 23:34:07 +02:00
|
|
|
|
textBoxCharacters.Text = string.Empty;
|
2011-06-18 08:20:32 +02:00
|
|
|
|
if (bestGuess != null)
|
|
|
|
|
{
|
|
|
|
|
buttonGuess.Visible = false; // hm... not too useful :(
|
|
|
|
|
buttonGuess.Text = bestGuess.Text;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buttonGuess.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_vobSubForm = vobSubForm;
|
2011-06-26 19:01:23 +02:00
|
|
|
|
_additions = additions;
|
2011-06-18 08:20:32 +02:00
|
|
|
|
|
2010-10-12 13:17:56 +02:00
|
|
|
|
buttonShrinkSelection.Visible = showShrink;
|
|
|
|
|
|
|
|
|
|
checkBoxItalic.Checked = italicChecked;
|
|
|
|
|
if (position.X != -1 && position.Y != -1)
|
|
|
|
|
{
|
|
|
|
|
StartPosition = FormStartPosition.Manual;
|
|
|
|
|
Left = position.X;
|
|
|
|
|
Top = position.Y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBoxSubtitleImage.Image = vobSubImage;
|
|
|
|
|
pictureBoxCharacter.Image = character.Bitmap;
|
|
|
|
|
|
2011-06-26 19:01:23 +02:00
|
|
|
|
if (_additions.Count > 0)
|
2011-06-18 08:20:32 +02:00
|
|
|
|
{
|
2011-06-26 19:01:23 +02:00
|
|
|
|
var last = _additions[_additions.Count - 1];
|
2011-06-18 08:20:32 +02:00
|
|
|
|
buttonLastEdit.Visible = true;
|
2011-06-26 19:01:23 +02:00
|
|
|
|
if (last.Italic)
|
2011-06-18 08:20:32 +02:00
|
|
|
|
buttonLastEdit.Font = new System.Drawing.Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size, FontStyle.Italic);
|
|
|
|
|
else
|
|
|
|
|
buttonLastEdit.Font = new System.Drawing.Font(buttonLastEdit.Font.FontFamily, buttonLastEdit.Font.Size);
|
|
|
|
|
pictureBoxLastEdit.Visible = true;
|
2011-06-26 19:01:23 +02:00
|
|
|
|
pictureBoxLastEdit.Image = last.Image;
|
|
|
|
|
buttonLastEdit.Text = string.Format(Configuration.Settings.Language.VobSubOcrCharacter.EditLastX, last.Text);
|
|
|
|
|
pictureBoxLastEdit.Top = buttonLastEdit.Top - last.Image.Height + buttonLastEdit.Height;
|
2011-06-18 08:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buttonLastEdit.Visible = false;
|
|
|
|
|
pictureBoxLastEdit.Visible = false;
|
2011-06-18 23:34:07 +02:00
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
|
|
|
|
|
Bitmap org = (Bitmap)vobSubImage.Clone();
|
|
|
|
|
Bitmap bm = new Bitmap(org.Width, org.Height);
|
|
|
|
|
Graphics g = Graphics.FromImage(bm);
|
|
|
|
|
g.DrawImage(org, 0, 0, org.Width, org.Height);
|
|
|
|
|
g.DrawRectangle(Pens.Red, character.X, character.Y, character.Bitmap.Width, character.Bitmap.Height - 1);
|
|
|
|
|
g.Dispose();
|
|
|
|
|
pictureBoxSubtitleImage.Image = bm;
|
2011-06-18 23:34:07 +02:00
|
|
|
|
|
|
|
|
|
pictureBoxCharacter.Top = labelCharacters.Top + 16;
|
|
|
|
|
pictureBoxLastEdit.Left = buttonLastEdit.Left + buttonLastEdit.Width + 5;
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonOkClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TextBoxCharactersKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter)
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
else if (e.KeyCode == Keys.Escape)
|
|
|
|
|
DialogResult = DialogResult.Cancel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckBoxItalicCheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBoxCharacters.Focus();
|
2011-06-18 08:20:32 +02:00
|
|
|
|
|
|
|
|
|
if (checkBoxItalic.Checked)
|
|
|
|
|
{
|
|
|
|
|
labelCharactersAsText.Font = new System.Drawing.Font(labelCharactersAsText.Font.FontFamily, labelCharactersAsText.Font.Size, FontStyle.Italic);
|
|
|
|
|
textBoxCharacters.Font = new System.Drawing.Font(textBoxCharacters.Font.FontFamily, textBoxCharacters.Font.Size, FontStyle.Italic);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
labelCharactersAsText.Font = new System.Drawing.Font(labelCharactersAsText.Font.FontFamily, labelCharactersAsText.Font.Size);
|
|
|
|
|
textBoxCharacters.Font = new System.Drawing.Font(textBoxCharacters.Font.FontFamily, textBoxCharacters.Font.Size);
|
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonExpandSelectionClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ExpandSelection = true;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonShrinkSelectionClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ShrinkSelection = true;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
2011-06-18 08:20:32 +02:00
|
|
|
|
|
|
|
|
|
private void buttonLastEdit_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2011-06-26 19:01:23 +02:00
|
|
|
|
if (_additions.Count > 0)
|
2011-06-20 19:26:24 +02:00
|
|
|
|
{
|
2011-06-26 19:01:23 +02:00
|
|
|
|
var last = _additions[_additions.Count - 1];
|
|
|
|
|
var result = _vobSubForm.EditImageCompareCharacters(last.Name, last.Text);
|
|
|
|
|
if (result == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
_additions.RemoveAt(_additions.Count - 1);
|
|
|
|
|
_vobSubForm.StartOcrFromDelayed();
|
|
|
|
|
DialogResult = DialogResult.Abort;
|
|
|
|
|
}
|
2011-06-20 19:26:24 +02:00
|
|
|
|
}
|
2011-06-18 08:20:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonGuess_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBoxCharacters.Text = buttonGuess.Text;
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InsertLanguageCharacter(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBoxCharacters.Text = textBoxCharacters.Text.Insert(textBoxCharacters.SelectionStart, (sender as ToolStripMenuItem).Text);
|
|
|
|
|
}
|
2011-06-18 23:34:07 +02:00
|
|
|
|
|
|
|
|
|
private void textBoxCharacters_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (checkBoxAutoSubmitOfFirstChar.Checked && textBoxCharacters.Text.Length > 0)
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VobSubOcrCharacter_Shown(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
textBoxCharacters.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkBoxAutoSubmitOfFirstChar_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Focus();
|
|
|
|
|
textBoxCharacters.Focus();
|
|
|
|
|
textBoxCharacters.Focus();
|
|
|
|
|
Application.DoEvents();
|
|
|
|
|
textBoxCharacters.Focus();
|
|
|
|
|
textBoxCharacters.Focus();
|
|
|
|
|
}
|
2011-07-05 07:17:43 +02:00
|
|
|
|
|
|
|
|
|
private void VobSubOcrCharacter_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.Left && buttonShrinkSelection.Visible)
|
|
|
|
|
{
|
|
|
|
|
ButtonShrinkSelectionClick(null, null);
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.Right && buttonExpandSelection.Visible)
|
|
|
|
|
{
|
|
|
|
|
ButtonExpandSelectionClick(null, null);
|
|
|
|
|
e.SuppressKeyPress = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-10-12 13:17:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|