/// <summary>
 /// Initializes a new instance of the <see cref="ParagraphEventArgs"/> class.
 /// </summary>
 /// <param name="seconds">
 /// The seconds.
 /// </param>
 /// <param name="p">
 /// The p.
 /// </param>
 /// <param name="b">
 /// The b.
 /// </param>
 /// <param name="mouseDownParagraphType">
 /// The mouse down paragraph type.
 /// </param>
 public ParagraphEventArgs(double seconds, Paragraph p, Paragraph b, MouseDownParagraphType mouseDownParagraphType)
 {
     this.Seconds = seconds;
     this.Paragraph = p;
     this.BeforeParagraph = b;
     this.MouseDownParagraphType = mouseDownParagraphType;
 }
 public ParagraphEventArgs(double seconds, Paragraph p, Paragraph b, MouseDownParagraphType mouseDownParagraphType)
 {
     Seconds = seconds;
     Paragraph = p;
     BeforeParagraph = b;
     MouseDownParagraphType = mouseDownParagraphType;
 }
        public Paragraph Constructor(TimeCode startTime, TimeCode endTime, string text)
        {
            Paragraph target = new Paragraph(startTime, endTime, text);
            return target;

            // TODO: add assertions to method ParagraphTest.Constructor(TimeCode, TimeCode, String)
        }
        public Paragraph Constructor(int startFrame, int endFrame, string text)
        {
            Paragraph target = new Paragraph(startFrame, endFrame, text);
            return target;

            // TODO: add assertions to method ParagraphTest.Constructor(Int32, Int32, String)
        }
        public Paragraph Constructor()
        {
            Paragraph target = new Paragraph();
            return target;

            // TODO: add assertions to method ParagraphTest.Constructor()
        }
 public void TestToStringNewParagraph()
 {
     string expectedOutput = "00:00:00,000 --> 00:00:00,000 ";
     var paragraph = new Paragraph();
     string actualOutput = paragraph.ToString();
     Assert.AreEqual(expectedOutput, actualOutput);
 }
 private void GeneratePreview()
 {
     Subtitle subtitle = new Subtitle();
     var p1 = new Paragraph("Line 1a." + Environment.NewLine + "Line 1b.", 1000, 3500);
     string start1 = GetTimeCode(p1.StartTime, comboBoxTimeCode.Text);
     string end1 = GetTimeCode(p1.EndTime, comboBoxTimeCode.Text);
     var p2 = new Paragraph("Line 2a." + Environment.NewLine + "Line 2b.", 1000, 3500);
     string start2 = GetTimeCode(p2.StartTime, comboBoxTimeCode.Text);
     string end2 = GetTimeCode(p2.EndTime, comboBoxTimeCode.Text);
     subtitle.Paragraphs.Add(p1);
     subtitle.Paragraphs.Add(p2);
     try
     {
         string newLine = comboBoxNewLine.Text.Replace(Configuration.Settings.Language.ExportCustomTextFormat.DoNotModify, EnglishDoNoModify);
         string template = GetParagraphTemplate(textBoxParagraph.Text);
         textBoxPreview.Text = GetHeaderOrFooter("Demo", subtitle, textBoxHeader.Text) +
                               GetParagraph(template, start1, end1, GetText(p1.Text, newLine), GetText("Linje 1a." + Environment.NewLine + "Line 1b.", newLine), 0, p1.Duration, comboBoxTimeCode.Text) +
                               GetParagraph(template, start2, end2, GetText(p2.Text, newLine), GetText("Linje 2a." + Environment.NewLine + "Line 2b.", newLine), 1, p2.Duration, comboBoxTimeCode.Text) +
                               GetHeaderOrFooter("Demo", subtitle, textBoxFooter.Text);
     }
     catch (Exception ex)
     {
         textBoxPreview.Text = ex.Message;
     }
 }
 public ParagraphEventArgs(double seconds, Paragraph p, Paragraph b, MouseDownParagraphType mouseDownParagraphType, bool movePreviousOrNext)
 {
     this.Seconds = seconds;
     this.Paragraph = p;
     this.BeforeParagraph = b;
     this.MouseDownParagraphType = mouseDownParagraphType;
     this.MovePreviousOrNext = movePreviousOrNext;
 }
 public void TestMethodAdjustOneSecond()
 {
     var paragraph = new Paragraph();
     paragraph.Adjust(0, 1);
     int startSeconds = paragraph.StartTime.Seconds;
     int endSeconds = paragraph.EndTime.Seconds;
     Assert.AreEqual(1, startSeconds);
     Assert.AreEqual(1, endSeconds);
 }
