Exemplo n.º 1
0
        private void UiElementChanged(object sender, EventArgs e)
        {
            var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1;

            if (idx < 0 || !_editOn)
            {
                return;
            }

            RulesProfiles[idx].Name = textBoxName.Text.Trim();
            RulesProfiles[idx].SubtitleLineMaximumLength           = (int)numericUpDownSubtitleLineMaximumLength.Value;
            RulesProfiles[idx].SubtitleOptimalCharactersPerSeconds = numericUpDownOptimalCharsSec.Value;
            RulesProfiles[idx].SubtitleMaximumCharactersPerSeconds = numericUpDownMaxCharsSec.Value;
            RulesProfiles[idx].SubtitleMinimumDisplayMilliseconds  = (int)numericUpDownDurationMin.Value;
            RulesProfiles[idx].SubtitleMaximumDisplayMilliseconds  = (int)numericUpDownDurationMax.Value;
            RulesProfiles[idx].MinimumMillisecondsBetweenLines     = (int)numericUpDownMinGapMs.Value;
            RulesProfiles[idx].MaxNumberOfLines = (int)numericUpDownMaxNumberOfLines.Value;
            RulesProfiles[idx].SubtitleMaximumWordsPerMinute = (int)numericUpDownMaxWordsMin.Value;
            RulesProfiles[idx].CpsIncludesSpace      = checkBoxCpsIncludeWhiteSpace.Checked;
            RulesProfiles[idx].MergeLinesShorterThan = comboBoxMergeShortLineLength.SelectedIndex + 10;
            RulesProfiles[idx].DialogStyle           = DialogSplitMerge.GetDialogStyleFromIndex(comboBoxDialogStyle.SelectedIndex);
            RulesProfiles[idx].ContinuationStyle     = ContinuationUtilities.GetContinuationStyleFromIndex(comboBoxContinuationStyle.SelectedIndex);
            UpdateRulesProfilesLine(idx);

            toolTipContinuationPreview.RemoveAll();
            toolTipContinuationPreview.SetToolTip(comboBoxContinuationStyle, ContinuationUtilities.GetContinuationStylePreview(RulesProfiles[idx].ContinuationStyle));
        }
Exemplo n.º 2
0
        private void UiElementChanged(object sender, EventArgs e)
        {
            var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1;
            if (idx < 0 || !_editOn)
            {
                return;
            }

            RulesProfiles[idx].Name = textBoxName.Text.Trim();
            RulesProfiles[idx].SubtitleLineMaximumLength = (int)numericUpDownSubtitleLineMaximumLength.Value;
            RulesProfiles[idx].SubtitleOptimalCharactersPerSeconds = numericUpDownOptimalCharsSec.Value;
            RulesProfiles[idx].SubtitleMaximumCharactersPerSeconds = numericUpDownMaxCharsSec.Value;
            RulesProfiles[idx].SubtitleMinimumDisplayMilliseconds = (int)numericUpDownDurationMin.Value;
            RulesProfiles[idx].SubtitleMaximumDisplayMilliseconds = (int)numericUpDownDurationMax.Value;
            RulesProfiles[idx].MinimumMillisecondsBetweenLines = (int)numericUpDownMinGapMs.Value;
            RulesProfiles[idx].MaxNumberOfLines = (int)numericUpDownMaxNumberOfLines.Value;
            RulesProfiles[idx].SubtitleMaximumWordsPerMinute = (int)numericUpDownMaxWordsMin.Value;
            RulesProfiles[idx].CpsLineLengthStrategy = (comboBoxCpsLineLenCalc.SelectedItem as CpsLineLength)?.Code;
            RulesProfiles[idx].MergeLinesShorterThan = comboBoxMergeShortLineLength.SelectedIndex + 1;
            RulesProfiles[idx].DialogStyle = DialogSplitMerge.GetDialogStyleFromIndex(comboBoxDialogStyle.SelectedIndex);
            RulesProfiles[idx].ContinuationStyle = ContinuationUtilities.GetContinuationStyleFromIndex(comboBoxContinuationStyle.SelectedIndex);
            UpdateRulesProfilesLine(idx);

            toolTipContinuationPreview.RemoveAll();
            toolTipContinuationPreview.SetToolTip(comboBoxContinuationStyle, ContinuationUtilities.GetContinuationStylePreview(RulesProfiles[idx].ContinuationStyle));

            toolTipDialogStylePreview.RemoveAll();
            toolTipDialogStylePreview.SetToolTip(comboBoxDialogStyle, DialogSplitMerge.GetDialogStylePreview(RulesProfiles[idx].DialogStyle));

            buttonEditCustomContinuationStyle.Visible = RulesProfiles[idx].ContinuationStyle == ContinuationStyle.Custom;
            comboBoxContinuationStyle.Width = RulesProfiles[idx].ContinuationStyle == ContinuationStyle.Custom ? (buttonEditCustomContinuationStyle.Left - comboBoxContinuationStyle.Left - 6) : (comboBoxDialogStyle.Right - comboBoxContinuationStyle.Left);
        }
