Beispiel #1
0
        public void LineContent()
        {
            var target   = new SubStationAlpha();
            var subtitle = new Subtitle();

            subtitle.Paragraphs.Add(new Paragraph("Line 1", 0, 3000));
            subtitle.Paragraphs.Add(new Paragraph("Line 2", 4000, 7000));
            subtitle.Paragraphs.Add(new Paragraph("Line 3", 8000, 11000));
            subtitle.Paragraphs.Add(new Paragraph("Line 4", 12000, 15000));

            foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
            {
                format.BatchMode = true;
                string text = format.ToText(subtitle, "test");
                var    list = new List <string>();
                foreach (string line in text.Replace("\r\n", "\n").Split('\n'))
                {
                    list.Add(line);
                }
                var s2 = new Subtitle();
                format.LoadSubtitle(s2, list, null);

                if (s2.Paragraphs.Count == 4)
                {
                    Assert.AreEqual(subtitle.Paragraphs[0].Text, s2.Paragraphs[0].Text, format.FriendlyName);
                    Assert.AreEqual(subtitle.Paragraphs[3].Text, s2.Paragraphs[3].Text, format.FriendlyName);
                }
            }
        }
Beispiel #2
0
        private string GetDefaultHeader()
        {
            SubtitleFormat format;

            if (_isSubStationAlpha)
            {
                format = new SubStationAlpha();
            }
            else
            {
                format = new AdvancedSubStationAlpha();
            }
            var    sub  = new Subtitle();
            string text = format.ToText(sub, string.Empty);

            string[] lineArray = text.Split(Environment.NewLine.ToCharArray());
            var      lines     = new List <string>();

            foreach (string line in lineArray)
            {
                lines.Add(line);
            }
            format.LoadSubtitle(sub, lines, string.Empty);
            return(sub.Header.Trim());
        }
Beispiel #3
0
        private void OpenFile2(string fileName)
        {
            var lines = new List <string>();

            foreach (var line in File.ReadAllLines(fileName))
            {
                lines.Add(line);
            }
            SubtitleFormat format = new SubRip();

            if (!format.IsMine(lines, fileName))
            {
                format = new AdvancedSubStationAlpha();
            }
            if (!format.IsMine(lines, fileName))
            {
                format = new SubStationAlpha();
            }

            if (format.IsMine(lines, fileName))
            {
                textBox2.Text = fileName;
                _subtitle2    = new Subtitle();
                format.LoadSubtitle(_subtitle2, lines, fileName);
                subtitleListView2.Fill(_subtitle2);
                if (_subtitle2.Paragraphs.Count > 0)
                {
                    subtitleListView1.SelectIndexAndEnsureVisible(0);
                }
                GeneratePreview();
            }
        }
Beispiel #4
0
        public void SsaSimpleFontColorAndItalic()
        {
            var target   = new SubStationAlpha();
            var subtitle = new Subtitle();

            target.LoadSubtitle(subtitle, GetSsaLines(@"{\c&HFFFF00&\i1}CYAN{\i0}"), null);
            string       actual   = subtitle.Paragraphs[0].Text;
            const string expected = "<font color=\"#00ffff\"><i>CYAN</i></font>";

            Assert.AreEqual(expected, actual);
        }
        private void ResetHeader()
        {
            SubtitleFormat format;

            if (_isSubStationAlpha)
            {
                format = new SubStationAlpha();
            }
            else
            {
                format = new AdvancedSubStationAlpha();
            }
            var    sub   = new Subtitle();
            string text  = format.ToText(sub, string.Empty);
            var    lines = text.SplitToLines();

            format.LoadSubtitle(sub, lines, string.Empty);
            _header = sub.Header;
        }
Beispiel #6
0
        private string GetDefaultHeader()
        {
            SubtitleFormat format;

            if (_isSubStationAlpha)
            {
                format = new SubStationAlpha();
            }
            else
            {
                format = new AdvancedSubStationAlpha();
            }
            var    sub   = new Subtitle();
            string text  = format.ToText(sub, string.Empty);
            var    lines = text.SplitToLines();

            format.LoadSubtitle(sub, lines, string.Empty);
            return(sub.Header.Trim());
        }
