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


C# Subtitle.AddTimeToAllParagraphs方法代码示例

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


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

示例1: LoadSubtitle


//.........这里部分代码省略.........
                    if (timeCode != "00:00:00:00" && regexTimeCodes.IsMatch(timeCode))
                    {
                        var p = new Paragraph();
                        p.StartTime = DecodeTimeCode(timeCode.Split(':'));
                        bool italic = buffer[i + 22] == 3; // 3=italic, 1=normal
                        int textStart = i + 25; // text starts 25 chars after time code
                        int textLength = 0;
                        while (textStart + textLength < buffer.Length && buffer[textStart + textLength] != 0)
                        {
                            textLength++;
                        }
                        if (textLength > 0)
                        {
                            p.Text = Encoding.GetEncoding(1252).GetString(buffer, textStart, textLength);
                            int rtIndex = p.Text.IndexOf("{\\rtf1", StringComparison.Ordinal);
                            if (rtIndex >= 0 && rtIndex < 10)
                            {
                                var rtBox = new System.Windows.Forms.RichTextBox();
                                try
                                {
                                    rtBox.Rtf = p.Text.Substring(rtIndex);
                                    p.Text = rtBox.Text;
                                }
                                catch (Exception exception)
                                {
                                    System.Diagnostics.Debug.WriteLine(exception.Message);
                                }
                                rtBox.Dispose();
                            }
                            else if (italic)
                            {
                                p.Text = "<i>" + p.Text + "</i>";
                            }
                        }
                        else
                        {
                            p.Text = string.Empty;
                        }
                        last = p;
                        subtitle.Paragraphs.Add(p);
                    }
                }
                i++;
            }
            if (last != null)
                last.EndTime.TotalMilliseconds = last.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(last.Text);

            for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds;
            }
            for (i = subtitle.Paragraphs.Count - 1; i >= 0; i--)
            {
                if (string.IsNullOrEmpty(subtitle.Paragraphs[i].Text))
                    subtitle.Paragraphs.RemoveAt(i);
            }

            var deletes = new List<int>();
            for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
                {
                    subtitle.Paragraphs[i].Text += Environment.NewLine + subtitle.Paragraphs[i + 1].Text;
                    subtitle.Paragraphs[i].EndTime = subtitle.Paragraphs[i + 1].EndTime;
                    deletes.Add(i + 1);
                }
            }
            deletes.Reverse();
            foreach (int index in deletes)
            {
                subtitle.Paragraphs.RemoveAt(index);
            }

            for (i = 0; i < subtitle.Paragraphs.Count - 1; i++)
            {
                if (subtitle.Paragraphs[i].StartTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
                {
                }
                else if (subtitle.Paragraphs[i].EndTime.TotalMilliseconds == subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds)
                {
                    subtitle.Paragraphs[i].EndTime.TotalMilliseconds = subtitle.Paragraphs[i + 1].StartTime.TotalMilliseconds - 1;
                }
            }
            subtitle.Renumber();

            // adjust all times
            if (buffer.Length > 1364)
            {
                try
                {
                    string adjust = Encoding.GetEncoding(1252).GetString(buffer, 1354, 11); // 00:59:59:28
                    TimeCode tc = DecodeTimeCode(adjust.Split(':'));
                    if (tc.TotalMilliseconds > 0)
                        subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(-tc.TotalMilliseconds));
                }
                catch
                {
                }
            }
        }
开发者ID:aisam97,项目名称:subtitleedit,代码行数:101,代码来源:CapMakerPlus.cs


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