Some fixes to reading writing font color/italic to/from SSA/ASS/DCiname + added more unit tests

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1279 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2012-06-30 19:23:04 +00:00
parent 38f38e631f
commit 9abadd83ce
9 changed files with 540 additions and 145 deletions

View File

@ -2,31 +2,33 @@ Subtitle Edit Changelog
3.3 Beta 1 (x July 2012)
* NEW:
* Edit -> Reverse RTL start/end (fix punctuations)
* Easy import of auto backed up files (File -> Restore auto-backup...)
* Improved support for Advanced Substation Alpha (+ Substation Alpha)
* Advanced Substation Alpha style viewer/creater (right click in list view)
* Support for D-Cinema smpte - thx Lillian
* File -> D-Cinema properties (for both smtpe and interop)
* Can now display frames instead of milliseconds in main window (see Options -> settings)
* New setting in Options: "Max. chars/second"
* New settings in Options regarding "Min. duration" + "Max. duration"
* New settings in Options regarding syntax coloring
* Tools -> Join subtitles (merge of multiple parts)
* Tools -> Apply duration limits
* Tools -> Sort -> Text - chars/sec
* Will now display any errors found in SubRip/MicroDvd/SSA/ASS on load
* Can now read NCI cap files - thx Ramon
* File -> Statistics: Displays info about current subtitle
* Click on status bar in footer will now show status history
* "Fix common errors" item to fix Turkish ANSI letters to Unicode - thx Adem
* Edit -> Reverse RTL start/end (fix punctuations)
* Easy import of auto backed up files (File -> Restore auto-backup...)
* Advanced Substation Alpha style viewer/creater (right click in list view)
* File -> D-Cinema properties (for both smtpe and interop)
* Can now display frames instead of milliseconds in main window (see Options -> settings)
* New setting in Options: "Max. chars/second"
* New settings in Options regarding "Min. duration" + "Max. duration"
* New settings in Options regarding syntax coloring
* Tools -> Join subtitles (merge of multiple parts)
* Tools -> Apply duration limits
* Tools -> Sort -> Text - chars/sec
* Will now display any errors found in SubRip/MicroDvd/SSA/ASS on load
* File -> Statistics: Displays info about current subtitle
* Click on status bar in footer will now show status history
* "Fix common errors" item to fix Turkish ANSI letters to Unicode - thx Adem
* Support for D-Cinema smpte - thx Lillian
* Can now read NCI cap files - thx Ramon
* Several other new subtitle formats
* IMPROVED:
* Added extra options for double click on list view line - thx Fredrik + TaeGyun
* Added extra options for export as text
* Added many new possible shortcut keys
* Find and replace, better undo, faster + a little UI - thx Adem
* Fix common errors -> Start with uppercase letter after colon/semicolon moved
to seperate fix item (no longer in "Start with uppercase after paragraph/period")
* Improved support for Advanced Substation Alpha (+ Substation Alpha)
* Added extra options for double click on list view line - thx Fredrik + TaeGyun
* Added extra options for export as text
* Added many new possible shortcut keys
* Find and replace, better undo, faster + a little UI - thx Adem
* Fix common errors -> Start with uppercase letter after colon/semicolon moved
to seperate fix item (no longer in "Start with uppercase after paragraph/period")
* Can now read Ulead format with positions - thx Steve
* FIXED:
* Auto-translate now works for English to Portuguese - thx w.tambley
* Fixed shortcuts with numbers (0-9)

View File

@ -153,7 +153,8 @@
this.Name = "AlignmentPicker";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.Text = "Form2";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Alignment";
this.Shown += new System.EventHandler(this.AlignmentPicker_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AlignmentPicker_KeyDown);
this.panel1.ResumeLayout(false);

