本文整理汇总了C#中Nikse.SubtitleEdit.Core.Paragraph类的典型用法代码示例。如果您正苦于以下问题:C# Paragraph类的具体用法?C# Paragraph怎么用?C# Paragraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Paragraph类属于Nikse.SubtitleEdit.Core命名空间,在下文中一共展示了Paragraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
{
int splitter = line.IndexOf(':') + 3;
string text = line.Remove(0, splitter);
var p = new Paragraph(DecodeTimeCode(line.Substring(0, splitter)), new TimeCode(0, 0, 0, 0), text);
subtitle.Paragraphs.Add(p);
text = text.Trim().Trim('–', '.', ';', ':').Trim();
if (text.Length > 0 && char.IsDigit(text[0]))
_errorCount++;
}
else
{
_errorCount += 2;
}
}
foreach (Paragraph p2 in subtitle.Paragraphs)
{
p2.Text = Utilities.AutoBreakLine(p2.Text);
}
subtitle.RecalculateDisplayTimes(Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds, null);
subtitle.Renumber();
}
示例3: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
int number = 0;
foreach (string line in lines)
{
if (string.IsNullOrWhiteSpace(line) || string.IsNullOrWhiteSpace(line.Trim('-')))
{
continue;
}
if (RegexTimeCodes.Match(line).Success)
{
string[] threePart = line.Split(new[] { ',' }, StringSplitOptions.None);
var p = new Paragraph();
if (threePart.Length > 2 &&
line.Length > 58 &&
GetTimeCode(p.StartTime, threePart[0].Trim()) &&
GetTimeCode(p.EndTime, threePart[1].Trim()))
{
number++;
p.Number = number;
p.Text = line.Remove(0, 57).Trim().Replace(" | ", Environment.NewLine).Replace("|", Environment.NewLine);
subtitle.Paragraphs.Add(p);
}
}
else
{
_errorCount++;
}
}
}
示例4: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
Paragraph paragraph = new Paragraph();
this._errorCount = 0;
subtitle.Paragraphs.Clear();
for (int i = 0; i < lines.Count; i++)
{
string line = lines[i].TrimEnd();
string next = string.Empty;
if (i + 1 < lines.Count)
{
next = lines[i + 1];
}
if (line.Contains(':') && !next.Contains(':') && RegexTimeCodes.IsMatch(line) && !RegexTimeCodes.IsMatch(next))
{
paragraph = new Paragraph();
if (TryReadTimeCodesLine(line, paragraph))
{
paragraph.Text = next;
if (!string.IsNullOrWhiteSpace(paragraph.Text))
{
subtitle.Paragraphs.Add(paragraph);
}
}
else if (!string.IsNullOrWhiteSpace(line))
{
this._errorCount++;
}
}
else
{
this._errorCount++;
}
}
foreach (Paragraph p in subtitle.Paragraphs)
{
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs)
{
index++;
Paragraph nextParagraph = subtitle.GetParagraphOrDefault(index);
if (nextParagraph != null)
{
p.EndTime.TotalMilliseconds = nextParagraph.StartTime.TotalMilliseconds - 1;
}
else
{
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + 2500;
}
p.Text = p.Text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
subtitle.Renumber();
}
示例5: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//00:01:54:19,00:01:56:17,We should be thankful|they accepted our offer.
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
if (line.IndexOf(':') == 2 && regexTimeCodes.IsMatch(line))
{
string start = line.Substring(0, 11);
string end = line.Substring(13, 11);
try
{
Paragraph p = new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), DecodeText(line.Substring(25).Trim()));
subtitle.Paragraphs.Add(p);
}
catch
{
_errorCount++;
}
}
else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("//") && !line.StartsWith('$'))
{
_errorCount++;
}
}
subtitle.Renumber();
}
示例6: TestAdjust2
public void TestAdjust2()
{
var p = new Paragraph { Text = string.Empty, StartTime = new TimeCode(0, 1, 1, 1), EndTime = new TimeCode(0, 1, 4, 1) };
p.Adjust(2, 10);
Assert.AreEqual(new TimeCode(0, 2, 12, 2).TotalMilliseconds, p.StartTime.TotalMilliseconds);
Assert.AreEqual(new TimeCode(0, 2, 18, 2).TotalMilliseconds, p.EndTime.TotalMilliseconds);
}
示例7: AddToListView
private void AddToListView(Paragraph p, int index)
{
var item = new ListViewItem(string.Empty) { Tag = index, Checked = true };
item.SubItems.Add(p.Number.ToString());
item.SubItems.Add(p.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString));
listViewFixes.Items.Add(item);
}
示例8: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//00:03:15:22 00:03:23:10 This is line one.
//This is line two.
subtitle.Paragraphs.Clear();
_errorCount = 0;
foreach (string line in lines)
{
if (regexTimeCodes.IsMatch(line))
{
string temp = line.Substring(0, regexTimeCodes.Match(line).Length);
string start = temp.Substring(0, 11);
string end = temp.Substring(12, 11);
string[] startParts = start.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
string[] endParts = end.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (startParts.Length == 4 && endParts.Length == 4)
{
string text = line.Remove(0, regexTimeCodes.Match(line).Length - 1).Trim();
text = text.Replace("//", Environment.NewLine);
var p = new Paragraph(DecodeTimeCode(startParts), DecodeTimeCode(endParts), text);
subtitle.Paragraphs.Add(p);
}
}
else
{
_errorCount += 10;
}
}
subtitle.Renumber();
}
示例9: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
var xml = new XmlDocument { XmlResolver = null };
xml.LoadXml(sb.ToString().Trim());
XmlNode div = xml.DocumentElement.SelectSingleNode("subtitles");
foreach (XmlNode node in div.ChildNodes)
{
try
{
//<subtitle duration="2256" effect="" end="124581" layer="0" margin-l="0" margin-r="0" margin-v="0" name="" note="" path="0" start="122325" style="Default" text="The fever hath weakened thee." translation="" />
var p = new Paragraph { StartTime = { TotalMilliseconds = int.Parse(node.Attributes["start"].Value) } };
p.EndTime.TotalMilliseconds = p.StartTime.TotalMilliseconds + int.Parse(node.Attributes["duration"].Value);
p.Text = node.Attributes["text"].Value;
subtitle.Paragraphs.Add(p);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
_errorCount++;
}
}
subtitle.Renumber();
}
示例10: WriteSubtitleBlock
public static void WriteSubtitleBlock(FileStream fs, Paragraph p, int number)
{
fs.WriteByte(0);
fs.WriteByte((byte)(number % 256)); // number - low byte
fs.WriteByte((byte)(number / 256)); // number - high byte
fs.WriteByte(0xff);
fs.WriteByte(0);
WriteTimeCode(fs, p.StartTime);
WriteTimeCode(fs, p.EndTime);
fs.WriteByte(1);
fs.WriteByte(2);
fs.WriteByte(0);
var buffer = Encoding.GetEncoding(1252).GetBytes(p.Text.Replace(Environment.NewLine, "Š"));
if (buffer.Length <= 128)
{
fs.Write(buffer, 0, buffer.Length);
for (int i = buffer.Length; i < TextLength; i++)
{
fs.WriteByte(0x8f);
}
}
else
{
for (int i = 0; i < TextLength; i++)
{
fs.WriteByte(buffer[i]);
}
}
}
示例11: SetEndTimeAndStartTime
private static void SetEndTimeAndStartTime(string name, Paragraph p)
{
if (name.Contains("-to-"))
{
var arr = name.Replace("-to-", "_").Split('_');
if (arr.Length == 3)
{
int startTime, endTime;
if (int.TryParse(arr[1], out startTime) && int.TryParse(arr[2], out endTime))
{
p.StartTime.TotalMilliseconds = startTime;
p.EndTime.TotalMilliseconds = endTime;
}
}
}
else if (TimeCodeFormat1.IsMatch(name) || TimeCodeFormat2.IsMatch(name))
{
var arr = name.Replace("__", "_").Split('_');
if (arr.Length >= 8)
{
try
{
p.StartTime = new TimeCode(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]), int.Parse(arr[3]));
p.EndTime = new TimeCode(int.Parse(arr[4]), int.Parse(arr[5]), int.Parse(arr[6]), int.Parse(arr[7]));
}
catch (Exception)
{
}
}
}
}
示例12: ParagraphEventArgs
public ParagraphEventArgs(double seconds, Paragraph p, Paragraph b, MouseDownParagraphType mouseDownParagraphType)
{
Seconds = seconds;
Paragraph = p;
BeforeParagraph = b;
MouseDownParagraphType = mouseDownParagraphType;
}
示例13: 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();
}
示例14: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
var sb = new StringBuilder();
foreach (string s in lines)
sb.Append(s);
string allText = sb.ToString();
if (!allText.Contains("text_tees"))
return;
var times = Json.ReadArray(allText, "text_tees");
var texts = Json.ReadArray(allText, "text_content");
for (int i = 0; i < Math.Min(times.Count, texts.Count); i++)
{
try
{
string text = texts[i];
if (text.StartsWith('['))
{
var textLines = Json.ReadArray("{\"text\":" + texts[i] + "}", "text");
var textSb = new StringBuilder();
foreach (string line in textLines)
{
string t = Json.DecodeJsonText(line);
if (t.StartsWith("[\"", StringComparison.Ordinal) && t.EndsWith("\"]", StringComparison.Ordinal))
{
var innerSb = new StringBuilder();
var innerTextLines = Json.ReadArray("{\"text\":" + t + "}", "text");
foreach (string innerLine in innerTextLines)
{
innerSb.Append(' ');
innerSb.Append(innerLine);
}
textSb.AppendLine(innerSb.ToString().Trim());
}
else
{
textSb.AppendLine(t);
}
}
text = textSb.ToString().Trim();
text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
}
var p = new Paragraph(text, int.Parse(times[i]), 0);
if (i + 1 < times.Count)
p.EndTime.TotalMilliseconds = int.Parse(times[i + 1]);
subtitle.Paragraphs.Add(p);
}
catch
{
_errorCount++;
}
}
subtitle.RemoveEmptyLines();
subtitle.Renumber();
}
示例15: LoadSubtitle
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//00:01:54:19,00:01:56:17,We should be thankful|they accepted our offer.
_errorCount = 0;
subtitle.Paragraphs.Clear();
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,.+", RegexOptions.Compiled);
if (fileName != null && fileName.EndsWith(".stl", StringComparison.OrdinalIgnoreCase)) // allow empty text if extension is ".stl"...
regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d:\d\d,\d\d:\d\d:\d\d:\d\d,", RegexOptions.Compiled);
foreach (string line in lines)
{
if (line.IndexOf(':') == 2 && regexTimeCodes.IsMatch(line))
{
string start = line.Substring(0, 11);
string end = line.Substring(12, 11);
try
{
Paragraph p = new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), DecodeText(line.Substring(24)));
subtitle.Paragraphs.Add(p);
}
catch
{
_errorCount++;
}
}
else if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("//") && !line.StartsWith('$'))
{
_errorCount++;
}
}
subtitle.Renumber();
}