diff --git a/src/Forms/VobSubNOcrEdit.cs b/src/Forms/VobSubNOcrEdit.cs index 504f84cb8..672ecb7dc 100644 --- a/src/Forms/VobSubNOcrEdit.cs +++ b/src/Forms/VobSubNOcrEdit.cs @@ -1,9 +1,9 @@ -using System; +using Nikse.SubtitleEdit.Logic; +using Nikse.SubtitleEdit.Logic.OCR; +using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; -using Nikse.SubtitleEdit.Logic; -using Nikse.SubtitleEdit.Logic.OCR; namespace Nikse.SubtitleEdit.Forms { @@ -11,7 +11,7 @@ namespace Nikse.SubtitleEdit.Forms { private List _nocrChars; - private NOcrChar _nocrChar = null; + private NOcrChar _nocrChar; private double _zoomFactor = 5.0; bool _drawLineOn; bool _startDone; @@ -127,7 +127,6 @@ namespace Nikse.SubtitleEdit.Forms private bool IsMatch() { NikseBitmap nbmp = new NikseBitmap(pictureBoxCharacter.Image as Bitmap); - var bmp = pictureBoxCharacter.Image as Bitmap; foreach (NOcrPoint op in _nocrChar.LinesForeground) { foreach (Point point in op.ScaledGetPoints(_nocrChar, nbmp.Width, nbmp.Height)) @@ -453,13 +452,14 @@ namespace Nikse.SubtitleEdit.Forms { int importedCount = 0; int notImportedCount = 0; - openFileDialog1.Filter = "nOCR files|nOCR_*.xml"; + openFileDialog1.Filter = "nOCR files|*.nocr"; openFileDialog1.InitialDirectory = Configuration.DataDirectory; openFileDialog1.FileName = string.Empty; openFileDialog1.Title = "Import existing nOCR database into current"; if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { - foreach (NOcrChar newChar in VobSubOcr.LoadNOcr(openFileDialog1.FileName)) + NOcrDb newDb = new NOcrDb(openFileDialog1.FileName); + foreach (NOcrChar newChar in newDb.OcrCharacters) { bool found = false; foreach (NOcrChar oldChar in _nocrChars) diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index 2ebca4109..4dcca3725 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -4191,45 +4191,6 @@ namespace Nikse.SubtitleEdit.Forms } } - public static List LoadNOcr(string fileName) - { - var nocrChars = new List(); - if (File.Exists(fileName)) - { - try - { - 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.ToInt32(node.Attributes["Width"].Value, CultureInfo.InvariantCulture); - oc.Height = Convert.ToInt32(node.Attributes["Height"].Value, CultureInfo.InvariantCulture); - oc.MarginTop = Convert.ToInt32(node.Attributes["MarginTop"].Value, CultureInfo.InvariantCulture); - if (node.Attributes["Italic"] != null) - oc.Italic = Convert.ToBoolean(node.Attributes["Italic"].Value, CultureInfo.InvariantCulture); - if (node.Attributes["ExpandCount"] != null) - oc.ExpandCount = Convert.ToInt32(node.Attributes["ExpandCount"].Value, CultureInfo.InvariantCulture); - foreach (XmlNode pointNode in node.SelectNodes("Point")) - { - var op = new NOcrPoint(DecodePoint(pointNode.Attributes["Start"].Value), DecodePoint(pointNode.Attributes["End"].Value)); - XmlAttribute a = pointNode.Attributes["On"]; - if (a != null && Convert.ToBoolean(a.Value)) - oc.LinesForeground.Add(op); - else - oc.LinesBackground.Add(op); - } - nocrChars.Add(oc); - } - } - catch (Exception exception) - { - MessageBox.Show(exception.Message); - } - } - return nocrChars; - } - public static List LoadNOcrForTesseract(string xmlRessourceName) { var nocrChars = new List(); @@ -5683,7 +5644,7 @@ namespace Nikse.SubtitleEdit.Forms string fileName = GetNOcrLanguageFileName(); if (!string.IsNullOrEmpty(fileName)) { - LoadNOcr(fileName); + _nOcrDb = new NOcrDb(fileName); } }