Exemplo n.º 3
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            string fixAction    = string.Format(Language.FixHyphensInDialogs, Configuration.Settings.General.DialogStyle);
            int    iFixes       = 0;
            var    dialogHelper = new DialogSplitMerge
            {
                DialogStyle           = Configuration.Settings.General.DialogStyle,
                TwoLetterLanguageCode = callbacks.Language,
                ContinuationStyle     = Configuration.Settings.General.ContinuationStyle
            };

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string oldText = p.Text;
                    var    prev    = subtitle.GetParagraphOrDefault(i - 1);
                    string text    = dialogHelper.FixDashesAndSpaces(p.Text, p, prev);
                    if (text != oldText)
                    {
                        p.Text = text;
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, fixAction);
        }
Exemplo n.º 4
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language     = Configuration.Settings.Language.FixCommonErrors;
            string fixAction    = string.Format(language.FixHyphensInDialogs, Configuration.Settings.General.DialogStyle);
            int    iFixes       = 0;
            var    dialogHelper = new DialogSplitMerge {
                DialogStyle = Configuration.Settings.General.DialogStyle
            };

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];
                if (callbacks.AllowFix(p, fixAction))
                {
                    string oldText = p.Text;
                    string text    = dialogHelper.FixDashesAndSpaces(p.Text);
                    if (text != oldText)
                    {
                        p.Text = text;
                        iFixes++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(iFixes, fixAction, language.XHyphensInDialogsFixed);
        }
Exemplo n.º 5
0
        public void FixHyphensFirstLineParentheses()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var result = splitMerge.FixSpaces($"-(howling){Environment.NewLine}-I see what's on the other side.");

            Assert.AreEqual($"- (howling){Environment.NewLine}- I see what's on the other side.", result);
        }
Exemplo n.º 6
0
        public void FixSpacesDashBothLinesWithSpace4()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var result = splitMerge.FixSpaces($"<i>-How are you?</i>{Environment.NewLine}<i>-I'm fine.</i>");

            Assert.AreEqual($"<i>- How are you?</i>{Environment.NewLine}<i>- I'm fine.</i>", result);
        }
Exemplo n.º 7
0
        public void FixSpacesDashSecondLineWithoutSpace1()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashSecondLineWithoutSpace
            };
            var result = splitMerge.FixSpaces($"How are you?{Environment.NewLine}- I'm fine.'");

            Assert.AreEqual($"How are you?{Environment.NewLine}-I'm fine.'", result);
        }
Exemplo n.º 8
0
        public void FixHyphensThreeLinesOneTwoDashSecondLineWithSpace()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashSecondLineWithSpace
            };
            var result = splitMerge.FixDashesAndSpaces($"-What are you?{Environment.NewLine}-I'm a{ Environment.NewLine}one-in-a-generation artist.");

            Assert.AreEqual($"What are you?{Environment.NewLine}- I'm a{ Environment.NewLine}one-in-a-generation artist.", result);
        }
Exemplo n.º 9
0
        public void FixSpacesDashBothLinesWithSpace3()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var result = splitMerge.FixSpaces($"{{\\an8}}-How are you?{Environment.NewLine}{{\\an8}}-I'm fine.");

            Assert.AreEqual($"{{\\an8}}- How are you?{Environment.NewLine}{{\\an8}}- I'm fine.", result);
        }
Exemplo n.º 10
0
        public void FixHyphensThreeLinesTwoOneNoSpace()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithoutSpace
            };
            var result = splitMerge.FixDashesAndSpaces($"- I'm a'{Environment.NewLine}one-in-a-generation artist.{Environment.NewLine}- Oh.");

            Assert.AreEqual($"-I'm a'{Environment.NewLine}one-in-a-generation artist.{Environment.NewLine}-Oh.", result);
        }
