コード例 #1
0
ファイル: VobSubOcr.cs プロジェクト: mgziminsky/subtitleedit
        private void LoadOcrFixEngine(string threeLetterISOLanguageName, string hunspellName)
        {
            if (string.IsNullOrEmpty(threeLetterISOLanguageName) && comboBoxTesseractLanguages.SelectedItem != null)
            {
                _languageId = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Id;
                threeLetterISOLanguageName = _languageId;
            }

            if (_ocrFixEngine != null)
                _ocrFixEngine.Dispose();
            _ocrFixEngine = new OcrFixEngine(threeLetterISOLanguageName, hunspellName, this);
            if (_ocrFixEngine.IsDictionaryLoaded)
            {
                string loadedDictionaryName = _ocrFixEngine.SpellCheckDictionaryName;
                int i = 0;
                comboBoxDictionaries.SelectedIndexChanged -= comboBoxDictionaries_SelectedIndexChanged;
                foreach (string item in comboBoxDictionaries.Items)
                {
                    if (item.Contains("[" + loadedDictionaryName + "]"))
                        comboBoxDictionaries.SelectedIndex = i;
                    i++;
                }
                comboBoxDictionaries.SelectedIndexChanged += comboBoxDictionaries_SelectedIndexChanged;
                comboBoxDictionaries.Left = labelDictionaryLoaded.Left + labelDictionaryLoaded.Width;
                comboBoxDictionaries.Width = groupBoxOcrAutoFix.Width - (comboBoxDictionaries.Left + 10 + buttonSpellCheckDownload.Width);
            }
            else
            {
                comboBoxDictionaries.SelectedIndex = 0;
            }

            if (_modiEnabled && checkBoxUseModiInTesseractForUnknownWords.Checked)
            {
                string tesseractLanguageText = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Text;
                int i = 0;
                foreach (var modiLanguage in comboBoxModiLanguage.Items)
                {
                    if ((modiLanguage as ModiLanguage).Text == tesseractLanguageText)
                        comboBoxModiLanguage.SelectedIndex = i;
                    i++;
                }
            }
            comboBoxModiLanguage.SelectedIndex = -1;
        }
コード例 #2
0
ファイル: VobSubOcr.cs プロジェクト: mgziminsky/subtitleedit
 private void ComboBoxTesseractLanguagesSelectedIndexChanged(object sender, EventArgs e)
 {
     Configuration.Settings.VobSubOcr.TesseractLastLanguage = (comboBoxTesseractLanguages.SelectedItem as TesseractLanguage).Id;
     if (_ocrFixEngine != null)
         _ocrFixEngine.Dispose();
     _ocrFixEngine = null;
     LoadOcrFixEngine(null, null);
 }
コード例 #3
0
ファイル: VobSubOcr.cs プロジェクト: mgziminsky/subtitleedit
 private void comboBoxDictionaries_SelectedIndexChanged(object sender, EventArgs e)
 {
     Configuration.Settings.General.SpellCheckLanguage = LanguageString;
     string threeLetterISOLanguageName = string.Empty;
     if (LanguageString == null)
     {
         if (_ocrFixEngine != null)
             _ocrFixEngine.Dispose();
         _ocrFixEngine = new OcrFixEngine(string.Empty, string.Empty, this);
         return;
     }
     try
     {
         if (_ocrFixEngine != null)
             _ocrFixEngine.Dispose();
         _ocrFixEngine = null;
         var ci = CultureInfo.GetCultureInfo(LanguageString.Replace("_", "-"));
         threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName;
     }
     catch
     {
         var arr = LanguageString.Split(new char[] { '-', '_' });
         if (arr.Length > 1 && arr[0].Length == 2)
         {
             foreach (var x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
             {
                 if (string.Equals(x.TwoLetterISOLanguageName, arr[0], StringComparison.OrdinalIgnoreCase))
                 {
                     threeLetterISOLanguageName = x.ThreeLetterISOLanguageName;
                     break;
                 }
             }
         }
     }
     LoadOcrFixEngine(threeLetterISOLanguageName, LanguageString);
 }
コード例 #4
0
ファイル: VobSubOcr.cs プロジェクト: mgziminsky/subtitleedit
 /// <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();
         if (_ocrFixEngine != null)
         {
             _ocrFixEngine.Dispose();
             _ocrFixEngine = null;
         }
     }
     base.Dispose(disposing);
 }
コード例 #5
0
ファイル: VobSubOcr.cs プロジェクト: suvjunmd/subtitleedit
 private void comboBoxDictionaries_SelectedIndexChanged(object sender, EventArgs e)
 {
     Configuration.Settings.General.SpellCheckLanguage = LanguageString;
     string threeLetterISOLanguageName = string.Empty;
     if (LanguageString == null)
     {
         if (_ocrFixEngine != null)
             _ocrFixEngine.Dispose();
         _ocrFixEngine = new OcrFixEngine(string.Empty, string.Empty, this);
         return;
     }
     try
     {
         if (_ocrFixEngine != null)
             _ocrFixEngine.Dispose();
         _ocrFixEngine = null;
         var ci = CultureInfo.GetCultureInfo(LanguageString.Replace("_", "-"));
         threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName;
     }
     catch
     {
     }
     LoadOcrFixEngine(threeLetterISOLanguageName, LanguageString);
 }
コード例 #6
0
ファイル: FixCommonErrors.cs プロジェクト: leeyikkong/testing
 public void FixOcrErrorsViaReplaceList(string threeLetterIsoLanguageName)
 {
     using (var ocrFixEngine = new OcrFixEngine(threeLetterIsoLanguageName, null, this))
     {
         string fixAction = _language.FixCommonOcrErrors;
         int noOfFixes = 0;
         string lastLine = string.Empty;
         for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
         {
             var p = Subtitle.Paragraphs[i];
             string text = ocrFixEngine.FixOcrErrors(p.Text, i, lastLine, false, OcrFixEngine.AutoGuessLevel.Cautious);
             lastLine = text;
             if (AllowFix(p, fixAction) && p.Text != text)
             {
                 string oldText = p.Text;
                 p.Text = text;
                 noOfFixes++;
                 AddFixToListView(p, fixAction, oldText, p.Text);
             }
             Application.DoEvents();
         }
         if (noOfFixes > 0)
         {
             _totalFixes += noOfFixes;
             LogStatus(_language.FixCommonOcrErrors, string.Format(_language.CommonOcrErrorsFixed, noOfFixes));
         }
     }
 }