Fix common errors: Added more italic stuff to "fix missing spaces" - thx dr. Jackson :)

+ fixed loading of QubeMasterImport + Uknown49
+ testing ocr


git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1683 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-02-28 07:38:20 +00:00
parent 81537c9481
commit e0cd085bdc
16 changed files with 1803 additions and 156 deletions

View File

@ -1517,6 +1517,57 @@ namespace Nikse.SubtitleEdit.Forms
}
}
//fix missing spaces in "The<i>Bombshell</i> will gone." to "The <i>Bombshell</i> will gone."
if ((p.Text.Contains("<i>") && p.Text.Length > 5))
{
int index = p.Text.IndexOf("<i>");
string newText = p.Text;
while (index != -1)
{
if (newText.Length > index + 6 && index > 1)
{
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3].ToString()) &&
Utilities.AllLettersAndNumbers.Contains(newText[index - 1].ToString()))
newText = newText.Insert(index, " ");
}
index = newText.IndexOf("<i>", index + 3);
}
if (newText != p.Text && AllowFix(p, fixAction))
{
_totalFixes++;
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
AddFixToListView(p, fixAction, oldText, p.Text);
}
}
//fix missing spaces in "The <i>Bombshell</i>will gone." to "The <i>Bombshell</i> will gone."
if ((p.Text.Contains("</i>") && p.Text.Length > 5))
{
int index = p.Text.IndexOf("</i>");
string newText = p.Text;
while (index != -1)
{
if (newText.Length > index + 6 && index > 1)
{
if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3].ToString()) &&
Utilities.AllLettersAndNumbers.Contains(newText[index - 1].ToString()))
newText = newText.Insert(index + 4, " ");
}
index = newText.IndexOf("</i>", index + 4);
}
if (newText != p.Text && AllowFix(p, fixAction))
{
_totalFixes++;
missingSpaces++;
string oldText = p.Text;
p.Text = newText;
AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
if (missingSpaces > 0)

View File

@ -56,13 +56,11 @@ namespace Nikse.SubtitleEdit.Forms
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxOcrMethod = new System.Windows.Forms.GroupBox();
this.comboBoxOcrMethod = new System.Windows.Forms.ComboBox();
this.GroupBoxTesseractMethod = new System.Windows.Forms.GroupBox();
this.checkBoxTesseractMusicOn = new System.Windows.Forms.CheckBox();
this.checkBoxTesseractItalicsOn = new System.Windows.Forms.CheckBox();
this.checkBoxUseModiInTesseractForUnknownWords = new System.Windows.Forms.CheckBox();
this.labelTesseractLanguage = new System.Windows.Forms.Label();
this.comboBoxTesseractLanguages = new System.Windows.Forms.ComboBox();
this.groupBoxNOCR = new System.Windows.Forms.GroupBox();
this.checkBoxNOcrCorrect = new System.Windows.Forms.CheckBox();
this.checkBoxRightToLeftNOCR = new System.Windows.Forms.CheckBox();
this.numericUpDownNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.NumericUpDown();
this.labelNumberOfPixelsIsSpaceNOCR = new System.Windows.Forms.Label();
this.groupBoxImageCompareMethod = new System.Windows.Forms.GroupBox();
this.checkBoxRightToLeft = new System.Windows.Forms.CheckBox();
this.numericUpDownPixelsIsSpace = new System.Windows.Forms.NumericUpDown();
@ -71,6 +69,13 @@ namespace Nikse.SubtitleEdit.Forms
this.comboBoxCharacterDatabase = new System.Windows.Forms.ComboBox();
this.labelImageDatabase = new System.Windows.Forms.Label();
this.buttonNewCharacterDatabase = new System.Windows.Forms.Button();
this.comboBoxOcrMethod = new System.Windows.Forms.ComboBox();
this.GroupBoxTesseractMethod = new System.Windows.Forms.GroupBox();
this.checkBoxTesseractMusicOn = new System.Windows.Forms.CheckBox();
this.checkBoxTesseractItalicsOn = new System.Windows.Forms.CheckBox();
this.checkBoxUseModiInTesseractForUnknownWords = new System.Windows.Forms.CheckBox();
this.labelTesseractLanguage = new System.Windows.Forms.Label();
this.comboBoxTesseractLanguages = new System.Windows.Forms.ComboBox();
this.groupBoxModiMethod = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.comboBoxModiLanguage = new System.Windows.Forms.ComboBox();
@ -84,6 +89,8 @@ namespace Nikse.SubtitleEdit.Forms
this.comboBoxDictionaries = new System.Windows.Forms.ComboBox();
this.checkBoxGuessUnknownWords = new System.Windows.Forms.CheckBox();
this.tabControlLogs = new System.Windows.Forms.TabControl();
this.contextMenuStripAllFixes = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemClearFixes = new System.Windows.Forms.ToolStripMenuItem();
this.tabPageAllFixes = new System.Windows.Forms.TabPage();
this.listBoxLog = new System.Windows.Forms.ListBox();
this.tabPageSuggestions = new System.Windows.Forms.TabPage();
@ -122,20 +129,22 @@ namespace Nikse.SubtitleEdit.Forms
this.splitContainerBottom = new System.Windows.Forms.SplitContainer();
this.textBoxCurrentText = new Nikse.SubtitleEdit.Controls.SETextBox();
this.subtitleListView1 = new Nikse.SubtitleEdit.Controls.SubtitleListView();
this.contextMenuStripAllFixes = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemClearFixes = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStripGuessesUsed = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemClearGuesses = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxNOcrItalic = new System.Windows.Forms.CheckBox();
this.contextMenuStripListview.SuspendLayout();
this.groupBoxOcrMethod.SuspendLayout();
this.GroupBoxTesseractMethod.SuspendLayout();
this.groupBoxNOCR.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).BeginInit();
this.groupBoxImageCompareMethod.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPixelsIsSpace)).BeginInit();
this.GroupBoxTesseractMethod.SuspendLayout();
this.groupBoxModiMethod.SuspendLayout();
this.groupBoxOCRControls.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownStartNumber)).BeginInit();
this.groupBoxOcrAutoFix.SuspendLayout();
this.tabControlLogs.SuspendLayout();
this.contextMenuStripAllFixes.SuspendLayout();
this.tabPageAllFixes.SuspendLayout();
this.tabPageSuggestions.SuspendLayout();
this.tabPageUnknownWords.SuspendLayout();
@ -150,7 +159,6 @@ namespace Nikse.SubtitleEdit.Forms
this.splitContainerBottom.Panel1.SuspendLayout();
this.splitContainerBottom.Panel2.SuspendLayout();
this.splitContainerBottom.SuspendLayout();
this.contextMenuStripAllFixes.SuspendLayout();
this.contextMenuStripGuessesUsed.SuspendLayout();
this.SuspendLayout();
//
@ -173,7 +181,7 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripSeparator3,
this.deleteToolStripMenuItem});
this.contextMenuStripListview.Name = "contextMenuStripListview";
this.contextMenuStripListview.Size = new System.Drawing.Size(306, 276);
this.contextMenuStripListview.Size = new System.Drawing.Size(306, 254);
this.contextMenuStripListview.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListviewOpening);
//
// normalToolStripMenuItem
@ -349,9 +357,10 @@ namespace Nikse.SubtitleEdit.Forms
//
// groupBoxOcrMethod
//
this.groupBoxOcrMethod.Controls.Add(this.groupBoxNOCR);
this.groupBoxOcrMethod.Controls.Add(this.groupBoxImageCompareMethod);
this.groupBoxOcrMethod.Controls.Add(this.comboBoxOcrMethod);
this.groupBoxOcrMethod.Controls.Add(this.GroupBoxTesseractMethod);
this.groupBoxOcrMethod.Controls.Add(this.groupBoxImageCompareMethod);
this.groupBoxOcrMethod.Controls.Add(this.groupBoxModiMethod);
this.groupBoxOcrMethod.Location = new System.Drawing.Point(13, 5);
this.groupBoxOcrMethod.Name = "groupBoxOcrMethod";
@ -360,89 +369,70 @@ namespace Nikse.SubtitleEdit.Forms
this.groupBoxOcrMethod.TabStop = false;
this.groupBoxOcrMethod.Text = "OCR method";
//
// comboBoxOcrMethod
// groupBoxNOCR
//
this.comboBoxOcrMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxOcrMethod.FormattingEnabled = true;
this.comboBoxOcrMethod.Items.AddRange(new object[] {
"OCR via tesseract",
"OCR via image compare",
"OCR via Microsoftr MODI"});
this.comboBoxOcrMethod.Location = new System.Drawing.Point(13, 20);
this.comboBoxOcrMethod.Name = "comboBoxOcrMethod";
this.comboBoxOcrMethod.Size = new System.Drawing.Size(366, 21);
this.comboBoxOcrMethod.TabIndex = 0;
this.comboBoxOcrMethod.SelectedIndexChanged += new System.EventHandler(this.ComboBoxOcrMethodSelectedIndexChanged);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrItalic);
this.groupBoxNOCR.Controls.Add(this.checkBoxNOcrCorrect);
this.groupBoxNOCR.Controls.Add(this.checkBoxRightToLeftNOCR);
this.groupBoxNOCR.Controls.Add(this.numericUpDownNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Controls.Add(this.labelNumberOfPixelsIsSpaceNOCR);
this.groupBoxNOCR.Location = new System.Drawing.Point(7, 38);
this.groupBoxNOCR.Name = "groupBoxNOCR";
this.groupBoxNOCR.Size = new System.Drawing.Size(366, 131);
this.groupBoxNOCR.TabIndex = 7;
this.groupBoxNOCR.TabStop = false;
this.groupBoxNOCR.Text = "nOCR";
//
// GroupBoxTesseractMethod
// checkBoxNOcrCorrect
//
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractMusicOn);
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractItalicsOn);
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxUseModiInTesseractForUnknownWords);
this.GroupBoxTesseractMethod.Controls.Add(this.labelTesseractLanguage);
this.GroupBoxTesseractMethod.Controls.Add(this.comboBoxTesseractLanguages);
this.GroupBoxTesseractMethod.Location = new System.Drawing.Point(13, 31);
this.GroupBoxTesseractMethod.Name = "GroupBoxTesseractMethod";
this.GroupBoxTesseractMethod.Size = new System.Drawing.Size(366, 131);
this.GroupBoxTesseractMethod.TabIndex = 1;
this.GroupBoxTesseractMethod.TabStop = false;
this.GroupBoxTesseractMethod.Text = "Tesseract";
this.checkBoxNOcrCorrect.AutoSize = true;
this.checkBoxNOcrCorrect.Location = new System.Drawing.Point(27, 38);
this.checkBoxNOcrCorrect.Name = "checkBoxNOcrCorrect";
this.checkBoxNOcrCorrect.Size = new System.Drawing.Size(116, 17);
this.checkBoxNOcrCorrect.TabIndex = 7;
this.checkBoxNOcrCorrect.Text = "Draw missing texts";
this.checkBoxNOcrCorrect.UseVisualStyleBackColor = true;
//
// checkBoxTesseractMusicOn
// checkBoxRightToLeftNOCR
//
this.checkBoxTesseractMusicOn.AutoSize = true;
this.checkBoxTesseractMusicOn.Checked = true;
this.checkBoxTesseractMusicOn.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxTesseractMusicOn.Location = new System.Drawing.Point(99, 101);
this.checkBoxTesseractMusicOn.Name = "checkBoxTesseractMusicOn";
this.checkBoxTesseractMusicOn.Size = new System.Drawing.Size(94, 17);
this.checkBoxTesseractMusicOn.TabIndex = 4;
this.checkBoxTesseractMusicOn.Text = "Music symbols";
this.checkBoxTesseractMusicOn.UseVisualStyleBackColor = true;
this.checkBoxRightToLeftNOCR.AutoSize = true;
this.checkBoxRightToLeftNOCR.Location = new System.Drawing.Point(173, 100);
this.checkBoxRightToLeftNOCR.Name = "checkBoxRightToLeftNOCR";
this.checkBoxRightToLeftNOCR.Size = new System.Drawing.Size(83, 17);
this.checkBoxRightToLeftNOCR.TabIndex = 6;
this.checkBoxRightToLeftNOCR.Text = "Right to left";
this.checkBoxRightToLeftNOCR.UseVisualStyleBackColor = true;
//
// checkBoxTesseractItalicsOn
// numericUpDownNumberOfPixelsIsSpaceNOCR
//
this.checkBoxTesseractItalicsOn.AutoSize = true;
this.checkBoxTesseractItalicsOn.Checked = true;
this.checkBoxTesseractItalicsOn.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxTesseractItalicsOn.Location = new System.Drawing.Point(22, 101);
this.checkBoxTesseractItalicsOn.Name = "checkBoxTesseractItalicsOn";
this.checkBoxTesseractItalicsOn.Size = new System.Drawing.Size(53, 17);
this.checkBoxTesseractItalicsOn.TabIndex = 3;
this.checkBoxTesseractItalicsOn.Text = "Italics";
this.checkBoxTesseractItalicsOn.UseVisualStyleBackColor = true;
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(173, 67);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Maximum = new decimal(new int[] {
50,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Name = "numericUpDownNumberOfPixelsIsSpaceNOCR";
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(50, 21);
this.numericUpDownNumberOfPixelsIsSpaceNOCR.TabIndex = 5;
this.numericUpDownNumberOfPixelsIsSpaceNOCR.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// checkBoxUseModiInTesseractForUnknownWords
// labelNumberOfPixelsIsSpaceNOCR
//
this.checkBoxUseModiInTesseractForUnknownWords.AutoSize = true;
this.checkBoxUseModiInTesseractForUnknownWords.Checked = true;
this.checkBoxUseModiInTesseractForUnknownWords.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxUseModiInTesseractForUnknownWords.Enabled = false;
this.checkBoxUseModiInTesseractForUnknownWords.Location = new System.Drawing.Point(22, 74);
this.checkBoxUseModiInTesseractForUnknownWords.Name = "checkBoxUseModiInTesseractForUnknownWords";
this.checkBoxUseModiInTesseractForUnknownWords.Size = new System.Drawing.Size(165, 17);
this.checkBoxUseModiInTesseractForUnknownWords.TabIndex = 2;
this.checkBoxUseModiInTesseractForUnknownWords.Text = "Try MODI for unknown words";
this.checkBoxUseModiInTesseractForUnknownWords.UseVisualStyleBackColor = true;
//
// labelTesseractLanguage
//
this.labelTesseractLanguage.AutoSize = true;
this.labelTesseractLanguage.Location = new System.Drawing.Point(18, 34);
this.labelTesseractLanguage.Name = "labelTesseractLanguage";
this.labelTesseractLanguage.Size = new System.Drawing.Size(54, 13);
this.labelTesseractLanguage.TabIndex = 0;
this.labelTesseractLanguage.Text = "Language";
//
// comboBoxTesseractLanguages
//
this.comboBoxTesseractLanguages.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxTesseractLanguages.FormattingEnabled = true;
this.comboBoxTesseractLanguages.Location = new System.Drawing.Point(99, 31);
this.comboBoxTesseractLanguages.Name = "comboBoxTesseractLanguages";
this.comboBoxTesseractLanguages.Size = new System.Drawing.Size(195, 21);
this.comboBoxTesseractLanguages.TabIndex = 1;
this.comboBoxTesseractLanguages.SelectedIndexChanged += new System.EventHandler(this.ComboBoxTesseractLanguagesSelectedIndexChanged);
this.labelNumberOfPixelsIsSpaceNOCR.AutoSize = true;
this.labelNumberOfPixelsIsSpaceNOCR.Location = new System.Drawing.Point(6, 69);
this.labelNumberOfPixelsIsSpaceNOCR.Name = "labelNumberOfPixelsIsSpaceNOCR";
this.labelNumberOfPixelsIsSpaceNOCR.Size = new System.Drawing.Size(104, 13);
this.labelNumberOfPixelsIsSpaceNOCR.TabIndex = 4;
this.labelNumberOfPixelsIsSpaceNOCR.Text = "No of pixels is space";
//
// groupBoxImageCompareMethod
//
@ -540,6 +530,91 @@ namespace Nikse.SubtitleEdit.Forms
this.buttonNewCharacterDatabase.UseVisualStyleBackColor = true;
this.buttonNewCharacterDatabase.Click += new System.EventHandler(this.ButtonNewCharacterDatabaseClick);
//
// comboBoxOcrMethod
//
this.comboBoxOcrMethod.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxOcrMethod.FormattingEnabled = true;
this.comboBoxOcrMethod.Items.AddRange(new object[] {
"OCR via tesseract",
"OCR via image compare",
"OCR via Microsoftr MODI",
"OCR via nOCR"});
this.comboBoxOcrMethod.Location = new System.Drawing.Point(13, 20);
this.comboBoxOcrMethod.Name = "comboBoxOcrMethod";
this.comboBoxOcrMethod.Size = new System.Drawing.Size(366, 21);
this.comboBoxOcrMethod.TabIndex = 0;
this.comboBoxOcrMethod.SelectedIndexChanged += new System.EventHandler(this.ComboBoxOcrMethodSelectedIndexChanged);
//
// GroupBoxTesseractMethod
//
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractMusicOn);
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxTesseractItalicsOn);
this.GroupBoxTesseractMethod.Controls.Add(this.checkBoxUseModiInTesseractForUnknownWords);
this.GroupBoxTesseractMethod.Controls.Add(this.labelTesseractLanguage);
this.GroupBoxTesseractMethod.Controls.Add(this.comboBoxTesseractLanguages);
this.GroupBoxTesseractMethod.Location = new System.Drawing.Point(13, 31);
this.GroupBoxTesseractMethod.Name = "GroupBoxTesseractMethod";
this.GroupBoxTesseractMethod.Size = new System.Drawing.Size(366, 131);
this.GroupBoxTesseractMethod.TabIndex = 1;
this.GroupBoxTesseractMethod.TabStop = false;
this.GroupBoxTesseractMethod.Text = "Tesseract";
//
// checkBoxTesseractMusicOn
//
this.checkBoxTesseractMusicOn.AutoSize = true;
this.checkBoxTesseractMusicOn.Checked = true;
this.checkBoxTesseractMusicOn.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxTesseractMusicOn.Location = new System.Drawing.Point(99, 101);
this.checkBoxTesseractMusicOn.Name = "checkBoxTesseractMusicOn";
this.checkBoxTesseractMusicOn.Size = new System.Drawing.Size(94, 17);
this.checkBoxTesseractMusicOn.TabIndex = 4;
this.checkBoxTesseractMusicOn.Text = "Music symbols";
this.checkBoxTesseractMusicOn.UseVisualStyleBackColor = true;
//
// checkBoxTesseractItalicsOn
//
this.checkBoxTesseractItalicsOn.AutoSize = true;
this.checkBoxTesseractItalicsOn.Checked = true;
this.checkBoxTesseractItalicsOn.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxTesseractItalicsOn.Location = new System.Drawing.Point(22, 101);
this.checkBoxTesseractItalicsOn.Name = "checkBoxTesseractItalicsOn";
this.checkBoxTesseractItalicsOn.Size = new System.Drawing.Size(53, 17);
this.checkBoxTesseractItalicsOn.TabIndex = 3;
this.checkBoxTesseractItalicsOn.Text = "Italics";
this.checkBoxTesseractItalicsOn.UseVisualStyleBackColor = true;
//
// checkBoxUseModiInTesseractForUnknownWords
//
this.checkBoxUseModiInTesseractForUnknownWords.AutoSize = true;
this.checkBoxUseModiInTesseractForUnknownWords.Checked = true;
this.checkBoxUseModiInTesseractForUnknownWords.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxUseModiInTesseractForUnknownWords.Enabled = false;
this.checkBoxUseModiInTesseractForUnknownWords.Location = new System.Drawing.Point(22, 74);
this.checkBoxUseModiInTesseractForUnknownWords.Name = "checkBoxUseModiInTesseractForUnknownWords";
this.checkBoxUseModiInTesseractForUnknownWords.Size = new System.Drawing.Size(165, 17);
this.checkBoxUseModiInTesseractForUnknownWords.TabIndex = 2;
this.checkBoxUseModiInTesseractForUnknownWords.Text = "Try MODI for unknown words";
this.checkBoxUseModiInTesseractForUnknownWords.UseVisualStyleBackColor = true;
//
// labelTesseractLanguage
//
this.labelTesseractLanguage.AutoSize = true;
this.labelTesseractLanguage.Location = new System.Drawing.Point(18, 34);
this.labelTesseractLanguage.Name = "labelTesseractLanguage";
this.labelTesseractLanguage.Size = new System.Drawing.Size(54, 13);
this.labelTesseractLanguage.TabIndex = 0;
this.labelTesseractLanguage.Text = "Language";
//
// comboBoxTesseractLanguages
//
this.comboBoxTesseractLanguages.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxTesseractLanguages.FormattingEnabled = true;
this.comboBoxTesseractLanguages.Location = new System.Drawing.Point(99, 31);
this.comboBoxTesseractLanguages.Name = "comboBoxTesseractLanguages";
this.comboBoxTesseractLanguages.Size = new System.Drawing.Size(195, 21);
this.comboBoxTesseractLanguages.TabIndex = 1;
this.comboBoxTesseractLanguages.SelectedIndexChanged += new System.EventHandler(this.ComboBoxTesseractLanguagesSelectedIndexChanged);
//
// groupBoxModiMethod
//
this.groupBoxModiMethod.Controls.Add(this.label1);
@ -704,6 +779,20 @@ namespace Nikse.SubtitleEdit.Forms
this.tabControlLogs.Size = new System.Drawing.Size(383, 181);
this.tabControlLogs.TabIndex = 7;
//
// contextMenuStripAllFixes
//
this.contextMenuStripAllFixes.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemClearFixes});
this.contextMenuStripAllFixes.Name = "contextMenuStripUnknownWords";
this.contextMenuStripAllFixes.Size = new System.Drawing.Size(102, 26);
//
// toolStripMenuItemClearFixes
//
this.toolStripMenuItemClearFixes.Name = "toolStripMenuItemClearFixes";
this.toolStripMenuItemClearFixes.Size = new System.Drawing.Size(101, 22);
this.toolStripMenuItemClearFixes.Text = "Clear";
this.toolStripMenuItemClearFixes.Click += new System.EventHandler(this.toolStripMenuItemClearFixes_Click);
//
// tabPageAllFixes
//
this.tabPageAllFixes.Controls.Add(this.listBoxLog);
@ -1136,34 +1225,30 @@ namespace Nikse.SubtitleEdit.Forms
this.subtitleListView1.SelectedIndexChanged += new System.EventHandler(this.SubtitleListView1SelectedIndexChanged);
this.subtitleListView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.subtitleListView1_KeyDown);
//
// contextMenuStripAllFixes
//
this.contextMenuStripAllFixes.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemClearFixes});
this.contextMenuStripAllFixes.Name = "contextMenuStripUnknownWords";
this.contextMenuStripAllFixes.Size = new System.Drawing.Size(102, 26);
//
// toolStripMenuItemClearFixes
//
this.toolStripMenuItemClearFixes.Name = "toolStripMenuItemClearFixes";
this.toolStripMenuItemClearFixes.Size = new System.Drawing.Size(101, 22);
this.toolStripMenuItemClearFixes.Text = "Clear";
this.toolStripMenuItemClearFixes.Click += new System.EventHandler(this.toolStripMenuItemClearFixes_Click);
//
// contextMenuStripGuessesUsed
//
this.contextMenuStripGuessesUsed.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemClearGuesses});
this.contextMenuStripGuessesUsed.Name = "contextMenuStripUnknownWords";
this.contextMenuStripGuessesUsed.Size = new System.Drawing.Size(153, 48);
this.contextMenuStripGuessesUsed.Size = new System.Drawing.Size(102, 26);
//
// toolStripMenuItemClearGuesses
//
this.toolStripMenuItemClearGuesses.Name = "toolStripMenuItemClearGuesses";
this.toolStripMenuItemClearGuesses.Size = new System.Drawing.Size(152, 22);
this.toolStripMenuItemClearGuesses.Size = new System.Drawing.Size(101, 22);
this.toolStripMenuItemClearGuesses.Text = "Clear";
this.toolStripMenuItemClearGuesses.Click += new System.EventHandler(this.toolStripMenuItemClearGuesses_Click);
//
// checkBoxNOcrItalic
//
this.checkBoxNOcrItalic.AutoSize = true;
this.checkBoxNOcrItalic.Location = new System.Drawing.Point(187, 28);
this.checkBoxNOcrItalic.Name = "checkBoxNOcrItalic";
this.checkBoxNOcrItalic.Size = new System.Drawing.Size(49, 17);
this.checkBoxNOcrItalic.TabIndex = 8;
this.checkBoxNOcrItalic.Text = "Italic";
this.checkBoxNOcrItalic.UseVisualStyleBackColor = true;
//
// VobSubOcr
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -1191,11 +1276,14 @@ namespace Nikse.SubtitleEdit.Forms
this.Resize += new System.EventHandler(this.VobSubOcr_Resize);
this.contextMenuStripListview.ResumeLayout(false);
this.groupBoxOcrMethod.ResumeLayout(false);
this.GroupBoxTesseractMethod.ResumeLayout(false);
this.GroupBoxTesseractMethod.PerformLayout();
this.groupBoxNOCR.ResumeLayout(false);
this.groupBoxNOCR.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownNumberOfPixelsIsSpaceNOCR)).EndInit();
this.groupBoxImageCompareMethod.ResumeLayout(false);
this.groupBoxImageCompareMethod.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownPixelsIsSpace)).EndInit();
this.GroupBoxTesseractMethod.ResumeLayout(false);
this.GroupBoxTesseractMethod.PerformLayout();
this.groupBoxModiMethod.ResumeLayout(false);
this.groupBoxModiMethod.PerformLayout();
this.groupBoxOCRControls.ResumeLayout(false);
@ -1204,6 +1292,7 @@ namespace Nikse.SubtitleEdit.Forms
this.groupBoxOcrAutoFix.ResumeLayout(false);
this.groupBoxOcrAutoFix.PerformLayout();
this.tabControlLogs.ResumeLayout(false);
this.contextMenuStripAllFixes.ResumeLayout(false);
this.tabPageAllFixes.ResumeLayout(false);
this.tabPageSuggestions.ResumeLayout(false);
this.tabPageUnknownWords.ResumeLayout(false);
@ -1221,7 +1310,6 @@ namespace Nikse.SubtitleEdit.Forms
this.splitContainerBottom.Panel1.PerformLayout();
this.splitContainerBottom.Panel2.ResumeLayout(false);
this.splitContainerBottom.ResumeLayout(false);
this.contextMenuStripAllFixes.ResumeLayout(false);
this.contextMenuStripGuessesUsed.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@ -1325,5 +1413,11 @@ namespace Nikse.SubtitleEdit.Forms
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemClearFixes;
private System.Windows.Forms.ContextMenuStrip contextMenuStripGuessesUsed;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemClearGuesses;
private System.Windows.Forms.GroupBox groupBoxNOCR;
private System.Windows.Forms.CheckBox checkBoxRightToLeftNOCR;
private System.Windows.Forms.NumericUpDown numericUpDownNumberOfPixelsIsSpaceNOCR;
private System.Windows.Forms.Label labelNumberOfPixelsIsSpaceNOCR;
private System.Windows.Forms.CheckBox checkBoxNOcrCorrect;
private System.Windows.Forms.CheckBox checkBoxNOcrItalic;
}
}

