当前位置: 首页>>代码示例>>C#>>正文


C# Core.Subtitle类代码示例

本文整理汇总了C#中Nikse.SubtitleEdit.Core.Subtitle的典型用法代码示例。如果您正苦于以下问题:C# Subtitle类的具体用法?C# Subtitle怎么用?C# Subtitle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Subtitle类属于Nikse.SubtitleEdit.Core命名空间,在下文中一共展示了Subtitle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        public void Initialize(Subtitle subtitle)
        {
            _subtitle = subtitle;

            FindAllNames();
            GeneratePreview();
        }
开发者ID:Gargamelll,项目名称:subtitleedit,代码行数:7,代码来源:ChangeCasingNames.cs

示例2: Initialize

        internal void Initialize(Ebu.EbuGeneralSubtitleInformation header, byte justificationCode, string fileName, Subtitle subtitle)
        {
            _header = header;
            _subtitle = subtitle;

            FillFromHeader(header);
            if (!string.IsNullOrEmpty(fileName))
            {
                try
                {
                    FillHeaderFromFile(fileName);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("EbuOptions unable to read existing file: " + fileName + "  - " + ex.Message);
                }
                string title = Path.GetFileNameWithoutExtension(fileName);
                if (title.Length > 32)
                    title = title.Substring(0, 32).Trim();
                textBoxOriginalProgramTitle.Text = title;
            }

            comboBoxJustificationCode.SelectedIndex = justificationCode;

            Text = Configuration.Settings.Language.EbuSaveOptions.Title;
            buttonOK.Text = Configuration.Settings.Language.General.Ok;
            buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
        }
开发者ID:hihihippp,项目名称:subtitleedit,代码行数:28,代码来源:EbuSaveOptions.cs

示例3: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("#\tAppearance\tCaption\t");
            sb.AppendLine();
            int count = 1;
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                string text = HtmlUtil.RemoveHtmlTags(p.Text);
                sb.AppendLine(string.Format("{0}\t{1}\t{2}\t", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.StartTime), text));
                sb.AppendLine("\t\t\t\t");
                Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
                if (next == null || Math.Abs(p.EndTime.TotalMilliseconds - next.StartTime.TotalMilliseconds) > 50)
                {
                    count++;
                    sb.AppendLine(string.Format("{0}\t{1}", count.ToString().PadLeft(5, ' '), MakeTimeCode(p.EndTime)));
                }

                count++;
            }

            RichTextBox rtBox = new RichTextBox();
            rtBox.Text = sb.ToString();
            string rtf = rtBox.Rtf;
            rtBox.Dispose();
            return rtf;
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:28,代码来源:UnknownSubtitle21.cs

示例4: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            const int startPosition = 0xa99;
            const int textPosition = 72;

            _errorCount = 0;
            subtitle.Paragraphs.Clear();
            subtitle.Header = null;
            var buffer = FileUtil.ReadAllBytesShared(fileName);
            int index = startPosition;
            if (buffer[index] != 1)
            {
                return;
            }

            while (index + textPosition < buffer.Length)
            {
                int textLength = buffer[index + 16];
                if (textLength > 0 && index + textPosition + textLength < buffer.Length)
                {
                    string text = GetText(index + textPosition, textLength, buffer);
                    if (!string.IsNullOrWhiteSpace(text))
                    {
                        int startFrames = GetFrames(index + 4, buffer);
                        int endFrames = GetFrames(index + 8, buffer);
                        subtitle.Paragraphs.Add(new Paragraph(text, FramesToMilliseconds(startFrames), FramesToMilliseconds(endFrames)));
                    }
                }
                index += textPosition + textLength;
            }
            subtitle.Renumber();
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:32,代码来源:Ayato.cs

示例5: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            string xmlStructure =
                "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
                "<root fps=\"25\" movie=\"program title\" language=\"GBR:English (UK)\" font=\"Arial\" style=\"normal\" size=\"48\">" + Environment.NewLine +
                "<reel start=\"\" first=\"\" last=\"\">" + Environment.NewLine +
                "</reel>" + Environment.NewLine +
                "</root>";

            var xml = new XmlDocument { XmlResolver = null };
            xml.LoadXml(xmlStructure);
            XmlNode reel = xml.DocumentElement.SelectSingleNode("reel");
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                XmlNode paragraph = xml.CreateElement("title");

                XmlAttribute start = xml.CreateAttribute("start");
                start.InnerText = ToTimeCode(p.StartTime.TotalMilliseconds);
                paragraph.Attributes.Append(start);

                XmlAttribute end = xml.CreateAttribute("end");
                end.InnerText = ToTimeCode(p.EndTime.TotalMilliseconds);
                paragraph.Attributes.Append(end);

                paragraph.InnerText = HtmlUtil.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, "|"), true);

                reel.AppendChild(paragraph);
            }

            return ToUtf8XmlString(xml);
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:31,代码来源:AbcIViewer.cs

