本文整理汇总了C#中Nikse.SubtitleEdit.Core.Subtitle.GetParagraphOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.GetParagraphOrDefault方法的具体用法?C# Subtitle.GetParagraphOrDefault怎么用?C# Subtitle.GetParagraphOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Core.Subtitle
的用法示例。
在下文中一共展示了Subtitle.GetParagraphOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
internal void Initialize(Subtitle subtitle, int firstSelectedIndex)
{
var sb = new StringBuilder();
foreach (Paragraph p in subtitle.Paragraphs)
sb.AppendLine(p.Text);
string watermark = ReadWaterMark(sb.ToString().Trim());
LabelWatermark.Text = string.Format("Watermark: {0}", watermark);
if (watermark.Length == 0)
{
buttonRemove.Enabled = false;
textBoxWatermark.Focus();
}
else
{
groupBoxGenerate.Enabled = false;
buttonOK.Focus();
}
_firstSelectedIndex = firstSelectedIndex;
Paragraph current = subtitle.GetParagraphOrDefault(_firstSelectedIndex);
if (current != null)
radioButtonCurrentLine.Text = radioButtonCurrentLine.Text + " " + current.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString);
else
radioButtonCurrentLine.Enabled = false;
}
示例2: 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;
}
示例3: ToText
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
sb.Append("{\"words\":[");
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
// split words
string text = p.Text.Replace(Environment.NewLine, " ").Replace(" ", " ");
string[] words = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
List<string> times = GenerateTimes(words, text, p.StartTime, p.EndTime);
for (int j = 0; j < words.Length; j++)
{
sb.Append("[\"");
sb.Append(times[j]);
sb.Append("\",\"");
sb.Append(Json.EncodeJsonText(words[j]));
sb.Append("\"]");
sb.Append(',');
}
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next == null || next.StartTime.TotalMilliseconds - 200 < p.EndTime.TotalMilliseconds)
{
sb.Append("[\"");
sb.Append(Convert.ToInt64(p.EndTime.TotalMilliseconds));
sb.Append("\",\"");
sb.Append("\"]");
sb.Append(',');
}
}
return sb.ToString().Trim().TrimEnd(',') + "],\"paragraphs\":[],\"speakers\":{}}";
}
示例4: ToText
public override string ToText(Subtitle subtitle, string title)
{
string header = @"<!DOCTYPE html>
<html>
<head>" + Environment.NewLine + "\t<meta charset=\"utf-8\">" + Environment.NewLine + "\t<title>SMIL Timesheet</title>" + @"
</head>
<body>" + Environment.NewLine + "\t<div id=\"media\" data-timecontainer=\"excl\" data-timeaction=\"display\">" + Environment.NewLine + "\t\t<video data-syncmaster=\"true\" data-timeaction=\"none\" controls=\"true\" preload=\"auto\">" + Environment.NewLine + "\t\t\t<source type=\"video/webm\" src=\"_TITLE_.webm\"/>" + Environment.NewLine + "\t\t\t<source type=\"video/ogg\" src=\"_TITLE_.ogv\" />" + Environment.NewLine + "\t\t\t<source type=\"video/mp4\" src=\"_TITLE_.mp4\" />" + Environment.NewLine + "\t\t\tYour browser does not support the HTML5 <video> tag" + Environment.NewLine + "\t\t</video>" + Environment.NewLine;
const string paragraphWriteFormatOpen = "\t\t<p data-begin=\"{0}\">\r\n{1}\r\n</p>";
const string paragraphWriteFormat = "\t\t<p data-begin=\"{0}\" data-end=\"{1}\">\r\n{2}\r\n</p>";
int count = 1;
StringBuilder sb = new StringBuilder();
sb.AppendLine(header.Replace("_TITLE_", title));
foreach (Paragraph p in subtitle.Paragraphs)
{
Paragraph next = subtitle.GetParagraphOrDefault(count);
string text = p.Text;
if (next != null && Math.Abs(next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds) < 100)
{
sb.AppendLine(string.Format(paragraphWriteFormatOpen, EncodeTime(p.StartTime), text));
}
else
{
sb.AppendLine(string.Format(paragraphWriteFormat, EncodeTime(p.StartTime), EncodeTime(p.EndTime), text));
}
count++;
}
sb.AppendLine("\t</div>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
return sb.ToString().Trim();
}
示例5: AdjustAllParagraphs
public Subtitle AdjustAllParagraphs(Subtitle subtitle)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
AdjustParagraph(p);
}
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next != null)
{
if (p.EndTime.TotalMilliseconds >= next.StartTime.TotalMilliseconds)
p.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
}
}
return subtitle;
}
示例6: ToText
public override string ToText(Subtitle subtitle, string title)
{
StringBuilder sb = new StringBuilder();
int index = 0;
int index2 = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
index++;
StringBuilder text = new StringBuilder();
text.Append(HtmlUtil.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " ")));
while (text.Length < 34)
{
text.Append(' ');
}
sb.AppendFormat("{0}{1}", text, EncodeTimeCode(p.StartTime));
if (index % 50 == 1)
{
index2++;
sb.Append(new string(' ', 25) + index2);
}
sb.AppendLine();
Paragraph next = subtitle.GetParagraphOrDefault(index);
if (next != null && next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 150)
{
text = new StringBuilder();
while (text.Length < 34)
{
text.Append(' ');
}
sb.AppendLine(string.Format("{0}{1}", text, EncodeTimeCode(p.EndTime)));
}
}
return sb.ToString();
}
示例7: GetSelectedParagraph
public Paragraph GetSelectedParagraph(Subtitle subtitle)
{
if (subtitle != null && SelectedItems.Count > 0)
return subtitle.GetParagraphOrDefault(SelectedItems[0].Index);
return null;
}
示例8: FixHyphensRemove
public static string FixHyphensRemove(Subtitle subtitle, int i)
{
Paragraph p = subtitle.Paragraphs[i];
string text = p.Text;
if (text.TrimStart().StartsWith('-') || text.TrimStart().StartsWith("<i>-", StringComparison.OrdinalIgnoreCase) || text.TrimStart().StartsWith("<i> -", StringComparison.OrdinalIgnoreCase) || text.Contains(Environment.NewLine + '-') || text.Contains(Environment.NewLine + " -") || text.Contains(Environment.NewLine + "<i>-") || text.Contains(Environment.NewLine + "<i> -") || text.Contains(Environment.NewLine + "<I>-") || text.Contains(Environment.NewLine + "<I> -"))
{
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-') || HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith("--", StringComparison.Ordinal))
{
string[] noTaglines = HtmlUtil.RemoveHtmlTags(p.Text).SplitToLines();
int startHyphenCount = noTaglines.Count(line => line.TrimStart().StartsWith('-'));
if (startHyphenCount == 1)
{
bool remove = true;
string[] noTagparts = HtmlUtil.RemoveHtmlTags(text).SplitToLines();
if (noTagparts.Length == 2)
{
if (noTagparts[0].TrimStart().StartsWith('-') && noTagparts[1].Contains(": "))
{
remove = false;
}
if (noTagparts[1].TrimStart().StartsWith('-') && noTagparts[0].Contains(": "))
{
remove = false;
}
}
if (remove)
{
int idx = text.IndexOf('-');
StripableText st = new StripableText(text);
if (idx < 5 && st.Pre.Length >= idx)
{
text = text.Remove(idx, 1).TrimStart();
idx = text.IndexOf('-');
st = new StripableText(text);
if (idx < 5 && idx >= 0 && st.Pre.Length >= idx)
{
text = text.Remove(idx, 1).TrimStart();
st = new StripableText(text);
}
idx = text.IndexOf('-');
if (idx < 5 && idx >= 0 && st.Pre.Length >= idx)
{
text = text.Remove(idx, 1).TrimStart();
}
text = RemoveSpacesBeginLine(text);
}
else
{
int indexOfNewLine = text.IndexOf(Environment.NewLine, StringComparison.Ordinal);
if (indexOfNewLine > 0)
{
idx = text.IndexOf('-', indexOfNewLine);
if (idx >= 0 && indexOfNewLine + 5 > indexOfNewLine)
{
text = text.Remove(idx, 1).TrimStart().Replace(Environment.NewLine + " ", Environment.NewLine);
idx = text.IndexOf('-', indexOfNewLine);
if (idx >= 0 && indexOfNewLine + 5 > indexOfNewLine)
{
text = text.Remove(idx, 1).TrimStart();
text = RemoveSpacesBeginLine(text);
}
}
}
}
}
}
}
}
else if (text.StartsWith("<font ", StringComparison.Ordinal))
{
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-') || HtmlUtil.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith("--", StringComparison.Ordinal))
{
StripableText st = new StripableText(text);
if (st.Pre.EndsWith('-') || st.Pre.EndsWith("- ", StringComparison.Ordinal))
{
text = st.Pre.TrimEnd('-', ' ') + st.StrippedText + st.Post;
}
}
}
return text;
}
示例9: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
this._errorCount = 0;
Paragraph p = null;
foreach (string line in lines)
{
string s = line.Trim();
if (s.Length > 4 && s[2] == ':' && regexTimeCodes.Match(s).Success)
{
if (p != null && !string.IsNullOrEmpty(p.Text))
{
subtitle.Paragraphs.Add(p);
}
p = new Paragraph();
try
{
string[] arr = s.Substring(0, 8).Split(':');
if (arr.Length == 3)
{
int hours = int.Parse(arr[0]);
int minutes = int.Parse(arr[1]);
int seconds = int.Parse(arr[2]);
p.StartTime = new TimeCode(hours, minutes, seconds, 0);
string text = s.Remove(0, 12).Trim();
p.Text = text;
}
}
catch
{
this._errorCount++;
}
}
else if (p != null && regexNumberAndText.Match(s).Success)
{
if (p.Text.Length > 1000)
{
this._errorCount += 100;
return;
}
string text = s.Remove(0, 2).Trim();
p.Text = (p.Text + Environment.NewLine + text).Trim();
}
else if (s.Length > 0 && !Utilities.IsInteger(s))
{
this._errorCount++;
}
}
if (p != null && !string.IsNullOrEmpty(p.Text))
{
subtitle.Paragraphs.Add(p);
}
int index = 1;
foreach (Paragraph paragraph in subtitle.Paragraphs)
{
Paragraph next = subtitle.GetParagraphOrDefault(index);
if (next != null)
{
paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
}
index++;
}
subtitle.RemoveEmptyLines();
subtitle.Renumber();
}
示例10: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var sb = new StringBuilder();
foreach (string l in lines)
sb.AppendLine(l);
string allInput = sb.ToString();
string allInputLower = allInput.ToLower();
const string syncTag = "<p ";
var syncStartPos = allInputLower.IndexOf(syncTag, StringComparison.Ordinal);
int index = syncStartPos + syncTag.Length;
while (syncStartPos >= 0)
{
var syncEndPos = allInputLower.IndexOf("</p>", index, StringComparison.Ordinal);
if (syncEndPos > 0)
{
string s = allInput.Substring(syncStartPos + 2, syncEndPos - syncStartPos - 2);
int indexOfBegin = s.IndexOf(" data-begin=", StringComparison.Ordinal);
int indexOfAttributesEnd = s.IndexOf('>');
if (indexOfBegin >= 0 && indexOfAttributesEnd > indexOfBegin)
{
string text = s.Substring(indexOfAttributesEnd + 1).Trim();
text = text.Replace("<br>", Environment.NewLine);
text = text.Replace("<br/>", Environment.NewLine);
text = text.Replace("<br />", Environment.NewLine);
text = text.Replace("\t", " ");
while (text.Contains(" "))
text = text.Replace(" ", " ");
while (text.Contains(Environment.NewLine + " "))
text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
while (text.Contains(Environment.NewLine + Environment.NewLine))
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
string begin = s.Substring(indexOfBegin + " data-begin=".Length);
var tcBegin = new StringBuilder();
for (int i = 0; i <= 10; i++)
{
if (begin.Length > i && @"0123456789:.".Contains(begin[i]))
{
tcBegin.Append(begin[i]);
}
}
var tcEnd = new StringBuilder();
var indexOfEnd = s.IndexOf(" data-end=", StringComparison.Ordinal);
if (indexOfEnd >= 0)
{
string end = s.Substring(indexOfEnd + " data-end=".Length);
for (int i = 0; i <= 10; i++)
{
if (end.Length > i && @"0123456789:.".Contains(end[i]))
{
tcEnd.Append(end[i]);
}
}
}
var arr = tcBegin.ToString().Split(new[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length == 3 || arr.Length == 4)
{
var p = new Paragraph();
p.Text = text;
try
{
p.StartTime = DecodeTimeCode(arr);
if (tcEnd.Length > 0)
{
arr = tcEnd.ToString().Split(new[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries);
p.EndTime = DecodeTimeCode(arr);
}
subtitle.Paragraphs.Add(p);
}
catch
{
_errorCount++;
}
}
}
}
if (syncEndPos <= 0)
{
syncStartPos = -1;
}
else
{
syncStartPos = allInputLower.IndexOf(syncTag, syncEndPos, StringComparison.Ordinal);
index = syncStartPos + syncTag.Length;
}
}
index = 1;
foreach (Paragraph paragraph in subtitle.Paragraphs)
{
Paragraph next = subtitle.GetParagraphOrDefault(index);
if (next != null)
{
paragraph.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - 1;
}
else if (paragraph.EndTime.TotalMilliseconds < 50)
{
//.........这里部分代码省略.........
示例11: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
Paragraph p = null;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
string s = line.Trim();
var match = regexTimeCodes2.Match(s);
if (match.Success)
{
s = s.Substring(0, match.Index + 13).Trim();
}
match = regexTimeCodes1.Match(s);
if (match.Success && match.Index > 13)
{
string text = s.Substring(0, match.Index).Trim();
string timeCode = s.Substring(match.Index).Trim();
string[] startParts = timeCode.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4)
{
try
{
p = new Paragraph(DecodeTimeCode(startParts), new TimeCode(0, 0, 0, 0), text);
subtitle.Paragraphs.Add(p);
}
catch (Exception exception)
{
_errorCount++;
System.Diagnostics.Debug.WriteLine(exception.Message);
}
}
}
else if (string.IsNullOrWhiteSpace(line) || regexTimeCodes1.IsMatch(" " + s))
{
// skip empty lines
}
else if (!string.IsNullOrWhiteSpace(line) && p != null)
{
_errorCount++;
}
}
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph current = subtitle.Paragraphs[i];
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next != null)
current.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
else
current.EndTime.TotalMilliseconds = current.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(current.Text);
if (current.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
current.EndTime.TotalMilliseconds = current.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
}
subtitle.RemoveEmptyLines();
subtitle.Renumber();
}
示例12: ToText
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
sb.AppendLine(@"File Format=MacCaption_MCC V1.0
///////////////////////////////////////////////////////////////////////////////////
// Computer Prompting and Captioning Company
// Ancillary Data Packet Transfer File
//
// Permission to generate this format is granted provided that
// 1. This ANC Transfer file format is used on an as-is basis and no warranty is given, and
// 2. This entire descriptive information text is included in a generated .mcc file.
//
// General file format:
// HH:MM:SS:FF(tab)[Hexadecimal ANC data in groups of 2 characters]
// Hexadecimal data starts with the Ancillary Data Packet DID (Data ID defined in S291M)
// and concludes with the Check Sum following the User Data Words.
// Each time code line must contain at most one complete ancillary data packet.
// To transfer additional ANC Data successive lines may contain identical time code.
// Time Code Rate=[24, 25, 30, 30DF, 50, 60]
//
// ANC data bytes may be represented by one ASCII character according to the following schema:
// G FAh 00h 00h
// H 2 x (FAh 00h 00h)
// I 3 x (FAh 00h 00h)
// J 4 x (FAh 00h 00h)
// K 5 x (FAh 00h 00h)
// L 6 x (FAh 00h 00h)
// M 7 x (FAh 00h 00h)
// N 8 x (FAh 00h 00h)
// O 9 x (FAh 00h 00h)
// P FBh 80h 80h
// Q FCh 80h 80h
// R FDh 80h 80h
// S 96h 69h
// T 61h 01h
// U E1h 00h 00h
// Z 00h
//
///////////////////////////////////////////////////////////////////////////////////");
sb.AppendLine();
sb.AppendLine("UUID=" + Guid.NewGuid().ToString().ToUpper());// UUID=9F6112F4-D9D0-4AAF-AA95-854710D3B57A
sb.AppendLine("Creation Program=Subtitle Edit");
sb.AppendLine("Creation Date=" + DateTime.Now.ToLongDateString());
sb.AppendLine("Creation Time=" + DateTime.Now.ToShortTimeString());
sb.AppendLine();
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph p = subtitle.Paragraphs[i];
sb.AppendLine(string.Format("{0}\t{1}", ToTimeCode(p.StartTime.TotalMilliseconds), p.Text)); // TODO: Encode text - how???
sb.AppendLine();
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next == null || Math.Abs(next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds) > 100)
{
sb.AppendLine(string.Format("{0}\t???", ToTimeCode(p.EndTime.TotalMilliseconds))); // TODO: Some end text???
sb.AppendLine();
}
}
return sb.ToString();
}
示例13: Save
/// <summary>
/// The save.
/// </summary>
/// <param name="fileName">
/// The file name.
/// </param>
/// <param name="subtitle">
/// The subtitle.
/// </param>
/// <param name="batchMode">
/// The batch mode.
/// </param>
public static void Save(string fileName, Subtitle subtitle, bool batchMode)
{
EbuGeneralSubtitleInformation header = new EbuGeneralSubtitleInformation();
using (EbuSaveOptions saveOptions = new EbuSaveOptions())
{
if (subtitle.Header != null && subtitle.Header.Length > 1024 && (subtitle.Header.Contains("STL24") || subtitle.Header.Contains("STL25") || subtitle.Header.Contains("STL29") || subtitle.Header.Contains("STL30")))
{
header = ReadHeader(Encoding.UTF8.GetBytes(subtitle.Header));
saveOptions.Initialize(header, 0, null, subtitle);
}
else
{
saveOptions.Initialize(header, 0, fileName, subtitle);
}
if (!batchMode && saveOptions.ShowDialog() != DialogResult.OK)
{
return;
}
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
header.TotalNumberOfSubtitles = subtitle.Paragraphs.Count.ToString("D5"); // seems to be 1 higher than actual number of subtitles
header.TotalNumberOfTextAndTimingInformationBlocks = header.TotalNumberOfSubtitles;
string today = string.Format("{0:yyMMdd}", DateTime.Now);
if (today.Length == 6)
{
header.CreationDate = today;
header.RevisionDate = today;
}
Paragraph firstParagraph = subtitle.GetParagraphOrDefault(0);
if (firstParagraph != null)
{
TimeCode tc = firstParagraph.StartTime;
string firstTimeCode = string.Format("{0:00}{1:00}{2:00}{3:00}", tc.Hours, tc.Minutes, tc.Seconds, EbuTextTimingInformation.GetFrameFromMilliseconds(tc.Milliseconds, header.FrameRate));
if (firstTimeCode.Length == 8)
{
header.TimeCodeFirstInCue = firstTimeCode;
}
}
byte[] buffer = Encoding.Default.GetBytes(header.ToString());
fs.Write(buffer, 0, buffer.Length);
int subtitleNumber = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
EbuTextTimingInformation tti = new EbuTextTimingInformation();
int rows;
if (!int.TryParse(header.MaximumNumberOfDisplayableRows, out rows))
{
rows = 23;
}
if (header.DisplayStandardCode == "1" || header.DisplayStandardCode == "2")
{
// teletext
rows = 23;
}
else if (header.DisplayStandardCode == "0" && header.MaximumNumberOfDisplayableRows == "02")
{
// open subtitling
rows = 15;
}
if (p.Text.StartsWith("{\\an7}", StringComparison.Ordinal) || p.Text.StartsWith("{\\an8}", StringComparison.Ordinal) || p.Text.StartsWith("{\\an9}", StringComparison.Ordinal))
{
tti.VerticalPosition = 1; // top (vertical)
}
else if (p.Text.StartsWith("{\\an4}", StringComparison.Ordinal) || p.Text.StartsWith("{\\an5}", StringComparison.Ordinal) || p.Text.StartsWith("{\\an6}", StringComparison.Ordinal))
{
tti.VerticalPosition = (byte)(rows / 2); // middle (vertical)
}
else
{
int startRow = (rows - 1) - Utilities.CountTagInText(p.Text, Environment.NewLine) * 2;
if (startRow < 0)
{
startRow = 0;
}
tti.VerticalPosition = (byte)startRow; // bottom (vertical)
}
tti.JustificationCode = saveOptions.JustificationCode;
//.........这里部分代码省略.........
示例14: LoadSubtitle
/// <summary>
/// The load subtitle.
/// </summary>
/// <param name="subtitle">
/// The subtitle.
/// </param>
/// <param name="lines">
/// The lines.
/// </param>
/// <param name="fileName">
/// The file name.
/// </param>
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
this._errorCount = 0;
StringBuilder sb = new StringBuilder();
foreach (string s in lines)
{
sb.Append(s);
}
string allText = sb.ToString();
if (!allText.Contains("\"words\"") && !allText.Contains("'words'"))
{
return;
}
List<string> words = Json.ReadArray(allText, "words");
foreach (string word in words)
{
List<string> elements = Json.ReadArray(word);
if (elements.Count == 2)
{
string milliseconds = elements[0].Trim('"').Trim();
string text = elements[1].Trim();
if (text.StartsWith('"'))
{
text = text.Remove(0, 1);
}
if (text.EndsWith('"'))
{
text = text.Remove(text.Length - 1, 1);
}
long number;
if (long.TryParse(milliseconds, out number))
{
subtitle.Paragraphs.Add(new Paragraph(text, number, number));
}
else
{
this._errorCount++;
}
}
}
sb = new StringBuilder();
Subtitle sub = new Subtitle();
double startMilliseconds = 0;
if (subtitle.Paragraphs.Count > 0)
{
startMilliseconds = subtitle.Paragraphs[0].StartTime.TotalMilliseconds;
}
for (int i = 0; i < subtitle.Paragraphs.Count - 1; i++)
{
Paragraph p = subtitle.Paragraphs[i];
Paragraph next = subtitle.Paragraphs[i + 1];
Paragraph prev = subtitle.GetParagraphOrDefault(i - 1);
if (sb.Length + p.Text.Length > (Configuration.Settings.General.SubtitleLineMaximumLength * 2) - 15)
{
// text too big
Paragraph newParagraph = new Paragraph(sb.ToString(), startMilliseconds, prev.EndTime.TotalMilliseconds);
sub.Paragraphs.Add(newParagraph);
sb = new StringBuilder();
if (!string.IsNullOrWhiteSpace(p.Text))
{
sb.Append(p.Text);
startMilliseconds = p.StartTime.TotalMilliseconds;
}
}
else if (next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds > 2000)
{
// long time to next sub
if (!string.IsNullOrWhiteSpace(p.Text))
{
sb.Append(' ');
sb.Append(p.Text);
}
Paragraph newParagraph = new Paragraph(sb.ToString(), startMilliseconds, next.StartTime.TotalMilliseconds);
sub.Paragraphs.Add(newParagraph);
sb = new StringBuilder();
startMilliseconds = next.StartTime.TotalMilliseconds;
}
else if (string.IsNullOrWhiteSpace(p.Text))
{
//.........这里部分代码省略.........
示例15: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
// 00:18:02: (斉藤)失礼な大人って! (悠子)何言ってんのあんた?
Paragraph p = null;
subtitle.Paragraphs.Clear();
_errorCount = 0;
foreach (string line in lines)
{
string s = line.Trim();
if (regexTimeCodes.IsMatch(s))
{
var temp = s.Substring(0, 8);
string[] startParts = temp.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 3)
{
try
{
string text = s.Remove(0, 10).Trim();
text = text.Replace(" ", Environment.NewLine);
p = new Paragraph(DecodeTimeCode(startParts), new TimeCode(0, 0, 0, 0), text);
subtitle.Paragraphs.Add(p);
}
catch (Exception exception)
{
_errorCount++;
System.Diagnostics.Debug.WriteLine(exception.Message);
}
}
}
else if (string.IsNullOrWhiteSpace(line))
{
// skip empty lines
}
else if (p != null)
{
_errorCount++;
}
}
for (int i = 0; i < subtitle.Paragraphs.Count; i++)
{
Paragraph current = subtitle.Paragraphs[i];
Paragraph next = subtitle.GetParagraphOrDefault(i + 1);
if (next != null)
current.EndTime.TotalMilliseconds = next.StartTime.TotalMilliseconds - Configuration.Settings.General.MinimumMillisecondsBetweenLines;
else
current.EndTime.TotalMilliseconds = current.StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(current.Text);
if (current.Duration.TotalMilliseconds > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
current.EndTime.TotalMilliseconds = current.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
}
subtitle.Renumber();
}