Exemplo n.º 11
0
        public void FixHyphensWithQuotes()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var result = splitMerge.FixDashes($"\"Into The Woods.\"{Environment.NewLine}- \"Sweeney Todd.\"");

            Assert.AreEqual($"- \"Into The Woods.\"{Environment.NewLine}- \"Sweeney Todd.\"", result);
        }
Exemplo n.º 12
0
        public void FixHyphensAddDash1()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var result = splitMerge.FixDashes($"Hi Joe!{Environment.NewLine}- Hi Pete!");

            Assert.AreEqual($"- Hi Joe!{Environment.NewLine}- Hi Pete!", result);
        }
Exemplo n.º 13
0
        public void FixHyphensTwoLinesWithSpaceMissingSecondLine()
        {
            var splitMerge = new DialogSplitMerge {
                DialogStyle = DialogType.DashBothLinesWithSpace
            };
            var p      = new Paragraph($"- You can't talk either.{Environment.NewLine}That's what I said.", 4000, 7000);
            var result = splitMerge.FixDashesAndSpaces(p.Text, p, null);

            Assert.AreEqual($"- You can't talk either.{Environment.NewLine}- That's what I said.", result);
        }
        public void Check(Subtitle subtitle, NetflixQualityController controller)
        {
            if (controller.Language == "ja")
            {
                return;
            }

            var dialogHelper = new DialogSplitMerge {
                DialogStyle = controller.SpeakerStyle
            };
            string comment = "Dual Speakers: Use a hyphen without a space";

            if (controller.SpeakerStyle == DialogType.DashBothLinesWithSpace)
            {
                comment = "Dual Speakers: Use a hyphen with a space";
            }
            else if (controller.SpeakerStyle == DialogType.DashSecondLineWithSpace)
            {
                comment = "Dual Speakers: Use a hyphen with a space to denote the second speaker only";
            }
            else if (controller.SpeakerStyle == DialogType.DashSecondLineWithoutSpace)
            {
                comment = "Dual Speakers: Use a hyphen without a space to denote the second speaker only";
            }

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var    p       = subtitle.Paragraphs[i];
                string oldText = p.Text;
                string newText = dialogHelper.FixDashesAndSpaces(p.Text, p, subtitle.GetParagraphOrDefault(i - 1));
                if (newText != oldText)
                {
                    var fixedParagraph = new Paragraph(p, false)
                    {
                        Text = newText
                    };
                    controller.AddRecord(p, fixedParagraph, comment);
                }
            }
        }
