本文整理汇总了C#中Nikse.SubtitleEdit.Core.SubtitleFormats.SubtitleFormat.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SubtitleFormat.GetType方法的具体用法?C# SubtitleFormat.GetType怎么用?C# SubtitleFormat.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nikse.SubtitleEdit.Core.SubtitleFormats.SubtitleFormat
的用法示例。
在下文中一共展示了SubtitleFormat.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveSubtitle
private DialogResult SaveSubtitle(SubtitleFormat format)
{
if (string.IsNullOrEmpty(_fileName) || _converted)
return FileSaveAs(false);
try
{
if (format != null && !format.IsTextBased)
{
if (format.GetType() == typeof(Ebu))
{
Ebu.Save(_fileName, _subtitle);
}
return DialogResult.OK;
}
string allText = _subtitle.ToText(format);
// Seungki begin
if (_splitDualSami && _subtitleAlternate != null)
{
var s = new Subtitle(_subtitle);
foreach (var p in _subtitleAlternate.Paragraphs)
s.Paragraphs.Add(p);
allText = s.ToText(format);
}
// Seungki end
var currentEncoding = GetCurrentEncoding();
bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
{
if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (!isUnicode)
{
allText = NormalizeUnicode(allText);
}
bool containsNegativeTime = false;
foreach (var p in _subtitle.Paragraphs)
{
if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
{
containsNegativeTime = true;
break;
}
}
if (containsNegativeTime)
{
if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (File.Exists(_fileName))
{
var fileInfo = new FileInfo(_fileName);
var fileOnDisk = fileInfo.LastWriteTime;
if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
{
if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
_fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (fileInfo.IsReadOnly)
{
MessageBox.Show(string.Format(_language.FileXIsReadOnly, _fileName));
return DialogResult.No;
}
}
if ((format.GetType() == typeof(WebVTT) || format.GetType() == typeof(WebVTTFileWithLineNumber)))
{
SetEncoding(Encoding.UTF8);
currentEncoding = Encoding.UTF8;
}
if (ModifierKeys == (Keys.Control | Keys.Shift))
allText = allText.Replace("\r\n", "\n");
if (format.GetType() == typeof(ItunesTimedText) || format.GetType() == typeof(ScenaristClosedCaptions) || format.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
{
file.Write(allText);
}
}
else if (currentEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
{
var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(_fileName, false, outputEnc)) // open file with encoding
{
file.Write(allText);
}
}
//.........这里部分代码省略.........
示例2: GetAlignmentFromParagraph
private static ContentAlignment GetAlignmentFromParagraph(MakeBitmapParameter p, SubtitleFormat format, Subtitle subtitle)
{
var alignment = ContentAlignment.BottomCenter;
if (p.AlignLeft)
alignment = ContentAlignment.BottomLeft;
else if (p.AlignRight)
alignment = ContentAlignment.BottomRight;
if (format.HasStyleSupport && !string.IsNullOrEmpty(p.P.Extra))
{
if (format.GetType() == typeof(SubStationAlpha))
{
var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
alignment = GetSsaAlignment("{\\a" + style.Alignment + "}", alignment);
}
else if (format.GetType() == typeof(AdvancedSubStationAlpha))
{
var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
alignment = GetAssAlignment("{\\an" + style.Alignment + "}", alignment);
}
}
string text = p.P.Text;
if (format.GetType() == typeof(SubStationAlpha) && text.Length > 5)
{
text = p.P.Text.Substring(0, 6);
alignment = GetSsaAlignment(text, alignment);
}
else if (text.Length > 6)
{
text = p.P.Text.Substring(0, 6);
alignment = GetAssAlignment(text, alignment);
}
return alignment;
}
示例3: CheckSkipFilter
private bool CheckSkipFilter(string fileName, SubtitleFormat format, Subtitle sub)
{
bool skip = false;
if (comboBoxFilter.SelectedIndex == 1)
{
if (format != null && format.GetType() == typeof(SubRip) && FileUtil.HasUtf8Bom(fileName))
skip = true;
}
else if (comboBoxFilter.SelectedIndex == 2)
{
skip = true;
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Text != null && Utilities.GetNumberOfLines(p.Text) > 2)
{
skip = false;
break;
}
}
}
else if (comboBoxFilter.SelectedIndex == 3 && !string.IsNullOrWhiteSpace(textBoxFilter.Text))
{
skip = true;
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Text != null && p.Text.Contains(textBoxFilter.Text, StringComparison.Ordinal))
{
skip = false;
break;
}
}
}
return skip;
}
示例4: BatchConvertSave
internal static bool BatchConvertSave(string toFormat, string offset, Encoding targetEncoding, string outputFolder, int count, ref int converted, ref int errors, IList<SubtitleFormat> formats, string fileName, Subtitle sub, SubtitleFormat format, bool overwrite, string pacCodePage, double? targetFrameRate)
{
double oldFrameRate = Configuration.Settings.General.CurrentFrameRate;
try
{
// adjust offset
if (!string.IsNullOrEmpty(offset) && (offset.StartsWith("/offset:") || offset.StartsWith("offset:")))
{
string[] parts = offset.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 5)
{
try
{
var ts = new TimeSpan(0, int.Parse(parts[1].TrimStart('-')), int.Parse(parts[2]), int.Parse(parts[3]), int.Parse(parts[4]));
if (parts[1].StartsWith('-'))
sub.AddTimeToAllParagraphs(ts.Negate());
else
sub.AddTimeToAllParagraphs(ts);
}
catch
{
Console.Write(" (unable to read offset " + offset + ")");
}
}
}
// adjust frame rate
if (targetFrameRate.HasValue)
{
sub.ChangeFrameRate(Configuration.Settings.General.CurrentFrameRate, targetFrameRate.Value);
Configuration.Settings.General.CurrentFrameRate = targetFrameRate.Value;
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat sf in formats)
{
if (sf.IsTextBased && (sf.Name.Replace(" ", string.Empty).Equals(toFormat, StringComparison.OrdinalIgnoreCase) || sf.Name.Replace(" ", string.Empty).Equals(toFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase)))
{
targetFormatFound = true;
sf.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
if ((sf.GetType() == typeof(WebVTT) || sf.GetType() == typeof(WebVTTFileWithLineNumber)))
{
targetEncoding = Encoding.UTF8;
}
if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
{
file.Write(sub.ToText(sf));
} // save and close it
}
else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
{
Encoding outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
{
file.Write(sub.ToText(sf));
} // save and close it
}
else
{
try
{
File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
errors++;
return false;
}
}
if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
{
var sami = (Sami)format;
foreach (string className in Sami.GetStylesFromHeader(sub.Header))
{
var newSub = new Subtitle();
foreach (Paragraph p in sub.Paragraphs)
{
if (p.Extra != null && p.Extra.Trim().Equals(className.Trim(), StringComparison.OrdinalIgnoreCase))
newSub.Paragraphs.Add(p);
}
if (newSub.Paragraphs.Count > 0 && newSub.Paragraphs.Count < sub.Paragraphs.Count)
{
string s = fileName;
if (s.LastIndexOf('.') > 0)
s = s.Insert(s.LastIndexOf('.'), "_" + className);
else
//.........这里部分代码省略.........
示例5: SaveSubtitle
private DialogResult SaveSubtitle(SubtitleFormat format)
{
if (string.IsNullOrEmpty(_fileName) || _converted)
return FileSaveAs(false);
try
{
var sub = GetSaveSubtitle(_subtitle);
if (format != null && !format.IsTextBased)
{
var ebu = format as Ebu;
if (ebu != null)
{
var header = new Ebu.EbuGeneralSubtitleInformation();
if (_subtitle != null && _subtitle.Header != null && (_subtitle.Header.Contains("STL2") || _subtitle.Header.Contains("STL3")))
{
header = Ebu.ReadHeader(Encoding.UTF8.GetBytes(_subtitle.Header));
}
if (ebu.Save(_fileName, sub, !_saveAsCalled, header))
{
_changeSubtitleToString = _subtitle.GetFastHashCode();
Configuration.Settings.RecentFiles.Add(_fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName, Configuration.Settings.General.CurrentVideoOffsetInMs);
Configuration.Settings.Save();
}
}
return DialogResult.OK;
}
string allText = sub.ToText(format);
// Seungki begin
if (_splitDualSami && _subtitleAlternate != null)
{
var s = new Subtitle(_subtitle);
foreach (var p in _subtitleAlternate.Paragraphs)
s.Paragraphs.Add(p);
allText = s.ToText(format);
}
// Seungki end
var currentEncoding = GetCurrentEncoding();
bool isUnicode = currentEncoding == Encoding.Unicode || currentEncoding == Encoding.UTF32 || currentEncoding == Encoding.GetEncoding(12001) || currentEncoding == Encoding.UTF7 || currentEncoding == Encoding.UTF8;
if (!isUnicode && (allText.Contains(new[] { '♪', '♫', '♥', '—', '―', '…' }))) // ANSI & music/unicode symbols
{
if (MessageBox.Show(string.Format(_language.UnicodeMusicSymbolsAnsiWarning), Title, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (!isUnicode)
{
allText = NormalizeUnicode(allText);
}
bool containsNegativeTime = false;
foreach (var p in sub.Paragraphs)
{
if (p.StartTime.TotalMilliseconds < 0 || p.EndTime.TotalMilliseconds < 0)
{
containsNegativeTime = true;
break;
}
}
if (containsNegativeTime)
{
if (MessageBox.Show(_language.NegativeTimeWarning, Title, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (File.Exists(_fileName))
{
var fileInfo = new FileInfo(_fileName);
var fileOnDisk = fileInfo.LastWriteTime;
if (_fileDateTime != fileOnDisk && _fileDateTime != new DateTime())
{
if (MessageBox.Show(string.Format(_language.OverwriteModifiedFile,
_fileName, fileOnDisk.ToShortDateString(), fileOnDisk.ToString("HH:mm:ss"),
Environment.NewLine, _fileDateTime.ToShortDateString(), _fileDateTime.ToString("HH:mm:ss")),
Title + " - " + _language.FileOnDiskModified, MessageBoxButtons.YesNo) == DialogResult.No)
return DialogResult.No;
}
if (fileInfo.IsReadOnly)
{
MessageBox.Show(string.Format(_language.FileXIsReadOnly, _fileName));
return DialogResult.No;
}
}
if ((format.GetType() == typeof(WebVTT) || format.GetType() == typeof(WebVTTFileWithLineNumber)))
{
SetEncoding(Encoding.UTF8);
currentEncoding = Encoding.UTF8;
}
if (ModifierKeys == (Keys.Control | Keys.Shift))
allText = allText.Replace("\r\n", "\n");
if (format.GetType() == typeof(ItunesTimedText) || format.GetType() == typeof(ScenaristClosedCaptions) || format.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
//.........这里部分代码省略.........
示例6: BatchConvertSave
//.........这里部分代码省略.........
changeCasing.FixCasing(sub, LanguageAutoDetect.AutoDetectGoogleLanguage(sub));
}
using (var changeCasingNames = new ChangeCasingNames())
{
changeCasingNames.Initialize(sub);
changeCasingNames.FixCasing();
}
}
if (multipleReplaceImportFiles != null && multipleReplaceImportFiles.Count() > 0)
{
using (var mr = new MultipleReplace())
{
mr.RunFromBatch(sub, multipleReplaceImportFiles);
sub = mr.FixedSubtitle;
sub.RemoveParagraphsByIndices(mr.DeleteIndices);
}
}
bool targetFormatFound = false;
string outputFileName;
foreach (SubtitleFormat sf in formats)
{
if (sf.IsTextBased && sf.Name.Replace(" ", string.Empty).Equals(targetFormat.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase))
{
targetFormatFound = true;
sf.BatchMode = true;
outputFileName = FormatOutputFileNameForBatchConvert(fileName, sf.Extension, outputFolder, overwrite);
Console.Write("{0}: {1} -> {2}...", count, Path.GetFileName(fileName), outputFileName);
if (sf.IsFrameBased && !sub.WasLoadedWithFrameNumbers)
sub.CalculateFrameNumbersFromTimeCodesNoCheck(Configuration.Settings.General.CurrentFrameRate);
else if (sf.IsTimeBased && sub.WasLoadedWithFrameNumbers)
sub.CalculateTimeCodesFromFrameNumbers(Configuration.Settings.General.CurrentFrameRate);
if (sf.GetType() == typeof(WebVTT))
{
targetEncoding = Encoding.UTF8;
}
try
{
if (sf.GetType() == typeof(ItunesTimedText) || sf.GetType() == typeof(ScenaristClosedCaptions) || sf.GetType() == typeof(ScenaristClosedCaptionsDropFrame))
{
var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
{
file.Write(sub.ToText(sf));
} // save and close it
}
else if (targetEncoding == Encoding.UTF8 && (format.GetType() == typeof(TmpegEncAW5) || format.GetType() == typeof(TmpegEncXml)))
{
var outputEnc = new UTF8Encoding(false); // create encoding with no BOM
using (var file = new StreamWriter(outputFileName, false, outputEnc)) // open file with encoding
{
file.Write(sub.ToText(sf));
} // save and close it
}
else
{
File.WriteAllText(outputFileName, sub.ToText(sf), targetEncoding);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
errors++;
return false;