Exemplo n.º 1
0
        public void Initialize(Subtitle subtitle, string fileName, SubtitleFormat format)
        {
            ShowBasic = false;
            _subtitle = subtitle;
            if (string.IsNullOrEmpty(fileName))
                textBoxFileName.Text = Configuration.Settings.Language.SplitSubtitle.Untitled;
            else
                textBoxFileName.Text = fileName;
            _fileName = fileName;
            foreach (Paragraph p in _subtitle.Paragraphs)
                _totalNumberOfCharacters += p.Text.Length;
            labelLines.Text = string.Format(Configuration.Settings.Language.Split.NumberOfLinesX, _subtitle.Paragraphs.Count);
            labelCharacters.Text = string.Format(Configuration.Settings.Language.Split.NumberOfCharactersX, _totalNumberOfCharacters);

            try
            {
                numericUpDownParts.Value = Configuration.Settings.Tools.SplitNumberOfParts;
            }
            catch
            {
            }

            if (Configuration.Settings.Tools.SplitVia.Trim().Equals("lines", StringComparison.OrdinalIgnoreCase))
                RadioButtonLines.Checked = true;
            else
                radioButtonCharacters.Checked = true;

            foreach (SubtitleFormat f in SubtitleFormat.AllSubtitleFormats)
            {
                if (!f.IsVobSubIndexFile)
                    comboBoxSubtitleFormats.Items.Add(f.FriendlyName);
                if (f.FriendlyName == format.FriendlyName)
                    comboBoxSubtitleFormats.SelectedIndex = comboBoxSubtitleFormats.Items.Count - 1;
            }

            comboBoxEncoding.Items.Clear();
            int encodingSelectedIndex = 0;
            comboBoxEncoding.Items.Add(Encoding.UTF8.EncodingName);
            foreach (EncodingInfo ei in Encoding.GetEncodings())
            {
                if (ei.Name != Encoding.UTF8.BodyName && ei.CodePage >= 949 && !ei.DisplayName.Contains("EBCDIC") && ei.CodePage != 1047)
                {
                    comboBoxEncoding.Items.Add(ei.CodePage + ": " + ei.DisplayName);
                    if (ei.Name == Configuration.Settings.General.DefaultEncoding)
                        encodingSelectedIndex = comboBoxEncoding.Items.Count - 1;
                }
            }
            comboBoxEncoding.SelectedIndex = encodingSelectedIndex;

            if (numericUpDownParts.Maximum > _subtitle.Paragraphs.Count)
                numericUpDownParts.Maximum = _subtitle.Paragraphs.Count / 2;

            if (!string.IsNullOrEmpty(_fileName))
                textBoxOutputFolder.Text = Path.GetDirectoryName(_fileName);
            else if (string.IsNullOrEmpty(Configuration.Settings.Tools.SplitOutputFolder) || !Directory.Exists(Configuration.Settings.Tools.SplitOutputFolder))
                textBoxOutputFolder.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            else
                textBoxOutputFolder.Text = Configuration.Settings.Tools.SplitOutputFolder;
        }
Exemplo n.º 2
0
 public void Initialize(Subtitle subtitle, string fileName, SubtitleFormat format, Encoding encoding, double lengthInSeconds)
 {
     ShowAdvanced = false;
     _subtitle = subtitle;
     _fileName = fileName;
     _format = format;
     _encoding = encoding;
     splitTimeUpDownAdjust.TimeCode = TimeCode.FromSeconds(lengthInSeconds);
 }
Exemplo n.º 3
0
 public ThreadDoWorkParameter(bool fixCommonErrors, bool multipleReplace, bool splitLongLinesActive, bool autoBalance, bool setMinDisplayTimeBetweenSubtitles, ListViewItem item, Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language, string fileName, string toFormat, SubtitleFormat sourceFormat)
 {
     FixCommonErrors = fixCommonErrors;
     MultipleReplaceActive = multipleReplace;
     SplitLongLinesActive = splitLongLinesActive;
     AutoBalanceActive = autoBalance;
     SetMinDisplayTimeBetweenSubtitles = setMinDisplayTimeBetweenSubtitles;
     Item = item;
     Subtitle = subtitle;
     Format = format;
     Encoding = encoding;
     Language = language;
     FileName = fileName;
     ToFormat = toFormat;
     SourceFormat = sourceFormat;
 }
Exemplo n.º 4
0
        public void Initialize(Subtitle subtitle, string fileName, SubtitleFormat format)
        {
            ShowBasic = false;
            _subtitle = subtitle;
            if (string.IsNullOrEmpty(fileName))
                textBoxFileName.Text = Configuration.Settings.Language.SplitSubtitle.Untitled;
            else
                textBoxFileName.Text = fileName;
            _fileName = fileName;
            foreach (Paragraph p in _subtitle.Paragraphs)
                _totalNumberOfCharacters += p.Text.Length;
            labelLines.Text = string.Format(Configuration.Settings.Language.Split.NumberOfLinesX, _subtitle.Paragraphs.Count);
            labelCharacters.Text = string.Format(Configuration.Settings.Language.Split.NumberOfCharactersX, _totalNumberOfCharacters);

            try
            {
                numericUpDownParts.Value = Configuration.Settings.Tools.SplitNumberOfParts;
            }
            catch
            {
            }

            if (Configuration.Settings.Tools.SplitVia.Trim().Equals("lines", StringComparison.OrdinalIgnoreCase))
                RadioButtonLines.Checked = true;
            else
                radioButtonCharacters.Checked = true;

            UiUtil.InitializeSubtitleFormatComboBox(comboBoxSubtitleFormats, format.FriendlyName);

            UiUtil.InitializeTextEncodingComboBox(comboBoxEncoding);

            if (numericUpDownParts.Maximum > _subtitle.Paragraphs.Count)
                numericUpDownParts.Maximum = _subtitle.Paragraphs.Count / 2;

            if (!string.IsNullOrEmpty(_fileName))
                textBoxOutputFolder.Text = Path.GetDirectoryName(_fileName);
            else if (string.IsNullOrEmpty(Configuration.Settings.Tools.SplitOutputFolder) || !Directory.Exists(Configuration.Settings.Tools.SplitOutputFolder))
                textBoxOutputFolder.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            else
                textBoxOutputFolder.Text = Configuration.Settings.Tools.SplitOutputFolder;
        }
Exemplo n.º 5
0
        public Statistics(Subtitle subtitle, string fileName, SubtitleFormat format)
        {
            InitializeComponent();

            _subtitle = subtitle;
            _format = format;

            _l = Configuration.Settings.Language.Statistics;
            if (string.IsNullOrEmpty(fileName))
                Text = _l.Title;
            else
                Text = string.Format(_l.TitleWithFileName, fileName);
            groupBoxGeneral.Text = _l.GeneralStatistics;
            groupBoxMostUsed.Text = _l.MostUsed;
            labelMostUsedWords.Text = _l.MostUsedWords;
            labelMostUsedLines.Text = _l.MostUsedLines;
            buttonExport.Text = _l.Export;
            buttonOK.Text = Configuration.Settings.Language.General.Ok;
            UiUtil.FixLargeFonts(this, buttonOK);

            CalculateGeneralStatistics();
            {
                textBoxGeneral.Text = _general;
                textBoxGeneral.SelectionStart = 0;
                textBoxGeneral.SelectionLength = 0;
                textBoxGeneral.ScrollToCaret();
            }
            CalculateMostUsedWords();
            {
                textBoxMostUsedWords.Text = _mostUsedWords;
            }
            CalculateMostUsedLines();
            {
                textBoxMostUsedLines.Text = _mostUsedLines;
            }
        }
Exemplo n.º 6
0
        private void ComboBoxSubtitleFormatsSelectedIndexChanged(object sender, EventArgs e)
        {
            _converted = true;
            if (_oldSubtitleFormat == null)
            {
                if (!_loading)
                    MakeHistoryForUndo(string.Format(_language.BeforeConvertingToX, GetCurrentSubtitleFormat().FriendlyName));
            }
            else
            {
                _subtitle.MakeHistoryForUndo(string.Format(_language.BeforeConvertingToX, GetCurrentSubtitleFormat().FriendlyName), _oldSubtitleFormat, _fileDateTime, _subtitleAlternate, _subtitleAlternateFileName, _subtitleListViewIndex, textBoxListViewText.SelectionStart, textBoxListViewTextAlternate.SelectionStart);
                _oldSubtitleFormat.RemoveNativeFormatting(_subtitle, GetCurrentSubtitleFormat());
                SaveSubtitleListviewIndices();
                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                RestoreSubtitleListviewIndices();

                if (_oldSubtitleFormat.HasStyleSupport && _networkSession == null)
                {
                    SubtitleListview1.HideExtraColumn();
                }
            }
            SubtitleFormat format = GetCurrentSubtitleFormat();
            if (_oldSubtitleFormat != null && !_oldSubtitleFormat.IsFrameBased && format.IsFrameBased)
                _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
            else if (_oldSubtitleFormat != null && _oldSubtitleFormat.IsFrameBased && !format.IsFrameBased)
                _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
            ShowSource();
            SubtitleListview1.DisplayExtraFromExtra = false;
            if (format != null)
            {
                ShowStatus(string.Format(_language.ConvertedToX, format.FriendlyName));
                _oldSubtitleFormat = format;

                if (format.HasStyleSupport && _networkSession == null)
                {
                    var styles = new List<string>();
                    var formatType = format.GetType();
                    if (formatType == typeof(AdvancedSubStationAlpha) || formatType == typeof(SubStationAlpha))
                        styles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
                    else if (formatType == typeof(TimedText10) || formatType == typeof(ItunesTimedText))
                        styles = TimedText10.GetStylesFromHeader(_subtitle.Header);
                    else if (formatType == typeof(Sami) || formatType == typeof(SamiModern))
                        styles = Sami.GetStylesFromHeader(_subtitle.Header);
                    else if (format.Name == "Nuendo")
                        styles = GetNuendoStyles();

                    foreach (var p in _subtitle.Paragraphs)
                    {
                        if (string.IsNullOrEmpty(p.Extra) && styles.Count > 0)
                            p.Extra = styles[0];
                    }

                    if (formatType == typeof(Sami) || formatType == typeof(SamiModern))
                        SubtitleListview1.ShowExtraColumn(_languageGeneral.Class);
                    else if (formatType == typeof(TimedText10) || formatType == typeof(ItunesTimedText))
                        SubtitleListview1.ShowExtraColumn(_languageGeneral.StyleLanguage);
                    else if (format.Name == "Nuendo")
                        SubtitleListview1.ShowExtraColumn(_languageGeneral.Character);
                    else
                        SubtitleListview1.ShowExtraColumn(_languageGeneral.Style);

                    SubtitleListview1.DisplayExtraFromExtra = true;
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                }
            }
            ShowHideTextBasedFeatures(format);
        }