示例6: GetVoices

        public static List<string> GetVoices(Subtitle subtitle)
        {
            var list = new List<string>();
            if (subtitle != null && subtitle.Paragraphs != null)
            {
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    string s = p.Text;
                    var startIndex = s.IndexOf("<v ", StringComparison.Ordinal);
                    while (startIndex >= 0)
                    {
                        int endIndex = s.IndexOf('>', startIndex);
                        if (endIndex > startIndex)
                        {
                            string voice = s.Substring(startIndex + 2, endIndex - startIndex - 2).Trim();
                            if (!list.Contains(voice))
                                list.Add(voice);
                        }

                        if (startIndex == s.Length - 1)
                            startIndex = -1;
                        else
                            startIndex = s.IndexOf("<v ", startIndex + 1, StringComparison.Ordinal);
                    }
                }
            }
            return list;
        }
开发者ID:aisam97,项目名称:subtitleedit,代码行数:28,代码来源:WebVTT.cs

示例7: StylesForm

        protected StylesForm(Subtitle subtitle)
        {
            _subtitle = subtitle;

            _previewTimer.Interval = 200;
            _previewTimer.Tick += PreviewTimerTick;
        }
开发者ID:ItsJustSean,项目名称:subtitleedit,代码行数:7,代码来源:StylesForm.cs

示例8: Save

        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <param name="subtitle">
        /// The subtitle.
        /// </param>
        public static void Save(string fileName, Subtitle subtitle)
        {
            FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);

            // header
            fs.WriteByte(1);
            for (int i = 1; i < 23; i++)
            {
                fs.WriteByte(0);
            }

            fs.WriteByte(0x60);

            // paragraphs
            int number = 0;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                WriteParagraph(p);
                number++;
            }

            // footer
            fs.WriteByte(0xff);
            for (int i = 0; i < 11; i++)
            {
                fs.WriteByte(0);
            }

            fs.WriteByte(0x11);
            byte[] footerBuffer = Encoding.ASCII.GetBytes("dummy end of file");
            fs.Write(footerBuffer, 0, footerBuffer.Length);

            fs.Close();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:43,代码来源:Spt.cs

示例9: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            StringBuilder sb = new StringBuilder();
            if (!string.IsNullOrEmpty(subtitle.Header) && (subtitle.Header.Contains("[ar:") || subtitle.Header.Contains("[ti:")))
            {
                sb.Append(subtitle.Header);
            }

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                Paragraph next = null;
                if (i + 1 < subtitle.Paragraphs.Count)
                {
                    next = subtitle.Paragraphs[i + 1];
                }

                string text = HtmlUtil.RemoveHtmlTags(p.Text);
                text = text.Replace(Environment.NewLine, " "); // text = text.Replace(Environment.NewLine, "|");
                sb.AppendLine(string.Format("[{0:00}:{1:00}.{2:00}]{3}", p.StartTime.Hours * 60 + p.StartTime.Minutes, p.StartTime.Seconds, (int)Math.Round(p.StartTime.Milliseconds / 10.0), text));

                if (next == null || next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 100)
                {
                    TimeCode tc = new TimeCode(p.EndTime.TotalMilliseconds);
                    sb.AppendLine(string.Format("[{0:00}:{1:00}.{2:00}]{3}", tc.Hours * 60 + tc.Minutes, tc.Seconds, (int)Math.Round(tc.Milliseconds / 10.0), string.Empty));
                }
            }

            return sb.ToString().Trim();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:30,代码来源:Lrc.cs