View File

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
@ -13,15 +9,11 @@ namespace Nikse.SubtitleEdit.Forms
public partial class AlignmentPicker : Form
{
Timer t1 = new Timer();
public ContentAlignment Alignment { get; set; }
public AlignmentPicker()
{
InitializeComponent();
t1.Interval = 100;
t1.Tick += new EventHandler(t1_Tick);
t1.Start();
Text = Configuration.Settings.Language.SubStationAlphaStyles.Alignment;
button1.Text = Configuration.Settings.Language.SubStationAlphaStyles.TopLeft;
@ -42,15 +34,6 @@ namespace Nikse.SubtitleEdit.Forms
DialogResult = DialogResult.OK;
}
void t1_Tick(object sender, EventArgs e)
{
var currentPos = System.Windows.Forms.Cursor.Position;
if (currentPos.X < this.Left || currentPos.X > this.Left + this.Width)
Close();
if (currentPos.Y < this.Top || currentPos.Y > this.Top + this.Height)
Close();
}
private void button1_Click(object sender, EventArgs e)
{
Alignment = ContentAlignment.TopLeft;

View File

@ -192,24 +192,9 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
return fontTag;
}
private static string GetFormattedText(string text)
public static string GetFormattedText(string text)
{
text = text.Replace("\\N", Environment.NewLine).Replace("\\n", Environment.NewLine);
text = text.Replace(@"{\i1}", "<i>");
text = text.Replace(@"{\i0}", "</i>");
if (Utilities.CountTagInText(text, "<i>") > Utilities.CountTagInText(text, "</i>"))
text += "</i>";
text = text.Replace(@"{\u1}", "<u>");
text = text.Replace(@"{\u0}", "</u>");
if (Utilities.CountTagInText(text, "<u>") > Utilities.CountTagInText(text, "</u>"))
text += "</u>";
text = text.Replace(@"{\b1}", "<b>");
text = text.Replace(@"{\b0}", "</b>");
if (Utilities.CountTagInText(text, "<b>") > Utilities.CountTagInText(text, "</b>"))
text += "</b>";
text = text.Replace("\\N", Environment.NewLine).Replace("\\n", Environment.NewLine);
for (int i = 0; i < 10; i++) // just look ten times...
{
@ -250,16 +235,22 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
{
string color = text.Substring(start + 4, end - (start + 4));
int indexOfNextTag = color.IndexOf("\\");
string nextTag = string.Empty;
if (indexOfNextTag > 1)
{
nextTag = "{" + color.Substring(indexOfNextTag) + "}";
color = color.Remove(indexOfNextTag);
}
color = color.Replace("&", string.Empty).TrimStart('H');
color = color.PadLeft(6, '0');
// switch to rrggbb from bbggrr
color = "#" + color.Remove(color.Length - 6) + color.Substring(color.Length - 2, 2) + color.Substring(color.Length - 4, 2) + color.Substring(color.Length - 6, 2);
color = color.ToLower();
text = text.Remove(start, end - start + 1);
text = text.Insert(start, "<font color=\"" + color + "\">");
text = text.Insert(start, "<font color=\"" + color + "\">" + nextTag);
text += "</font>";
}
}
@ -272,22 +263,42 @@ Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
{
string color = text.Substring(start + 5, end - (start + 5));
int indexOfNextTag = color.IndexOf("\\");
string nextTag = string.Empty;
if (indexOfNextTag > 1)
{
nextTag = "{" + color.Substring(indexOfNextTag) + "}";
color = color.Remove(indexOfNextTag);
}
color = color.Replace("&", string.Empty).TrimStart('H');
color = color.PadLeft(6, '0');
// switch to rrggbb from bbggrr
color = "#" + color.Remove(color.Length - 6) + color.Substring(color.Length - 2, 2) + color.Substring(color.Length - 4, 2) + color.Substring(color.Length - 6, 2);
color = color.ToLower();
text = text.Remove(start, end - start + 1);
text = text.Insert(start, "<font color=\"" + color + "\">");
text = text.Insert(start, "<font color=\"" + color + "\">" + nextTag);
text += "</font>";
}
}
}
text = text.Replace(@"{\i1}", "<i>");
text = text.Replace(@"{\i0}", "</i>");
if (Utilities.CountTagInText(text, "<i>") > Utilities.CountTagInText(text, "</i>"))
text += "</i>";
text = text.Replace(@"{\u1}", "<u>");
text = text.Replace(@"{\u0}", "</u>");
if (Utilities.CountTagInText(text, "<u>") > Utilities.CountTagInText(text, "</u>"))
text += "</u>";
text = text.Replace(@"{\b1}", "<b>");
text = text.Replace(@"{\b0}", "</b>");
if (Utilities.CountTagInText(text, "<b>") > Utilities.CountTagInText(text, "</b>"))
text += "</b>";
return text;
}

