本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例7: StylesForm
protected StylesForm(Subtitle subtitle)
{
_subtitle = subtitle;
_previewTimer.Interval = 200;
_previewTimer.Tick += PreviewTimerTick;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}