示例10: Initialize

        public void Initialize(Subtitle subtitle, bool autoBalance)
        {
            _modeAutoBalance = autoBalance;
            _paragraphs = new List<Paragraph>();

            foreach (Paragraph p in subtitle.Paragraphs)
                _paragraphs.Add(p);

            if (autoBalance)
            {
                labelCondition.Text = Configuration.Settings.Language.AutoBreakUnbreakLines.OnlyBreakLinesLongerThan;
                const int start = 10;
                const int max = 60;
                for (int i = start; i <= max; i++)
                    comboBoxConditions.Items.Add(i.ToString(CultureInfo.InvariantCulture));

                int index = Configuration.Settings.Tools.MergeLinesShorterThan - (start + 1);
                if (index > 0 && index < max)
                    comboBoxConditions.SelectedIndex = index;
                else
                    comboBoxConditions.SelectedIndex = 30;

                AutoBalance();
            }
            else
            {
                labelCondition.Text = Configuration.Settings.Language.AutoBreakUnbreakLines.OnlyUnbreakLinesLongerThan;
                for (int i = 5; i < 51; i++)
                    comboBoxConditions.Items.Add(i.ToString(CultureInfo.InvariantCulture));
                comboBoxConditions.SelectedIndex = 5;

                Unbreak();
            }
            comboBoxConditions.SelectedIndexChanged += ComboBoxConditionsSelectedIndexChanged;
        }
开发者ID:Gargamelll,项目名称:subtitleedit,代码行数:35,代码来源:AutoBreakUnbreakLines.cs

示例11: ExportTextST

        public ExportTextST(Subtitle subtitle)
        {
            InitializeComponent();

            SetGroupBoxProperties(groupBoxPropertiesPalette);
            SetGroupBoxProperties(groupBoxPropertiesRegionStyle);
            SetGroupBoxProperties(groupBoxPropertiesUserStyle);
            SetGroupBoxProperties(groupBoxPresentationSegmentRegion);
            SetGroupBoxProperties(groupBoxFontStyle);
            SetGroupBoxProperties(groupBoxChangeFontSize);
            SetGroupBoxProperties(groupBoxSubtitleText);
            SetGroupBoxProperties(groupBoxChangeFontColor);
            SetGroupBoxProperties(groupBoxFontSet);

            _subtitle = subtitle;

            _textST = new TextST
            {
                StyleSegment = TextST.DialogStyleSegment.DefaultDialogStyleSegment,
                PresentationSegments = new List<TextST.DialogPresentationSegment>(),
            };
            _textST.StyleSegment.NumberOfDialogPresentationSegments = _subtitle.Paragraphs.Count;
            foreach (var paragraph in _subtitle.Paragraphs)
            {
                var dps = new TextST.DialogPresentationSegment(paragraph, _textST.StyleSegment.RegionStyles[0]);
                _textST.PresentationSegments.Add(dps);
            }

            UpdateTreeview();
        }
开发者ID:YangEunYong,项目名称:subtitleedit,代码行数:30,代码来源:ExportTextST.cs

示例12: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            StringBuilder temp = new StringBuilder();
            foreach (string l in lines)
            {
                temp.Append(l);
            }

            string all = temp.ToString();
            if (!all.Contains("{\"content\":\""))
            {
                return;
            }

            string[] arr = all.Replace("\n", string.Empty).Replace("{\"content\":\"", "\n").Split('\n');

            this._errorCount = 0;
            subtitle.Paragraphs.Clear();

            // {"content":"La ce se gandeste  Oh Ha Ni a noastra <br> de la inceputul dimineti?","start_time":314071,"end_time":317833},
            for (int i = 0; i < arr.Length; i++)
            {
                string line = arr[i].Trim();

                int indexStartTime = line.IndexOf("\"start_time\":", StringComparison.Ordinal);
                int indexEndTime = line.IndexOf("\"end_time\":", StringComparison.Ordinal);
                if (indexStartTime > 0 && indexEndTime > 0)
                {
                    int indexEndText = indexStartTime;
                    if (indexStartTime > indexEndTime)
                    {
                        indexEndText = indexEndTime;
                    }

                    string text = line.Substring(0, indexEndText - 1).Trim().TrimEnd('\"');
                    text = text.Replace("<br>", Environment.NewLine).Replace("<BR>", Environment.NewLine);
                    text = text.Replace("<br/>", Environment.NewLine).Replace("<BR/>", Environment.NewLine);
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                    text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                    text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                    text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                    try
                    {
                        string start = line.Substring(indexStartTime);
                        string end = line.Substring(indexEndTime);
                        Paragraph paragraph = new Paragraph { Text = text, StartTime = { TotalMilliseconds = GetMilliseconds(start) }, EndTime = { TotalMilliseconds = GetMilliseconds(end) } };
                        subtitle.Paragraphs.Add(paragraph);
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception.Message);
                        this._errorCount++;
                    }
                }
            }

            subtitle.Renumber();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:60,代码来源:UnknownSubtitle10.cs