View File

@ -13,6 +13,7 @@ using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.OCR;
using Nikse.SubtitleEdit.Logic.SubtitleFormats;
using Nikse.SubtitleEdit.Logic.VobSub;
using System.Globalization;
namespace Nikse.SubtitleEdit.Forms
{
@ -149,6 +150,9 @@ namespace Nikse.SubtitleEdit.Forms
List<ImageCompareAddition> _lastAdditions = new List<ImageCompareAddition>();
VobSubOcrCharacter _vobSubOcrCharacter = new VobSubOcrCharacter();
List<NOcrChar> _nocrChars = null;
VobSubOcrNOcrCharacter _vobSubOcrNOcrCharacter = new VobSubOcrNOcrCharacter();
Keys _italicShortcut = Utilities.GetKeys(Configuration.Settings.Shortcuts.MainTextBoxItalic);
Keys _mainGeneralGoToNextSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToNextSubtitle);
Keys _mainGeneralGoToPrevSubtitle = Utilities.GetKeys(Configuration.Settings.Shortcuts.GeneralGoToPrevSubtitle);
@ -238,6 +242,7 @@ namespace Nikse.SubtitleEdit.Forms
comboBoxOcrMethod.Items.Add(language.OcrViaTesseract);
comboBoxOcrMethod.Items.Add(language.OcrViaImageCompare);
comboBoxOcrMethod.Items.Add(language.OcrViaModi);
comboBoxOcrMethod.Items.Add(language.OcrViaNOCR);
checkBoxUseModiInTesseractForUnknownWords.Text = language.TryModiForUnknownWords;
checkBoxTesseractItalicsOn.Checked = Configuration.Settings.VobSubOcr.UseItalicsInTesseract;
@ -416,12 +421,7 @@ namespace Nikse.SubtitleEdit.Forms
InitializeTesseract();
LoadImageCompareCharacterDatabaseList();
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
FileName = vobSubFileName;
Text += " - " + Path.GetFileName(FileName);
@ -448,12 +448,7 @@ namespace Nikse.SubtitleEdit.Forms
InitializeTesseract();
LoadImageCompareCharacterDatabaseList();
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
_vobSubMergedPackist = vobSubMergedPackist;
_palette = palette;
@ -585,12 +580,7 @@ namespace Nikse.SubtitleEdit.Forms
InitializeTesseract();
LoadImageCompareCharacterDatabaseList();
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
_bluRaySubtitlesOriginal = subtitles;
@ -1175,6 +1165,134 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private string NOcrFindBestMatch(Bitmap bmp, out bool italic)
{
italic = false;
NikseBitmap nbmp = new NikseBitmap(bmp);
//var nbmp = bmp;
double widthPercent = nbmp.Height * 100.0 / nbmp.Width;
foreach (NOcrChar oc in _nocrChars)
{
if (Math.Abs(oc.Width - widthPercent) < 90)
{
bool ok = true;
foreach (NOcrPoint op in oc.LinesForeground)
{
foreach (Point point in op.GetPoints(nbmp.Width, nbmp.Height))
{
if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(point.X, point.Y);
if (c.A > 150 && c.R > 100 && c.G > 100 && c.B > 100)
{
}
else
{
ok = false;
break;
}
}
}
}
foreach (NOcrPoint op in oc.LinesBackground)
{
foreach (Point point in op.GetPoints(nbmp.Width, nbmp.Height))
{
if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(point.X, point.Y);
if (c.A > 150 && c.R > 100 && c.G > 100 && c.B > 100)
{
ok = false;
break;
}
}
}
}
if (ok)
return oc.Text;
}
}
if (checkBoxNOcrItalic.Checked)
{
var unItalicedBmp = UnItalic(bmp, _unItalicFactor);
int crop;
nbmp = new NikseBitmap(ImageSplitter.CropTopAndBottom(unItalicedBmp, out crop));
unItalicedBmp.Dispose();
//NikseBitmap nbmp = new NikseBitmap(bmp);
// nbmp = unItalicedBmp;
//TODO:SOme cropping!!!!
foreach (NOcrChar oc in _nocrChars)
{
if (Math.Abs(oc.Width - widthPercent) < 99)
{
bool ok = true;
foreach (NOcrPoint op in oc.LinesForeground)
{
foreach (Point point in op.GetPoints(nbmp.Width, nbmp.Height))
{
if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(point.X, point.Y);
if (c.A > 100 && c.R > 90 && c.G > 90 && c.B > 90)
{
}
else
{
ok = false;
break;
}
}
}
}
foreach (NOcrPoint op in oc.LinesBackground)
{
foreach (Point point in op.GetPoints(nbmp.Width, nbmp.Height))
{
if (point.X >= 0 && point.Y >= 0 && point.X < nbmp.Width && point.Y < nbmp.Height)
{
Color c = nbmp.GetPixel(point.X, point.Y);
if (c.A > 140 && c.R > 120 && c.G > 120 && c.B > 120)
{
ok = false;
break;
}
}
}
}
if (ok)
{
italic = true;
return oc.Text;
}
}
}
}
return null;
}
private CompareMatch GetNOcrCompareMatch(ImageSplitterItem targetItem, Bitmap parentBitmap, out CompareMatch secondBestGuess)
{
secondBestGuess = null;
bool italic;
var result = NOcrFindBestMatch(targetItem.Bitmap, out italic);
if (result == null)
{
if (checkBoxNOcrCorrect.Checked)
return null;
else
return new CompareMatch("?", false, 0, null);
}
return new CompareMatch(result, false, 0, null);
}
private CompareMatch GetCompareMatch(ImageSplitterItem targetItem, Bitmap parentBitmap, out CompareMatch secondBestGuess)
{
secondBestGuess = null;
@ -1754,6 +1872,274 @@ namespace Nikse.SubtitleEdit.Forms
return line;
}
private void SaveNOcr(string fileName)
{
try
{
var textWriter = new XmlTextWriter(fileName, null) { Formatting = Formatting.Indented };
textWriter.WriteStartDocument();
textWriter.WriteStartElement("NOCR", "");
textWriter.WriteAttributeString("Language", "en");
foreach (NOcrChar oc in _nocrChars)
{
textWriter.WriteStartElement("Char", "");
textWriter.WriteAttributeString("Text", oc.Text);
textWriter.WriteElementString("Width", oc.Width.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("MaxErrorPercent", oc.MaxErrorPercent.ToString(CultureInfo.InvariantCulture));
foreach (NOcrPoint op in oc.LinesForeground)
{
textWriter.WriteStartElement("PointForeground", "");
textWriter.WriteElementString("Start", op.Start.X.ToString(CultureInfo.InvariantCulture) + "," + op.Start.Y.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("End", op.End.X.ToString(CultureInfo.InvariantCulture) + "," + op.End.Y.ToString(CultureInfo.InvariantCulture));
textWriter.WriteEndElement();
}
foreach (NOcrPoint op in oc.LinesBackground)
{
textWriter.WriteStartElement("PointBackground", "");
textWriter.WriteElementString("Start", op.Start.X.ToString(CultureInfo.InvariantCulture) + "," + op.Start.Y.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("End", op.End.X.ToString(CultureInfo.InvariantCulture) + "," + op.End.Y.ToString(CultureInfo.InvariantCulture));
textWriter.WriteEndElement();
}
textWriter.WriteEndElement();
}
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
private void LoadNOcr(string fileName)
{
if (File.Exists(fileName))
{
try
{
_nocrChars = new List<NOcrChar>();
var doc = new XmlDocument();
doc.Load(fileName);
foreach (XmlNode node in doc.DocumentElement.SelectNodes("Char"))
{
var oc = new NOcrChar(node.Attributes["Text"].Value);
oc.Width = Convert.ToDouble(node.SelectSingleNode("Width").InnerText, CultureInfo.InvariantCulture);
foreach (XmlNode pointNode in node.SelectNodes("PointForeground"))
{
var op = new NOcrPoint();
op.Start = DecodePoint(pointNode.SelectSingleNode("Start").InnerText);
op.End = DecodePoint(pointNode.SelectSingleNode("End").InnerText);
oc.LinesForeground.Add(op);
}
foreach (XmlNode pointNode in node.SelectNodes("PointBackground"))
{
var op = new NOcrPoint();
op.Start = DecodePoint(pointNode.SelectSingleNode("Start").InnerText);
op.End = DecodePoint(pointNode.SelectSingleNode("End").InnerText);
oc.LinesBackground.Add(op);
}
_nocrChars.Add(oc);
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
private PointF DecodePoint(string text)
{
var arr = text.Split(',');
return new PointF((float)(Convert.ToDouble(arr[0], CultureInfo.InvariantCulture)), (float)Convert.ToDouble(Convert.ToDouble(arr[1], CultureInfo.InvariantCulture)));
}
private string OcrViaNOCR(Bitmap bitmap, int listViewIndex)
{
if (_ocrFixEngine == null)
LoadOcrFixEngine();
if (_nocrChars == null)
LoadNOcr(Path.Combine(Configuration.DictionariesFolder, "nOCR_eng.xml"));
var matches = new List<CompareMatch>();
List<ImageSplitterItem> list = ImageSplitter.SplitBitmapToLetters(bitmap, (int)numericUpDownPixelsIsSpace.Value, checkBoxRightToLeft.Checked, Configuration.Settings.VobSubOcr.TopToBottom);
int index = 0;
bool expandSelection = false;
bool shrinkSelection = false;
var expandSelectionList = new List<ImageSplitterItem>();
while (index < list.Count)
{
ImageSplitterItem item = list[index];
if (expandSelection || shrinkSelection)
{
expandSelection = false;
if (shrinkSelection && index > 0)
{
shrinkSelection = false;
}
else if (index + 1 < list.Count && list[index + 1].Bitmap != null) // only allow expand to EndOfLine or space
{
index++;
expandSelectionList.Add(list[index]);
}
item = GetExpandedSelection(bitmap, expandSelectionList);
_vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, expandSelectionList.Count > 1, null, _lastAdditions, this);
DialogResult result = _vobSubOcrNOcrCharacter.ShowDialog(this);
_manualOcrDialogPosition = _vobSubOcrNOcrCharacter.FormPosition;
if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ShrinkSelection)
{
shrinkSelection = true;
index--;
if (expandSelectionList.Count > 0)
expandSelectionList.RemoveAt(expandSelectionList.Count - 1);
}
else if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ExpandSelection)
{
expandSelection = true;
}
else if (result == DialogResult.OK)
{
_nocrChars.Add(_vobSubOcrNOcrCharacter.NOcrChar);
SaveNOcr(Path.Combine(Configuration.DictionariesFolder, "nOCR_eng.xml"));
string text = _vobSubOcrNOcrCharacter.NOcrChar.Text;
string name = SaveCompareItem(item.Bitmap, text, _vobSubOcrNOcrCharacter.IsItalic, expandSelectionList.Count);
var addition = new ImageCompareAddition(name, text, item.Bitmap, _vobSubOcrNOcrCharacter.IsItalic, listViewIndex);
_lastAdditions.Add(addition);
matches.Add(new CompareMatch(text, _vobSubOcrNOcrCharacter.IsItalic, expandSelectionList.Count, null));
expandSelectionList = new List<ImageSplitterItem>();
}
else if (result == DialogResult.Abort)
{
_abort = true;
}
else
{
matches.Add(new CompareMatch("*", false, 0, null));
}
_italicCheckedLast = _vobSubOcrNOcrCharacter.IsItalic;
}
else if (item.Bitmap == null)
{
matches.Add(new CompareMatch(item.SpecialCharacter, false, 0, null));
}
else
{
CompareMatch bestGuess;
CompareMatch match = GetNOcrCompareMatch(item, bitmap, out bestGuess);
if (match == null)
{
_vobSubOcrNOcrCharacter.Initialize(bitmap, item, _manualOcrDialogPosition, false, bestGuess, _lastAdditions, this);
DialogResult result = _vobSubOcrNOcrCharacter.ShowDialog(this);
_manualOcrDialogPosition = _vobSubOcrNOcrCharacter.FormPosition;
if (result == DialogResult.OK && _vobSubOcrNOcrCharacter.ExpandSelection)
{
expandSelectionList.Add(item);
expandSelection = true;
}
else if (result == DialogResult.OK)
{
_nocrChars.Add(_vobSubOcrNOcrCharacter.NOcrChar);
SaveNOcr(Path.Combine(Configuration.DictionariesFolder, "nOCR_eng.xml"));
string text = _vobSubOcrNOcrCharacter.NOcrChar.Text;
string name = SaveCompareItem(item.Bitmap, text, _vobSubOcrNOcrCharacter.IsItalic, 0);
var addition = new ImageCompareAddition(name, text, item.Bitmap, _vobSubOcrNOcrCharacter.IsItalic, listViewIndex);
_lastAdditions.Add(addition);
matches.Add(new CompareMatch(text, _vobSubOcrNOcrCharacter.IsItalic, 0, null));
}
else if (result == DialogResult.Abort)
{
_abort = true;
}
else
{
matches.Add(new CompareMatch("*", false, 0, null));
}
_italicCheckedLast = _vobSubOcrNOcrCharacter.IsItalic;
}
else // found image match
{
matches.Add(new CompareMatch(match.Text, match.Italic, 0, null));
if (match.ExpandCount > 0)
index += match.ExpandCount - 1;
}
}
if (_abort)
return string.Empty;
if (!expandSelection && !shrinkSelection)
index++;
if (shrinkSelection && expandSelectionList.Count < 2)
{
//index--;
shrinkSelection = false;
expandSelectionList = new List<ImageSplitterItem>();
}
}
string line = GetStringWithItalicTags(matches);
if (checkBoxAutoFixCommonErrors.Checked)
line = OcrFixEngine.FixOcrErrorsViaHardcodedRules(line, _lastLine, null); // TODO: add abbreviations list
if (checkBoxRightToLeft.Checked)
line = ReverseNumberStrings(line);
//ocr fix engine
string textWithOutFixes = line;
if (_ocrFixEngine.IsDictionaryLoaded)
{
if (checkBoxAutoFixCommonErrors.Checked)
line = _ocrFixEngine.FixOcrErrors(line, index, _lastLine, true, checkBoxGuessUnknownWords.Checked);
int correctWords;
int wordsNotFound = _ocrFixEngine.CountUnknownWordsViaDictionary(line, out correctWords);
if (wordsNotFound > 0 || correctWords == 0 || textWithOutFixes != null && textWithOutFixes.ToString().Replace("~", string.Empty).Trim().Length == 0)
{
_ocrFixEngine.AutoGuessesUsed.Clear();
_ocrFixEngine.UnknownWordsFound.Clear();
line = _ocrFixEngine.FixUnknownWordsViaGuessOrPrompt(out wordsNotFound, line, listViewIndex, bitmap, checkBoxAutoFixCommonErrors.Checked, checkBoxPromptForUnknownWords.Checked, true, checkBoxGuessUnknownWords.Checked);
}
if (_ocrFixEngine.Abort)
{
ButtonStopClick(null, null);
_ocrFixEngine.Abort = false;
return string.Empty;
}
// Log used word guesses (via word replace list)
foreach (string guess in _ocrFixEngine.AutoGuessesUsed)
listBoxLogSuggestions.Items.Add(guess);
_ocrFixEngine.AutoGuessesUsed.Clear();
// Log unkown words guess (found via spelling dictionaries)
LogUnknownWords();
if (wordsNotFound >= 3)
subtitleListView1.SetBackgroundColor(listViewIndex, Color.Red);
if (wordsNotFound == 2)
subtitleListView1.SetBackgroundColor(listViewIndex, Color.Orange);
else if (wordsNotFound == 1)
subtitleListView1.SetBackgroundColor(listViewIndex, Color.Yellow);
else if (line.Trim().Length == 0)
subtitleListView1.SetBackgroundColor(listViewIndex, Color.Orange);
else
subtitleListView1.SetBackgroundColor(listViewIndex, Color.LightGreen);
}
if (textWithOutFixes.Trim() != line.Trim())
{
_tesseractOcrAutoFixes++;
labelFixesMade.Text = string.Format(" - {0}", _tesseractOcrAutoFixes);
LogOcrFix(listViewIndex, textWithOutFixes.ToString(), line);
}
return line;
}
private string ReverseNumberStrings(string line)
{
Regex regex = new Regex(@"\b\d+\b");
@ -2139,8 +2525,10 @@ namespace Nikse.SubtitleEdit.Forms
text = OcrViaTesseract(GetSubtitleBitmap(i), i);
else if (comboBoxOcrMethod.SelectedIndex == 1)
text = SplitAndOcrBitmapNormal(GetSubtitleBitmap(i), i);
else
else if (comboBoxOcrMethod.SelectedIndex == 2)
text = CallModi(i);
else
text = OcrViaNOCR(GetSubtitleBitmap(i), i);
_lastLine = text;
@ -3342,6 +3730,11 @@ namespace Nikse.SubtitleEdit.Forms
ShowOcrMethodGroupBox(groupBoxModiMethod);
Configuration.Settings.VobSubOcr.LastOcrMethod = "MODI";
}
else if (comboBoxOcrMethod.SelectedIndex == 3)
{
ShowOcrMethodGroupBox(groupBoxNOCR);
Configuration.Settings.VobSubOcr.LastOcrMethod = "nOCR";
}
}
private void ShowOcrMethodGroupBox(GroupBox groupBox)
@ -3349,6 +3742,7 @@ namespace Nikse.SubtitleEdit.Forms
GroupBoxTesseractMethod.Visible = false;
groupBoxImageCompareMethod.Visible = false;
groupBoxModiMethod.Visible = false;
groupBoxNOCR.Visible = false;
groupBox.Visible = true;
groupBox.BringToFront();
@ -3658,12 +4052,7 @@ namespace Nikse.SubtitleEdit.Forms
InitializeTesseract();
LoadImageCompareCharacterDatabaseList();
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
groupBoxImagePalette.Visible = isSon;
@ -3673,6 +4062,18 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxAutoTransparentBackground.Checked = true;
}
private void SetOcrMethod()
{
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "nOCR" && comboBoxOcrMethod.Items.Count > 3)
comboBoxOcrMethod.SelectedIndex = 3;
else
comboBoxOcrMethod.SelectedIndex = 0;
}
internal void StartOcrFromDelayed()
{
if (_lastAdditions.Count > 0)
@ -3893,13 +4294,7 @@ namespace Nikse.SubtitleEdit.Forms
if (_palette == null)
checkBoxCustomFourColors.Checked = true;
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
FileName = fileName;
Text += " - " + Path.GetFileName(FileName);
@ -3964,12 +4359,7 @@ namespace Nikse.SubtitleEdit.Forms
if (_palette == null)
checkBoxCustomFourColors.Checked = true;
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
FileName = fileName;
Text += " - " + Path.GetFileName(FileName);
@ -4010,12 +4400,7 @@ namespace Nikse.SubtitleEdit.Forms
checkBoxAutoTransparentBackground.Enabled = true;
checkBoxAutoTransparentBackground.Enabled = false;
if (Configuration.Settings.VobSubOcr.LastOcrMethod == "BitmapCompare" && comboBoxOcrMethod.Items.Count > 1)
comboBoxOcrMethod.SelectedIndex = 1;
else if (Configuration.Settings.VobSubOcr.LastOcrMethod == "MODI" && comboBoxOcrMethod.Items.Count > 2)
comboBoxOcrMethod.SelectedIndex = 2;
else
comboBoxOcrMethod.SelectedIndex = 0;
SetOcrMethod();
FileName = fileName;
Text += " - " + Path.GetFileName(FileName);

View File

@ -0,0 +1,378 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class VobSubOcrNOcrCharacter
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.buttonShrinkSelection = new System.Windows.Forms.Button();
this.buttonExpandSelection = new System.Windows.Forms.Button();
this.buttonAbort = new System.Windows.Forms.Button();
this.labelCharacters = new System.Windows.Forms.Label();
this.pictureBoxCharacter = new System.Windows.Forms.PictureBox();
this.labelCharactersAsText = new System.Windows.Forms.Label();
this.textBoxCharacters = new System.Windows.Forms.TextBox();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelSubtitleImage = new System.Windows.Forms.Label();
this.pictureBoxSubtitleImage = new System.Windows.Forms.PictureBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonZoomOut = new System.Windows.Forms.Button();
this.buttonZoomIn = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.radioButtonCold = new System.Windows.Forms.RadioButton();
this.radioButtonHot = new System.Windows.Forms.RadioButton();
this.label2 = new System.Windows.Forms.Label();
this.listBoxlinesBackground = new System.Windows.Forms.ListBox();
this.labelLines = new System.Windows.Forms.Label();
this.listBoxLinesForeground = new System.Windows.Forms.ListBox();
this.contextMenuStripLinesBackground = new System.Windows.Forms.ContextMenuStrip(this.components);
this.removeBackToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuLinesForeground = new System.Windows.Forms.ContextMenuStrip(this.components);
this.removeForegroundToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCharacter)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSubtitleImage)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.contextMenuStripLinesBackground.SuspendLayout();
this.contextMenuLinesForeground.SuspendLayout();
this.SuspendLayout();
//
// buttonShrinkSelection
//
this.buttonShrinkSelection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonShrinkSelection.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonShrinkSelection.Location = new System.Drawing.Point(385, 9);
this.buttonShrinkSelection.Name = "buttonShrinkSelection";
this.buttonShrinkSelection.Size = new System.Drawing.Size(112, 21);
this.buttonShrinkSelection.TabIndex = 32;
this.buttonShrinkSelection.Text = "Shrink selection";
this.buttonShrinkSelection.UseVisualStyleBackColor = true;
this.buttonShrinkSelection.Click += new System.EventHandler(this.buttonShrinkSelection_Click);
//
// buttonExpandSelection
//
this.buttonExpandSelection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonExpandSelection.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonExpandSelection.Location = new System.Drawing.Point(503, 9);
this.buttonExpandSelection.Name = "buttonExpandSelection";
this.buttonExpandSelection.Size = new System.Drawing.Size(112, 21);
this.buttonExpandSelection.TabIndex = 31;
this.buttonExpandSelection.Text = "Expand selection";
this.buttonExpandSelection.UseVisualStyleBackColor = true;
this.buttonExpandSelection.Click += new System.EventHandler(this.buttonExpandSelection_Click);
//
// buttonAbort
//
this.buttonAbort.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
this.buttonAbort.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonAbort.Location = new System.Drawing.Point(541, 523);
this.buttonAbort.Name = "buttonAbort";
this.buttonAbort.Size = new System.Drawing.Size(75, 21);
this.buttonAbort.TabIndex = 25;
this.buttonAbort.Text = "&Abort";
this.buttonAbort.UseVisualStyleBackColor = true;
//
// labelCharacters
//
this.labelCharacters.AutoSize = true;
this.labelCharacters.Location = new System.Drawing.Point(185, 38);
this.labelCharacters.Name = "labelCharacters";
this.labelCharacters.Size = new System.Drawing.Size(64, 13);
this.labelCharacters.TabIndex = 30;
this.labelCharacters.Text = "Character(s)";
//
// pictureBoxCharacter
//
this.pictureBoxCharacter.Location = new System.Drawing.Point(183, 59);
this.pictureBoxCharacter.Name = "pictureBoxCharacter";
this.pictureBoxCharacter.Size = new System.Drawing.Size(99, 47);
this.pictureBoxCharacter.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCharacter.TabIndex = 29;
this.pictureBoxCharacter.TabStop = false;
this.pictureBoxCharacter.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxCharacter_Paint);
this.pictureBoxCharacter.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBoxCharacter_MouseClick);
this.pictureBoxCharacter.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBoxCharacter_MouseMove);
//
// labelCharactersAsText
//
this.labelCharactersAsText.AutoSize = true;
this.labelCharactersAsText.Location = new System.Drawing.Point(9, 89);
this.labelCharactersAsText.Name = "labelCharactersAsText";
this.labelCharactersAsText.Size = new System.Drawing.Size(98, 13);
this.labelCharactersAsText.TabIndex = 28;
this.labelCharactersAsText.Text = "Character(s) as text";
//
// textBoxCharacters
//
this.textBoxCharacters.Location = new System.Drawing.Point(12, 110);
this.textBoxCharacters.Name = "textBoxCharacters";
this.textBoxCharacters.Size = new System.Drawing.Size(107, 20);
this.textBoxCharacters.TabIndex = 22;
//
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(379, 523);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 21);
this.buttonOK.TabIndex = 23;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(460, 523);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 21);
this.buttonCancel.TabIndex = 24;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// labelSubtitleImage
//
this.labelSubtitleImage.AutoSize = true;
this.labelSubtitleImage.Location = new System.Drawing.Point(33, 15);
this.labelSubtitleImage.Name = "labelSubtitleImage";
this.labelSubtitleImage.Size = new System.Drawing.Size(73, 13);
this.labelSubtitleImage.TabIndex = 27;
this.labelSubtitleImage.Text = "Subtitle image";
//
// pictureBoxSubtitleImage
//
this.pictureBoxSubtitleImage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBoxSubtitleImage.Location = new System.Drawing.Point(36, 36);
this.pictureBoxSubtitleImage.Name = "pictureBoxSubtitleImage";
this.pictureBoxSubtitleImage.Size = new System.Drawing.Size(580, 205);
this.pictureBoxSubtitleImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBoxSubtitleImage.TabIndex = 26;
this.pictureBoxSubtitleImage.TabStop = false;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonZoomOut);
this.groupBox1.Controls.Add(this.buttonZoomIn);
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.listBoxlinesBackground);
this.groupBox1.Controls.Add(this.labelLines);
this.groupBox1.Controls.Add(this.labelCharacters);
this.groupBox1.Controls.Add(this.pictureBoxCharacter);
this.groupBox1.Controls.Add(this.listBoxLinesForeground);
this.groupBox1.Controls.Add(this.labelCharactersAsText);
this.groupBox1.Controls.Add(this.textBoxCharacters);
this.groupBox1.Location = new System.Drawing.Point(36, 247);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(579, 270);
this.groupBox1.TabIndex = 33;
this.groupBox1.TabStop = false;
//
// buttonZoomOut
//
this.buttonZoomOut.Location = new System.Drawing.Point(255, 27);
this.buttonZoomOut.Name = "buttonZoomOut";
this.buttonZoomOut.Size = new System.Drawing.Size(25, 23);
this.buttonZoomOut.TabIndex = 32;
this.buttonZoomOut.Text = "-";
this.buttonZoomOut.UseVisualStyleBackColor = true;
this.buttonZoomOut.Click += new System.EventHandler(this.buttonZoomOut_Click);
//
// buttonZoomIn
//
this.buttonZoomIn.Location = new System.Drawing.Point(286, 27);
this.buttonZoomIn.Name = "buttonZoomIn";
this.buttonZoomIn.Size = new System.Drawing.Size(25, 23);
this.buttonZoomIn.TabIndex = 31;
this.buttonZoomIn.Text = "+";
this.buttonZoomIn.UseVisualStyleBackColor = true;
this.buttonZoomIn.Click += new System.EventHandler(this.buttonZoomIn_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.radioButtonCold);
this.groupBox2.Controls.Add(this.radioButtonHot);
this.groupBox2.Location = new System.Drawing.Point(6, 19);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(157, 61);
this.groupBox2.TabIndex = 21;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "New lines are";
//
// radioButtonCold
//
this.radioButtonCold.AutoSize = true;
this.radioButtonCold.Location = new System.Drawing.Point(6, 40);
this.radioButtonCold.Name = "radioButtonCold";
this.radioButtonCold.Size = new System.Drawing.Size(102, 17);
this.radioButtonCold.TabIndex = 1;
this.radioButtonCold.Text = "NOT foreground";
this.radioButtonCold.UseVisualStyleBackColor = true;
//
// radioButtonHot
//
this.radioButtonHot.AutoSize = true;
this.radioButtonHot.Checked = true;
this.radioButtonHot.Location = new System.Drawing.Point(6, 17);
this.radioButtonHot.Name = "radioButtonHot";
this.radioButtonHot.Size = new System.Drawing.Size(79, 17);
this.radioButtonHot.TabIndex = 0;
this.radioButtonHot.TabStop = true;
this.radioButtonHot.Text = "Foreground";
this.radioButtonHot.UseVisualStyleBackColor = true;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(410, 146);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(110, 13);
this.label2.TabIndex = 20;
this.label2.Text = "Lines - not foreground";
//
// listBoxlinesBackground
//
this.listBoxlinesBackground.ContextMenuStrip = this.contextMenuStripLinesBackground;
this.listBoxlinesBackground.FormattingEnabled = true;
this.listBoxlinesBackground.Location = new System.Drawing.Point(410, 162);
this.listBoxlinesBackground.Name = "listBoxlinesBackground";
this.listBoxlinesBackground.Size = new System.Drawing.Size(160, 95);
this.listBoxlinesBackground.TabIndex = 19;
//
// labelLines
//
this.labelLines.AutoSize = true;
this.labelLines.Location = new System.Drawing.Point(407, 19);
this.labelLines.Name = "labelLines";
this.labelLines.Size = new System.Drawing.Size(92, 13);
this.labelLines.TabIndex = 18;
this.labelLines.Text = "Lines - foreground";
//
// listBoxLinesForeground
//
this.listBoxLinesForeground.ContextMenuStrip = this.contextMenuLinesForeground;
this.listBoxLinesForeground.FormattingEnabled = true;
this.listBoxLinesForeground.Location = new System.Drawing.Point(410, 35);
this.listBoxLinesForeground.Name = "listBoxLinesForeground";
this.listBoxLinesForeground.Size = new System.Drawing.Size(160, 95);
this.listBoxLinesForeground.TabIndex = 17;
//
// contextMenuStripLinesBackground
//
this.contextMenuStripLinesBackground.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.removeBackToolStripMenuItem});
this.contextMenuStripLinesBackground.Name = "contextMenuStripLines";
this.contextMenuStripLinesBackground.Size = new System.Drawing.Size(118, 26);
//
// removeBackToolStripMenuItem
//
this.removeBackToolStripMenuItem.Name = "removeBackToolStripMenuItem";
this.removeBackToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.removeBackToolStripMenuItem.Text = "Remove";
this.removeBackToolStripMenuItem.Click += new System.EventHandler(this.removeForegroundToolStripMenuItem_Click);
//
// contextMenuLinesForeground
//
this.contextMenuLinesForeground.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.removeForegroundToolStripMenuItem});
this.contextMenuLinesForeground.Name = "contextMenuStripLines";
this.contextMenuLinesForeground.Size = new System.Drawing.Size(153, 48);
//
// removeForegroundToolStripMenuItem
//
this.removeForegroundToolStripMenuItem.Name = "removeForegroundToolStripMenuItem";
this.removeForegroundToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.removeForegroundToolStripMenuItem.Text = "Remove";
this.removeForegroundToolStripMenuItem.Click += new System.EventHandler(this.removeForegroundToolStripMenuItem_Click_1);
//
// VobSubOcrNOcrCharacter
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(648, 552);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.buttonShrinkSelection);
this.Controls.Add(this.buttonExpandSelection);
this.Controls.Add(this.buttonAbort);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.labelSubtitleImage);
this.Controls.Add(this.pictureBoxSubtitleImage);
this.KeyPreview = true;
this.Name = "VobSubOcrNOcrCharacter";
this.Text = "VobSubOcrNOcrCharacter";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.VobSubOcrNOcrCharacter_KeyDown);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCharacter)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSubtitleImage)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.contextMenuStripLinesBackground.ResumeLayout(false);
this.contextMenuLinesForeground.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonShrinkSelection;
private System.Windows.Forms.Button buttonExpandSelection;
private System.Windows.Forms.Button buttonAbort;
private System.Windows.Forms.Label labelCharacters;
private System.Windows.Forms.PictureBox pictureBoxCharacter;
private System.Windows.Forms.Label labelCharactersAsText;
private System.Windows.Forms.TextBox textBoxCharacters;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.Label labelSubtitleImage;
private System.Windows.Forms.PictureBox pictureBoxSubtitleImage;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button buttonZoomOut;
private System.Windows.Forms.Button buttonZoomIn;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton radioButtonCold;
private System.Windows.Forms.RadioButton radioButtonHot;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox listBoxlinesBackground;
private System.Windows.Forms.Label labelLines;
private System.Windows.Forms.ListBox listBoxLinesForeground;
private System.Windows.Forms.ContextMenuStrip contextMenuStripLinesBackground;
private System.Windows.Forms.ToolStripMenuItem removeBackToolStripMenuItem;
private System.Windows.Forms.ContextMenuStrip contextMenuLinesForeground;
private System.Windows.Forms.ToolStripMenuItem removeForegroundToolStripMenuItem;
}
}

