當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。