Beispiel #7
0
        public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName)
        {
            InitializeComponent();
            _subtitle          = subtitle;
            _isSubStationAlpha = format.FriendlyName == new SubStationAlpha().FriendlyName;
            _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)
            {
                SubStationAlpha ssa   = new SubStationAlpha();
                var             sub   = new Subtitle();
                var             lines = new List <string>();
                foreach (string line in subtitle.ToText(ssa).Replace(Environment.NewLine, "\n").Split('\n'))
                {
                    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.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                {
                    string s = line.ToLower().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().ToLower() == "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;

            FixLargeFonts();
        }
        public SubStationAlphaProperties(Subtitle subtitle, SubtitleFormat format, string videoFileName, string subtitleFileName)
        {
            UiUtil.PreInitialize(this);
            InitializeComponent();
            UiUtil.FixFonts(this);
            _subtitle          = subtitle;
            _isSubStationAlpha = format.Name == SubStationAlpha.NameOfFormat;
            _videoFileName     = videoFileName;

            var l = LanguageSettings.Current.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 = subtitle.ToText(ssa).SplitToLines();
                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:", StringComparison.Ordinal))
                    {
                        textBoxTitle.Text = s.Remove(0, 6).Trim();
                    }
                    else if (s.StartsWith("original script:", StringComparison.Ordinal))
                    {
                        textBoxOriginalScript.Text = s.Remove(0, 16).Trim();
                    }
                    else if (s.StartsWith("original translation:", StringComparison.Ordinal))
                    {
                        textBoxTranslation.Text = s.Remove(0, 21).Trim();
                    }
                    else if (s.StartsWith("original editing:", StringComparison.Ordinal))
                    {
                        textBoxEditing.Text = s.Remove(0, 17).Trim();
                    }
                    else if (s.StartsWith("original timing:", StringComparison.Ordinal))
                    {
                        textBoxTiming.Text = s.Remove(0, 16).Trim();
                    }
                    else if (s.StartsWith("synch point:", StringComparison.Ordinal))
                    {
                        textBoxSyncPoint.Text = s.Remove(0, 12).Trim();
                    }
                    else if (s.StartsWith("script updated by:", StringComparison.Ordinal))
                    {
                        textBoxUpdatedBy.Text = s.Remove(0, 18).Trim();
                    }
                    else if (s.StartsWith("update details:", StringComparison.Ordinal))
                    {
                        textBoxUpdateDetails.Text = s.Remove(0, 15).Trim();
                    }
                    else if (s.StartsWith("collisions:", StringComparison.Ordinal))
                    {
                        if (s.Remove(0, 11).Trim() == "reverse")
                        {
                            comboBoxCollision.SelectedIndex = 1;
                        }
                    }
                    else if (s.StartsWith("playresx:", StringComparison.Ordinal))
                    {
                        if (int.TryParse(s.Remove(0, 9).Trim(), out var number))
                        {
                            numericUpDownVideoWidth.Value = number;
                        }
                    }
                    else if (s.StartsWith("playresy:", StringComparison.Ordinal))
                    {
                        if (int.TryParse(s.Remove(0, 9).Trim(), out var number))
                        {
                            numericUpDownVideoHeight.Value = number;
                        }
                    }
                    else if (s.StartsWith("scaledborderandshadow:", StringComparison.Ordinal))
                    {
                        checkBoxScaleBorderAndShadow.Checked = s.Remove(0, 22).Trim().ToLowerInvariant().Equals("yes");
                    }
                    else if (s.StartsWith("wrapstyle:", StringComparison.Ordinal))
                    {
                        var wrapStyle = s.Remove(0, 10).Trim();
                        for (int i = 0; i < comboBoxWrapStyle.Items.Count; i++)
                        {
                            if (i.ToString(CultureInfo.InvariantCulture) == wrapStyle)
                            {
                                comboBoxWrapStyle.SelectedIndex = i;
                            }
                        }
                    }
                }
            }

            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     = LanguageSettings.Current.General.Ok;
            buttonCancel.Text = LanguageSettings.Current.General.Cancel;

            UiUtil.FixLargeFonts(this, buttonCancel);
        }
        private void ButtonRemoveAll_Click(object sender, EventArgs e)
        {
            this.listViewStyles.Items.Clear();
            var sub = new Subtitle();
            if (this.isSubStationAlpha)
            {
                var ssa = new SubStationAlpha();
                string text = ssa.ToText(sub, string.Empty);
                string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                var lines = new List<string>();
                foreach (string line in lineArray)
                {
                    lines.Add(line);
                }

                ssa.LoadSubtitle(sub, lines, string.Empty);
                this.header = this.header.Remove(this.header.IndexOf("[V4 Styles]", StringComparison.Ordinal)) + sub.Header.Substring(sub.Header.IndexOf("[V4 Styles]", StringComparison.Ordinal));
            }
            else
            {
                var ass = new AdvancedSubStationAlpha();
                string text = ass.ToText(sub, string.Empty);
                string[] lineArray = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                var lines = new List<string>();
                foreach (string line in lineArray)
                {
                    lines.Add(line);
                }

                ass.LoadSubtitle(sub, lines, string.Empty);
                this.header = this.header.Remove(this.header.IndexOf("[V4+ Styles]", StringComparison.Ordinal)) + sub.Header.Substring(sub.Header.IndexOf("[V4+ Styles]", StringComparison.Ordinal));
            }

            this.InitializeListView();
        }
        internal static SubtitleFormat LoadMatroskaTextSubtitle(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska, List<MatroskaSubtitle> sub, Subtitle subtitle)
        {
            if (subtitle == null)
            {
                throw new ArgumentNullException("subtitle");
            }

            subtitle.Paragraphs.Clear();

            var isSsa = false;
            SubtitleFormat format = new SubRip();
            if (matroskaSubtitleInfo.CodecPrivate.Contains("[script info]", StringComparison.OrdinalIgnoreCase))
            {
                if (matroskaSubtitleInfo.CodecPrivate.Contains("[V4 Styles]", StringComparison.OrdinalIgnoreCase))
                {
                    format = new SubStationAlpha();
                }
                else
                {
                    format = new AdvancedSubStationAlpha();
                }

                isSsa = true;
            }

            if (isSsa)
            {
                foreach (var p in LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs)
                {
                    subtitle.Paragraphs.Add(p);
                }

                if (!string.IsNullOrEmpty(matroskaSubtitleInfo.CodecPrivate))
                {
                    bool eventsStarted = false;
                    bool fontsStarted = false;
                    bool graphicsStarted = false;
                    var header = new StringBuilder();
                    foreach (string line in matroskaSubtitleInfo.CodecPrivate.Replace(Environment.NewLine, "\n").Split('\n'))
                    {
                        if (!eventsStarted && !fontsStarted && !graphicsStarted)
                        {
                            header.AppendLine(line);
                        }

                        if (line.TrimStart().StartsWith("dialog:", StringComparison.OrdinalIgnoreCase))
                        {
                            eventsStarted = true;
                            fontsStarted = false;
                            graphicsStarted = false;
                        }
                        else if (line.Trim().Equals("[events]", StringComparison.OrdinalIgnoreCase))
                        {
                            eventsStarted = true;
                            fontsStarted = false;
                            graphicsStarted = false;
                        }
                        else if (line.Trim().Equals("[fonts]", StringComparison.OrdinalIgnoreCase))
                        {
                            eventsStarted = false;
                            fontsStarted = true;
                            graphicsStarted = false;
                        }
                        else if (line.Trim().Equals("[graphics]", StringComparison.OrdinalIgnoreCase))
                        {
                            eventsStarted = false;
                            fontsStarted = false;
                            graphicsStarted = true;
                        }
                    }

                    subtitle.Header = header.ToString().TrimEnd();
                    if (!subtitle.Header.Contains("[events]", StringComparison.OrdinalIgnoreCase))
                    {
                        subtitle.Header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine;
                    }
                }
            }
            else
            {
                foreach (var p in sub)
                {
                    subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End));
                }
            }

            subtitle.Renumber();
            return format;
        }