Exemple #10
0
 private static void SetTimeCodes(string fileName, ListViewItem item)
 {
     string name = Path.GetFileNameWithoutExtension(fileName);
     var p = new Paragraph();
     SetEndTimeAndStartTime(name, p);
     item.SubItems.Add(p.StartTime.ToString());
     item.SubItems.Add(p.EndTime.ToString());
     item.SubItems.Add(p.Duration.ToShortString());
 }
 public Paragraph Constructor(
     string text,
     double startTotalMilliseconds,
     double endTotalMilliseconds
 )
 {
     Paragraph target = new Paragraph(text, startTotalMilliseconds, endTotalMilliseconds);
     return target;
     // TODO: add assertions to method ParagraphTest.Constructor(String, Double, Double)
 }
        public static Paragraph Create(Paragraph paragraph_paragraph1)
        {
            Paragraph paragraph = new Paragraph(paragraph_paragraph1);
            return paragraph;

            // TODO: Edit factory method of Paragraph
            // This method should be able to configure the object in all possible ways.
            // Add as many parameters as needed,
            // and assign their values to each field by using the API.
        }
        internal void Initialize(Paragraph paragraph)
        {
            _paragraph = paragraph;

            labelPreview.Text = paragraph.Text;
            labelTotalMillisecs.Text = string.Format("{0:#,##0.000}", paragraph.Duration.TotalMilliseconds / 1000);
            numericUpDownDelay.Maximum = (decimal)((paragraph.Duration.TotalMilliseconds - 500) / 1000);
            numericUpDownDelay.Minimum = 0;

            numericUpDownDelay.Left = labelEndDelay.Left + labelEndDelay.Width + 5;
        }
        private void AddToListView(Paragraph p, string lineNumbers, string newText)
        {
            var item = new ListViewItem(string.Empty) { Tag = p, Checked = true };

            var subItem = new ListViewItem.ListViewSubItem(item, lineNumbers);
            item.SubItems.Add(subItem);
            subItem = new ListViewItem.ListViewSubItem(item, newText.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
            item.SubItems.Add(subItem);

            listViewFixes.Items.Add(item);
        }
 private void AddFixToListView(Paragraph p, string before, string after)
 {
     if (_onlyListFixes)
     {
         var item = new ListViewItem(string.Empty) { Checked = true, Tag = p };
         item.SubItems.Add(p.Number.ToString());
         item.SubItems.Add(before.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
         item.SubItems.Add(after.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
         listViewFixes.Items.Add(item);
     }
 }
        public bool AllowFix(Paragraph p)
        {
            if (_onlyListFixes)
                return true;

            string ln = p.Number.ToString();
            foreach (ListViewItem item in listViewFixes.Items)
            {
                if (item.SubItems[1].Text == ln)
                    return item.Checked;
            }
            return false;
        }
 private void buttonOK_Click(object sender, EventArgs e)
 {
     DateTimeSubtitle = new Subtitle();
     DateTime start = GetStartDateTime();
     double durationInSeconds = timeUpDownDuration.TimeCode.TotalSeconds;
     for (int i = 0; i < durationInSeconds; i++)
     {
         Paragraph p = new Paragraph();
         p.Text = FormatDateTime(start);
         start = start.AddSeconds(1);
         p.StartTime = TimeCode.FromSeconds(i);
         p.EndTime = TimeCode.FromSeconds(i + 0.999);
         DateTimeSubtitle.Paragraphs.Add(p);
     }
     DialogResult = DialogResult.OK;
 }
        private static void SetEndTimeAndStartTime(string name, Paragraph p)
        {
            if (name.Contains("-to-"))
            {
                var arr = name.Replace("-to-", "_").Split('_');
                if (arr.Length == 3)
                {
                    if (Utilities.IsInteger(arr[1]) && Utilities.IsInteger(arr[2]))
                    {
                        p.StartTime.TotalMilliseconds = Convert.ToInt32(arr[1]);
                        p.EndTime.TotalMilliseconds = Convert.ToInt32(arr[2]);

                    }
                }
            }
        }
        private void AddToListView(Paragraph p, string lineNumbers, string newText)
        {
            var item = new ListViewItem(string.Empty) { Tag = p, Checked = true };

            var subItem = new ListViewItem.ListViewSubItem(item, lineNumbers.TrimEnd(','));
            item.SubItems.Add(subItem);
            subItem = new ListViewItem.ListViewSubItem(item, newText.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
            item.SubItems.Add(subItem);

            listViewFixes.Items.Add(item);

            foreach (string number in lineNumbers.TrimEnd(',').Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                _isFixAllowedList.Add(Convert.ToInt32(number), true);
            }
        }
Exemple #20
0
 private static void SetEndTimeAndStartTime(string name, Paragraph p)
 {
     if (name.Contains("-to-"))
     {
         var arr = name.Replace("-to-", "_").Split('_');
         if (arr.Length == 3)
         {
             int startTime, endTime;
             if (int.TryParse(arr[1], out startTime) && int.TryParse(arr[2], out endTime))
             {
                 p.StartTime.TotalMilliseconds = startTime;
                 p.EndTime.TotalMilliseconds = endTime;
             }
         }
     }
 }
        public void VobSubWriteAndReadTwoBitmaps()
        {
            string fileName = Guid.NewGuid() + ".sub";
            using (var writer = new VobSubWriter(fileName, 800, 600, 10, 10, 32, Color.White, Color.Black, true, "English", "en"))
            {
                var p1 = new Paragraph("Line1", 0, 1000);
                var p2 = new Paragraph("Line2", 2000, 3000);
                writer.WriteParagraph(p1, new Bitmap(200, 20), ContentAlignment.BottomCenter);
                writer.WriteParagraph(p2, new Bitmap(200, 20), ContentAlignment.BottomCenter);
            }

            var reader = new VobSubParser(true);
            reader.Open(fileName);
            var list = reader.MergeVobSubPacks();

            Assert.IsTrue(list.Count == 2);
        }
        internal void Initialize(Paragraph paragraph)
        {
            _paragraph = paragraph;
            _animation = new List<Paragraph>();

            colorDialog1.Color = Color.Red;
            labelColor.Text = Utilities.ColorToHex(colorDialog1.Color);
            panelColor.BackColor = colorDialog1.Color;

            AddToPreview(richTextBoxPreview, paragraph.Text);
            RefreshPreview();
            labelTotalMillisecs.Text = string.Format("{0:#,##0.000}", paragraph.Duration.TotalMilliseconds / 1000);
            numericUpDownDelay.Maximum = (int)((paragraph.Duration.TotalMilliseconds - 500) / 1000);
            numericUpDownDelay.Minimum = 0;

            numericUpDownDelay.Left = labelEndDelay.Left + labelEndDelay.Width + 5;
        }
Exemple #23
0
 public Paragraph(Paragraph paragraph)
 {
     Number = paragraph.Number;
     Text = paragraph.Text;
     StartTime = new TimeCode(paragraph.StartTime.TimeSpan);
     EndTime = new TimeCode(paragraph.EndTime.TimeSpan);
     StartFrame = paragraph.StartFrame;
     EndFrame = paragraph.EndFrame;
     Forced = paragraph.Forced;
     Extra = paragraph.Extra;
     IsComment = paragraph.IsComment;
     Actor = paragraph.Actor;
     Effect = paragraph.Effect;
     Layer = paragraph.Layer;
     ID = paragraph.ID;
     Language = paragraph.Language;
     Style = paragraph.Style;
 }
 public Paragraph(Paragraph paragraph)
 {
     Number = paragraph.Number;
     Text = paragraph.Text;
     StartTime = new TimeCode(paragraph.StartTime.TotalMilliseconds);
     EndTime = new TimeCode(paragraph.EndTime.TotalMilliseconds);
     StartFrame = paragraph.StartFrame;
     EndFrame = paragraph.EndFrame;
     Forced = paragraph.Forced;
     Extra = paragraph.Extra;
     IsComment = paragraph.IsComment;
     Actor = paragraph.Actor;
     Effect = paragraph.Effect;
     Layer = paragraph.Layer;
     Id = GenerateId(); // Do not reuse unique ID
     Language = paragraph.Language;
     Style = paragraph.Style;
     NewSection = paragraph.NewSection;
 }
 private bool IsFixAllowed(Paragraph p)
 {
     foreach (ListViewItem item in listViewFixes.Items)
     {
         if ((item.Tag as Paragraph) == p)
             return item.Checked;
     }
     return true;
 }
        public void ContinueSpellcheck(Subtitle subtitle)
        {
            _subtitle = subtitle;

            buttonUndo.Visible = false;
            _undoList = new List<UndoObject>();

            if (_currentIndex >= subtitle.Paragraphs.Count)
                _currentIndex = 0;

            _currentParagraph = _subtitle.GetParagraphOrDefault(_currentIndex);
            if (_currentParagraph == null)
                return;

            SetWords(_currentParagraph.Text);
            _wordsIndex = -1;

            PrepareNextWord();
        }
        private void PrepareNextWord()
        {
            while (true)
            {
                if (_wordsIndex + 1 < _words.Count)
                {
                    _wordsIndex++;
                    _currentWord = _words[_wordsIndex].Text;
                    _currentSpellCheckWord = _words[_wordsIndex];
                }
                else
                {
                    if (_currentIndex + 1 < _subtitle.Paragraphs.Count)
                    {
                        _currentIndex++;
                        _currentParagraph = _subtitle.Paragraphs[_currentIndex];
                        SetWords(_currentParagraph.Text);
                        _wordsIndex = 0;
                        if (_words.Count == 0)
                        {
                            _currentWord = string.Empty;
                        }
                        else
                        {
                            _currentWord = _words[_wordsIndex].Text;
                            _currentSpellCheckWord = _words[_wordsIndex];
                        }
                    }
                    else
                    {
                        ShowEndStatusMessage(Configuration.Settings.Language.SpellCheck.SpellCheckCompleted);
                        DialogResult = DialogResult.OK;
                        return;
                    }
                }

                int minLength = 2;
                if (Configuration.Settings.Tools.SpellCheckOneLetterWords)
                    minLength = 1;

                if (_currentWord.Trim().Length >= minLength &&
                    !_currentWord.Contains("0") &&
                    !_currentWord.Contains("1") &&
                    !_currentWord.Contains("2") &&
                    !_currentWord.Contains("3") &&
                    !_currentWord.Contains("4") &&
                    !_currentWord.Contains("5") &&
                    !_currentWord.Contains("6") &&
                    !_currentWord.Contains("7") &&
                    !_currentWord.Contains("8") &&
                    !_currentWord.Contains("9") &&
                    !_currentWord.Contains("%") &&
                    !_currentWord.Contains("&") &&
                    !_currentWord.Contains("@") &&
                    !_currentWord.Contains("$") &&
                    !_currentWord.Contains("*") &&
                    !_currentWord.Contains("=") &&
                    !_currentWord.Contains("£") &&
                    !_currentWord.Contains("#") &&
                    !_currentWord.Contains("_") &&
                    !_currentWord.Contains("½") &&
                    !_currentWord.Contains("^") &&
                    !_currentWord.Contains("£")
                    )
                {
                    _prefix = string.Empty;
                    _postfix = string.Empty;
                    if (_currentWord.Length > 1)
                    {
                        if (_currentWord.StartsWith("'"))
                        {
                            _prefix = "'";
                            _currentWord = _currentWord.Substring(1);
                        }
                        if (_currentWord.StartsWith("`"))
                        {
                            _prefix = "`";
                            _currentWord = _currentWord.Substring(1);
                        }

                    }
                    if (_namesEtcList.IndexOf(_currentWord) >= 0)
                    {
                        _noOfNamesEtc++;
                    }
                    else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _namesEtcList.IndexOf(_currentWord.Trim("'".ToCharArray())) >= 0)
                    {
                        _noOfNamesEtc++;
                    }
                    else if (_skipAllList.IndexOf(_currentWord.ToUpper()) >= 0)
                    {
                        _noOfSkippedWords++;
                    }
                    else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _skipAllList.IndexOf(_currentWord.ToUpper().Trim("'".ToCharArray())) >= 0)
                    {
                        _noOfSkippedWords++;
                    }
                    else if (_userWordList.IndexOf(_currentWord.ToLower()) >= 0)
                    {
                        _noOfCorrectWords++;
                    }
                    else if ((_currentWord.EndsWith("'") || _currentWord.StartsWith("'")) && _userWordList.IndexOf(_currentWord.Trim("'".ToCharArray()).ToLower()) >= 0)
                    {
                        _noOfCorrectWords++;
                    }
                    else if (_changeAllDictionary.ContainsKey(_currentWord))
                    {
                        _noOfChangedWords++;
                        _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord, ref _firstChange);
                    }
                    else if (_changeAllDictionary.ContainsKey(_currentWord.Trim("'".ToCharArray())))
                    {
                        _noOfChangedWords++;
                        _mainWindow.CorrectWord(_changeAllDictionary[_currentWord], _currentParagraph, _currentWord.Trim("'".ToCharArray()), ref _firstChange);
                    }
                    else if (_namesEtcListUppercase.IndexOf(_currentWord) >= 0)
                    {
                        _noOfNamesEtc++;
                    }
                    else if (_namesEtcListWithApostrophe.IndexOf(_currentWord) >= 0)
                    {
                        _noOfNamesEtc++;
                    }
                    else if (Utilities.IsInNamesEtcMultiWordList(_namesEtcMultiWordList, _currentParagraph.Text, _currentWord)) //TODO: verify this!
                    {
                        _noOfNamesEtc++;
                    }
                    else if (IsWordInUserPhrases(_userPhraseList, _wordsIndex, _words))
                    {
                        _noOfCorrectWords++;
                    }
                    else
                    {
                        bool correct;

                        if (_prefix == "'" && _currentWord.Length >= 1 && (DoSpell(_prefix + _currentWord) || _userWordList.Contains(_prefix + _currentWord)))
                        {
                            correct = true;
                        }
                        else if (_currentWord.Length > 1)
                        {
                            correct = DoSpell(_currentWord);
                            if (!correct && (_currentWord.EndsWith("'") || _currentWord.EndsWith("`")))
                                correct = DoSpell(_currentWord.TrimEnd('\'').TrimEnd('`'));
                            if (!correct && _currentWord.EndsWith("'s") && _currentWord.Length > 4)
                                correct = DoSpell(_currentWord.TrimEnd('s').TrimEnd('\''));
                            if (!correct && _currentWord.EndsWith("'") && DoSpell(_currentWord.TrimEnd("'".ToCharArray())))
                            {
                                _currentWord = _currentWord.TrimEnd("'".ToCharArray());
                                correct = true;
                            }
                        }
                        else
                        {
                            correct = false;
                            if (_currentWord == "'")
                                correct = true;
                            else if (_languageName.StartsWith("en_") && (_currentWord.ToLower() == "a" || _currentWord == "I"))
                                correct = true;
                            else if (_languageName.StartsWith("da_") && _currentWord.ToLower() == "i")
                                correct = true;
                        }

                        if (!correct && Configuration.Settings.Tools.SpellCheckEnglishAllowInQuoteAsIng &&
                            _languageName.StartsWith("en_") && _currentWord.ToLower().EndsWith("in'"))
                        {
                            correct = DoSpell(_currentWord.TrimEnd('\'') + "g");
                        }

                        if (correct)
                        {
                            _noOfCorrectWords++;
                        }
                        else
                        {
                            _mainWindow.FocusParagraph(_currentIndex);

                            List<string> suggestions = new List<string>();

                            if ((_currentWord == "Lt's" || _currentWord == "Lt'S") && _languageName.StartsWith("en_"))
                            {
                                suggestions.Add("It's");
                            }
                            else
                            {
                                if (_currentWord.ToUpper() != "LT'S" && _currentWord.ToUpper() != "SOX'S") //TODO: get fixed nhunspell
                                    suggestions = DoSuggest(_currentWord); //TODO: 0.9.6 fails on "Lt'S"
                                if (_languageName.StartsWith("fr_") && (_currentWord.StartsWith("I'") || _currentWord.StartsWith("I’")))
                                {
                                    if (_currentWord.Length > 3 && Utilities.LowercaseLetters.Contains(_currentWord[2].ToString()))
                                    {
                                        if (_currentSpellCheckWord.Index > 3)
                                        {
                                            string ending = _currentParagraph.Text.Substring(0, _currentSpellCheckWord.Index - 1).Trim();
                                            if (!ending.EndsWith(".") && !ending.EndsWith("!") && !ending.EndsWith("?"))
                                            {
                                                for (int i = 0; i < suggestions.Count; i++)
                                                {
                                                    if (suggestions[i].StartsWith("L'") || suggestions[i].StartsWith("L’"))
                                                        suggestions[i] = suggestions[i].Remove(0, 1).Insert(0, "l");
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            suggestions.Remove(_currentWord);
                            if (_currentWord.Length == 1)
                            {
                                if ((_currentWord == "L") && _languageName.StartsWith("en_"))
                                {
                                    suggestions.Remove("I");
                                    suggestions.Insert(0, "I");
                                }
                            }

                            if (AutoFixNames && _currentWord.Length > 1 && suggestions.Contains(_currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1)))
                            {
                                ChangeWord = _currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1);
                                DoAction(SpellCheckAction.ChangeAll);
                                return;
                            }
                            else if (AutoFixNames && _currentWord.Length > 1 && suggestions.Contains(_currentWord.ToUpper()))
                            {
                                ChangeWord = _currentWord.ToUpper();
                                DoAction(SpellCheckAction.ChangeAll);
                                return;
                            }
                            else if (AutoFixNames && _currentWord.Length > 1 && _namesEtcList.Contains(_currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1)))
                            {
                                ChangeWord = _currentWord.Substring(0, 1).ToUpper() + _currentWord.Substring(1);
                                DoAction(SpellCheckAction.ChangeAll);
                                return;
                            }
                            else
                            {
                                if (_prefix != null && _prefix == "''" && _currentWord.EndsWith("''"))
                                {
                                    _prefix = string.Empty;
                                    _currentSpellCheckWord.Index += 2;
                                    _currentWord = _currentWord.Trim("'".ToCharArray());
                                }
                                if (_prefix != null && _prefix == "'" && _currentWord.EndsWith("'"))
                                {
                                    _prefix = string.Empty;
                                    _currentSpellCheckWord.Index++;
                                    _currentWord = _currentWord.Trim("'".ToCharArray());
                                }

                                if (_postfix != null && _postfix == "'")
                                {
                                    _currentSpellCheckWord.Text = _currentWord + _postfix;
                                    Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
                                }
                                else
                                {
                                    _currentSpellCheckWord.Text = _currentWord;
                                    Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
                                }
                                if (!this.Visible)
                                    this.ShowDialog(_mainWindow);
                                return; // wait for user input
                            }
                        }

                    }
                }
            }
        }
        public void DoSpellCheck(bool autoDetect, Subtitle subtitle, string dictionaryFolder, Main mainWindow, int startLine)
        {
            _subtitle = subtitle;
            LanguageStructure.Main mainLanguage = Configuration.Settings.Language.Main;
            _mainWindow = mainWindow;

            _namesEtcList = new List<string>();
            _namesEtcMultiWordList = new List<string>();
            _namesEtcListUppercase = new List<string>();
            _namesEtcListWithApostrophe = new List<string>();

            _skipAllList = new List<string>();

            _noOfSkippedWords = 0;
            _noOfChangedWords = 0;
            _noOfCorrectWords = 0;
            _noOfNamesEtc = 0;
            _noOfAddedWords = 0;
            _firstChange = true;

            if (!string.IsNullOrEmpty(Configuration.Settings.General.SpellCheckLanguage))
            {
                _languageName = Configuration.Settings.General.SpellCheckLanguage;
            }
            else
            {
                string name = Utilities.GetDictionaryLanguages()[0];
                int start = name.LastIndexOf('[');
                int end = name.LastIndexOf(']');
                if (start > 0 && end > start)
                {
                    start++;
                    name = name.Substring(start, end - start);
                    _languageName = name;
                }
                else
                {
                    MessageBox.Show(string.Format(mainLanguage.InvalidLanguageNameX, name));
                    return;
                }
            }
            if (autoDetect || string.IsNullOrEmpty(_languageName))
                _languageName = Utilities.AutoDetectLanguageName(_languageName, subtitle);
            string dictionary = Utilities.DictionaryFolder + _languageName;

            Utilities.LoadNamesEtcWordLists(_namesEtcList, _namesEtcMultiWordList, _languageName);
            foreach (string namesItem in _namesEtcList)
                _namesEtcListUppercase.Add(namesItem.ToUpper());

            if (_languageName.ToLower().StartsWith("en_"))
            {
                foreach (string namesItem in _namesEtcList)
                {
                    if (!namesItem.EndsWith("s"))
                        _namesEtcListWithApostrophe.Add(namesItem + "'s");
                    if (!namesItem.EndsWith("s"))
                        _namesEtcListWithApostrophe.Add(namesItem + "’s");
                    else if (!namesItem.EndsWith("'"))
                        _namesEtcListWithApostrophe.Add(namesItem + "'");
                }
            }

            _userWordList = new List<string>();
            _userPhraseList = new List<string>();
            if (File.Exists(dictionaryFolder + _languageName + "_user.xml"))
            {
                var userWordDictionary = new XmlDocument();
                userWordDictionary.Load(dictionaryFolder + _languageName + "_user.xml");
                foreach (XmlNode node in userWordDictionary.DocumentElement.SelectNodes("word"))
                {
                    string word = node.InnerText.Trim().ToLower();
                    if (word.Contains(" "))
                        _userPhraseList.Add(word);
                    else
                        _userWordList.Add(word);
                }
            }

            // Add names/userdic with "." or " " or "-"
            _wordsWithDashesOrPeriods = new List<string>();
            _wordsWithDashesOrPeriods.AddRange(_namesEtcMultiWordList);
            foreach (string name in _namesEtcList)
            {
                if (name.Contains(".") || name.Contains("-"))
                    _wordsWithDashesOrPeriods.Add(name);
            }
            foreach (string word in _userWordList)
            {
                if (word.Contains(".") || word.Contains("-"))
                    _wordsWithDashesOrPeriods.Add(word);
            }
            _wordsWithDashesOrPeriods.AddRange(_userPhraseList);

            _changeAllDictionary = new Dictionary<string, string>();
            LoadHunspell(dictionary);
            _currentIndex = 0;
            if (startLine >= 0 && startLine < _subtitle.Paragraphs.Count)
                _currentIndex = startLine;
            _currentParagraph = _subtitle.Paragraphs[_currentIndex];
            SetWords(_currentParagraph.Text);
            _wordsIndex = -1;

            PrepareNextWord();
        }
        public void SetStartTimeAndDuration(int index, Paragraph paragraph)
        {
            if (index >= 0 && index < Items.Count)
            {
                ListViewItem item = Items[index];
                if (Configuration.Settings != null && Configuration.Settings.General.UseTimeFormatHHMMSSFF)
                {
                    if (paragraph.StartTime.IsMaxTime)
                        item.SubItems[ColumnIndexStart].Text = "-";
                    else
                        item.SubItems[ColumnIndexStart].Text = paragraph.StartTime.ToHHMMSSFF();

                    if (paragraph.EndTime.IsMaxTime)
                        item.SubItems[ColumnIndexEnd].Text = "-";
                    else
                        item.SubItems[ColumnIndexEnd].Text = paragraph.EndTime.ToHHMMSSFF();
                }
                else
                {
                    if (paragraph.StartTime.IsMaxTime)
                        item.SubItems[ColumnIndexStart].Text = "-";
                    else
                        item.SubItems[ColumnIndexStart].Text = paragraph.StartTime.ToString();

                    if (paragraph.EndTime.IsMaxTime)
                        item.SubItems[ColumnIndexEnd].Text = "-";
                    else
                        item.SubItems[ColumnIndexEnd].Text = paragraph.EndTime.ToString();
                }
            }
        }
        public Subtitle SplitLongLinesInSubtitle(Subtitle subtitle, List<int> splittedIndexes, List<int> autoBreakedIndexes, out int numberOfSplits, int totalLineMaxCharacters, int singleLineMaxCharacters, bool clearFixes)
        {
            listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
                listViewFixes.Items.Clear();
            numberOfSplits = 0;
            string language = Utilities.AutoDetectGoogleLanguage(subtitle);
            Subtitle splittedSubtitle = new Subtitle();
            Paragraph p = null;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                bool added = false;
                p = subtitle.GetParagraphOrDefault(i);
                if (p != null && p.Text != null)
                {
                    string oldText = Utilities.RemoveHtmlTags(p.Text);
                    if (SplitLongLinesHelper.QualifiesForSplit(p.Text, singleLineMaxCharacters, totalLineMaxCharacters) && IsFixAllowed(p))
                    {
                        bool isDialog = false;
                        string dialogText = string.Empty;
                        if (p.Text.Contains('-'))
                        {
                            dialogText = Utilities.AutoBreakLine(p.Text, 5, 1, language);
                            string[] arr = dialogText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                            if (arr.Length == 2 && (arr[0].StartsWith('-') || arr[0].StartsWith("<i>-")) && (arr[1].StartsWith('-') || arr[1].StartsWith("<i>-")))
                                isDialog = true;

                        }

                        if (!isDialog && !SplitLongLinesHelper.QualifiesForSplit(Utilities.AutoBreakLine(p.Text, language), singleLineMaxCharacters, totalLineMaxCharacters))
                        {
                            Paragraph newParagraph = new Paragraph(p);
                            newParagraph.Text = Utilities.AutoBreakLine(p.Text, language);
                            if (clearFixes)
                                AddToListView(p, (splittedSubtitle.Paragraphs.Count + 1).ToString(), oldText);
                            autoBreakedIndexes.Add(splittedSubtitle.Paragraphs.Count);
                            splittedSubtitle.Paragraphs.Add(newParagraph);
                            added = true;
                            numberOfSplits++;
                        }
                        else
                        {
                            string text = Utilities.AutoBreakLine(p.Text, language);
                            if (isDialog)
                                text = dialogText;
                            if (text.Contains(Environment.NewLine))
                            {
                                string[] arr = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                if (arr.Length == 2)
                                {
                                    int spacing1 = Configuration.Settings.General.MininumMillisecondsBetweenLines / 2;
                                    int spacing2 = Configuration.Settings.General.MininumMillisecondsBetweenLines / 2;
                                    if (Configuration.Settings.General.MininumMillisecondsBetweenLines % 2 == 1)
                                        spacing2++;

                                    Paragraph newParagraph1 = new Paragraph(p);
                                    Paragraph newParagraph2 = new Paragraph(p);
                                    newParagraph1.Text = Utilities.AutoBreakLine(arr[0], language);

                                    double startFactor = 0;
                                    double middle = p.StartTime.TotalMilliseconds + (p.Duration.TotalMilliseconds / 2);
                                    if (Utilities.RemoveHtmlTags(oldText).Trim().Length > 0)
                                    {
                                        startFactor = (double)Utilities.RemoveHtmlTags(newParagraph1.Text).Length / Utilities.RemoveHtmlTags(oldText).Length;
                                        if (startFactor < 0.25)
                                            startFactor = 0.25;
                                        if (startFactor > 0.75)
                                            startFactor = 0.75;
                                        middle = p.StartTime.TotalMilliseconds + (p.Duration.TotalMilliseconds * startFactor);
                                    }

                                    newParagraph1.EndTime.TotalMilliseconds = middle - spacing1;
                                    newParagraph2.Text = Utilities.AutoBreakLine(arr[1], language);
                                    newParagraph2.StartTime.TotalMilliseconds = newParagraph1.EndTime.TotalMilliseconds + spacing2;

                                    if (clearFixes)
                                        AddToListView(p, (splittedSubtitle.Paragraphs.Count + 1).ToString(), oldText);
                                    splittedIndexes.Add(splittedSubtitle.Paragraphs.Count);
                                    splittedIndexes.Add(splittedSubtitle.Paragraphs.Count + 1);

                                    string p1 = Utilities.RemoveHtmlTags(newParagraph1.Text);
                                    if (p1.EndsWith('.') || p1.EndsWith('!') || p1.EndsWith('?') || p1.EndsWith(':') || p1.EndsWith(')') || p1.EndsWith(']') || p1.EndsWith('♪'))
                                    {
                                        if (newParagraph1.Text.StartsWith('-') && newParagraph2.Text.StartsWith('-'))
                                        {
                                            newParagraph1.Text = newParagraph1.Text.Remove(0, 1).Trim();
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, 1).Trim();
                                        }
                                        else if (newParagraph1.Text.StartsWith("<i>-") && newParagraph2.Text.StartsWith('-'))
                                        {
                                            newParagraph1.Text = newParagraph1.Text.Remove(3, 1).Trim();
                                            if (newParagraph1.Text.StartsWith("<i> "))
                                                newParagraph1.Text = newParagraph1.Text.Remove(3, 1).Trim();
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, 1).Trim();
                                        }
                                    }
                                    else
                                    {
                                        bool endsWithComma = newParagraph1.Text.EndsWith(',') || newParagraph1.Text.EndsWith(",</i>");

                                        string post = string.Empty;
                                        if (newParagraph1.Text.EndsWith("</i>"))
                                        {
                                            post = "</i>";
                                            newParagraph1.Text = newParagraph1.Text.Remove(newParagraph1.Text.Length - post.Length);
                                        }
                                        if (endsWithComma)
                                            newParagraph1.Text += post;
                                        else
                                            newParagraph1.Text += comboBoxLineContinuationEnd.Text.TrimEnd() + post;

                                        string pre = string.Empty;
                                        if (newParagraph2.Text.StartsWith("<i>"))
                                        {
                                            pre = "<i>";
                                            newParagraph2.Text = newParagraph2.Text.Remove(0, pre.Length);
                                        }
                                        if (endsWithComma)
                                            newParagraph2.Text = pre + newParagraph2.Text;
                                        else
                                            newParagraph2.Text = pre + comboBoxLineContinuationBegin.Text + newParagraph2.Text;
                                    }

                                    if (newParagraph1.Text.IndexOf("<i>") >= 0 && newParagraph1.Text.IndexOf("<i>") < 10 & newParagraph1.Text.IndexOf("</i>") < 0 &&
                                        newParagraph2.Text.Contains("</i>") && newParagraph2.Text.IndexOf("<i>") < 0)
                                    {
                                        newParagraph1.Text += "</i>";
                                        newParagraph2.Text = "<i>" + newParagraph2.Text;
                                    }

                                    splittedSubtitle.Paragraphs.Add(newParagraph1);
                                    splittedSubtitle.Paragraphs.Add(newParagraph2);
                                    added = true;
                                    numberOfSplits++;
                                }
                            }
                        }
                    }
                }
                if (!added)
                    splittedSubtitle.Paragraphs.Add(new Paragraph(p));
            }
            listViewFixes.ItemChecked += listViewFixes_ItemChecked;
            splittedSubtitle.Renumber(1);
            return splittedSubtitle;
        }
Exemple #31
0
        public bool FindPrevious(Subtitle subtitle, Subtitle originalSubtitle, int startIndex, int position, bool allowEditOfOriginalSubtitle)
        {
            Success = false;
            int  index = startIndex;
            bool first = true;

            for (var i = startIndex; i >= 0; i--)
            {
                Paragraph p = subtitle.Paragraphs[i];

                if (originalSubtitle != null && allowEditOfOriginalSubtitle)
                {
                    if (!first || MatchInOriginal)
                    {
                        Paragraph o = Utilities.GetOriginalParagraph(index, p, originalSubtitle.Paragraphs);
                        if (o != null)
                        {
                            if (!first)
                            {
                                position = o.Text.Length - 1;
                            }

                            for (var j = 0; j <= position; j++)
                            {
                                if (position - j >= 0 && position - j + j < o.Text.Length)
                                {
                                    var t   = o.Text.Substring(position - j, j);
                                    int pos = FindPositionInText(t, 0);
                                    if (pos >= 0)
                                    {
                                        pos             += position - j;
                                        MatchInOriginal  = true;
                                        SelectedIndex    = index;
                                        SelectedPosition = pos;
                                        Success          = true;
                                        return(true);
                                    }
                                }
                            }
                        }
                        position = p.Text.Length - 1;
                    }
                }

                MatchInOriginal = false;
                if (!first)
                {
                    position = p.Text.Length - 1;
                }

                for (var j = 0; j <= position; j++)
                {
                    if (position - j >= 0 && position < p.Text.Length)
                    {
                        var t   = p.Text.Substring(position - j, j + 1);
                        int pos = FindPositionInText(t, 0);
                        if (pos >= 0)
                        {
                            pos             += position - j;
                            MatchInOriginal  = false;
                            SelectedIndex    = index;
                            SelectedPosition = pos;
                            Success          = true;
                            return(true);
                        }
                    }
                }
                position = 0;
                first    = false;
                index--;
            }
            return(false);
        }
Exemple #32
0
        private static void TimeOutRefresh(Subtitle subtitle, VideoPlayerContainer videoPlayerContainer, Paragraph p = null)
        {
            if (DateTime.UtcNow.Ticks - _lastShowSubTicks > 10000 * 1000) // more than 1+ seconds ago
            {
                var newHash = subtitle.GetFastHashCode(string.Empty);
                if (newHash != _lastShowSubHash)
                {
                    videoPlayerContainer.SetSubtitleText(p == null ? string.Empty : p.Text, p, subtitle);
                    _lastShowSubHash = newHash;
                }

                _lastShowSubTicks = DateTime.UtcNow.Ticks;
            }
        }