Exemplo n.º 15
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language      = Configuration.Settings.Language.FixCommonErrors;
            string languageCode  = callbacks.Language;
            string fixAction     = language.FixMissingSpace;
            int    missingSpaces = 0;
            var    dialogHelper  = new DialogSplitMerge {
                DialogStyle = Configuration.Settings.General.DialogStyle
            };
            const string expectedChars = @"""”<.";

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                var p = subtitle.Paragraphs[i];

                // missing space after comma ","
                var match = FixMissingSpacesReComma.Match(p.Text);
                while (match.Success)
                {
                    bool doFix = !expectedChars.Contains(p.Text[match.Index + 2]);

                    if (doFix && languageCode == "el" &&
                        (p.Text.Substring(match.Index).StartsWith("ό,τι", StringComparison.Ordinal) ||
                         p.Text.Substring(match.Index).StartsWith("O,τι", StringComparison.Ordinal) ||
                         p.Text.Substring(match.Index).StartsWith("Ό,τι", StringComparison.Ordinal) ||
                         p.Text.Substring(match.Index).StartsWith("Ο,ΤΙ", StringComparison.Ordinal) ||
                         p.Text.Substring(match.Index).StartsWith("ο,τι", StringComparison.Ordinal)))
                    {
                        doFix = false;
                    }

                    if (doFix && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = p.Text.Replace(match.Value, match.Value[0] + ", " + match.Value[match.Value.Length - 1]);
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    match = match.NextMatch();
                }

                bool allowFix = callbacks.AllowFix(p, fixAction);

                // missing space after "?"
                match = FixMissingSpacesReQuestionMark.Match(p.Text);
                while (match.Success)
                {
                    if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = p.Text.Replace(match.Value, match.Value[0] + "? " + match.Value[match.Value.Length - 1]);
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    match = FixMissingSpacesReQuestionMark.Match(p.Text, match.Index + 1);
                }

                // missing space after "!"
                match = FixMissingSpacesReExclamation.Match(p.Text);
                while (match.Success)
                {
                    if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = p.Text.Replace(match.Value, match.Value[0] + "! " + match.Value[match.Value.Length - 1]);
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    match = FixMissingSpacesReExclamation.Match(p.Text, match.Index + 1);
                }

                // missing space after ":"
                match = FixMissingSpacesReColon.Match(p.Text);
                while (match.Success)
                {
                    int start = match.Index;
                    start -= 4;
                    if (start < 0)
                    {
                        start = 0;
                    }

                    int indexOfStartCodeTag = p.Text.IndexOf('{', start);
                    int indexOfEndCodeTag   = p.Text.IndexOf('}', start);
                    if (indexOfStartCodeTag >= 0 && indexOfEndCodeTag >= 0 && indexOfStartCodeTag < match.Index)
                    {
                        // we are inside a tag: like indexOfEndCodeTag "{y:i}Is this italic?"
                    }
                    else if (allowFix && !@"""<".Contains(p.Text[match.Index + 2]))
                    {
                        bool skipSwedishOrFinish = false;
                        if (languageCode == "sv" || languageCode == "fi")
                        {
                            var m = FixMissingSpacesReColonWithAfter.Match(p.Text, match.Index);
                            skipSwedishOrFinish = IsSwedishSkipValue(languageCode, m) || IsFinnishSkipValue(languageCode, m);
                        }
                        if (!skipSwedishOrFinish)
                        {
                            missingSpaces++;
                            string oldText = p.Text;
                            p.Text = p.Text.Replace(match.Value, match.Value[0] + ": " + match.Value[match.Value.Length - 1]);
                            callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                        }
                    }
                    match = FixMissingSpacesReColon.Match(p.Text, match.Index + 1);
                }

                // missing space after period "."
                match = FixMissingSpacesRePeriod.Match(p.Text);
                while (match.Success)
                {
                    if (!p.Text.Contains("www.", StringComparison.OrdinalIgnoreCase) &&
                        !p.Text.Contains("http://", StringComparison.OrdinalIgnoreCase) &&
                        !Url.IsMatch(p.Text)) // Skip urls.
                    {
                        bool isMatchAbbreviation = false;

                        string word = GetWordFromIndex(p.Text, match.Index);
                        if (Utilities.CountTagInText(word, '.') > 1)
                        {
                            isMatchAbbreviation = true;
                        }

                        if (!isMatchAbbreviation && word.Contains('@')) // skip emails
                        {
                            isMatchAbbreviation = true;
                        }

                        if (match.Value.Equals("h.d", StringComparison.OrdinalIgnoreCase) && match.Index > 0 && p.Text.Substring(match.Index - 1, 4).Equals("ph.d", StringComparison.OrdinalIgnoreCase))
                        {
                            isMatchAbbreviation = true;
                        }

                        if (!isMatchAbbreviation && callbacks.AllowFix(p, fixAction))
                        {
                            missingSpaces++;
                            string oldText = p.Text;
                            p.Text = p.Text.Replace(match.Value, match.Value.Replace(".", ". "));
                            callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                        }
                    }
                    match = match.NextMatch();
                }

                if (!p.Text.StartsWith("--", StringComparison.Ordinal))
                {
                    var newText = dialogHelper.AddSpaces(p.Text);
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }

                //fix missing spaces before/after quotes - Get a"get out of jail free"card. -> Get a "get out of jail free" card.
                if (Utilities.CountTagInText(p.Text, '"') == 2)
                {
                    int    start = p.Text.IndexOf('"');
                    int    end   = p.Text.LastIndexOf('"');
                    string quote = p.Text.Substring(start, end - start + 1);
                    if (!quote.Contains(Environment.NewLine))
                    {
                        string newText         = p.Text;
                        int    indexOfFontTag  = newText.IndexOf("<font ", StringComparison.OrdinalIgnoreCase);
                        bool   isAfterAssTag   = newText.Contains("{\\") && start > 0 && newText[start - 1] == '}';
                        bool   isAfterEllipsis = start >= 3 && newText.Substring(start - 3, 3) == "...";
                        if (!isAfterAssTag && !isAfterEllipsis && start > 0 && !(Environment.NewLine + @" >[(♪♫¿").Contains(p.Text[start - 1]))
                        {
                            if (indexOfFontTag < 0 || start > newText.IndexOf('>', indexOfFontTag)) // font tags can contain "
                            {
                                newText = newText.Insert(start, " ");
                                end++;
                            }
                        }
                        if (end < newText.Length - 2 && !(Environment.NewLine + @" <,.!?:;])♪♫¿").Contains(p.Text[end + 1]))
                        {
                            if (indexOfFontTag < 0 || end > newText.IndexOf('>', indexOfFontTag)) // font tags can contain "
                            {
                                newText = newText.Insert(end + 1, " ");
                            }
                        }
                        if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                        {
                            missingSpaces++;
                            string oldText = p.Text;
                            p.Text = newText;
                            callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                        }
                    }
                }

                //fix missing spaces before/after music quotes - #He's so happy# -> #He's so happy#
                var musicSymbols = new[] { '#', '♪', '♫' };
                if (p.Text.Length > 5 && p.Text.Contains(musicSymbols))
                {
                    var lines = p.Text.SplitToLines();
                    for (var lineIndex = 0; lineIndex < lines.Count; lineIndex++)
                    {
                        var lineNoHtmlAndMusicTags = HtmlUtil.RemoveHtmlTags(lines[lineIndex], true)
                                                     .RemoveChar('#')
                                                     .RemoveChar('♪')
                                                     .RemoveChar('♫');
                        if (lineNoHtmlAndMusicTags.Length > 1)
                        {
                            foreach (var musicSymbol in musicSymbols)
                            {
                                var fix = !(musicSymbol == '#' && Utilities.CountTagInText(lines[lineIndex], musicSymbol) == 1 && !lines[lineIndex].EndsWith(musicSymbol));
                                if (fix)
                                {
                                    lines[lineIndex] = FixMissingSpaceBeforeAfterMusicQuotes(lines[lineIndex], musicSymbol);
                                }
                            }
                        }
                    }
                    string newText = string.Join(Environment.NewLine, lines);
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }

                //fix missing spaces in "Hey...move it!" to "Hey... move it!"
                int index = p.Text.IndexOf("...", StringComparison.Ordinal);
                if (index > 0 && p.Text.Length > 5)
                {
                    string newText = p.Text;
                    while (index != -1)
                    {
                        if (newText.Length > index + 4 && index >= 1)
                        {
                            if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3]) &&
                                Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
                            {
                                newText = newText.Insert(index + 3, " ");
                            }
                        }
                        index = newText.IndexOf("...", index + 2, StringComparison.Ordinal);
                    }
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }

                //fix missing spaces in "The<i>Bombshell</i> will gone." to "The <i>Bombshell</i> will gone."
                index = p.Text.IndexOf("<i>", StringComparison.OrdinalIgnoreCase);
                if (index >= 0 && p.Text.Length > 5)
                {
                    string newText = p.Text;
                    while (index != -1)
                    {
                        if (newText.Length > index + 6 && index > 1)
                        {
                            if (Utilities.AllLettersAndNumbers.Contains(newText[index + 3]) &&
                                Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
                            {
                                newText = newText.Insert(index, " ");
                            }
                        }
                        index = newText.IndexOf("<i>", index + 3, StringComparison.OrdinalIgnoreCase);
                    }
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }

                //fix missing spaces in "The <i>Bombshell</i>will gone." to "The <i>Bombshell</i> will gone."
                index = p.Text.IndexOf("</i>", StringComparison.OrdinalIgnoreCase);
                if (index > 3 && p.Text.Length > 5)
                {
                    string newText = p.Text;
                    while (index != -1)
                    {
                        if (newText.Length > index + 6 && index > 1)
                        {
                            if (Utilities.AllLettersAndNumbers.Contains(newText[index + 4]) &&
                                Utilities.AllLettersAndNumbers.Contains(newText[index - 1]))
                            {
                                newText = newText.Insert(index + 4, " ");
                            }
                        }
                        index = newText.IndexOf("</i>", index + 4, StringComparison.OrdinalIgnoreCase);
                    }
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }

                if (callbacks.Language == "fr") // special rules for French
                {
                    string newText = p.Text;
                    int    j       = 1;
                    while (j < newText.Length)
                    {
                        if (@"!?:;".Contains(newText[j]) && char.IsLetter(newText[j - 1]))
                        {
                            newText = newText.Insert(j++, " ");
                        }
                        j++;
                    }
                    if (newText != p.Text && callbacks.AllowFix(p, fixAction))
                    {
                        missingSpaces++;
                        string oldText = p.Text;
                        p.Text = newText;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                }
            }
            callbacks.UpdateFixStatus(missingSpaces, language.FixMissingSpaces, string.Format(language.XMissingSpacesAdded, missingSpaces));
        }