View File

@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.OCR;
namespace Nikse.SubtitleEdit.Forms
{
public partial class VobSubOcrNOcrCharacter : Form
{
VobSubOcr _vobSubForm;
List<VobSubOcr.ImageCompareAddition> _additions;
NOcrChar _nocrChar = null;
bool _drawLineOn;
bool _startDone;
Point _start;
Point _end;
double _zoomFactor = 1.0;
int _imageWidth;
int _imageHeight;
int _mx;
int _my;
public VobSubOcrNOcrCharacter()
{
InitializeComponent();
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);
}
}
public NOcrChar NOcrChar
{
get
{
return _nocrChar;
}
}
public Point FormPosition
{
get
{
return new Point(Left, Top);
}
}
public bool ExpandSelection { get; private set; }
public bool ShrinkSelection { get; private set; }
internal void Initialize(Bitmap vobSubImage, ImageSplitterItem character, Point position, bool showShrink, VobSubOcr.CompareMatch bestGuess, List<VobSubOcr.ImageCompareAddition> additions, VobSubOcr vobSubForm)
{
radioButtonHot.Checked = true;
ShrinkSelection = false;
ExpandSelection = false;
textBoxCharacters.Text = string.Empty;
_vobSubForm = vobSubForm;
_additions = additions;
_nocrChar = new NOcrChar();
_imageWidth = character.Bitmap.Width;
_imageHeight = character.Bitmap.Height;
buttonShrinkSelection.Visible = showShrink;
if (position.X != -1 && position.Y != -1)
{
StartPosition = FormStartPosition.Manual;
Left = position.X;
Top = position.Y;
}
pictureBoxSubtitleImage.Image = vobSubImage;
pictureBoxCharacter.Image = character.Bitmap;
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;
pictureBoxCharacter.Top = labelCharacters.Top + 16;
SizePictureBox();
}
private void buttonExpandSelection_Click(object sender, EventArgs e)
{
ExpandSelection = true;
DialogResult = DialogResult.OK;
}
private void buttonShrinkSelection_Click(object sender, EventArgs e)
{
ShrinkSelection = true;
DialogResult = DialogResult.OK;
}
private void buttonOK_Click(object sender, EventArgs e)
{
if (textBoxCharacters.Text.Length == 0)
{
MessageBox.Show("Text is empty!");
return;
}
_nocrChar.Text = textBoxCharacters.Text;
DialogResult = DialogResult.OK;
}
public bool IsItalic { get; set; }
private void pictureBoxCharacter_Paint(object sender, PaintEventArgs e)
{
var foreground = new Pen(new SolidBrush(Color.Green));
var background = new Pen(new SolidBrush(Color.Red));
if (pictureBoxCharacter.Image != null)
{
foreach (NOcrPoint op in _nocrChar.LinesForeground)
{
e.Graphics.DrawLine(foreground, op.GetStart(pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetEnd(pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
foreach (NOcrPoint op in _nocrChar.LinesBackground)
{
e.Graphics.DrawLine(background, op.GetStart(pictureBoxCharacter.Width, pictureBoxCharacter.Height), op.GetEnd(pictureBoxCharacter.Width, pictureBoxCharacter.Height));
}
}
if (_drawLineOn)
{
if (_startDone)
{
var p = foreground;
if (radioButtonCold.Checked)
p = background;
e.Graphics.DrawLine(p, new Point((int)Math.Round(_start.X * _zoomFactor), (int)Math.Round(_start.Y * _zoomFactor)), new Point(_mx, _my));
}
}
}
private void SizePictureBox()
{
pictureBoxCharacter.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBoxCharacter.Width = (int)Math.Round(_imageWidth * _zoomFactor);
pictureBoxCharacter.Height = (int)Math.Round(_imageHeight * _zoomFactor);
pictureBoxCharacter.Invalidate();
}
private void buttonZoomIn_Click(object sender, EventArgs e)
{
if (_zoomFactor < 10)
{
_zoomFactor++;
SizePictureBox();
}
}
private void buttonZoomOut_Click(object sender, EventArgs e)
{
if (_zoomFactor > 1)
{
_zoomFactor--;
SizePictureBox();
}
}
private void ShowOcrPoints()
{
listBoxLinesForeground.Items.Clear();
foreach (NOcrPoint op in _nocrChar.LinesForeground)
{
listBoxLinesForeground.Items.Add(op);
}
listBoxlinesBackground.Items.Clear();
foreach (NOcrPoint op in _nocrChar.LinesBackground)
{
listBoxlinesBackground.Items.Add(op);
}
pictureBoxCharacter.Invalidate();
}
private void pictureBoxCharacter_MouseClick(object sender, MouseEventArgs e)
{
if (_drawLineOn)
{
if (_startDone)
{
_end = new Point((int)Math.Round(e.Location.X / _zoomFactor), (int)Math.Round(e.Location.Y / _zoomFactor));
_nocrChar.Width = pictureBoxCharacter.Image.Height * 100.0 / pictureBoxCharacter.Image.Width;
if (radioButtonHot.Checked)
_nocrChar.LinesForeground.Add(new NOcrPoint(_start, _end, _imageWidth, _imageHeight));
else
_nocrChar.LinesBackground.Add(new NOcrPoint(_start, _end, _imageWidth, _imageHeight));
_drawLineOn = false;
pictureBoxCharacter.Invalidate();
ShowOcrPoints();
}
else
{
_start = new Point((int)Math.Round(e.Location.X / _zoomFactor), (int)Math.Round(e.Location.Y / _zoomFactor));
_startDone = true;
pictureBoxCharacter.Invalidate();
}
}
else
{
_startDone = false;
_drawLineOn = true;
_start = new Point((int)Math.Round(e.Location.X / _zoomFactor), (int)Math.Round(e.Location.Y / _zoomFactor));
_startDone = true;
pictureBoxCharacter.Invalidate();
}
}
private void pictureBoxCharacter_MouseMove(object sender, MouseEventArgs e)
{
if (_drawLineOn)
{
_mx = e.X;
_my = e.Y;
pictureBoxCharacter.Invalidate();
}
}
private void VobSubOcrNOcrCharacter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
_drawLineOn = false;
_startDone = false;
pictureBoxCharacter.Invalidate();
}
}
private void removeForegroundToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listBoxlinesBackground.SelectedItems.Count == 1)
{
var op = listBoxlinesBackground.Items[listBoxlinesBackground.SelectedIndex] as NOcrPoint;
_nocrChar.LinesBackground.Remove(op);
}
ShowOcrPoints();
}
private void removeForegroundToolStripMenuItem_Click_1(object sender, EventArgs e)
{
if (listBoxLinesForeground.SelectedItems.Count == 1)
{
var op = listBoxLinesForeground.Items[listBoxLinesForeground.SelectedIndex] as NOcrPoint;
_nocrChar.LinesForeground.Remove(op);
}
ShowOcrPoints();
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStripLinesBackground.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>733, 17</value>
</metadata>
<metadata name="contextMenuLinesForeground.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>975, 17</value>
</metadata>
</root>

View File

@ -1924,6 +1924,7 @@ Keep changes?",
UnknownWords = "Unknown words",
OcrAutoCorrectionSpellchecking = "OCR auto correction / spellchecking",
OcrViaTesseract = "OCR via Tesseract",
OcrViaNOCR = "OCR via nOCR",
FixOcrErrors = "Fix OCR errors",
ImportTextWithMatchingTimeCodes = "Import text with matching time codes...",
SaveSubtitleImageAs = "Save subtitle image as...",

View File

@ -1803,6 +1803,7 @@
public string OcrMethod { get; set; }
public string OcrViaModi { get; set; }
public string OcrViaTesseract { get; set; }
public string OcrViaNOCR { get; set; }
public string Language { get; set; }
public string OcrViaImageCompare { get; set; }
public string ImageDatabase { get; set; }

34
src/Logic/OCR/NOcrChar.cs Normal file
View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Logic.OCR
{
public class NOcrChar
{
public string Text { get; set; }
public Double Width { get; set; }
public Double MaxErrorPercent { get; set; }
public List<NOcrPoint> LinesForeground { get; private set; }
public List<NOcrPoint> LinesBackground { get; private set; }
public string Id { get; set; }
public NOcrChar()
{
Id = Guid.NewGuid().ToString();
LinesForeground = new List<NOcrPoint>();
LinesBackground = new List<NOcrPoint>();
Text = string.Empty;
MaxErrorPercent = 0;
}
public NOcrChar(string text) : this()
{
Text = text;
}
public override string ToString()
{
return Text;
}
}
}

View File

@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
namespace Nikse.SubtitleEdit.Logic.OCR
{
public class NOcrPoint
{
public PointF Start { get; set; }
public PointF End { get; set; }
public string Id { get; set; }
public NOcrPoint()
{
Id = Guid.NewGuid().ToString();
Start = new Point();
End = new Point();
}
public NOcrPoint(Point start, Point end, int pixelWidth, int pixelHeight) : this()
{
Start = PointPixelsToPercent(start, pixelWidth, pixelHeight);
End = PointPixelsToPercent(end, pixelWidth, pixelHeight);
}
public PointF PointPixelsToPercent(Point p, int pixelWidth, int pixelHeight)
{
return new PointF((float)(p.X * 100.0 / pixelWidth), (float)(p.Y * 100.0 / pixelHeight));
}
public Point PointPercentToPixels(PointF p, int pixelWidth, int pixelHeight)
{
return new Point((int)Math.Round(p.X / 100.0 * pixelWidth), (int)Math.Round(p.Y / 100.0 * pixelHeight));
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0:0.#},{1:0.#} -> {2:0.#},{3:0.#} ", Start.X, Start.Y, End.X, End.Y);
}
public Point GetStart(int width, int height)
{
return PointPercentToPixels(Start, width, height);
}
public Point GetEnd(int width, int height)
{
return PointPercentToPixels(End, width, height);
}
public List<Point> GetPoints(int width, int height)
{
return GetPoints(GetStart(width, height), GetEnd(width, height));
}
public static List<Point> GetPoints(Point start, Point end)
{
var list = new List<Point>();
int x1 = start.X;
int x2 = end.X;
int y1 = start.Y;
int y2 = end.Y;
if (Math.Abs(start.X - end.X) > Math.Abs(start.Y - end.Y))
{
if (x1 > x2)
{
x2 = start.X;
x1 = end.X;
y2 = start.Y;
y1 = end.Y;
}
double factor = (double) (y2-y1) /(x2-x1);
for (int i=x1; i<=x2; i++)
list.Add(new Point(i, (int)Math.Round(y1 + factor * (i-x1))));
}
else
{
if (y1 > y2)
{
x2 = start.X;
x1 = end.X;
y2 = start.Y;
y1 = end.Y;
}
double factor = (double) (x2 - x1) / (y2 - y1);
for (int i = y1; i <= y2; i++)
list.Add(new Point((int)Math.Round(x1 + factor * (i-y1)), i));
}
return list;
}
}
}

View File

@ -215,12 +215,12 @@ namespace Nikse.SubtitleEdit.Logic
{
if (smpte)
{
CurrentDCinemaSubtitleId = "urn:uuid:40950d85-63eb-4ee2-b1e8-45c126601b94";
CurrentDCinemaSubtitleId = "urn:uuid:" + Guid.NewGuid().ToString();
CurrentDCinemaLanguage = "en";
}
else
{
CurrentDCinemaSubtitleId = "40950d85-63eb-4ee2-b1e8-45c126601b94";
CurrentDCinemaSubtitleId = Guid.NewGuid().ToString();
CurrentDCinemaLanguage = "English";
}
CurrentDCinemaIssueDate = DateTime.Now.ToString("s") + ".000-00:00";

View File

@ -68,6 +68,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
bool expectStartTime = true;
var p = new Paragraph();
subtitle.Paragraphs.Clear();
foreach (string line in lines)
@ -81,10 +82,17 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
try
{
if (p.StartTime.TotalMilliseconds == 0)
if (expectStartTime)
{
p.StartTime = DecodeTimeCode(parts);
expectStartTime = false;
}
else
{
if (p.EndTime.TotalMilliseconds < 0.01)
_errorCount++;
p.EndTime = DecodeTimeCode(parts);
}
}
catch (Exception exception)
{
@ -97,15 +105,16 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
if (p != null)
{
if (p.StartTime.TotalMilliseconds > 0 && p.EndTime.TotalMilliseconds > 0)
subtitle.Paragraphs.Add(p);
if (p.StartTime.TotalMilliseconds == 0 && p.EndTime.TotalMilliseconds == 0)
_errorCount++;
else
_errorCount++;
subtitle.Paragraphs.Add(p);
p = new Paragraph();
}
}
else if (line.Trim().Length > 0 && p != null)
{
expectStartTime = true;
p.Text = (p.Text + Environment.NewLine + line).Trim();
if (p.Text.Length > 500)
{

View File

@ -160,6 +160,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
new UnknownSubtitle46(),
new UnknownSubtitle47(),
new UnknownSubtitle48(),
new UnknownSubtitle49(),
};
}
}

View File

@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
{
public class UnknownSubtitle49 : SubtitleFormat
{
static readonly Regex RegexTimeCode = new Regex(@"^\d\d \d\d \d\d \d\d $", RegexOptions.Compiled);
static readonly Regex RegexTimeCode2 = new Regex(@"^\d\d \d\d \d\d \d\d$", RegexOptions.Compiled);
enum ExpectingLine
{
TimeStart,
TimeEnd,
Text
}
public override string Extension
{
get { return ".txt"; }
}
public override string Name
{
get { return "Unknown 49"; }
}
public override bool IsTimeBased
{
get { return true; }
}
public override bool IsMine(List<string> lines, string fileName)
{
var subtitle = new Subtitle();
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
public override string ToText(Subtitle subtitle, string title)
{
//10 04 36 02
//10 04 37 04
//
//Greetings.
//10 04 37 06
//10 04 40 08
//It's confirmed, after reading
//Not Out on the poster..
//10 04 40 15
//10 04 44 06
//..you have not come to pass you
//time, in this unique story.
const string paragraphWriteFormat = "{0}{3}{1}{3}{2}";
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
{
string text = Utilities.RemoveHtmlFontTag(p.Text);
if (!text.Contains(Environment.NewLine))
text = Environment.NewLine + text;
sb.AppendLine(string.Format(paragraphWriteFormat, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), text, Environment.NewLine));
}
return sb.ToString().Trim();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
Paragraph paragraph = null;
ExpectingLine expecting = ExpectingLine.TimeStart;
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
if (paragraph == null && expecting == ExpectingLine.TimeStart && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line)))
{
paragraph = new Paragraph();
}
else if (paragraph != null && expecting == ExpectingLine.Text && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line)))
{
if (string.IsNullOrEmpty(paragraph.Text))
_errorCount ++;
if (paragraph.StartTime.TotalMilliseconds < 0.1)
_errorCount++;
subtitle.Paragraphs.Add(paragraph);
paragraph = new Paragraph();
expecting = ExpectingLine.TimeStart;
}
if (paragraph != null && expecting == ExpectingLine.TimeStart && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line)))
{
string[] parts = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 4)
{
try
{
var tc = DecodeTimeCode(parts);
paragraph.StartTime = tc;
expecting = ExpectingLine.TimeEnd;
}
catch
{
_errorCount++;
expecting = ExpectingLine.TimeStart;
}
}
}
else if (paragraph != null && expecting == ExpectingLine.TimeEnd && (RegexTimeCode.IsMatch(line) || RegexTimeCode2.IsMatch(line)))
{
string[] parts = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 4)
{
try
{
var tc = DecodeTimeCode(parts);
paragraph.EndTime = tc;
expecting = ExpectingLine.Text;
}
catch
{
_errorCount++;
expecting = ExpectingLine.TimeStart;
}
}
}
else
{
if (paragraph != null && expecting == ExpectingLine.Text)
{
if (line.Length > 0)
{
string s = line;
paragraph.Text = (paragraph.Text + Environment.NewLine + s).Trim();
if (paragraph.Text.Length > 2000)
{
_errorCount += 100;
return;
}
}
}
}
}
if (paragraph != null && !string.IsNullOrEmpty(paragraph.Text))
subtitle.Paragraphs.Add(paragraph);
subtitle.Renumber(1);
}
private string EncodeTimeCode(TimeCode time)
{
return string.Format("{0:00} {1:00} {2:00} {3:00} ", time.Hours, time.Minutes, time.Seconds, MillisecondsToFramesMaxFrameRate(time.Milliseconds));
}
private TimeCode DecodeTimeCode(string[] parts)
{
string hour = parts[0];
string minutes = parts[1];
string seconds = parts[2];
string frames = parts[3];
return new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), FramesToMillisecondsMax999(int.Parse(frames)));
}
}
}