Exemplo n.º 7
0
        private DialogResult SaveOriginalSubtitle(SubtitleFormat format)
        {
            try
            {
                string allText = _subtitleAlternate.ToText(format).Trim();
                var currentEncoding = GetCurrentEncoding();
                bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
                if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
                {
                    if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (!isUnicode)
                {
                    allText = NormalizeUnicode(allText);
                }

                bool containsNegativeTime = false;
                foreach (var p in _subtitleAlternate.Paragraphs)
                {
                    if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
                    {
                        containsNegativeTime = true;
                        break;
                    }
                }
                if (containsNegativeTime)
                {
                    if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                File.WriteAllText(_subtitleAlternateFileName, allText, currentEncoding);
                ShowStatus(string.Format(_language.SavedOriginalSubtitleX, _subtitleAlternateFileName));
                _changeAlternateSubtitleToString = _subtitleAlternate.ToText(new SubRip()).Trim();
                return DialogResult.OK;
            }
            catch
            {
                MessageBox.Show(string.Format(_language.UnableToSaveSubtitleX, _fileName));
                return DialogResult.Cancel;
            }
        }
Exemplo n.º 8
0
        private void ImportAndOcrDost(string fileName, SubtitleFormat format, List<string> list)
        {
            using (var formSubOcr = new VobSubOcr())
            {
                var sub = new Subtitle();
                format.LoadSubtitle(sub, list, fileName);
                sub.FileName = fileName;
                formSubOcr.Initialize(sub, Configuration.Settings.VobSubOcr, false);
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingBdnXml);
                    FileNew();
                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (var p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    _subtitleListViewIndex = -1;
                    SubtitleListview1.FirstVisibleIndex = -1;
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    _fileName = Path.ChangeExtension(formSubOcr.FileName, ".srt");
                    SetTitle();
                    _converted = true;
                }
            }
        }
Exemplo n.º 9
0
        public void SetCurrentFormat(SubtitleFormat format)
        {
            if (format.IsVobSubIndexFile)
            {
                comboBoxSubtitleFormats.Items.Clear();
                comboBoxSubtitleFormats.Items.Add(format.FriendlyName);

                SubtitleListview1.HideNonVobSubColumns();
            }
            else if (comboBoxSubtitleFormats.Items.Count == 1)
            {
                SetFormatToSubRip();
                SubtitleListview1.ShowAllColumns();
            }

            int i = 0;
            foreach (object obj in comboBoxSubtitleFormats.Items)
            {
                if (obj.ToString() == format.FriendlyName)
                {
                    comboBoxSubtitleFormats.SelectedIndex = i;
                    return;
                }
                i++;
            }
        }
Exemplo n.º 10
0
 public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
 {
     foreach (Paragraph p in subtitle.Paragraphs)
     {
         if (p.Text.Contains('<'))
         {
             string text = p.Text;
             text = RemoveTag("v", text);
             text = RemoveTag("rt", text);
             text = RemoveTag("ruby", text);
             text = RemoveTag("c", text);
             p.Text = RemoveTag("span", text);
         }
     }
 }
Exemplo n.º 11
0
 public virtual void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
 {
 }
Exemplo n.º 12
0
        public SubStationAlphaStyles(Subtitle subtitle, SubtitleFormat format)
            : base(subtitle)
        {
            InitializeComponent();

            labelStatus.Text = string.Empty;
            _header = subtitle.Header;
            _format = format;
            _isSubStationAlpha = _format.Name == SubStationAlpha.NameOfFormat;
            if (_header == null || !_header.Contains("style:", StringComparison.OrdinalIgnoreCase))
                ResetHeader();

            comboBoxFontName.Items.Clear();
            foreach (var x in FontFamily.Families)
                comboBoxFontName.Items.Add(x.Name);

            var l = Configuration.Settings.Language.SubStationAlphaStyles;
            Text = l.Title;
            groupBoxStyles.Text = l.Styles;
            listViewStyles.Columns[0].Text = l.Name;
            listViewStyles.Columns[1].Text = l.FontName;
            listViewStyles.Columns[2].Text = l.FontSize;
            listViewStyles.Columns[3].Text = l.UseCount;
            listViewStyles.Columns[4].Text = l.Primary;
            listViewStyles.Columns[5].Text = l.Outline;
            groupBoxProperties.Text = l.Properties;
            labelStyleName.Text = l.Name;
            groupBoxFont.Text = l.Font;
            labelFontName.Text = l.FontName;
            labelFontSize.Text = l.FontSize;
            checkBoxFontItalic.Text = Configuration.Settings.Language.General.Italic;
            checkBoxFontBold.Text = Configuration.Settings.Language.General.Bold;
            checkBoxFontUnderline.Text = Configuration.Settings.Language.General.Underline;
            groupBoxAlignment.Text = l.Alignment;
            radioButtonTopLeft.Text = l.TopLeft;
            radioButtonTopCenter.Text = l.TopCenter;
            radioButtonTopRight.Text = l.TopRight;
            radioButtonMiddleLeft.Text = l.MiddleLeft;
            radioButtonMiddleCenter.Text = l.MiddleCenter;
            radioButtonMiddleRight.Text = l.MiddleRight;
            radioButtonBottomLeft.Text = l.BottomLeft;
            radioButtonBottomCenter.Text = l.BottomCenter;
            radioButtonBottomRight.Text = l.BottomRight;
            groupBoxColors.Text = l.Colors;
            buttonPrimaryColor.Text = l.Primary;
            buttonSecondaryColor.Text = l.Secondary;
            buttonOutlineColor.Text = l.Outline;
            buttonBackColor.Text = l.Shadow;
            groupBoxMargins.Text = l.Margins;
            labelMarginLeft.Text = l.MarginLeft;
            labelMarginRight.Text = l.MarginRight;
            labelMarginVertical.Text = l.MarginVertical;
            groupBoxBorder.Text = l.Border;
            radioButtonOutline.Text = l.Outline;
            labelShadow.Text = l.PlusShadow;
            radioButtonOpaqueBox.Text = l.OpaqueBox;
            buttonImport.Text = l.Import;
            buttonExport.Text = l.Export;
            buttonCopy.Text = l.Copy;
            buttonAdd.Text = l.New;
            buttonRemove.Text = l.Remove;
            buttonRemoveAll.Text = l.RemoveAll;
            groupBoxPreview.Text = Configuration.Settings.Language.General.Preview;

            if (_isSubStationAlpha)
            {
                Text = l.TitleSubstationAlpha;
                buttonOutlineColor.Text = l.Tertiary;
                buttonBackColor.Text = l.Back;
                listViewStyles.Columns[5].Text = l.Back;
                checkBoxFontUnderline.Visible = false;
            }

            buttonOK.Text = Configuration.Settings.Language.General.Ok;
            buttonCancel.Text = Configuration.Settings.Language.General.Cancel;

            InitializeListView();
            UiUtil.FixLargeFonts(this, buttonCancel);

            comboBoxFontName.Left = labelFontName.Left + labelFontName.Width + 10;
            numericUpDownFontSize.Left = labelFontSize.Left + labelFontSize.Width + 10;
            if (comboBoxFontName.Left > numericUpDownFontSize.Left)
                numericUpDownFontSize.Left = comboBoxFontName.Left;
            else
                comboBoxFontName.Left = numericUpDownFontSize.Left;

            numericUpDownOutline.Left = radioButtonOutline.Left + radioButtonOutline.Width + 5;
            labelShadow.Left = numericUpDownOutline.Left + numericUpDownOutline.Width + 5;
            numericUpDownShadowWidth.Left = labelShadow.Left + labelShadow.Width + 5;
            listViewStyles.Columns[5].Width = -2;
            checkBoxFontItalic.Left = checkBoxFontBold.Left + checkBoxFontBold.Width + 12;
            checkBoxFontUnderline.Left = checkBoxFontItalic.Left + checkBoxFontItalic.Width + 12;
        }
        public SubStationAlphaStylesBatchConvert(Subtitle subtitle, SubtitleFormat format)
            : base(subtitle)
        {
            InitializeComponent();

            comboBoxWrapStyle.SelectedIndex = 2;
            comboBoxCollision.SelectedIndex = 0;
            _header = subtitle.Header;
            _format = format;
            _isSubStationAlpha = _format.Name == SubStationAlpha.NameOfFormat;
            if (_header == null || !_header.Contains("style:", StringComparison.OrdinalIgnoreCase))
                ResetHeader();

            comboBoxFontName.Items.Clear();
            foreach (var x in FontFamily.Families)
                comboBoxFontName.Items.Add(x.Name);

            var l = Configuration.Settings.Language.SubStationAlphaStyles;
            Text = l.Title;
            // groupBoxStyles.Text = l.Styles;
            groupBoxProperties.Text = l.Properties;
            groupBoxFont.Text = l.Font;
            labelFontName.Text = l.FontName;
            labelFontSize.Text = l.FontSize;
            checkBoxFontItalic.Text = Configuration.Settings.Language.General.Italic;
            checkBoxFontBold.Text = Configuration.Settings.Language.General.Bold;
            checkBoxFontUnderline.Text = Configuration.Settings.Language.General.Underline;
            groupBoxAlignment.Text = l.Alignment;
            radioButtonTopLeft.Text = l.TopLeft;
            radioButtonTopCenter.Text = l.TopCenter;
            radioButtonTopRight.Text = l.TopRight;
            radioButtonMiddleLeft.Text = l.MiddleLeft;
            radioButtonMiddleCenter.Text = l.MiddleCenter;
            radioButtonMiddleRight.Text = l.MiddleRight;
            radioButtonBottomLeft.Text = l.BottomLeft;
            radioButtonBottomCenter.Text = l.BottomCenter;
            radioButtonBottomRight.Text = l.BottomRight;
            groupBoxColors.Text = l.Colors;
            buttonPrimaryColor.Text = l.Primary;
            buttonSecondaryColor.Text = l.Secondary;
            buttonOutlineColor.Text = l.Outline;
            buttonBackColor.Text = l.Shadow;
            groupBoxMargins.Text = l.Margins;
            labelMarginLeft.Text = l.MarginLeft;
            labelMarginRight.Text = l.MarginRight;
            labelMarginVertical.Text = l.MarginVertical;
            groupBoxBorder.Text = l.Border;
            radioButtonOutline.Text = l.Outline;
            labelShadow.Text = l.PlusShadow;
            radioButtonOpaqueBox.Text = l.OpaqueBox;
            //buttonExport.Text = l.Export;
            groupBoxPreview.Text = Configuration.Settings.Language.General.Preview;

            if (_isSubStationAlpha)
            {
                Text = l.TitleSubstationAlpha;
                buttonOutlineColor.Text = l.Tertiary;
                buttonBackColor.Text = l.Back;
                checkBoxFontUnderline.Visible = false;

                labelWrapStyle.Visible = false;
                comboBoxWrapStyle.Visible = false;
                checkBoxScaleBorderAndShadow.Visible = false;
            }

            buttonOK.Text = Configuration.Settings.Language.General.Ok;
            buttonCancel.Text = Configuration.Settings.Language.General.Cancel;

            UiUtil.FixLargeFonts(this, buttonCancel);

            comboBoxFontName.Left = labelFontName.Left + labelFontName.Width + 10;
            numericUpDownFontSize.Left = labelFontSize.Left + labelFontSize.Width + 10;
            if (comboBoxFontName.Left > numericUpDownFontSize.Left)
                numericUpDownFontSize.Left = comboBoxFontName.Left;
            else
                comboBoxFontName.Left = numericUpDownFontSize.Left;

            numericUpDownOutline.Left = radioButtonOutline.Left + radioButtonOutline.Width + 5;
            labelShadow.Left = numericUpDownOutline.Left + numericUpDownOutline.Width + 5;
            numericUpDownShadowWidth.Left = labelShadow.Left + labelShadow.Width + 5;
            checkBoxFontItalic.Left = checkBoxFontBold.Left + checkBoxFontBold.Width + 12;
            checkBoxFontUnderline.Left = checkBoxFontItalic.Left + checkBoxFontItalic.Width + 12;

            var l2 = Configuration.Settings.Language.SubStationAlphaProperties;
            groupBoxResolution.Text = l2.Resolution;
            labelVideoResolution.Text = l2.VideoResolution;
            groupBoxOptions.Text = l2.Options;
            labelCollision.Text = l2.Collision;
            labelWrapStyle.Text = l2.WrapStyle;
            checkBoxScaleBorderAndShadow.Text = l2.ScaleBorderAndShadow;
        }
Exemplo n.º 14
0
 public static void SetSaveDialogFilter(SaveFileDialog saveFileDialog, SubtitleFormat currentFormat)
 {
     var sb = new StringBuilder();
     int index = 0;
     foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
     {
         sb.Append(format.Name + "|*" + format.Extension + "|");
         if (currentFormat.Name == format.Name)
             saveFileDialog.FilterIndex = index + 1;
         index++;
     }
     saveFileDialog.Filter = sb.ToString().TrimEnd('|');
 }
Exemplo n.º 15
0
        public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName)
        {
            InitializeComponent();
            _subtitle = subtitle;
            _isSubStationAlpha = format.Name == SubStationAlpha.NameOfFormat;
            _videoFileName = videoFileName;

            var l = Configuration.Settings.Language.SubStationAlphaProperties;
            if (_isSubStationAlpha)
            {
                Text = l.TitleSubstationAlpha;
                labelWrapStyle.Visible = false;
                comboBoxWrapStyle.Visible = false;
                checkBoxScaleBorderAndShadow.Visible = false;
                Height = Height - (comboBoxWrapStyle.Height + checkBoxScaleBorderAndShadow.Height + 8);
            }
            else
            {
                Text = l.Title;
            }

            comboBoxWrapStyle.SelectedIndex = 2;
            comboBoxCollision.SelectedIndex = 0;

            string header = subtitle.Header;
            if (subtitle.Header == null)
            {
                var ssa = new SubStationAlpha();
                var sub = new Subtitle();
                var lines = new List<string>();
                foreach (string line in subtitle.ToText(ssa).SplitToLines())
                    lines.Add(line);
                string title = "Untitled";
                if (!string.IsNullOrEmpty(subtitleFileName))
                    title = Path.GetFileNameWithoutExtension(subtitleFileName);
                else if (!string.IsNullOrEmpty(videoFileName))
                    title = Path.GetFileNameWithoutExtension(videoFileName);
                ssa.LoadSubtitle(sub, lines, title);
                header = sub.Header;
            }

            if (header != null)
            {
                foreach (string line in header.SplitToLines())
                {
                    string s = line.ToLowerInvariant().Trim();
                    if (s.StartsWith("title:"))
                    {
                        textBoxTitle.Text = s.Remove(0, 6).Trim();
                    }
                    else if (s.StartsWith("original script:"))
                    {
                        textBoxOriginalScript.Text = s.Remove(0, 16).Trim();
                    }
                    else if (s.StartsWith("original translation:"))
                    {
                        textBoxTranslation.Text = s.Remove(0, 21).Trim();
                    }
                    else if (s.StartsWith("original editing:"))
                    {
                        textBoxEditing.Text = s.Remove(0, 17).Trim();
                    }
                    else if (s.StartsWith("original timing:"))
                    {
                        textBoxTiming.Text = s.Remove(0, 16).Trim();
                    }
                    else if (s.StartsWith("synch point:"))
                    {
                        textBoxSyncPoint.Text = s.Remove(0, 12).Trim();
                    }
                    else if (s.StartsWith("script updated by:"))
                    {
                        textBoxUpdatedBy.Text = s.Remove(0, 18).Trim();
                    }
                    else if (s.StartsWith("update details:"))
                    {
                        textBoxUpdateDetails.Text = s.Remove(0, 15).Trim();
                    }
                    else if (s.StartsWith("collisions:"))
                    {
                        if (s.Remove(0, 11).Trim() == "reverse")
                            comboBoxCollision.SelectedIndex = 1;
                    }
                    else if (s.StartsWith("playresx:"))
                    {
                        int number;
                        if (int.TryParse(s.Remove(0, 9).Trim(), out number))
                            numericUpDownVideoWidth.Value = number;
                    }
                    else if (s.StartsWith("playresy:"))
                    {
                        int number;
                        if (int.TryParse(s.Remove(0, 9).Trim(), out number))
                            numericUpDownVideoHeight.Value = number;
                    }
                    else if (s.StartsWith("scaledborderandshadow:"))
                    {
                        checkBoxScaleBorderAndShadow.Checked = s.Remove(0, 22).Trim().Equals("yes");
                    }
                }
            }

            groupBoxScript.Text = l.Script;
            labelTitle.Text = l.ScriptTitle;
            labelOriginalScript.Text = l.OriginalScript;
            labelTranslation.Text = l.Translation;
            labelEditing.Text = l.Editing;
            labelTiming.Text = l.Timing;
            labelSyncPoint.Text = l.SyncPoint;
            labelUpdatedBy.Text = l.UpdatedBy;
            labelUpdateDetails.Text = l.UpdateDetails;
            groupBoxResolution.Text = l.Resolution;
            labelVideoResolution.Text = l.VideoResolution;
            groupBoxOptions.Text = l.Options;
            labelCollision.Text = l.Collision;
            labelWrapStyle.Text = l.WrapStyle;
            checkBoxScaleBorderAndShadow.Text = l.ScaleBorderAndShadow;

            buttonOK.Text = Configuration.Settings.Language.General.Ok;
            buttonCancel.Text = Configuration.Settings.Language.General.Cancel;

            Utilities.FixLargeFonts(this, buttonCancel);
        }
 public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
 {
     new WebVTT().RemoveNativeFormatting(subtitle, newFormat);
 }