Exemplo n.º 16
0
        private void listViewProfiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            var idx = listViewProfiles.SelectedItems.Count > 0 ? listViewProfiles.SelectedItems[0].Index : -1;
            if (idx < 0 || idx >= RulesProfiles.Count)
            {
                return;
            }

            var oldEditOn = _editOn;
            _editOn = false;
            var p = RulesProfiles[idx];
            textBoxName.Text = p.Name;
            if (p.SubtitleLineMaximumLength >= numericUpDownSubtitleLineMaximumLength.Minimum && p.SubtitleLineMaximumLength <= numericUpDownSubtitleLineMaximumLength.Maximum)
            {
                numericUpDownSubtitleLineMaximumLength.Value = p.SubtitleLineMaximumLength;
            }
            if (p.SubtitleOptimalCharactersPerSeconds >= numericUpDownOptimalCharsSec.Minimum && p.SubtitleOptimalCharactersPerSeconds <= numericUpDownOptimalCharsSec.Maximum)
            {
                numericUpDownOptimalCharsSec.Value = p.SubtitleOptimalCharactersPerSeconds;
            }
            if (p.SubtitleMaximumCharactersPerSeconds >= numericUpDownMaxCharsSec.Minimum && p.SubtitleMaximumCharactersPerSeconds <= numericUpDownMaxCharsSec.Maximum)
            {
                numericUpDownMaxCharsSec.Value = p.SubtitleMaximumCharactersPerSeconds;
            }
            if (p.SubtitleMinimumDisplayMilliseconds >= numericUpDownDurationMin.Minimum && p.SubtitleMinimumDisplayMilliseconds <= numericUpDownDurationMin.Maximum)
            {
                numericUpDownDurationMin.Value = p.SubtitleMinimumDisplayMilliseconds;
            }
            if (p.SubtitleMaximumDisplayMilliseconds >= numericUpDownDurationMax.Minimum && p.SubtitleMaximumDisplayMilliseconds <= numericUpDownDurationMax.Maximum)
            {
                numericUpDownDurationMax.Value = p.SubtitleMaximumDisplayMilliseconds;
            }
            if (p.MinimumMillisecondsBetweenLines >= numericUpDownMinGapMs.Minimum && p.MinimumMillisecondsBetweenLines <= numericUpDownMinGapMs.Maximum)
            {
                numericUpDownMinGapMs.Value = p.MinimumMillisecondsBetweenLines;
            }
            if (p.MaxNumberOfLines >= numericUpDownMaxNumberOfLines.Minimum && p.MaxNumberOfLines <= numericUpDownMaxNumberOfLines.Maximum)
            {
                numericUpDownMaxNumberOfLines.Value = p.MaxNumberOfLines;
            }
            else
            {
                numericUpDownMaxNumberOfLines.Value = numericUpDownMaxNumberOfLines.Minimum;
            }
            if (p.SubtitleMaximumWordsPerMinute >= numericUpDownMaxWordsMin.Minimum && p.SubtitleMaximumWordsPerMinute <= numericUpDownMaxWordsMin.Maximum)
            {
                numericUpDownMaxWordsMin.Value = p.SubtitleMaximumWordsPerMinute;
            }

            SetCpsLineLengthStyle(RulesProfiles[idx].CpsLineLengthStrategy);
            var comboIdx = RulesProfiles[idx].MergeLinesShorterThan - 1;
            if (comboIdx >= 0 && comboIdx < comboBoxMergeShortLineLength.Items.Count)
            {
                try
                {
                    comboBoxMergeShortLineLength.SelectedIndex = comboIdx;
                }
                catch
                {
                    comboBoxMergeShortLineLength.SelectedIndex = 0;
                }
            }
            else
            {
                comboBoxMergeShortLineLength.SelectedIndex = 0;
            }

            comboBoxDialogStyle.Items.Clear();
            comboBoxDialogStyle.Items.Add(LanguageSettings.Current.Settings.DialogStyleDashBothLinesWithSpace);
            comboBoxDialogStyle.Items.Add(LanguageSettings.Current.Settings.DialogStyleDashBothLinesWithoutSpace);
            comboBoxDialogStyle.Items.Add(LanguageSettings.Current.Settings.DialogStyleDashSecondLineWithSpace);
            comboBoxDialogStyle.Items.Add(LanguageSettings.Current.Settings.DialogStyleDashSecondLineWithoutSpace);
            toolTipDialogStylePreview.RemoveAll();
            switch (RulesProfiles[idx].DialogStyle)
            {
                case DialogType.DashBothLinesWithSpace:
                    comboBoxDialogStyle.SelectedIndex = 0;
                    toolTipDialogStylePreview.SetToolTip(comboBoxDialogStyle, DialogSplitMerge.GetDialogStylePreview(DialogType.DashBothLinesWithSpace));
                    break;
                case DialogType.DashBothLinesWithoutSpace:
                    comboBoxDialogStyle.SelectedIndex = 1;
                    toolTipDialogStylePreview.SetToolTip(comboBoxDialogStyle, DialogSplitMerge.GetDialogStylePreview(DialogType.DashBothLinesWithoutSpace));
                    break;
                case DialogType.DashSecondLineWithSpace:
                    comboBoxDialogStyle.SelectedIndex = 2;
                    toolTipDialogStylePreview.SetToolTip(comboBoxDialogStyle, DialogSplitMerge.GetDialogStylePreview(DialogType.DashSecondLineWithSpace));
                    break;
                case DialogType.DashSecondLineWithoutSpace:
                    comboBoxDialogStyle.SelectedIndex = 3;
                    toolTipDialogStylePreview.SetToolTip(comboBoxDialogStyle, DialogSplitMerge.GetDialogStylePreview(DialogType.DashSecondLineWithoutSpace));
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            comboBoxContinuationStyle.Items.Clear();
            foreach (var style in ContinuationUtilities.ContinuationStyles)
            {
                comboBoxContinuationStyle.Items.Add(UiUtil.GetContinuationStyleName(style));
            }
            comboBoxContinuationStyle.SelectedIndex = 0;
            toolTipContinuationPreview.RemoveAll();
            toolTipContinuationPreview.SetToolTip(comboBoxContinuationStyle, ContinuationUtilities.GetContinuationStylePreview(RulesProfiles[idx].ContinuationStyle));
            try
            {
                comboBoxContinuationStyle.SelectedIndex = ContinuationUtilities.GetIndexFromContinuationStyle(RulesProfiles[idx].ContinuationStyle);
            }
            catch
            { 
                // ignore
            }

            buttonEditCustomContinuationStyle.Visible = RulesProfiles[idx].ContinuationStyle == ContinuationStyle.Custom;
            comboBoxContinuationStyle.Width = RulesProfiles[idx].ContinuationStyle == ContinuationStyle.Custom ? (buttonEditCustomContinuationStyle.Left - comboBoxContinuationStyle.Left - 6) : (comboBoxDialogStyle.Right - comboBoxContinuationStyle.Left);

            _editOn = oldEditOn;
        }