View File

@ -614,6 +614,12 @@
<Compile Include="Forms\VobSubOcrNewFolder.Designer.cs">
<DependentUpon>VobSubOcrNewFolder.cs</DependentUpon>
</Compile>
<Compile Include="Forms\VobSubOcrNOcrCharacter.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\VobSubOcrNOcrCharacter.Designer.cs">
<DependentUpon>VobSubOcrNOcrCharacter.cs</DependentUpon>
</Compile>
<Compile Include="Forms\VobSubOcrSetItalicFactor.cs">
<SubType>Form</SubType>
</Compile>
@ -731,9 +737,11 @@
<Compile Include="Logic\NikseBitmap.cs" />
<Compile Include="Logic\OCR\ModiLanguage.cs" />
<Compile Include="Logic\OCR\OcrAlphabet.cs" />
<Compile Include="Logic\OCR\NOcrChar.cs" />
<Compile Include="Logic\OCR\OcrCharacter.cs" />
<Compile Include="Logic\OCR\OcrFixEngine.cs" />
<Compile Include="Logic\OCR\OcrImage.cs" />
<Compile Include="Logic\OCR\NOcrPoint.cs" />
<Compile Include="Logic\OCR\SpellcheckOcrTextResult.cs" />
<Compile Include="Logic\PositionAndSize.cs" />
<Compile Include="Logic\PositionsAndSizes.cs" />
@ -874,6 +882,7 @@
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle46.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle47.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle48.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle49.cs" />
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
@ -1236,6 +1245,9 @@
<DependentUpon>VobSubOcrNewFolder.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\VobSubOcrNOcrCharacter.resx">
<DependentUpon>VobSubOcrNOcrCharacter.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\VobSubOcrSetItalicFactor.resx">
<DependentUpon>VobSubOcrSetItalicFactor.cs</DependentUpon>
</EmbeddedResource>

View File

@ -338,5 +338,28 @@ namespace Test
}
#endregion
#region Fix missingspaces
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingSpacesItalicBegin()
{
var target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "The<i>Bombshell</i> will gone.");
target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void FixMissingSpacesItalicEnd()
{
var target = new FixCommonErrors_Accessor();
InitializeFixCommonErrorsLine(target, "The<i>Bombshell</i> will gone.");
target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
}
#endregion
}
}