public void AssSimpleBold()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\b1}Bold{\b0}"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<b>Bold</b>";
     Assert.AreEqual(expected, actual);
 }
 public void AssSimpleFontColor2()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\c&HFF00&}Font"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<font color=\"#00ff00\">Font</font>";
     Assert.AreEqual(expected, actual);
 }
 public void AssFontNameAndSize()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\fnViner Hand ITC\fs28}Testing"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<font face=\"Viner Hand ITC\" size=\"28\">Testing</font>";
     Assert.AreEqual(expected, actual);
 }
 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 = new List<string>();
     foreach (string line in text.SplitToLines())
         lines.Add(line);
     format.LoadSubtitle(sub, lines, string.Empty);
     return sub.Header.Trim();
 }
Esempio n. 5
0
        private Subtitle LoadMatroskaSubtitleForSync(MatroskaTrackInfo matroskaSubtitleInfo, MatroskaFile matroska)
        {
            var subtitle = new Subtitle();
            bool isSsa = false;

            if (matroskaSubtitleInfo.CodecId.Equals("S_VOBSUB", StringComparison.OrdinalIgnoreCase))
            {
                return subtitle;
            }
            if (matroskaSubtitleInfo.CodecId.Equals("S_HDMV/PGS", StringComparison.OrdinalIgnoreCase))
            {
                return subtitle;
            }

            SubtitleFormat format;
            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;
            }
            else
            {
                format = new SubRip();
            }

            var sub = matroska.GetSubtitle(matroskaSubtitleInfo.TrackNumber, MatroskaProgress);
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
            if (isSsa)
            {
                foreach (var p in Utilities.LoadMatroskaSSA(matroskaSubtitleInfo, matroska.Path, format, sub).Paragraphs)
                {
                    subtitle.Paragraphs.Add(p);
                }
            }
            else
            {
                foreach (var p in sub)
                {
                    subtitle.Paragraphs.Add(new Paragraph(p.Text, p.Start, p.End));
                }
            }
            return subtitle;
        }
 public void AssSimpleFontColorAndItalic()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\1c&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);
 }
 public void AssSimpleFontName()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\fnArial}Font"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<font face=\"Arial\">Font</font>";
     Assert.AreEqual(expected, actual);
 }
 public void AssSimpleUnderline()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\u1}Underline{\u0}"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<u>Underline</u>";
     Assert.AreEqual(expected, actual);
 }
 public void AssSimpleItalic()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\i1}Italic{\i0}"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<i>Italic</i>";
     Assert.AreEqual(expected, actual);
 }
Esempio n. 10
0
        public 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;
        }
Esempio n. 11
0
 private void ShowAssSsaStyles()
 {
     SubStationAlphaStyles form = null;
     try
     {
         var assa = new AdvancedSubStationAlpha();
         if (comboBoxSubtitleFormats.Text == assa.Name)
         {
             form = new SubStationAlphaStyles(new Subtitle(), assa);
             form.MakeOnlyOneStyle();
             if (form.ShowDialog(this) == DialogResult.OK)
             {
                 _assStyle = form.Header;
             }
         }
         else
         {
             var ssa = new SubStationAlpha();
             if (comboBoxSubtitleFormats.Text == ssa.Name)
             {
                 form = new SubStationAlphaStyles(new Subtitle(), ssa);
                 if (form.ShowDialog(this) == DialogResult.OK)
                 {
                     _ssaStyle = form.Header;
                 }
             }
         }
     }
     finally
     {
         if (form != null)
         {
             form.Dispose();
         }
     }
 }
 private void buttonRemoveAll_Click(object sender, EventArgs e)
 {
     listViewStyles.Items.Clear();
     var sub = new Subtitle();
     if (_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);
         _header = _header.Remove(_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);
         _header = _header.Remove(_header.IndexOf("[V4+ Styles]", StringComparison.Ordinal)) + sub.Header.Substring(sub.Header.IndexOf("[V4+ Styles]", StringComparison.Ordinal));
     }
     InitializeListView();
 }
 public void AssSizeAndOtherTags()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\fs20\pos(1,1)\blur5}Bla-bla-bla"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<font size=\"20\">{\\pos(1,1)\\blur5}Bla-bla-bla</font>";
     Assert.AreEqual(expected, actual);
 }
 public void AssSimpleFontSizeMultipleToText()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     subtitle.Paragraphs.Add(new Paragraph("<font size=\"1\">T</font><font size=\"2\">E</font><font size=\"3\">S</font><font size=\"4\">T</font>", 0, 2000));
     var result = target.ToText(subtitle, "");
     Assert.IsTrue(result.Contains(@"{\fs1}T{\fs2}E{\fs3}S{\fs4}T"));
 }
 public void AssSimpleFontSizeMultiple()
 {
     var target = new AdvancedSubStationAlpha();
     var subtitle = new Subtitle();
     target.LoadSubtitle(subtitle, GetAssLines(@"{\fs1}T{\fs2}E{\fs3}S{\fs4}T"), null);
     string actual = subtitle.Paragraphs[0].Text;
     const string expected = "<font size=\"1\">T</font><font size=\"2\">E</font><font size=\"3\">S</font><font size=\"4\">T</font>";
     Assert.AreEqual(expected, actual);
 }
Esempio n. 16
0
 private void ShowAssSsaStyles()
 {
     SubStationAlphaStylesBatchConvert form = null;
     try
     {
         var assa = new AdvancedSubStationAlpha();
         var sub = new Subtitle();
         if (comboBoxSubtitleFormats.Text == assa.Name)
         {
             if (!string.IsNullOrEmpty(_assStyle))
             {
                 sub.Header = _assStyle;
             }
             form = new SubStationAlphaStylesBatchConvert(sub, assa);
             if (form.ShowDialog(this) == DialogResult.OK)
             {
                 _assStyle = form.Header;
             }
         }
         else
         {
             if (!string.IsNullOrEmpty(_ssaStyle))
             {
                 sub.Header = _ssaStyle;
             }
             var ssa = new SubStationAlpha();
             if (comboBoxSubtitleFormats.Text == ssa.Name)
             {
                 form = new SubStationAlphaStylesBatchConvert(sub, ssa);
                 if (form.ShowDialog(this) == DialogResult.OK)
                 {
                     _ssaStyle = form.Header;
                 }
             }
         }
     }
     finally
     {
         if (form != null)
         {
             form.Dispose();
         }
     }
 }