Exemplo n.º 17
0
 private bool CheckSkipFilter(string fileName, SubtitleFormat format, Subtitle sub)
 {
     bool skip = false;
     if (comboBoxFilter.SelectedIndex == 1)
     {
         if (format != null && format.GetType() == typeof(SubRip) && FileUtil.HasUtf8Bom(fileName))
             skip = true;
     }
     else if (comboBoxFilter.SelectedIndex == 2)
     {
         skip = true;
         foreach (Paragraph p in sub.Paragraphs)
         {
             if (p.Text != null && Utilities.GetNumberOfLines(p.Text) > 2)
             {
                 skip = false;
                 break;
             }
         }
     }
     else if (comboBoxFilter.SelectedIndex == 3 && !string.IsNullOrWhiteSpace(textBoxFilter.Text))
     {
         skip = true;
         foreach (Paragraph p in sub.Paragraphs)
         {
             if (p.Text != null && p.Text.Contains(textBoxFilter.Text, StringComparison.Ordinal))
             {
                 skip = false;
                 break;
             }
         }
     }
     return skip;
 }
Exemplo n.º 18
0
        internal void InitializeFromVobSubOcr(Subtitle subtitle, SubtitleFormat format, string exportType, string fileName, VobSubOcr vobSubOcr, string languageString)
        {
            _vobSubOcr = vobSubOcr;
            Initialize(subtitle, format, exportType, fileName, null, _videoFileName);

            //set language
            if (!string.IsNullOrEmpty(languageString))
            {
                if (languageString.Contains('(') && languageString[0] != '(')
                    languageString = languageString.Substring(0, languageString.IndexOf('(') - 1).Trim();
                for (int i = 0; i < comboBoxLanguage.Items.Count; i++)
                {
                    string l = comboBoxLanguage.Items[i].ToString();
                    if (l == languageString && i < comboBoxLanguage.Items.Count)
                        comboBoxLanguage.SelectedIndex = i;
                }
            }

            //Disable options not available when exporting existing images
            comboBoxSubtitleFont.Enabled = false;
            comboBoxSubtitleFontSize.Enabled = false;

            buttonColor.Visible = false;
            panelColor.Visible = false;
            checkBoxBold.Visible = false;
            checkBoxSimpleRender.Visible = false;
            comboBox3D.Enabled = false;
            numericUpDownDepth3D.Enabled = false;

            buttonBorderColor.Visible = false;
            panelBorderColor.Visible = false;
            labelBorderWidth.Visible = false;
            comboBoxBorderWidth.Visible = false;

            buttonShadowColor.Visible = false;
            panelShadowColor.Visible = false;
            labelShadowWidth.Visible = false;
            comboBoxShadowWidth.Visible = false;
            labelShadowTransparency.Visible = false;
            numericUpDownShadowTransparency.Visible = false;
            labelLineHeight.Visible = false;
            numericUpDownLineSpacing.Visible = false;
        }
        public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
        {
            if (newFormat != null && newFormat.Name == SubStationAlpha.NameOfFormat)
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    string s = p.Text;
                    if (s.Contains('{') && s.Contains('}'))
                    {
                        s = s.Replace(@"\u0", string.Empty);
                        s = s.Replace(@"\u1", string.Empty);
                        s = s.Replace(@"\s0", string.Empty);
                        s = s.Replace(@"\s1", string.Empty);
                        s = s.Replace(@"\be0", string.Empty);
                        s = s.Replace(@"\be1", string.Empty);

                        s = RemoveTag(s, "shad");
                        s = RemoveTag(s, "fsc");
                        s = RemoveTag(s, "fsp");
                        s = RemoveTag(s, "fr");

                        s = RemoveTag(s, "t(");
                        s = RemoveTag(s, "move(");
                        s = RemoveTag(s, "Position(");
                        s = RemoveTag(s, "org(");
                        s = RemoveTag(s, "fade(");
                        s = RemoveTag(s, "fad(");
                        s = RemoveTag(s, "clip(");
                        s = RemoveTag(s, "pbo(");

                        // TODO: Alignment tags

                        s = s.Replace("{}", string.Empty);

                        p.Text = s;
                    }
                }
            }
            else
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    int indexOfBegin = p.Text.IndexOf('{');
                    string pre = string.Empty;
                    while (indexOfBegin >= 0 && p.Text.IndexOf('}') > indexOfBegin)
                    {
                        string s = p.Text.Substring(indexOfBegin);
                        if (s.StartsWith("{\\an1}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an2}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an3}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an4}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an5}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an6}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an7}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an8}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an9}", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 6);
                        }
                        else if (s.StartsWith("{\\an1\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an2\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an3\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an4\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an5\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an6\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an7\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an8\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an9\\", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 5) + "}";
                        }
                        int indexOfEnd = p.Text.IndexOf('}');
                        p.Text = p.Text.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1);

                        indexOfBegin = p.Text.IndexOf('{');
                    }
                    p.Text = pre + p.Text;
                }
            }
        }
        public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
        {
            if (newFormat != null && newFormat.Name == AdvancedSubStationAlpha.NameOfFormat)
            {
                // do we need any conversion?
            }
            else
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    int indexOfBegin = p.Text.IndexOf('{');
                    string pre = string.Empty;
                    while (indexOfBegin >= 0 && p.Text.IndexOf('}') > indexOfBegin)
                    {
                        string s = p.Text.Substring(indexOfBegin);
                        if (s.StartsWith("{\\an1}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an2}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an3}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an4}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an5}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an6}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an7}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an8}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an9}", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 6);
                        }
                        else if (s.StartsWith("{\\an1\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an2\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an3\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an4\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an5\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an6\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an7\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an8\\", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an9\\", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 5) + "}";
                        }
                        else if (s.StartsWith("{\\a1}", StringComparison.Ordinal) || s.StartsWith("{\\a1\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\a3}", StringComparison.Ordinal) || s.StartsWith("{\\a3\\", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 4) + "}";
                        }
                        else if (s.StartsWith("{\\a9}", StringComparison.Ordinal) || s.StartsWith("{\\a9\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an4}";
                        }
                        else if (s.StartsWith("{\\a10}", StringComparison.Ordinal) || s.StartsWith("{\\a10\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an5}";
                        }
                        else if (s.StartsWith("{\\a11}", StringComparison.Ordinal) || s.StartsWith("{\\a11\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an6}";
                        }
                        else if (s.StartsWith("{\\a5}", StringComparison.Ordinal) || s.StartsWith("{\\a5\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an7}";
                        }
                        else if (s.StartsWith("{\\a6}", StringComparison.Ordinal) || s.StartsWith("{\\a6\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an8}";
                        }
                        else if (s.StartsWith("{\\a7}", StringComparison.Ordinal) || s.StartsWith("{\\a7\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an9}";
                        }
                        int indexOfEnd = p.Text.IndexOf('}');
                        p.Text = p.Text.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1);

                        indexOfBegin = p.Text.IndexOf('{');
                    }
                    p.Text = pre + p.Text;
                }
            }
        }
Exemplo n.º 21
0
        public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
        {
            var regexWebVttColorMulti   = new Regex(@"<c.[a-z0-9_\.]*>", RegexOptions.Compiled);
            var regexRemoveCTags        = new Regex(@"\</?c([a-zA-Z\._\d]*)\>", RegexOptions.Compiled);
            var regexRemoveTimeCodes    = new Regex(@"\<\d+:\d+:\d+\.\d+\>", RegexOptions.Compiled);  // <00:00:10.049>
            var regexTagsPlusWhiteSpace = new Regex(@"(\{\\an\d\})[\s\r\n]+", RegexOptions.Compiled); // <00:00:10.049>

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (p.Text.Contains('<') || p.Text.Contains('&'))
                {
                    var text = p.Text.Replace("&rlm;", string.Empty).Replace("&lrm;", string.Empty); // or use rlm=\u202B, lrm=\u202A ?
                    foreach (var knownLanguage in KnownLanguages)
                    {
                        text = text.Replace("<c." + knownLanguage + ">", string.Empty).Replace("</c." + knownLanguage + ">", string.Empty);
                    }
                    text = System.Net.WebUtility.HtmlDecode(text);

                    var match = regexWebVttColorMulti.Match(text);
                    while (match.Success)
                    {
                        var tag = match.Value.Substring(3, match.Value.Length - 4);
                        tag = FindBestColorTagOrDefault(tag);
                        if (tag == null)
                        {
                            text  = text.Replace(match.Value, string.Empty);
                            text  = text.Replace(match.Value.Insert(1, "/"), string.Empty);
                            match = regexWebVttColorMulti.Match(text);
                            continue;
                        }
                        var fontString = "<font color=\"" + tag + "\">";
                        fontString = fontString.Trim('"').Trim('\'');
                        text       = text.Remove(match.Index, match.Length).Insert(match.Index, fontString);
                        var endIndex = text.IndexOf("</c>", match.Index, StringComparison.OrdinalIgnoreCase);
                        if (endIndex >= 0)
                        {
                            text = text.Remove(endIndex, 4).Insert(endIndex, "</font>");
                        }
                        else
                        {
                            endIndex = text.IndexOf("</c.", match.Index, StringComparison.OrdinalIgnoreCase);
                            if (endIndex >= 0)
                            {
                                var endEndIndex = text.IndexOf('>', endIndex);
                                if (endEndIndex > 0)
                                {
                                    text = text.Remove(endIndex, endEndIndex - endIndex).Insert(endIndex, "</font>");
                                }
                            }
                        }
                        match = regexWebVttColorMulti.Match(text);
                    }

                    text   = RemoveTag("v", text);
                    text   = RemoveTag("rt", text);
                    text   = RemoveTag("ruby", text);
                    text   = RemoveTag("span", text);
                    text   = regexRemoveCTags.Replace(text, string.Empty).Trim();
                    text   = regexRemoveTimeCodes.Replace(text, string.Empty).Trim();
                    text   = regexTagsPlusWhiteSpace.Replace(text, "$1");
                    p.Text = text;
                }
            }
        }
Exemplo n.º 22
0
        private void OpenSubtitle(string fileName, Encoding encoding, string videoFileName, string originalFileName)
        {
            if (File.Exists(fileName))
            {
                bool videoFileLoaded = false;
                var file = new FileInfo(fileName);
                var ext = file.Extension.ToLowerInvariant();

                // save last first visible index + first selected index from listview
                if (!string.IsNullOrEmpty(_fileName))
                    Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, originalFileName);

                openFileDialog1.InitialDirectory = file.DirectoryName;

                if (ext == ".sub" && IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                    }
                    return;
                }

                if (ext == ".sup")
                {
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        ImportAndOcrBluRaySup(fileName, _loading);
                        return;
                    }
                    else if (FileUtil.IsSpDvdSup(fileName))
                    {
                        ImportAndOcrSpDvdSup(fileName, _loading);
                        return;
                    }
                }

                if (ext == ".mkv" || ext == ".mks")
                {
                    ImportSubtitleFromMatroskaFile(fileName);
                    return;
                }

                if (ext == ".divx" || ext == ".avi")
                {
                    if (ImportSubtitleFromDivX(fileName))
                        return;
                }

                if ((ext == ".ts" || ext == ".rec" || ext == ".mpeg" || ext == ".mpg") && file.Length > 10000 && FileUtil.IsTransportStream(fileName))
                {
                    ImportSubtitleFromTransportStream(fileName);
                    return;
                }

                if (((ext == ".m2ts" || ext == ".ts") && file.Length > 10000 && FileUtil.IsM2TransportStream(fileName)) ||
                    (ext == ".textst" && FileUtil.IsMpeg2PrivateStream2(fileName)))
                {
                    bool isTextSt = false;
                    if (file.Length < 2000000)
                    {
                        var textSt = new TextST();
                        isTextSt = textSt.IsMine(null, fileName);
                    }

                    if (!isTextSt)
                    {
                        ImportSubtitleFromTransportStream(fileName);
                        return;
                    }
                }

                if ((ext == ".mp4" || ext == ".m4v" || ext == ".3gp") && file.Length > 10000)
                {
                    if (ImportSubtitleFromMp4(fileName))
                        OpenVideo(fileName);
                    return;
                }

                if (ext == ".mxf")
                {
                    if (FileUtil.IsMaterialExchangeFormat(fileName))
                    {
                        var parser = new MxfParser(fileName);
                        if (parser.IsValid)
                        {
                            var subtitles = parser.GetSubtitles();
                            if (subtitles.Count > 0)
                            {
                                SetEncoding(Configuration.Settings.General.DefaultEncoding);
                                encoding = GetCurrentEncoding();
                                var list = new List<string>(subtitles[0].SplitToLines());
                                _subtitle = new Subtitle();
                                var mxfFormat = _subtitle.ReloadLoadSubtitle(list, null, null);
                                SetCurrentFormat(mxfFormat);
                                _fileName = Path.GetFileNameWithoutExtension(fileName);
                                SetTitle();
                                ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
                                _sourceViewChange = false;
                                _changeSubtitleToString = _subtitle.GetFastHashCode();
                                ResetHistory();
                                SetUndockedWindowsTitle();
                                _converted = true;
                                ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, mxfFormat.FriendlyName));

                                ShowSource();
                                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                                _subtitleListViewIndex = -1;
                                SubtitleListview1.FirstVisibleIndex = -1;
                                SubtitleListview1.SelectIndexAndEnsureVisible(0);

                                return;
                            }
                            MessageBox.Show("No subtitles found!");
                            return;
                        }
                    }
                }

                if (file.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    // retry Blu-ray sup (file with wrong extension)
                    if (FileUtil.IsBluRaySup(fileName))
                    {
                        ImportAndOcrBluRaySup(fileName, _loading);
                        return;
                    }

                    // retry vobsub (file with wrong extension)
                    if (IsVobSubFile(fileName, false))
                    {
                        if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                        }
                        return;
                    }

                    var text = string.Format(_language.FileXIsLargerThan10MB + Environment.NewLine + Environment.NewLine + _language.ContinueAnyway, fileName);
                    if (MessageBox.Show(this, text, Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                if (_subtitle.HistoryItems.Count > 0 || _subtitle.Paragraphs.Count > 0)
                    MakeHistoryForUndo(string.Format(_language.BeforeLoadOf, Path.GetFileName(fileName)));

                bool change = _changeSubtitleToString != _subtitle.GetFastHashCode();
                if (change)
                    change = _lastDoNotPrompt != _subtitle.GetFastHashCode();

                SubtitleFormat format = _subtitle.LoadSubtitle(fileName, out encoding, encoding);
                if (!change)
                    _changeSubtitleToString = _subtitle.GetFastHashCode();

                ShowHideTextBasedFeatures(format);

                bool justConverted = false;
                if (format == null)
                {
                    var ebu = new Ebu();
                    if (ebu.IsMine(null, fileName))
                    {
                        ebu.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ebu;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pac = new Pac();
                    if (pac.IsMine(null, fileName))
                    {
                        pac.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pac;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".m2ts" || ext == ".textst")
                {
                    var textST = new TextST();
                    if (textST.IsMine(null, fileName))
                    {
                        textST.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = textST;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pns = new Pns();
                    if (pns.IsMine(null, fileName))
                    {
                        pns.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pns;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }


                if (format == null)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.IsMine(null, fileName))
                    {
                        cavena890.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = cavena890;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var spt = new Spt();
                    if (spt.IsMine(null, fileName))
                    {
                        spt.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = spt;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null && ext == ".wsb")
                {
                    var wsb = new Wsb();
                    var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                    if (wsb.IsMine(list, fileName))
                    {
                        wsb.LoadSubtitle(_subtitle, list, fileName);
                        _oldSubtitleFormat = wsb;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var cheetahCaption = new CheetahCaption();
                    if (cheetahCaption.IsMine(null, fileName))
                    {
                        cheetahCaption.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = cheetahCaption;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var capMakerPlus = new CapMakerPlus();
                    if (capMakerPlus.IsMine(null, fileName))
                    {
                        capMakerPlus.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = capMakerPlus;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var captionsInc = new CaptionsInc();
                    if (captionsInc.IsMine(null, fileName))
                    {
                        captionsInc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = captionsInc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ultech130 = new Ultech130();
                    if (ultech130.IsMine(null, fileName))
                    {
                        ultech130.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ultech130;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var nciCaption = new NciCaption();
                    if (nciCaption.IsMine(null, fileName))
                    {
                        nciCaption.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = nciCaption;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var tsb4 = new TSB4();
                    if (tsb4.IsMine(null, fileName))
                    {
                        tsb4.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = tsb4;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var avidStl = new AvidStl();
                    if (avidStl.IsMine(null, fileName))
                    {
                        avidStl.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = avidStl;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var chk = new Chk();
                    if (chk.IsMine(null, fileName))
                    {
                        chk.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = chk;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var ayato = new Ayato();
                    if (ayato.IsMine(null, fileName))
                    {
                        ayato.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = ayato;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var pacUnicode = new PacUnicode();
                    if (pacUnicode.IsMine(null, fileName))
                    {
                        pacUnicode.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = pacUnicode;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var iai = new IaiSub();
                    if (iai.IsMine(null, fileName))
                    {
                        iai.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = iai;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var bdnXml = new BdnXml();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (bdnXml.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                            {
                                ImportAndOcrBdnXml(fileName, bdnXml, list);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var fcpImage = new FinalCutProImage();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (fcpImage.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                            {
                                ImportAndOcrDost(fileName, fcpImage, list);
                            }
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    var elr = new ELRStudioClosedCaption();
                    if (elr.IsMine(null, fileName))
                    {
                        elr.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = elr;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = asc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var asc = new TimeLineFootageAscii();
                    if (asc.IsMine(null, fileName))
                    {
                        asc.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = asc;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (format == null)
                {
                    var mtv = new TimeLineMvt();
                    if (mtv.IsMine(null, fileName))
                    {
                        mtv.LoadSubtitle(_subtitle, null, fileName);
                        _oldSubtitleFormat = mtv;
                        SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                        SetEncoding(Configuration.Settings.General.DefaultEncoding);
                        encoding = GetCurrentEncoding();
                        justConverted = true;
                        format = GetCurrentSubtitleFormat();
                    }
                }

                if (ext == ".dost")
                {
                    try
                    {
                        var dost = new Dost();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (dost.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, dost, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var timedtextImage = new TimedTextImage();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (timedtextImage.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, timedtextImage, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var seImageHtmlIndex = new SeImageHtmlIndex();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (seImageHtmlIndex.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrDost(fileName, seImageHtmlIndex, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var son = new Son();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (son.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSon(fileName, son, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == SubRip.NameOfFormat)
                {
                    if (_subtitle.Paragraphs.Count > 1)
                    {
                        int imageCount = 0;
                        foreach (var p in _subtitle.Paragraphs)
                        {
                            string s = p.Text.ToLowerInvariant();
                            if (s.EndsWith(".bmp", StringComparison.Ordinal) || s.EndsWith(".png", StringComparison.Ordinal) || s.EndsWith(".jpg", StringComparison.Ordinal) || s.EndsWith(".tif", StringComparison.Ordinal))
                            {
                                imageCount++;
                            }
                        }
                        if (imageCount > 2 && imageCount >= _subtitle.Paragraphs.Count - 2)
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSrt(_subtitle);
                            return;
                        }
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var satBoxPng = new SatBoxPng();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (satBoxPng.IsMine(list, fileName))
                        {
                            var subtitle = new Subtitle();
                            satBoxPng.LoadSubtitle(subtitle, list, fileName);
                            if (ContinueNewOrExit())
                                ImportAndOcrSrt(subtitle);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null || format.Name == Scenarist.NameOfFormat)
                {
                    try
                    {
                        var sst = new SonicScenaristBitmaps();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (sst.IsMine(list, fileName))
                        {
                            if (ContinueNewOrExit())
                                ImportAndOcrSst(fileName, sst, list);
                            return;
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                if (format == null)
                {
                    try
                    {
                        var htmlSamiArray = new HtmlSamiArray();
                        var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
                        if (htmlSamiArray.IsMine(list, fileName))
                        {
                            htmlSamiArray.LoadSubtitle(_subtitle, list, fileName);
                            _oldSubtitleFormat = htmlSamiArray;
                            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = GetCurrentEncoding();
                            justConverted = true;
                            format = GetCurrentSubtitleFormat();
                        }
                    }
                    catch
                    {
                        format = null;
                    }
                }

                // retry vobsub (file with wrong extension)
                if (format == null && file.Length > 500 && IsVobSubFile(fileName, false))
                {
                    if (MessageBox.Show(this, _language.ImportThisVobSubSubtitle, _title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ImportAndOcrVobSubSubtitleNew(fileName, _loading);
                    }
                    return;
                }

                // retry Blu-ray (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsBluRaySup(fileName))
                {
                    ImportAndOcrBluRaySup(fileName, _loading);
                    return;
                }

                // retry SP DVD (file with wrong extension)
                if (format == null && file.Length > 500 && FileUtil.IsSpDvdSup(fileName))
                {
                    ImportAndOcrSpDvdSup(fileName, _loading);
                    return;
                }

                // retry Matroska (file with wrong extension)
                if (format == null && !string.IsNullOrWhiteSpace(fileName))
                {
                    var matroska = new MatroskaFile(fileName);
                    if (matroska.IsValid)
                    {
                        var subtitleList = matroska.GetTracks(true);
                        if (subtitleList.Count > 0)
                        {
                            ImportSubtitleFromMatroskaFile(fileName);
                            return;
                        }
                    }
                }

                // check for idx file
                if (format == null && file.Length > 100 && ext == ".idx")
                {
                    MessageBox.Show(_language.ErrorLoadIdx);
                    return;
                }

                // check for .rar file
                if (format == null && file.Length > 100 && FileUtil.IsRar(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadRar);
                    return;
                }

                // check for .zip file
                if (format == null && file.Length > 100 && FileUtil.IsZip(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadZip);
                    return;
                }

                // check for .png file
                if (format == null && file.Length > 100 && FileUtil.IsPng(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadPng);
                    return;
                }

                // check for .jpg file
                if (format == null && file.Length > 100 && FileUtil.IsJpg(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadJpg);
                    return;
                }

                // check for .srr file
                if (format == null && file.Length > 100 && ext == ".srr" && FileUtil.IsSrr(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadSrr);
                    return;
                }

                // check for Torrent file
                if (format == null && file.Length > 50 && FileUtil.IsTorrentFile(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadTorrent);
                    return;
                }

                // check for all binary zeroes (I've heard about this a few times... perhaps related to crashes?)
                if (format == null && file.Length > 50 && FileUtil.IsSubtitleFileAllBinaryZeroes(fileName))
                {
                    MessageBox.Show(_language.ErrorLoadBinaryZeroes);
                    return;
                }

                if (format == null && file.Length < 100 * 1000000 && TransportStreamParser.IsDvbSup(fileName))
                {
                    ImportSubtitleFromDvbSupFile(fileName);
                    return;
                }

                if (format == null && file.Length < 500000)
                {
                    // check for valid timed text
                    if (ext == ".xml" || ext == ".dfxp")
                    {
                        var sb = new StringBuilder();
                        foreach (var line in File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)))
                            sb.AppendLine(line);
                        var xmlAsString = sb.ToString().Trim();

                        if (xmlAsString.Contains("http://www.w3.org/ns/ttml") && xmlAsString.Contains("<?xml version=") ||
                            xmlAsString.Contains("http://www.w3.org/") && xmlAsString.Contains("/ttaf1"))
                        {
                            var xml = new System.Xml.XmlDocument();
                            try
                            {
                                xml.LoadXml(xmlAsString);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Timed text is not valid (xml is not well-formed): " + ex.Message);
                                return;
                            }
                        }
                    }


                    // Try to use a generic subtitle format parser (guessing subtitle format)
                    try
                    {
                        var enc = LanguageAutoDetect.GetEncodingFromFile(fileName);
                        var s = File.ReadAllText(fileName, enc);

                        // check for RTF file
                        if (ext == ".rtf" && s.TrimStart().StartsWith("{\\rtf", StringComparison.Ordinal))
                        {
                            using (var rtb = new RichTextBox { Rtf = s })
                            {
                                s = rtb.Text;
                            }
                        }
                        var uknownFormatImporter = new UknownFormatImporter { UseFrames = true };
                        var genericParseSubtitle = uknownFormatImporter.AutoGuessImport(s.SplitToLines());
                        if (genericParseSubtitle.Paragraphs.Count > 1)
                        {
                            _subtitle = genericParseSubtitle;
                            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                            SetEncoding(Configuration.Settings.General.DefaultEncoding);
                            encoding = GetCurrentEncoding();
                            justConverted = true;
                            format = GetCurrentSubtitleFormat();
                            ShowStatus("Guessed subtitle format via generic subtitle parser!");
                        }
                    }
                    catch
                    {
                    }
                }

                _fileDateTime = File.GetLastWriteTime(fileName);

                if (format != null && format.IsFrameBased)
                    _subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                else
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                if (format != null)
                {
                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                    {
                        _subtitle.RemoveEmptyLines();
                    }

                    foreach (var p in _subtitle.Paragraphs)
                    {
                        // Replace U+0456 (CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I) by U+0069 (LATIN SMALL LETTER I)
                        p.Text = p.Text.Replace("<і>", "<i>").Replace("</і>", "</i>");
                    }

                    _subtitleListViewIndex = -1;
                    SetCurrentFormat(format);
                    _subtitleAlternateFileName = null;
                    if (LoadAlternateSubtitleFile(originalFileName))
                        _subtitleAlternateFileName = originalFileName;

                    // Seungki begin
                    _splitDualSami = false;
                    if (Configuration.Settings.SubtitleSettings.SamiDisplayTwoClassesAsTwoSubtitles && format.GetType() == typeof(Sami) && Sami.GetStylesFromHeader(_subtitle.Header).Count == 2)
                    {
                        var classes = Sami.GetStylesFromHeader(_subtitle.Header);
                        var s1 = new Subtitle(_subtitle);
                        var s2 = new Subtitle(_subtitle);
                        s1.Paragraphs.Clear();
                        s2.Paragraphs.Clear();
                        foreach (var p in _subtitle.Paragraphs)
                        {
                            if (p.Extra != null && p.Extra.Equals(classes[0], StringComparison.OrdinalIgnoreCase))
                                s1.Paragraphs.Add(p);
                            else
                                s2.Paragraphs.Add(p);
                        }
                        if (s1.Paragraphs.Count == 0 || s2.Paragraphs.Count == 0)
                            return;

                        _subtitle = s1;
                        _subtitleAlternate = s2;
                        _subtitleAlternateFileName = _fileName;
                        SubtitleListview1.HideExtraColumn();
                        SubtitleListview1.ShowAlternateTextColumn(classes[1]);
                        _splitDualSami = true;
                    }
                    // Seungki end

                    textBoxSource.Text = _subtitle.ToText(format);
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    if (SubtitleListview1.Items.Count > 0)
                        SubtitleListview1.Items[0].Selected = true;
                    _findHelper = null;
                    _spellCheckForm = null;

                    if (_resetVideo)
                    {
                        _videoFileName = null;
                        _videoInfo = null;
                        _videoAudioTrackNumber = -1;
                        labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
                        audioVisualizer.WavePeaks = null;
                        audioVisualizer.Spectrogram = null;
                    }

                    if (Configuration.Settings.General.ShowVideoPlayer || Configuration.Settings.General.ShowAudioVisualizer)
                    {
                        if (!Configuration.Settings.General.DisableVideoAutoLoading)
                        {
                            if (!string.IsNullOrEmpty(videoFileName) && File.Exists(videoFileName))
                            {
                                OpenVideo(videoFileName);
                            }
                            else if (!string.IsNullOrEmpty(fileName) && (toolStripButtonToggleVideo.Checked || toolStripButtonToggleWaveform.Checked))
                            {
                                TryToFindAndOpenVideoFile(Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)));
                            }
                        }
                    }
                    videoFileLoaded = _videoFileName != null;

                    if (Configuration.Settings.RecentFiles.Files.Count > 0 &&
                        Configuration.Settings.RecentFiles.Files[0].FileName == fileName)
                    {
                    }
                    else
                    {
                        Configuration.Settings.RecentFiles.Add(fileName, _videoFileName, _subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        UpdateRecentFilesUI();
                    }
                    _fileName = fileName;
                    SetTitle();
                    ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName));
                    _sourceViewChange = false;
                    _changeSubtitleToString = _subtitle.GetFastHashCode();
                    _converted = false;
                    ResetHistory();

                    SetUndockedWindowsTitle();

                    if (justConverted)
                    {
                        _converted = true;
                        ShowStatus(string.Format(_language.LoadedSubtitleX, _fileName) + " - " + string.Format(_language.ConvertedToX, format.FriendlyName));
                    }
                    if (Configuration.Settings.General.AutoConvertToUtf8)
                        encoding = Encoding.UTF8;
                    SetEncoding(encoding);

                    var formatType = format.GetType();
                    if (formatType == typeof(SubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        errors = (format as SubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(AdvancedSubStationAlpha))
                    {
                        string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        errors = (format as AdvancedSubStationAlpha).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(SubRip))
                    {
                        string errors = (format as SubRip).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(MicroDvd))
                    {
                        string errors = (format as MicroDvd).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(this, errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2007))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2007).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (formatType == typeof(DCinemaSmpte2010))
                    {
                        format.ToText(_subtitle, string.Empty);
                        string errors = (format as DCinemaSmpte2010).Errors;
                        if (!string.IsNullOrEmpty(errors))
                            MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    if (file.Length < 50)
                    {
                        _findHelper = null;
                        _spellCheckForm = null;
                        _videoFileName = null;
                        _videoInfo = null;
                        _videoAudioTrackNumber = -1;
                        labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
                        audioVisualizer.WavePeaks = null;
                        audioVisualizer.Spectrogram = null;

                        Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName);
                        Configuration.Settings.Save();
                        UpdateRecentFilesUI();
                        _fileName = fileName;
                        SetTitle();
                        ShowStatus(string.Format(_language.LoadedEmptyOrShort, _fileName));
                        _sourceViewChange = false;
                        _converted = false;

                        MessageBox.Show(_language.FileIsEmptyOrShort);
                    }
                    else
                    {
                        ShowUnknownSubtitle();
                        return;
                    }
                }

                if (!videoFileLoaded && mediaPlayer.VideoPlayer != null)
                {
                    mediaPlayer.VideoPlayer.DisposeVideoPlayer();
                    mediaPlayer.VideoPlayer = null;
                    timer1.Stop();
                }
                ResetShowEarlierOrLater();
            }
            else
            {
                MessageBox.Show(string.Format(_language.FileNotFound, fileName));
            }
        }
Exemplo n.º 23
0
        public void Initialize(Subtitle subtitle, SubtitleFormat format, Encoding encoding)
        {
            _autoDetectGoogleLanguage = Utilities.AutoDetectGoogleLanguage(encoding); // Guess language via encoding
            if (string.IsNullOrEmpty(_autoDetectGoogleLanguage))
                _autoDetectGoogleLanguage = Utilities.AutoDetectGoogleLanguage(subtitle); // Guess language based on subtitle contents
            if (_autoDetectGoogleLanguage.Equals("zh", StringComparison.OrdinalIgnoreCase))
                _autoDetectGoogleLanguage = "zh-CHS"; // Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures
            CultureInfo ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
            string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;

            comboBoxLanguage.Items.Clear();
            foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
                comboBoxLanguage.Items.Add(x);
            comboBoxLanguage.Sorted = true;
            int languageIndex = 0;
            int j = 0;
            foreach (var x in comboBoxLanguage.Items)
            {
                var xci = (CultureInfo)x;
                if (xci.TwoLetterISOLanguageName == ci.TwoLetterISOLanguageName)
                {
                    languageIndex = j;
                    break;
                }
                if (xci.TwoLetterISOLanguageName == "en")
                {
                    languageIndex = j;
                }
                j++;
            }
            comboBoxLanguage.SelectedIndex = languageIndex;

            AddFixActions(threeLetterIsoLanguageName);

            _originalSubtitle = new Subtitle(subtitle); // copy constructor
            Subtitle = new Subtitle(subtitle); // copy constructor
            _format = format;
            _encoding = encoding;
            InitUserInterface();
        }
Exemplo n.º 24
0
 private void ShowHideTextBasedFeatures(SubtitleFormat format)
 {
     if (format != null && !format.IsTextBased)
     {
         textBoxSource.Enabled = false;
     }
     else
     {
         textBoxSource.Enabled = true;
     }
 }
Exemplo n.º 25
0
        public void RunBatch(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language)
        {
            _autoDetectGoogleLanguage = language;
            var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
            string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;

            comboBoxLanguage.Items.Clear();
            foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
                comboBoxLanguage.Items.Add(x);
            comboBoxLanguage.Sorted = true;
            int languageIndex = 0;
            int j = 0;
            foreach (var x in comboBoxLanguage.Items)
            {
                var xci = (CultureInfo)x;
                if (xci.TwoLetterISOLanguageName == ci.TwoLetterISOLanguageName)
                {
                    languageIndex = j;
                    break;
                }
                if (xci.TwoLetterISOLanguageName == "en")
                {
                    languageIndex = j;
                }
                j++;
            }
            comboBoxLanguage.SelectedIndex = languageIndex;

            AddFixActions(threeLetterIsoLanguageName);

            _originalSubtitle = new Subtitle(subtitle); // copy constructor
            Subtitle = new Subtitle(subtitle); // copy constructor
            _format = format;
            _encoding = encoding;
            _onlyListFixes = true;
            _hasFixesBeenMade = true;
            _numberOfImportantLogMessages = 0;
            _onlyListFixes = false;
            _totalFixes = 0;
            _totalErrors = 0;
            _batchMode = true;
            RunSelectedActions();
            _originalSubtitle = Subtitle;
        }
Exemplo n.º 26
0
        private DialogResult SaveSubtitle(SubtitleFormat format)
        {
            if (string.IsNullOrEmpty(_fileName) || _converted)
                return FileSaveAs(false);

            try
            {
                if (format != null && !format.IsTextBased)
                {
                    if (format.GetType() == typeof(Ebu))
                    {
                        Ebu.Save(_fileName, _subtitle);
                    }
                    return DialogResult.OK;
                }

                string allText = _subtitle.ToText(format);

                // Seungki begin
                if (_splitDualSami && _subtitleAlternate != null)
                {
                    var s = new Subtitle(_subtitle);
                    foreach (var p in _subtitleAlternate.Paragraphs)
                        s.Paragraphs.Add(p);
                    allText = s.ToText(format);
                }
                // Seungki end

                var currentEncoding = GetCurrentEncoding();
                bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
                if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
                {
                    if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (!isUnicode)
                {
                    allText = NormalizeUnicode(allText);
                }

                bool containsNegativeTime = false;
                foreach (var p in _subtitle.Paragraphs)
                {
                    if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
                    {
                        containsNegativeTime = true;
                        break;
                    }
                }
                if (containsNegativeTime)
                {
                    if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
                        return DialogResult.No;
                }

                if (File.Exists(_fileName))
                {
                    var fileInfo = new FileInfo(_fileName);
                    var fileOnDisk = fileInfo.LastWriteTime;
                    if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
                    {
                        if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
                            _fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
                            Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
                            Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNo) == DialogResult.No)
                            return DialogResult.No;
                    }
                    if (fileInfo.IsReadOnly)
                    {
                        MessageBox.Show(string.Format(_language.FileXIsReadOnly, _fileName));
                        return DialogResult.No;
                    }
                }

                if ((format.GetType() == typeof(WebVTT) || format.GetType() == typeof(WebVTTFileWithLineNumber)))
                {
                    SetEncoding(Encoding.UTF8);
                    currentEncoding = Encoding.UTF8;
                }

                if (ModifierKeys == (Keys.Control | Keys.Shift))
                    allText = allText.Replace("\r\n", "\n");

                if (format.GetType() == typeof(ItunesTimedText) || format.GetType() == typeof(ScenaristClosedCaptions) || format.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
                {
                    var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                    using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
                    {
                        file.Write(allText);
                    }
                }
                else if (currentEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
                {
                    var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
                    using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
                    {
                        file.Write(allText);
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(allText))
                    {
                        MessageBox.Show(string.Format(_language.UnableToSaveSubtitleX, _fileName), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return DialogResult.Cancel;
                    }

                    using (var fs = File.Create(_fileName, 1024, FileOptions.WriteThrough)) // use 'WriteThough' in order to try to avoid issue with power failure
                    using (var sw = new StreamWriter(fs, currentEncoding))
                    {
                        sw.Write(allText);
                    }
                }

                _fileDateTime = File.GetLastWriteTime(_fileName);
                ShowStatus(string.Format(_language.SavedSubtitleX, _fileName));
                _changeSubtitleToString = _subtitle.GetFastHashCode();
                return DialogResult.OK;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                return DialogResult.Cancel;
            }
        }
Exemplo n.º 27
0
        public void RunBatchSettings(Subtitle subtitle, SubtitleFormat format, Encoding encoding, string language)
        {
            _autoDetectGoogleLanguage = language;
            var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
            string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;

            comboBoxLanguage.Items.Clear();
            foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
                comboBoxLanguage.Items.Add(x);
            comboBoxLanguage.Sorted = true;
            int languageIndex = 0;
            int j = 0;
            foreach (var x in comboBoxLanguage.Items)
            {
                var xci = (CultureInfo)x;
                if (xci.TwoLetterISOLanguageName == ci.TwoLetterISOLanguageName)
                {
                    languageIndex = j;
                    break;
                }
                if (xci.TwoLetterISOLanguageName == "en")
                {
                    languageIndex = j;
                }
                j++;
            }
            comboBoxLanguage.SelectedIndex = languageIndex;
            AddFixActions(threeLetterIsoLanguageName);
            _originalSubtitle = new Subtitle(subtitle); // copy constructor
            Subtitle = new Subtitle(subtitle); // copy constructor
            _format = format;
            _encoding = encoding;
            _onlyListFixes = false;
            InitUserInterface();
            groupBoxStep1.Text = string.Empty;
            buttonBack.Visible = false;
            buttonNextFinish.Visible = false;
            buttonCancel.Text = _languageGeneral.Ok;
        }
Exemplo n.º 28
0
        private void ResetSubtitle()
        {
            SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);

            labelStartTimeWarning.Text = string.Empty;
            labelDurationWarning.Text = string.Empty;

            _subtitle = new Subtitle(_subtitle.HistoryItems);
            _changeAlternateSubtitleToString = string.Empty;
            _changeSubtitleToString = string.Empty;
            _subtitleAlternateFileName = null;
            textBoxSource.Text = string.Empty;
            SubtitleListview1.Items.Clear();
            _fileName = string.Empty;
            _fileDateTime = new DateTime();
            Text = Title;
            _oldSubtitleFormat = null;
            labelSingleLine.Text = string.Empty;
            RemoveAlternate(true);
            _splitDualSami = false;

            SubtitleListview1.HideExtraColumn();
            SubtitleListview1.DisplayExtraFromExtra = false;

            ComboBoxSubtitleFormatsSelectedIndexChanged(null, null);

            toolStripComboBoxFrameRate.Text = Configuration.Settings.General.DefaultFrameRate.ToString();

            SetEncoding(Configuration.Settings.General.DefaultEncoding);

            toolStripComboBoxFrameRate.Text = Configuration.Settings.General.DefaultFrameRate.ToString();
            _findHelper = null;
            _spellCheckForm = null;
            _videoFileName = null;
            _videoInfo = null;
            _videoAudioTrackNumber = -1;
            labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
            audioVisualizer.WavePeaks = null;
            audioVisualizer.Spectrogram = null;

            _sourceViewChange = false;

            _subtitleListViewIndex = -1;
            textBoxListViewText.Text = string.Empty;
            textBoxListViewTextAlternate.Text = string.Empty;
            textBoxListViewText.Enabled = false;
            labelTextLineLengths.Text = string.Empty;
            labelCharactersPerSecond.Text = string.Empty;
            labelTextLineTotal.Text = string.Empty;

            _listViewTextUndoLast = null;
            _listViewAlternateTextUndoLast = null;
            _listViewTextUndoIndex = -1;

            if (mediaPlayer.VideoPlayer != null)
            {
                mediaPlayer.VideoPlayer.DisposeVideoPlayer();
                mediaPlayer.VideoPlayer = null;
            }

            _changeSubtitleToString = _subtitle.GetFastHashCode();
            _converted = false;

            SetUndockedWindowsTitle();
            mediaPlayer.SubtitleText = string.Empty;
            ShowStatus(_language.New);

            ResetShowEarlierOrLater();
        }
Exemplo n.º 29
0
        public override void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
        {
            if (newFormat != null && newFormat.Name == AdvancedSubStationAlpha.NameOfFormat)
            {
                // do we need any conversion?
            }
            else
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    int    indexOfBegin = p.Text.IndexOf('{');
                    string pre          = string.Empty;
                    while (indexOfBegin >= 0 && p.Text.IndexOf('}') > indexOfBegin)
                    {
                        string s = p.Text.Substring(indexOfBegin);
                        if (s.StartsWith("{\\an1}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an2}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an3}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an4}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an5}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an6}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an7}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an8}", StringComparison.Ordinal) ||
                            s.StartsWith("{\\an9}", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 6);
                        }
                        else if (s.StartsWith("{\\an1\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an2\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an3\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an4\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an5\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an6\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an7\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an8\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\an9\\", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 5) + "}";
                        }
                        else if (s.StartsWith("{\\a1}", StringComparison.Ordinal) || s.StartsWith("{\\a1\\", StringComparison.Ordinal) ||
                                 s.StartsWith("{\\a3}", StringComparison.Ordinal) || s.StartsWith("{\\a3\\", StringComparison.Ordinal))
                        {
                            pre = s.Substring(0, 4) + "}";
                        }
                        else if (s.StartsWith("{\\a9}", StringComparison.Ordinal) || s.StartsWith("{\\a9\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an4}";
                        }
                        else if (s.StartsWith("{\\a10}", StringComparison.Ordinal) || s.StartsWith("{\\a10\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an5}";
                        }
                        else if (s.StartsWith("{\\a11}", StringComparison.Ordinal) || s.StartsWith("{\\a11\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an6}";
                        }
                        else if (s.StartsWith("{\\a5}", StringComparison.Ordinal) || s.StartsWith("{\\a5\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an7}";
                        }
                        else if (s.StartsWith("{\\a6}", StringComparison.Ordinal) || s.StartsWith("{\\a6\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an8}";
                        }
                        else if (s.StartsWith("{\\a7}", StringComparison.Ordinal) || s.StartsWith("{\\a7\\", StringComparison.Ordinal))
                        {
                            pre = "{\\an9}";
                        }
                        int indexOfEnd = p.Text.IndexOf('}');
                        p.Text = p.Text.Remove(indexOfBegin, (indexOfEnd - indexOfBegin) + 1);

                        indexOfBegin = p.Text.IndexOf('{');
                    }
                    p.Text = pre + p.Text;
                }
            }
        }
Exemplo n.º 30
0
 private void ComboBoxSubtitleFormatsEnter(object sender, EventArgs e)
 {
     SubtitleFormat format = GetCurrentSubtitleFormat();
     if (format != null)
         _oldSubtitleFormat = format;
 }
Exemplo n.º 31
0
        public static Subtitle LoadMatroskaSSA(MatroskaTrackInfo matroskaSubtitleInfo, string fileName, SubtitleFormat format, List<MatroskaSubtitle> sub)
        {
            var subtitle = new Subtitle { Header = matroskaSubtitleInfo.CodecPrivate };
            var lines = new List<string>();
            foreach (string l in subtitle.Header.Trim().SplitToLines())
                lines.Add(l);
            var footer = new StringBuilder();
            var comments = new Subtitle();
            if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate))
            {
                bool footerOn = false;
                foreach (string line in lines)
                {
                    if (footerOn)
                    {
                        footer.AppendLine(line);
                    }
                    else if (line.Trim() == "[Events]")
                    {
                    }
                    else if (line.Trim() == "[Fonts]" || line.Trim() == "[Graphics]")
                    {
                        footerOn = true;
                        footer.AppendLine();
                        footer.AppendLine();
                        footer.AppendLine(line);
                    }
                    else if (line.StartsWith("Comment:", StringComparison.Ordinal))
                    {
                        var arr = line.Split(',');
                        if (arr.Length > 3)
                        {
                            arr = arr[1].Split(new[] { ':', '.' });
                            if (arr.Length == 4)
                            {
                                int hour;
                                int min;
                                int sec;
                                int ms;
                                if (int.TryParse(arr[0], out hour) && int.TryParse(arr[1], out min) &&
                                    int.TryParse(arr[2], out sec) && int.TryParse(arr[3], out ms))
                                {
                                    comments.Paragraphs.Add(new Paragraph(new TimeCode(hour, min, sec, ms * 10), new TimeCode(0, 0, 0, 0), line));
                                }
                            }
                        }
                    }
                }
            }
            const string headerFormat = "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text";
            if (!subtitle.Header.Contains("[Events]"))
            {
                subtitle.Header = subtitle.Header.Trim() + Environment.NewLine +
                                   Environment.NewLine +
                                   "[Events]" + Environment.NewLine +
                                   headerFormat + Environment.NewLine;
            }
            else
            {
                subtitle.Header = subtitle.Header.Remove(subtitle.Header.IndexOf("[Events]", StringComparison.Ordinal));
                subtitle.Header = subtitle.Header.Trim() + Environment.NewLine +
                                   Environment.NewLine +
                                   "[Events]" + Environment.NewLine +
                                   headerFormat + Environment.NewLine;
            }
            lines = new List<string>();
            foreach (string l in subtitle.Header.Trim().SplitToLines())
                lines.Add(l);

            const string timeCodeFormat = "{0}:{1:00}:{2:00}.{3:00}"; // h:mm:ss.cc
            foreach (var mp in sub)
            {
                var p = new Paragraph(string.Empty, mp.Start, mp.End);
                string start = string.Format(timeCodeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds / 10);
                string end = string.Format(timeCodeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds / 10);

                //MKS contains this: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text

                for (int commentIndex = 0; commentIndex < comments.Paragraphs.Count; commentIndex++)
                {
                    var cp = comments.Paragraphs[commentIndex];
                    if (cp.StartTime.TotalMilliseconds <= p.StartTime.TotalMilliseconds)
                        lines.Add(cp.Text);
                }
                for (int commentIndex = comments.Paragraphs.Count - 1; commentIndex >= 0; commentIndex--)
                {
                    var cp = comments.Paragraphs[commentIndex];
                    if (cp.StartTime.TotalMilliseconds <= p.StartTime.TotalMilliseconds)
                        comments.Paragraphs.RemoveAt(commentIndex);
                }

                string text = mp.Text.Replace(Environment.NewLine, "\\N");
                int idx = text.IndexOf(',') + 1;
                if (idx > 0 && idx < text.Length)
                {
                    text = text.Remove(0, idx); // remove ReadOrder
                    idx = text.IndexOf(',');
                    text = text.Insert(idx, "," + start + "," + end);
                    lines.Add("Dialogue: " + text);
                }
            }
            for (int commentIndex = 0; commentIndex < comments.Paragraphs.Count; commentIndex++)
            {
                var cp = comments.Paragraphs[commentIndex];
                lines.Add(cp.Text);
            }

            foreach (string l in footer.ToString().SplitToLines())
                lines.Add(l);

            format.LoadSubtitle(subtitle, lines, fileName);
            return subtitle;
        }
Exemplo n.º 32
0
        public override void LoadSubtitle(Subtitle subtitle, List <string> lines, string fileName)
        {
            _errorCount = 0;

            var sb = new StringBuilder();

            lines.ForEach(line => sb.AppendLine(line));
            var xml = new XmlDocument {
                XmlResolver = null
            };

            xml.LoadXml(sb.ToString().Replace(" & ", " &amp; ").Replace("Q&A", "Q&amp;A").RemoveControlCharactersButWhiteSpace().Trim());

            var nsmgr = new XmlNamespaceManager(xml.NameTable);

            nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);

            var div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);

            if (div == null)
            {
                div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).FirstChild;
            }

            var styleDic = new Dictionary <string, string>();

            foreach (XmlNode node in xml.DocumentElement.SelectNodes("//ttaf1:style", nsmgr))
            {
                if (node.Attributes["tts:fontStyle"] != null && node.Attributes["xml:id"] != null)
                {
                    styleDic.Add(node.Attributes["xml:id"].Value, node.Attributes["tts:fontStyle"].Value);
                }
            }
            bool couldBeFrames = true;
            bool couldBeMillisecondsWithMissingLastDigit = true;

            foreach (XmlNode node in div.ChildNodes)
            {
                try
                {
                    var pText = new StringBuilder();
                    foreach (XmlNode innerNode in node.ChildNodes)
                    {
                        switch (innerNode.Name.Replace("tt:", string.Empty))
                        {
                        case "br":
                            pText.AppendLine();
                            break;

                        case "span":
                            bool italic = false;
                            if (innerNode.Attributes["style"] != null && styleDic.ContainsKey(innerNode.Attributes["style"].Value))
                            {
                                if (styleDic[innerNode.Attributes["style"].Value].Contains("italic"))
                                {
                                    italic = true;
                                    pText.Append("<i>");
                                }
                            }
                            if (!italic && innerNode.Attributes != null)
                            {
                                var fs = innerNode.Attributes.GetNamedItem("tts:fontStyle");
                                if (fs != null && fs.Value == "italic")
                                {
                                    italic = true;
                                    pText.Append("<i>");
                                }
                            }
                            if (innerNode.HasChildNodes)
                            {
                                foreach (XmlNode innerInnerNode in innerNode.ChildNodes)
                                {
                                    if (innerInnerNode.Name == "br" || innerInnerNode.Name == "tt:br")
                                    {
                                        pText.AppendLine();
                                    }
                                    else
                                    {
                                        pText.Append(innerInnerNode.InnerText);
                                    }
                                }
                            }
                            else
                            {
                                pText.Append(innerNode.InnerText);
                            }
                            if (italic)
                            {
                                pText.Append("</i>");
                            }
                            break;

                        case "i":
                            pText.Append("<i>" + innerNode.InnerText + "</i>");
                            break;

                        case "b":
                            pText.Append("<b>" + innerNode.InnerText + "</b>");
                            break;

                        default:
                            pText.Append(innerNode.InnerText);
                            break;
                        }
                    }

                    string start = null;
                    string end   = null;
                    string dur   = null;
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name.EndsWith("begin", StringComparison.Ordinal))
                        {
                            start = attr.InnerText;
                        }
                        else if (attr.Name.EndsWith("end", StringComparison.Ordinal))
                        {
                            end = attr.InnerText;
                        }
                        else if (attr.Name.EndsWith("duration", StringComparison.Ordinal))
                        {
                            dur = attr.InnerText;
                        }
                    }
                    string text = pText.ToString();
                    text = text.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
                    text = text.Replace("<i></i>", string.Empty).Trim();
                    if (end != null)
                    {
                        if (end.Length != 11 || end.Substring(8, 1) != ":" || start == null || start.Length != 11 || start.Substring(8, 1) != ":")
                        {
                            couldBeFrames = false;
                        }

                        if (couldBeMillisecondsWithMissingLastDigit && (end.Length != 11 || start == null || start.Length != 11 || end.Substring(8, 1) != "." || start.Substring(8, 1) != "."))
                        {
                            couldBeMillisecondsWithMissingLastDigit = false;
                        }

                        double dBegin, dEnd;
                        if (!start.Contains(':') && Utilities.CountTagInText(start, '.') == 1 &&
                            !end.Contains(':') && Utilities.CountTagInText(end, '.') == 1 &&
                            double.TryParse(start, NumberStyles.Float, CultureInfo.InvariantCulture, out dBegin) && double.TryParse(end, NumberStyles.Float, CultureInfo.InvariantCulture, out dEnd))
                        {
                            subtitle.Paragraphs.Add(new Paragraph(text, dBegin * TimeCode.BaseUnit, dEnd * TimeCode.BaseUnit));
                        }
                        else
                        {
                            if (start.Length == 8 && start[2] == ':' && start[5] == ':' && end.Length == 8 && end[2] == ':' && end[5] == ':')
                            {
                                var p     = new Paragraph();
                                var parts = start.Split(SplitCharColon);
                                p.StartTime = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                parts       = end.Split(SplitCharColon);
                                p.EndTime   = new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), 0);
                                p.Text      = text;
                                subtitle.Paragraphs.Add(p);
                            }
                            else
                            {
                                subtitle.Paragraphs.Add(new Paragraph(TimedText10.GetTimeCode(start, false), TimedText10.GetTimeCode(end, false), text));
                            }
                        }
                    }
                    else if (dur != null)
                    {
                        if (dur.Length != 11 || dur.Substring(8, 1) != ":" || start == null || start.Length != 11 || start.Substring(8, 1) != ":")
                        {
                            couldBeFrames = false;
                        }

                        if (couldBeMillisecondsWithMissingLastDigit && (dur.Length != 11 || start == null || start.Length != 11 || dur.Substring(8, 1) != "." || start.Substring(8, 1) != "."))
                        {
                            couldBeMillisecondsWithMissingLastDigit = false;
                        }

                        TimeCode duration  = TimedText10.GetTimeCode(dur, false);
                        TimeCode startTime = TimedText10.GetTimeCode(start, false);
                        var      endTime   = new TimeCode(startTime.TotalMilliseconds + duration.TotalMilliseconds);
                        subtitle.Paragraphs.Add(new Paragraph(startTime, endTime, text));
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    _errorCount++;
                }
            }
            subtitle.RemoveEmptyLines();

            if (couldBeFrames)
            {
                bool all30OrBelow = true;
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    if (p.StartTime.Milliseconds > 30 || p.EndTime.Milliseconds > 30)
                    {
                        all30OrBelow = false;
                        break;
                    }
                }
                if (all30OrBelow)
                {
                    foreach (Paragraph p in subtitle.Paragraphs)
                    {
                        p.StartTime.Milliseconds = SubtitleFormat.FramesToMillisecondsMax999(p.StartTime.Milliseconds);
                        p.EndTime.Milliseconds   = SubtitleFormat.FramesToMillisecondsMax999(p.EndTime.Milliseconds);
                    }
                }
            }
            else if (couldBeMillisecondsWithMissingLastDigit && Configuration.Settings.SubtitleSettings.TimedText10TimeCodeFormatSource != "hh:mm:ss.ms-two-digits")
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    p.StartTime.Milliseconds *= 10;
                    p.EndTime.Milliseconds   *= 10;
                }
            }

            subtitle.Renumber();
        }
Exemplo n.º 33
0
        internal void Initialize(Subtitle subtitle, SubtitleFormat format, string exportType, string fileName, VideoInfo videoInfo, string videoFileName)
        {
            _exportType = exportType;
            _fileName = fileName;
            _format = format;
            _videoFileName = videoFileName;
            if (exportType == "BLURAYSUP")
                Text = "Blu-ray SUP";
            else if (exportType == "VOBSUB")
                Text = "VobSub (sub/idx)";
            else if (exportType == "FAB")
                Text = "FAB Image Script";
            else if (exportType == "IMAGE/FRAME")
                Text = "Image per frame";
            else if (exportType == "STL")
                Text = "DVD Studio Pro STL";
            else if (exportType == "FCP")
                Text = "Final Cut Pro";
            else if (exportType == "DOST")
                Text = "DOST";
            else if (exportType == "EDL")
                Text = "EDL";
            else if (exportType == "DCINEMA_INTEROP")
                Text = "DCinema interop/png";
            else
                Text = Configuration.Settings.Language.ExportPngXml.Title;

            if (_exportType == "VOBSUB" && !string.IsNullOrEmpty(Configuration.Settings.Tools.ExportVobSubFontName))
                _subtitleFontName = Configuration.Settings.Tools.ExportVobSubFontName;
            else if ((_exportType == "BLURAYSUP" || _exportType == "DOST") && !string.IsNullOrEmpty(Configuration.Settings.Tools.ExportBluRayFontName))
                _subtitleFontName = Configuration.Settings.Tools.ExportBluRayFontName;
            else if (_exportType == "FCP" && !string.IsNullOrEmpty(Configuration.Settings.Tools.ExportFcpFontName))
                _subtitleFontName = Configuration.Settings.Tools.ExportFcpFontName;
            else if (!string.IsNullOrEmpty(Configuration.Settings.Tools.ExportFontNameOther))
                _subtitleFontName = Configuration.Settings.Tools.ExportFontNameOther;
            if (_exportType == "VOBSUB" && Configuration.Settings.Tools.ExportVobSubFontSize > 0)
                _subtitleFontSize = Configuration.Settings.Tools.ExportVobSubFontSize;
            else if ((_exportType == "BLURAYSUP" || _exportType == "DOST") && Configuration.Settings.Tools.ExportBluRayFontSize > 0)
                _subtitleFontSize = Configuration.Settings.Tools.ExportBluRayFontSize;
            else if (_exportType == "FCP" && Configuration.Settings.Tools.ExportFcpFontSize > 0)
                _subtitleFontSize = Configuration.Settings.Tools.ExportFcpFontSize;
            else if (Configuration.Settings.Tools.ExportLastFontSize > 0)
                _subtitleFontSize = Configuration.Settings.Tools.ExportLastFontSize;

            if (_exportType == "FCP")
            {
                comboBoxImageFormat.Items.Add("8-bit png");
                int i = 0;
                foreach (string item in comboBoxImageFormat.Items)
                {
                    if (item == Configuration.Settings.Tools.ExportFcpImageType)
                    {
                        comboBoxImageFormat.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
            }

            if (_exportType == "VOBSUB")
            {
                comboBoxSubtitleFontSize.SelectedIndex = 7;
                int i = 0;
                foreach (string item in comboBoxSubtitleFontSize.Items)
                {
                    if (item == Convert.ToInt32(_subtitleFontSize).ToString(CultureInfo.InvariantCulture))
                    {
                        comboBoxSubtitleFontSize.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
                checkBoxSimpleRender.Checked = Configuration.Settings.Tools.ExportVobSubSimpleRendering;
                checkBoxTransAntiAliase.Checked = Configuration.Settings.Tools.ExportVobAntiAliasingWithTransparency;
            }
            else if (_exportType == "BLURAYSUP" || _exportType == "DOST" || _exportType == "FCP")
            {
                comboBoxSubtitleFontSize.SelectedIndex = 16;
                int i = 0;
                foreach (string item in comboBoxSubtitleFontSize.Items)
                {
                    if (item == Convert.ToInt32(_subtitleFontSize).ToString(CultureInfo.InvariantCulture))
                    {
                        comboBoxSubtitleFontSize.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
            }
            else
            {
                comboBoxSubtitleFontSize.SelectedIndex = 16;
                int i = 0;
                foreach (string item in comboBoxSubtitleFontSize.Items)
                {
                    if (item == Convert.ToInt32(_subtitleFontSize).ToString(CultureInfo.InvariantCulture))
                    {
                        comboBoxSubtitleFontSize.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
            }

            groupBoxImageSettings.Text = Configuration.Settings.Language.ExportPngXml.ImageSettings;
            labelSubtitleFont.Text = Configuration.Settings.Language.ExportPngXml.FontFamily;
            labelSubtitleFontSize.Text = Configuration.Settings.Language.ExportPngXml.FontSize;
            labelResolution.Text = Configuration.Settings.Language.ExportPngXml.VideoResolution;
            buttonColor.Text = Configuration.Settings.Language.ExportPngXml.FontColor;
            checkBoxBold.Text = Configuration.Settings.Language.General.Bold;
            checkBoxSimpleRender.Text = Configuration.Settings.Language.ExportPngXml.SimpleRendering;
            checkBoxTransAntiAliase.Text = Configuration.Settings.Language.ExportPngXml.AntiAliasingWithTransparency;

            normalToolStripMenuItem.Text = Configuration.Settings.Language.Main.Menu.ContextMenu.Normal;
            italicToolStripMenuItem.Text = Configuration.Settings.Language.General.Italic;
            boxSingleLineToolStripMenuItem.Text = Configuration.Settings.Language.ExportPngXml.BoxSingleLine;
            boxMultiLineToolStripMenuItem.Text = Configuration.Settings.Language.ExportPngXml.BoxMultiLine;

            comboBox3D.Items.Clear();
            comboBox3D.Items.Add(Configuration.Settings.Language.General.None);
            comboBox3D.Items.Add(Configuration.Settings.Language.ExportPngXml.SideBySide3D);
            comboBox3D.Items.Add(Configuration.Settings.Language.ExportPngXml.HalfTopBottom3D);
            comboBox3D.SelectedIndex = 0;

            labelDepth.Text = Configuration.Settings.Language.ExportPngXml.Depth;

            numericUpDownDepth3D.Left = labelDepth.Left + labelDepth.Width + 3;

            label3D.Text = Configuration.Settings.Language.ExportPngXml.Text3D;

            comboBox3D.Left = label3D.Left + label3D.Width + 3;

            buttonBorderColor.Text = Configuration.Settings.Language.ExportPngXml.BorderColor;
            //labelBorderWidth.Text = Configuration.Settings.Language.ExportPngXml.BorderWidth;
            labelBorderWidth.Text = Configuration.Settings.Language.ExportPngXml.BorderStyle;
            labelImageFormat.Text = Configuration.Settings.Language.ExportPngXml.ImageFormat;
            checkBoxFullFrameImage.Text = Configuration.Settings.Language.ExportPngXml.FullFrameImage;

            buttonExport.Text = Configuration.Settings.Language.ExportPngXml.ExportAllLines;
            buttonCancel.Text = Configuration.Settings.Language.General.Ok;
            labelLanguage.Text = Configuration.Settings.Language.ChooseLanguage.Language;
            labelFrameRate.Text = Configuration.Settings.Language.General.FrameRate;
            labelHorizontalAlign.Text = Configuration.Settings.Language.ExportPngXml.Align;
            labelBottomMargin.Text = Configuration.Settings.Language.ExportPngXml.BottomMargin;
            labelLeftRightMargin.Text = Configuration.Settings.Language.ExportPngXml.LeftRightMargin;
            if (Configuration.Settings.Language.ExportPngXml.Left != null &&
                Configuration.Settings.Language.ExportPngXml.Center != null &&
                Configuration.Settings.Language.ExportPngXml.Right != null)
            {
                comboBoxHAlign.Items.Clear();
                comboBoxHAlign.Items.Add(Configuration.Settings.Language.ExportPngXml.Left);
                comboBoxHAlign.Items.Add(Configuration.Settings.Language.ExportPngXml.Center);
                comboBoxHAlign.Items.Add(Configuration.Settings.Language.ExportPngXml.Right);
            }

            buttonShadowColor.Text = Configuration.Settings.Language.ExportPngXml.ShadowColor;
            labelShadowWidth.Text = Configuration.Settings.Language.ExportPngXml.ShadowWidth;
            labelShadowTransparency.Text = Configuration.Settings.Language.ExportPngXml.Transparency;
            labelLineHeight.Text = Configuration.Settings.Language.ExportPngXml.LineHeight;

            linkLabelPreview.Text = Configuration.Settings.Language.General.Preview;
            linkLabelPreview.Left = groupBoxExportImage.Width - linkLabelPreview.Width - 3;

            saveImageAsToolStripMenuItem.Text = Configuration.Settings.Language.ExportPngXml.SaveImageAs;

            SubtitleListView1InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings);
            Utilities.InitializeSubtitleFont(subtitleListView1);
            SubtitleListView1AutoSizeAllColumns();

            _subtitle = new Subtitle(subtitle);
            _subtitle.Header = subtitle.Header;
            _subtitle.Footer = subtitle.Footer;

            panelColor.BackColor = _subtitleColor;
            panelBorderColor.BackColor = _borderColor;
            InitBorderStyle();
            comboBoxHAlign.SelectedIndex = 1;
            comboBoxResolution.SelectedIndex = 3;

            if (Configuration.Settings.Tools.ExportLastShadowTransparency <= numericUpDownShadowTransparency.Maximum && Configuration.Settings.Tools.ExportLastShadowTransparency > 0)
            {
                numericUpDownShadowTransparency.Value = Configuration.Settings.Tools.ExportLastShadowTransparency;
            }

            if ((_exportType == "BLURAYSUP" || _exportType == "DOST") && !string.IsNullOrEmpty(Configuration.Settings.Tools.ExportBluRayVideoResolution))
                SetResolution(Configuration.Settings.Tools.ExportBluRayVideoResolution);

            if (exportType == "VOBSUB")
            {
                comboBoxBorderWidth.SelectedIndex = 6;
                if (_exportType == "VOBSUB" && !string.IsNullOrEmpty(Configuration.Settings.Tools.ExportVobSubVideoResolution))
                    SetResolution(Configuration.Settings.Tools.ExportVobSubVideoResolution);
                else
                    comboBoxResolution.SelectedIndex = 8;
                labelLanguage.Visible = true;
                comboBoxLanguage.Visible = true;
                comboBoxLanguage.Items.Clear();
                string languageCode = Utilities.AutoDetectGoogleLanguageOrNull(subtitle);
                if (languageCode == null)
                    languageCode = Configuration.Settings.Tools.ExportVobSubLanguage;
                for (int i = 0; i < IfoParser.ArrayOfLanguage.Count; i++)
                {
                    comboBoxLanguage.Items.Add(IfoParser.ArrayOfLanguage[i]);
                    if (IfoParser.ArrayOfLanguageCode[i] == languageCode || IfoParser.ArrayOfLanguage[i] == languageCode)
                        comboBoxLanguage.SelectedIndex = i;
                }
                if (comboBoxLanguage.SelectedIndex == -1 && comboBoxLanguage.Items.Count > 25)
                    comboBoxLanguage.SelectedIndex = 25;
            }

            bool showImageFormat = exportType == "FAB" || exportType == "IMAGE/FRAME" || exportType == "STL" || exportType == "FCP" || exportType == "BDNXML";
            checkBoxFullFrameImage.Visible = exportType == "FAB" || exportType == "BLURAYSUP";
            comboBoxImageFormat.Visible = showImageFormat;
            labelImageFormat.Visible = showImageFormat;
            labelFrameRate.Visible = exportType == "BDNXML" || exportType == "BLURAYSUP" || exportType == "DOST" || exportType == "IMAGE/FRAME";
            comboBoxFrameRate.Visible = exportType == "BDNXML" || exportType == "BLURAYSUP" || exportType == "DOST" || exportType == "IMAGE/FRAME" || exportType == "FAB" || exportType == "FCP";
            checkBoxTransAntiAliase.Visible = exportType == "VOBSUB";
            if (exportType == "BDNXML")
            {
                labelFrameRate.Top = labelLanguage.Top;
                comboBoxFrameRate.Top = comboBoxLanguage.Top;
                comboBoxFrameRate.Items.Add("23.976");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("30");
                comboBoxFrameRate.Items.Add("50");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.SelectedIndex = 2;

                comboBoxImageFormat.Items.Clear();
                comboBoxImageFormat.Items.Add("Png 32-bit");
                comboBoxImageFormat.Items.Add("Png 8-bit");
                if (comboBoxImageFormat.Items[1].ToString() == Configuration.Settings.Tools.ExportBdnXmlImageType)
                    comboBoxImageFormat.SelectedIndex = 1;
                else
                    comboBoxImageFormat.SelectedIndex = 0;
            }
            else if (exportType == "DOST")
            {
                labelFrameRate.Top = labelLanguage.Top;
                comboBoxFrameRate.Top = comboBoxLanguage.Top;
                comboBoxFrameRate.Items.Add("23.98");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("30");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.SelectedIndex = 2;
            }
            else if (exportType == "IMAGE/FRAME")
            {
                labelFrameRate.Top = labelLanguage.Top;
                comboBoxFrameRate.Top = comboBoxLanguage.Top;
                comboBoxFrameRate.Items.Add("23.976");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("30");
                comboBoxFrameRate.Items.Add("50");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.Items.Add("60");
                comboBoxFrameRate.SelectedIndex = 2;
            }
            else if (exportType == "BLURAYSUP")
            {
                labelFrameRate.Top = labelLanguage.Top;
                comboBoxFrameRate.Top = comboBoxLanguage.Top;
                comboBoxFrameRate.Items.Add("23.976");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("50");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.SelectedIndex = 1;
                comboBoxFrameRate.DropDownStyle = ComboBoxStyle.DropDownList;

                checkBoxFullFrameImage.Top = comboBoxImageFormat.Top + 2;
                panelFullFrameBackground.Top = checkBoxFullFrameImage.Top;
            }
            else if (exportType == "FAB")
            {
                labelFrameRate.Visible = true;
                comboBoxFrameRate.Items.Add("23.976");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("50");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.SelectedIndex = 1;
                comboBoxFrameRate.DropDownStyle = ComboBoxStyle.DropDownList;
            }
            else if (exportType == "FCP")
            {
                labelFrameRate.Visible = true;
                comboBoxFrameRate.Items.Add("23.976");
                comboBoxFrameRate.Items.Add("24");
                comboBoxFrameRate.Items.Add("25");
                comboBoxFrameRate.Items.Add("29.97");
                comboBoxFrameRate.Items.Add("50");
                comboBoxFrameRate.Items.Add("59.94");
                comboBoxFrameRate.Items.Add("60");
                comboBoxFrameRate.SelectedIndex = 2;
                comboBoxFrameRate.DropDownStyle = ComboBoxStyle.DropDownList;
            }
            if (comboBoxFrameRate.Items.Count >= 2)
            {
                SetLastFrameRate(Configuration.Settings.Tools.ExportLastFrameRate);
            }
            panelShadowColor.BackColor = Configuration.Settings.Tools.ExportShadowColor;

            for (int i = 0; i < 1000; i++)
                comboBoxBottomMargin.Items.Add(i);
            if (Configuration.Settings.Tools.ExportBottomMargin >= 0 && Configuration.Settings.Tools.ExportBottomMargin < comboBoxBottomMargin.Items.Count)
                comboBoxBottomMargin.SelectedIndex = Configuration.Settings.Tools.ExportBottomMargin;

            if (exportType == "BLURAYSUP" || exportType == "IMAGE/FRAME" && Configuration.Settings.Tools.ExportBluRayBottomMargin >= 0 && Configuration.Settings.Tools.ExportBluRayBottomMargin < comboBoxBottomMargin.Items.Count)
                comboBoxBottomMargin.SelectedIndex = Configuration.Settings.Tools.ExportBluRayBottomMargin;

            if (_exportType == "BLURAYSUP" || _exportType == "VOBSUB" || _exportType == "IMAGE/FRAME" || _exportType == "BDNXML" || _exportType == "DOST" || _exportType == "FAB" || _exportType == "EDL")
            {
                comboBoxBottomMargin.Visible = true;
                labelBottomMargin.Visible = true;

                comboBoxLeftRightMargin.Visible = true;
                labelLeftRightMargin.Visible = true;
                comboBoxLeftRightMargin.SelectedIndex = 10;
            }
            else
            {
                comboBoxBottomMargin.Visible = false;
                labelBottomMargin.Visible = false;

                comboBoxLeftRightMargin.Visible = false;
                labelLeftRightMargin.Visible = false;
            }

            checkBoxSkipEmptyFrameAtStart.Visible = exportType == "IMAGE/FRAME";

            foreach (var x in FontFamily.Families)
            {
                if (x.IsStyleAvailable(FontStyle.Regular) || x.IsStyleAvailable(FontStyle.Bold))
                {
                    comboBoxSubtitleFont.Items.Add(x.Name);
                    if (x.Name.Equals(_subtitleFontName, StringComparison.OrdinalIgnoreCase))
                        comboBoxSubtitleFont.SelectedIndex = comboBoxSubtitleFont.Items.Count - 1;
                }
            }
            if (comboBoxSubtitleFont.SelectedIndex == -1)
                comboBoxSubtitleFont.SelectedIndex = 0; // take first font if default font not found (e.g. linux)

            if (videoInfo != null && videoInfo.Height > 0 && videoInfo.Width > 0)
            {
                comboBoxResolution.Items[comboBoxResolution.Items.Count - 1] = videoInfo.Width + "x" + videoInfo.Height;
                comboBoxResolution.SelectedIndex = comboBoxResolution.Items.Count - 1;
            }

            if (_subtitleFontSize == Configuration.Settings.Tools.ExportLastFontSize && Configuration.Settings.Tools.ExportLastLineHeight >= numericUpDownLineSpacing.Minimum &&
                Configuration.Settings.Tools.ExportLastLineHeight <= numericUpDownLineSpacing.Maximum && Configuration.Settings.Tools.ExportLastLineHeight > 0)
            {
                numericUpDownLineSpacing.Value = Configuration.Settings.Tools.ExportLastLineHeight;
            }

            if (Configuration.Settings.Tools.ExportLastBorderWidth >= 0 && Configuration.Settings.Tools.ExportLastBorderWidth < comboBoxBorderWidth.Items.Count)
            {
                try
                {
                    comboBoxBorderWidth.SelectedIndex = Configuration.Settings.Tools.ExportLastBorderWidth;
                }
                catch
                {
                }
            }
            checkBoxBold.Checked = Configuration.Settings.Tools.ExportLastFontBold;

            if (Configuration.Settings.Tools.Export3DType >= 0 && Configuration.Settings.Tools.Export3DType < comboBox3D.Items.Count)
                comboBox3D.SelectedIndex = Configuration.Settings.Tools.Export3DType;
            if (Configuration.Settings.Tools.Export3DDepth >= numericUpDownDepth3D.Minimum && Configuration.Settings.Tools.Export3DDepth <= numericUpDownDepth3D.Maximum)
                numericUpDownDepth3D.Value = Configuration.Settings.Tools.Export3DDepth;

            if (Configuration.Settings.Tools.ExportHorizontalAlignment >= 0 && Configuration.Settings.Tools.ExportHorizontalAlignment < comboBoxHAlign.Items.Count)
                comboBoxHAlign.SelectedIndex = Configuration.Settings.Tools.ExportHorizontalAlignment;

            if (exportType == "DCINEMA_INTEROP")
            {
                comboBox3D.Visible = false;
                numericUpDownDepth3D.Enabled = true;
                labelDepth.Enabled = true;
                labelDepth.Text = Configuration.Settings.Language.DCinemaProperties.ZPosition;
            }

            if (_exportType == "FCP")
            {
                comboBoxResolution.Items.Clear();
                comboBoxResolution.Items.Add("NTSC-601");
                comboBoxResolution.Items.Add("PAL-601");
                comboBoxResolution.Items.Add("square");
                comboBoxResolution.Items.Add("DVCPROHD-720P");
                comboBoxResolution.Items.Add("HD-(960x720)");
                comboBoxResolution.Items.Add("DVCPROHD-1080i60");
                comboBoxResolution.Items.Add("HD-(1280x1080)");
                comboBoxResolution.Items.Add("DVCPROHD-1080i50");
                comboBoxResolution.Items.Add("HD-(1440x1080)");
                comboBoxResolution.SelectedIndex = 3; // 720p
                buttonCustomResolution.Visible = true; // we still allow for custom resolutions

                labelLanguage.Text = "NTSC/PAL";
                comboBoxLanguage.Items.Clear();
                comboBoxLanguage.Items.Add("PAL");
                comboBoxLanguage.Items.Add("NTSC");
                comboBoxLanguage.SelectedIndex = 0;
                comboBoxLanguage.Visible = true;
                labelLanguage.Visible = true;
            }

            comboBoxShadowWidth.SelectedIndex = 0;
            bool shadowVisible = _exportType == "BDNXML" || _exportType == "BLURAYSUP" || _exportType == "DOST" || _exportType == "IMAGE/FRAME" || _exportType == "FCP" || _exportType == "DCINEMA_INTEROP" || _exportType == "EDL";
            labelShadowWidth.Visible = shadowVisible;
            buttonShadowColor.Visible = shadowVisible;
            comboBoxShadowWidth.Visible = shadowVisible;
            if (shadowVisible && Configuration.Settings.Tools.ExportBluRayShadow < comboBoxShadowWidth.Items.Count)
                comboBoxShadowWidth.SelectedIndex = Configuration.Settings.Tools.ExportBluRayShadow;
            panelShadowColor.Visible = shadowVisible;
            labelShadowTransparency.Visible = shadowVisible;
            numericUpDownShadowTransparency.Visible = shadowVisible;

            if (exportType == "BLURAYSUP" || exportType == "VOBSUB" || exportType == "BDNXML")
            {
                subtitleListView1.CheckBoxes = true;
                subtitleListView1.Columns.Insert(0, Configuration.Settings.Language.ExportPngXml.Forced);

                SubtitleListView1Fill(_subtitle);

                if (_vobSubOcr != null)
                {
                    for (int index = 0; index < _subtitle.Paragraphs.Count; index++)
                    {
                        if (_vobSubOcr.GetIsForced(index))
                            subtitleListView1.Items[index].Checked = true;
                    }
                }

                SubtitleListView1SelectIndexAndEnsureVisible(0);
            }
            else
            {
                SubtitleListView1Fill(_subtitle);
                SubtitleListView1SelectIndexAndEnsureVisible(0);
            }
        }
Exemplo n.º 34
0
 public virtual void RemoveNativeFormatting(Subtitle subtitle, SubtitleFormat newFormat)
 {
 }
Exemplo n.º 35
0
        private static ContentAlignment GetAlignmentFromParagraph(MakeBitmapParameter p, SubtitleFormat format, Subtitle subtitle)
        {
            var alignment = ContentAlignment.BottomCenter;
            if (p.AlignLeft)
                alignment = ContentAlignment.BottomLeft;
            else if (p.AlignRight)
                alignment = ContentAlignment.BottomRight;

            if (format.HasStyleSupport && !string.IsNullOrEmpty(p.P.Extra))
            {
                if (format.GetType() == typeof(SubStationAlpha))
                {
                    var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
                    alignment = GetSsaAlignment("{\\a" + style.Alignment + "}", alignment);
                }
                else if (format.GetType() == typeof(AdvancedSubStationAlpha))
                {
                    var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
                    alignment = GetAssAlignment("{\\an" + style.Alignment + "}", alignment);
                }
            }

            string text = p.P.Text;
            if (format.GetType() == typeof(SubStationAlpha) && text.Length > 5)
            {
                text = p.P.Text.Substring(0, 6);
                alignment = GetSsaAlignment(text, alignment);
            }
            else if (text.Length > 6)
            {
                text = p.P.Text.Substring(0, 6);
                alignment = GetAssAlignment(text, alignment);
            }
            return alignment;
        }