示例13: LoadSubtitle

        public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
        {
            _errorCount = 0;
            Paragraph p = null;
            foreach (string line in lines)
            {
                string s = line.Trim();
                if (regexTimeCodes.Match(s).Success)
                {
                    if (p != null && !string.IsNullOrEmpty(p.Text))
                        subtitle.Paragraphs.Add(p);
                    p = new Paragraph();

                    try
                    {
                        string[] arr = s.Substring(0, 11).Split(':');
                        if (arr.Length == 4)
                        {
                            int hours = int.Parse(arr[0]);
                            int minutes = int.Parse(arr[1]);
                            int seconds = int.Parse(arr[2]);
                            int frames = int.Parse(arr[3]);
                            p.StartTime = new TimeCode(hours, minutes, seconds, FramesToMillisecondsMax999(frames));
                            string text = s.Remove(0, 11).Trim();
                            p.Text = text;
                            if (text.Length > 1 && Utilities.IsInteger(text.Substring(0, 2)))
                                _errorCount++;
                        }
                    }
                    catch
                    {
                        _errorCount++;
                    }
                }
                else if (s.Length > 0)
                {
                    _errorCount++;
                }
            }
            if (p != null && !string.IsNullOrEmpty(p.Text))
                subtitle.Paragraphs.Add(p);

            int index = 1;
            foreach (Paragraph paragraph in subtitle.Paragraphs)
            {
                paragraph.Text = paragraph.Text.Replace("\\M", "♪");

                Paragraph next = subtitle.GetParagraphOrDefault(index);
                if (next != null)
                {
                    paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
                }
                else
                {
                    paragraph.EndTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(paragraph.Text);
                }
                index++;
            }
            subtitle.RemoveEmptyLines();
        }
开发者ID:socialpercon,项目名称:subtitleedit,代码行数:60,代码来源:UnknownSubtitle53.cs

示例14: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            // 10 04 36 02
            // 10 04 37 04
            // Greetings.
            // 10 04 37 06
            // 10 04 40 08
            // It's confirmed, after reading
            // Not Out on the poster..
            // 10 04 40 15
            // 10 04 44 06
            // ..you have not come to pass you
            // time, in this unique story.
            const string paragraphWriteFormat = "{0}{3}{1}{3}{2}";
            StringBuilder sb = new StringBuilder();
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                string text = HtmlUtil.RemoveOpenCloseTags(p.Text, HtmlUtil.TagFont);
                if (!text.Contains(Environment.NewLine))
                {
                    text = Environment.NewLine + text;
                }

                sb.AppendLine(string.Format(paragraphWriteFormat, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), text, Environment.NewLine));
            }

            return sb.ToString().Trim();
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:28,代码来源:UnknownSubtitle49.cs

示例15: ToText

        public override string ToText(Subtitle subtitle, string title)
        {
            // <Phrase TimeStart="4020" TimeEnd="6020">
            // <Text>XYZ PRESENTS</Text>
            // </Phrase>
            string xmlStructure = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine + "<Subtitle xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"></Subtitle>";

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStructure);

            int id = 1;
            foreach (Paragraph p in subtitle.Paragraphs)
            {
                XmlNode paragraph = xml.CreateElement("Phrase");

                XmlAttribute start = xml.CreateAttribute("TimeStart");
                start.InnerText = p.StartTime.TotalMilliseconds.ToString();
                paragraph.Attributes.Append(start);

                XmlAttribute duration = xml.CreateAttribute("TimeEnd");
                duration.InnerText = p.EndTime.TotalMilliseconds.ToString();
                paragraph.Attributes.Append(duration);

                XmlNode text = xml.CreateElement("Text");
                text.InnerText = HtmlUtil.RemoveHtmlTags(p.Text).Replace(Environment.NewLine, "\\n");
                paragraph.AppendChild(text);

                xml.DocumentElement.AppendChild(paragraph);
                id++;
            }

            return ToUtf8XmlString(xml);
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:33,代码来源:UnknownSubtitle14.cs


注:本文中的Nikse.SubtitleEdit.Core.Subtitle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。