View File

@ -122,6 +122,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (string.IsNullOrEmpty(ss.CurrentDCinemaMovieTitle))
ss.CurrentDCinemaMovieTitle = title;
if (ss.CurrentDCinemaFontSize == 0 || string.IsNullOrEmpty(ss.CurrentDCinemaFontEffect))
Configuration.Settings.SubtitleSettings.InitializeDCinameSettings(true);
xml.DocumentElement.SelectSingleNode("MovieTitle").InnerText = ss.CurrentDCinemaMovieTitle;
xml.DocumentElement.SelectSingleNode("SubtitleID").InnerText = ss.CurrentDCinemaSubtitleId;
xml.DocumentElement.SelectSingleNode("ReelNumber").InnerText = ss.CurrentDCinemaReelNumber;
@ -256,6 +260,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
italic.InnerText = "yes";
fontNode.Attributes.Append(italic);
if (line.Length > i + 5 && line.Substring(i + 4).StartsWith("</font>"))
{
XmlAttribute fontColor = xml.CreateAttribute("Color");
fontColor.InnerText = fontColors.Pop();
fontNode.Attributes.Append(fontColor);
fontNo--;
i += 7;
}
fontNode.InnerText = Utilities.RemoveHtmlTags(txt.ToString());
html.Append(fontNode.OuterXml);
txt = new StringBuilder();
@ -290,6 +303,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
fontColor.InnerText = fontColors.Pop();
fontNode.Attributes.Append(fontColor);
if (line.Length > i + 9 && line.Substring(i + 7).StartsWith("</i>"))
{
XmlAttribute italic = xml.CreateAttribute("Italic");
italic.InnerText = "yes";
fontNode.Attributes.Append(italic);
isItalic = false;
i += 4;
}
fontNode.InnerText = Utilities.RemoveHtmlTags(txt.ToString());
html.Append(fontNode.OuterXml);
txt = new StringBuilder();
@ -445,13 +467,19 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
foreach (XmlNode innerInnerNode in innerNode)
{
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
if (innerInnerNode.Attributes["Color"] != null)
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
else
{

View File

@ -128,6 +128,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (string.IsNullOrEmpty(ss.CurrentDCinemaMovieTitle))
ss.CurrentDCinemaMovieTitle = title;
if (ss.CurrentDCinemaFontSize == 0 || string.IsNullOrEmpty(ss.CurrentDCinemaFontEffect))
Configuration.Settings.SubtitleSettings.InitializeDCinameSettings(true);
xml.DocumentElement.SelectSingleNode("dcst:ContentTitleText", nsmgr).InnerText = ss.CurrentDCinemaMovieTitle;
xml.DocumentElement.SelectSingleNode("dcst:Id", nsmgr).InnerText = ss.CurrentDCinemaSubtitleId;
xml.DocumentElement.SelectSingleNode("dcst:ReelNumber", nsmgr).InnerText = ss.CurrentDCinemaReelNumber;
@ -266,6 +270,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
italic.InnerText = "yes";
fontNode.Attributes.Append(italic);
if (line.Length > i + 5 && line.Substring(i+4).StartsWith("</font>"))
{
XmlAttribute fontColor = xml.CreateAttribute("Color");
fontColor.InnerText = fontColors.Pop();
fontNode.Attributes.Append(fontColor);
fontNo--;
i += 7;
}
fontNode.InnerText = Utilities.RemoveHtmlTags(txt.ToString());
html.Append(fontNode.OuterXml);
txt = new StringBuilder();
@ -300,6 +313,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
fontColor.InnerText = fontColors.Pop();
fontNode.Attributes.Append(fontColor);
if (line.Length > i + 9 && line.Substring(i + 7).StartsWith("</i>"))
{
XmlAttribute italic = xml.CreateAttribute("Italic");
italic.InnerText = "yes";
fontNode.Attributes.Append(italic);
isItalic = false;
i += 4;
}
fontNode.InnerText = Utilities.RemoveHtmlTags(txt.ToString());
html.Append(fontNode.OuterXml);
txt = new StringBuilder();
@ -350,7 +372,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var writer = new XmlTextWriter(ms, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
xml.Save(writer);
return Encoding.UTF8.GetString(ms.ToArray()).Trim().Replace("encoding=\"utf-8\"", "encoding=\"UTF-8\"");
return Encoding.UTF8.GetString(ms.ToArray()).Trim().Replace("encoding=\"utf-8\"", "encoding=\"UTF-8\"").Replace(" xmlns:dcst=\"dcst\"", string.Empty);
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
@ -468,11 +490,17 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
{
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
if (innerInnerNode.Attributes["Color"] != null)
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<i>" + innerInnerNode.InnerText + "</i>");
}
else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null)
{
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
pText.Append("<i><font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font><i>");
else
pText.Append("<font color=\"" + GetColorStringFromDCinema(innerInnerNode.Attributes["Color"].Value) + "\">" + innerInnerNode.InnerText + "</font>");
}
else
{

View File

@ -147,83 +147,7 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
}
return fontTag;
}
private static string GetFormattedText(string text)
{
text = text.Replace("\\N", Environment.NewLine).Replace("\\n", Environment.NewLine);
text = text.Replace(@"{\i1}", "<i>");
text = text.Replace(@"{\i0}", "</i>");
if (Utilities.CountTagInText(text, "<i>") > Utilities.CountTagInText(text, "</i>"))
text += "</i>";
text = text.Replace(@"{\u1}", "<u>");
text = text.Replace(@"{\u0}", "</u>");
if (Utilities.CountTagInText(text, "<u>") > Utilities.CountTagInText(text, "</u>"))
text += "</u>";
text = text.Replace(@"{\b1}", "<b>");
text = text.Replace(@"{\b0}", "</b>");
if (Utilities.CountTagInText(text, "<b>") > Utilities.CountTagInText(text, "</b>"))
text += "</b>";
for (int i = 0; i < 10; i++) // just look ten times...
{
if (text.Contains(@"{\fn"))
{
int start = text.IndexOf(@"{\fn");
int end = text.IndexOf('}', start);
if (end > 0)
{
string fontName = text.Substring(start + 4, end - (start + 4));
text = text.Remove(start, end - start + 1);
text = text.Insert(start, "<font name=\"" + fontName + "\">");
text += "</font>";
}
}
if (text.Contains(@"{\fs"))
{
int start = text.IndexOf(@"{\fs");
int end = text.IndexOf('}', start);
if (end > 0)
{
string fontSize = text.Substring(start + 4, end - (start + 4));
if (Utilities.IsInteger(fontSize))
{
text = text.Remove(start, end - start + 1);
text = text.Insert(start, "<font size=\"" + fontSize + "\">");
text += "</font>";
}
}
}
if (text.Contains(@"{\c"))
{
int start = text.IndexOf(@"{\c");
int end = text.IndexOf('}', start);
if (end > 0)
{
string color = text.Substring(start + 4, end - (start + 4));
int indexOfNextTag = color.IndexOf("\\");
if (indexOfNextTag > 1)
color = color.Remove(indexOfNextTag);
color = color.Replace("&", string.Empty).TrimStart('H');
color = color.PadLeft(6, '0');
// switch to rrggbb from bbggrr
color = "#" + color.Remove(color.Length-6) + color.Substring(color.Length-2,2) + color.Substring(color.Length-4,2) + color.Substring(color.Length-6,2);
text = text.Remove(start, end - start + 1);
text = text.Insert(start, "<font color=\"" + color + "\">");
text += "</font>";
}
}
}
return text;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
@ -303,7 +227,7 @@ Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
p.StartTime = GetTimeCodeFromString(start);
p.EndTime = GetTimeCodeFromString(end);
p.Text = GetFormattedText(text);
p.Text = AdvancedSubStationAlpha.GetFormattedText(text);
if (!string.IsNullOrEmpty(style))
p.Extra = style;
p.IsComment = s.StartsWith("comment:");

View File

@ -0,0 +1,416 @@
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.SubtitleFormats;
namespace Test
{
/// <summary>
///This is a test class for subtitle formats and is intended
///to contain all subtitle formats Unit Tests
///</summary>
[TestClass()]
public class SubtitleFormatsTest
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion
#region Subrip (.srt)
private List<string> GetSrtLines(string text)
{
var lines = new List<string>();
string[] arr = text.Replace(Environment.NewLine, "\r").Replace("\n", "\r").Split('\r');
foreach (string line in arr)
lines.Add(line);
return lines;
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SrtCoordinates()
{
var target = new SubRip_Accessor();
var subtitle = new Subtitle();
string text =
@"1
00:00:02,001 --> 00:00:16,001 X1:000 X2:000 Y1:050 Y2:100
Let us have some! Let us have some!";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "Let us have some! Let us have some!";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SrtNoLineNumbers()
{
var target = new SubRip_Accessor();
var subtitle = new Subtitle();
string text =
@"00:00:03,000 --> 00:00:08,000
Line1.
00:00:08,000 --> 00:00:09,920
Line 2.";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
string actual = subtitle.Paragraphs.Count.ToString();
string expected = "2";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SrtDotsInsteadOfCommas()
{
var target = new SubRip_Accessor();
var subtitle = new Subtitle();
string text =
@"2
00:00:04.501 --> 00:00:08.500
Dots instead of commas";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "Dots instead of commas";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SrtTwoLiner()
{
var target = new SubRip_Accessor();
var subtitle = new Subtitle();
string text =
@"2
00:00:04.501 --> 00:00:08.500
Line 1
Line 2";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "Line 1" + Environment.NewLine + "Line 2";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SrtThreeLiner()
{
var target = new SubRip_Accessor();
var subtitle = new Subtitle();
string text =
@"2
00:00:04.501 --> 00:00:08.500
Line 1
Line 2
Line 3";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "Line 1" + Environment.NewLine + "Line 2" + Environment.NewLine + "Line 3";
Assert.AreEqual(expected, actual);
}
#endregion
#region Advanced Sub Station alpha (.ass)
private List<string> GetAssLines(string lineOneText)
{
var text =
@"[Script Info]
Title:
Original Script: swk
Update Details:
ScriptType: v4.00+
Collisions: Normal
PlayDepth: 0
PlayResX: 1920
PlayResY: 1080
Timer: 100,0000
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,73,&H00FFFFFF,&H0000FFFF,&H00000000,&H4B404040,0,0,0,0,100,100,0,0,1,2,0,2,20,20,100,0
Style: Rahmen,Arial,73,&H00FFFFFF,&H00FFFFFF,&H00000000,&H4B404040,0,0,0,0,100,100,0,0,3,20,0,2,20,20,100,0
Style: Rahmen2,Arial,73,&H00FFFFFF,&H00FFFFFF,&H00000000,&H4B404040,0,0,0,0,100,100,0,0,3,20,0,2,20,20,50,0
Style: links,Arial,73,&H00FFFFFF,&H0000FFFF,&H00000000,&H4B404040,0,0,0,0,100,100,0,0,1,2,0,1,200,20,100,0
Style: rechts,Arial,73,&H00FFFFFF,&H0000FFFF,&H00000000,&H4B404040,0,0,0,0,100,100,0,0,1,2,0,3,20,200,100,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:16.84,0:00:18.16,rechts,,0000,0000,0000,," + lineOneText;
var lines = new List<string>();
string[] arr = text.Replace(Environment.NewLine, "\r").Replace("\n", "\r").Split('\r');
foreach (string line in arr)
lines.Add(line);
return lines;
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleItalic()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\i1}Italic{\i0}"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<i>Italic</i>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleBold()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\b1}Bold{\b0}"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<b>Bold</b>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleUnderline()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\u1}Underline{\u0}"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<u>Underline</u>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontSize()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\fs28}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font size=\"28\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontName()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\fnArial}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font name=\"Arial\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontColor1()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\c&HFF&}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#ff0000\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontColor2()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\c&HFF00&}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#00ff00\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontColor3()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\c&HFF0000&}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#0000ff\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontColor4()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\c&HFFFFFF&}Font"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#ffffff\">Font</font>";
Assert.AreEqual(expected, actual);
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void AssSimpleFontColorAndItalic()
{
var target = new AdvancedSubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetAssLines(@"{\1c&HFFFF00&\i1}CYAN{\i0}"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#00ffff\"><i>CYAN</i></font>";
Assert.AreEqual(expected, actual);
}
#endregion
#region Sub Station Alpha (.ssa)
private List<string> GetSsaLines(string lineOneText)
{
var text =
@"[Script Info]
; This is a Sub Station Alpha v4 script.
Title: TEST
ScriptType: v4.00
Collisions: Normal
PlayDepth: 0
[V4 Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding
Style: Default,Arial,20,16777215,65535,65535,-2147483640,-1,0,1,3,0,2,30,30,30,0,0
[Events]
Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," + lineOneText;
var lines = new List<string>();
string[] arr = text.Replace(Environment.NewLine, "\r").Replace("\n", "\r").Split('\r');
foreach (string line in arr)
lines.Add(line);
return lines;
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void SsaSimpleFontColorAndItalic()
{
var target = new SubStationAlpha_Accessor();
var subtitle = new Subtitle();
target.LoadSubtitle(subtitle, GetSsaLines(@"{\c&HFFFF00&\i1}CYAN{\i0}"), null);
string actual = subtitle.Paragraphs[0].Text;
string expected = "<font color=\"#00ffff\"><i>CYAN</i></font>";
Assert.AreEqual(expected, actual);
}
#endregion
#region DCinema smpte (.xml)
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void DcinemaSmpteItalic()
{
var target = new DCinemaSmpte_Accessor();
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph("<i>Italic</i>", 1000, 5000));
string text = target.ToText(subtitle, "title");
Assert.IsTrue(text.Contains("<dcst:Font Italic=\"yes\">Italic</dcst:Font>"));
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void DcinemaSmpteColorAndItalic()
{
var target = new DCinemaSmpte_Accessor();
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph("<font color=\"#ff0000\"><i>Red</i></font>", 1000, 5000));
string text = target.ToText(subtitle, "title");
Assert.IsTrue(text.Contains("<dcst:Font Italic=\"yes\" Color=\"FFFF0000\">Red</dcst:Font>"));
}
#endregion
#region DCinema interop (.xml)
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void DcinemaInteropItalic()
{
var target = new DCSubtitle_Accessor();
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph("<i>Italic</i>", 1000, 5000));
string text = target.ToText(subtitle, "title");
Assert.IsTrue(text.Contains("<Font Italic=\"yes\">Italic</Font>"));
}
[TestMethod()]
[DeploymentItem("SubtitleEdit.exe")]
public void DcinemaInteropColorAndItalic()
{
var target = new DCSubtitle_Accessor();
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph("<font color=\"#ff0000\"><i>Red</i></font>", 1000, 5000));
string text = target.ToText(subtitle, "title");
Assert.IsTrue(text.Contains("<Font Italic=\"yes\" Color=\"FFFF0000\">Red</Font>"));
}
#endregion
}
}

View File

@ -63,6 +63,7 @@
<Compile Include="FixCommonErrorsTest.cs" />
<Compile Include="RemoveTextForHearImpairedTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SubtitleFormatsTest.cs" />
</ItemGroup>
<ItemGroup>
<Shadow Include="Test References\SubtitleEdit.accessor" />
@ -78,6 +79,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.