Exemplo n.º 17
0
        public Subtitle SplitLongLinesInSubtitle(Subtitle subtitle, List <int> splitIndexes, List <int> autoBreakIndexes, out int numberOfSplits, int totalLineMaxCharacters, int singleLineMaxCharacters, bool clearFixes)
        {
            listViewFixes.ItemChecked -= listViewFixes_ItemChecked;
            if (clearFixes)
            {
                listViewFixes.Items.Clear();
            }

            numberOfSplits = 0;
            string language      = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
            var    splitSubtitle = new Subtitle();

            string[] expectedPunctuations = { ". -", "! -", "? -" };
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                bool added = false;
                var  p     = subtitle.Paragraphs[i];
                if (p?.Text != null)
                {
                    if (SplitLongLinesHelper.QualifiesForSplit(p.Text, singleLineMaxCharacters, totalLineMaxCharacters) && IsFixAllowed(p))
                    {
                        string oldText    = HtmlUtil.RemoveHtmlTags(p.Text);
                        bool   isDialog   = false;
                        string dialogText = string.Empty;
                        if (p.Text.Contains('-'))
                        {
                            dialogText = Utilities.AutoBreakLine(p.Text, 5, 1, language);

                            var tempText = p.Text.Replace(Environment.NewLine, " ").Replace("  ", " ");
                            if (Utilities.CountTagInText(tempText, '-') == 2 && (p.Text.StartsWith('-') || p.Text.StartsWith("<i>-", StringComparison.Ordinal)))
                            {
                                int idx = tempText.IndexOfAny(expectedPunctuations, StringComparison.Ordinal);
                                if (idx > 1)
                                {
                                    dialogText = tempText.Remove(idx + 1, 1).Insert(idx + 1, Environment.NewLine);
                                }
                            }

                            var dialogHelper = new DialogSplitMerge();
                            if (dialogHelper.IsDialog(dialogText.SplitToLines()))
                            {
                                isDialog = true;
                            }
                        }

                        if (!isDialog && !SplitLongLinesHelper.QualifiesForSplit(Utilities.AutoBreakLine(p.Text, language), singleLineMaxCharacters, totalLineMaxCharacters))
                        {
                            var newParagraph = new Paragraph(p)
                            {
                                Text = Utilities.AutoBreakLine(p.Text, language)
                            };
                            if (clearFixes)
                            {
                                AddToListView(p, (splitSubtitle.Paragraphs.Count + 1).ToString(CultureInfo.InvariantCulture), oldText);
                            }

                            autoBreakIndexes.Add(splitSubtitle.Paragraphs.Count);
                            splitSubtitle.Paragraphs.Add(newParagraph);
                            added = true;
                            numberOfSplits++;
                        }
                        else
                        {
                            string text = Utilities.AutoBreakLine(p.Text, language);
                            if (isDialog)
                            {
                                text = dialogText;
                            }

                            if (isDialog || text.Contains(Environment.NewLine))
                            {
                                var arr = text.SplitToLines();
                                if (arr.Count == 2)
                                {
                                    int spacing1 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
                                    int spacing2 = Configuration.Settings.General.MinimumMillisecondsBetweenLines / 2;
                                    if (Configuration.Settings.General.MinimumMillisecondsBetweenLines % 2 == 1)
                                    {
                                        spacing2++;
                                    }

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

                                    double middle = p.StartTime.TotalMilliseconds + p.Duration.TotalMilliseconds / 2;
                                    if (!string.IsNullOrWhiteSpace(oldText))
                                    {
                                        var startFactor = (double)HtmlUtil.RemoveHtmlTags(newParagraph1.Text).Length / 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 (Configuration.Settings.General.SplitRemovesDashes && isDialog)
                                    {
                                        newParagraph1.Text = DialogSplitMerge.RemoveStartDash(newParagraph1.Text);
                                        newParagraph2.Text = DialogSplitMerge.RemoveStartDash(newParagraph2.Text);
                                    }

                                    if (clearFixes)
                                    {
                                        AddToListView(p, (splitSubtitle.Paragraphs.Count + 1).ToString(CultureInfo.InvariantCulture), oldText);
                                    }

                                    splitIndexes.Add(splitSubtitle.Paragraphs.Count);
                                    splitIndexes.Add(splitSubtitle.Paragraphs.Count + 1);

                                    string p1 = HtmlUtil.RemoveHtmlTags(newParagraph1.Text).TrimEnd();
                                    if (!p1.EndsWith('.') && !p1.EndsWith('!') && !p1.EndsWith('?') && !p1.EndsWith(':') && !p1.EndsWith(')') && !p1.EndsWith(']') && !p1.EndsWith('♪'))
                                    {
                                        bool endsWithComma = newParagraph1.Text.EndsWith(',') || newParagraph1.Text.EndsWith(",</i>", StringComparison.Ordinal);

                                        string post = string.Empty;
                                        if (newParagraph1.Text.EndsWith("</i>", StringComparison.Ordinal))
                                        {
                                            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>", StringComparison.Ordinal))
                                        {
                                            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;
                                        }
                                    }

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

                                    splitSubtitle.Paragraphs.Add(newParagraph1);
                                    splitSubtitle.Paragraphs.Add(newParagraph2);
                                    added = true;
                                    numberOfSplits++;
                                }
                            }
                        }
                    }
                    if (!added)
                    {
                        splitSubtitle.Paragraphs.Add(new Paragraph(p));
                    }
                }
            }
            listViewFixes.ItemChecked += listViewFixes_ItemChecked;
            splitSubtitle.Renumber();
            return(splitSubtitle);
        }