mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Issue 180 - Italics when exporting to Softni were not formatted correctly. Also, the top-position tag {\an8} - thx Adrian :)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2213 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
822e23111a
commit
4f3fa4b5f0
@ -42,28 +42,85 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
foreach (Paragraph p in subtitle.Paragraphs)
|
foreach (Paragraph p in subtitle.Paragraphs)
|
||||||
{
|
{
|
||||||
string text = p.Text;
|
string text = p.Text;
|
||||||
if (text.StartsWith("<i>") && text.EndsWith("</i>"))
|
bool positionTop = false;
|
||||||
text = "[" + text;
|
|
||||||
|
// If text starts with {\an8}, subtitle appears at the top
|
||||||
|
if (text.StartsWith("{\\an8}"))
|
||||||
|
{
|
||||||
|
positionTop = true;
|
||||||
|
// Remove the tag {\an8}.
|
||||||
|
text = text.Remove(0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split lines (split a subtitle into its lines)
|
||||||
|
var lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
int count = 0;
|
||||||
|
var lineSb = new StringBuilder();
|
||||||
|
string tempLine = string.Empty;
|
||||||
|
Boolean nextLineInItalics = false;
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
// Append line break in every line except the first one
|
||||||
|
if (count > 0)
|
||||||
|
lineSb.Append(Environment.NewLine);
|
||||||
|
|
||||||
|
tempLine = line;
|
||||||
|
|
||||||
|
// This line should be in italics (it was detected in previous line)
|
||||||
|
if (nextLineInItalics)
|
||||||
|
{
|
||||||
|
tempLine = "<i>" + tempLine;
|
||||||
|
nextLineInItalics = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tempLine.StartsWith("<i>") && tempLine.EndsWith("</i>"))
|
||||||
|
{
|
||||||
|
// Whole line is in italics
|
||||||
|
// Remove <i> from the beginning
|
||||||
|
tempLine = tempLine.Remove(0, 3);
|
||||||
|
// Remove </i> from the end
|
||||||
|
tempLine = tempLine.Remove(tempLine.Length - 4, 4);
|
||||||
|
// Add new italics tag at the beginning
|
||||||
|
tempLine = "[" + tempLine;
|
||||||
|
}
|
||||||
|
else if (tempLine.StartsWith("<i>") && Utilities.CountTagInText(tempLine, "<i>") > Utilities.CountTagInText(tempLine, "</i>"))
|
||||||
|
{
|
||||||
|
// Line starts with <i> but italics are not closed. So the next line should be in italics
|
||||||
|
nextLineInItalics = true;
|
||||||
|
}
|
||||||
|
lineSb.Append(tempLine);
|
||||||
|
count++;
|
||||||
|
|
||||||
|
text = lineSb.ToString();
|
||||||
|
// Replace remaining italics tags
|
||||||
|
text = text.Replace("<i>", @"[");
|
||||||
|
text = text.Replace("</i>", @"]");
|
||||||
text = Utilities.RemoveHtmlTags(text);
|
text = Utilities.RemoveHtmlTags(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add top-position SoftNI marker "{" at the beginning of first line.
|
||||||
|
if (positionTop)
|
||||||
|
text = "{" + text;
|
||||||
|
|
||||||
sb.AppendLine(string.Format("{0}{1}{2}\\{3}", text, Environment.NewLine, p.StartTime.ToHHMMSSPeriodFF(), p.EndTime.ToHHMMSSPeriodFF()));
|
sb.AppendLine(string.Format("{0}{1}{2}\\{3}", text, Environment.NewLine, p.StartTime.ToHHMMSSPeriodFF(), p.EndTime.ToHHMMSSPeriodFF()));
|
||||||
}
|
}
|
||||||
sb.AppendLine(@"*END*
|
sb.AppendLine(@"*END*");
|
||||||
...........\...........
|
sb.AppendLine(@"...........\...........");
|
||||||
*CODE*
|
sb.AppendLine(@"*CODE*");
|
||||||
0000000000000000
|
sb.AppendLine(@"0000000000000000");
|
||||||
*CAST*
|
sb.AppendLine(@"*CAST*");
|
||||||
*GENERATOR*
|
sb.AppendLine(@"*GENERATOR*");
|
||||||
*FONTS*
|
sb.AppendLine(@"*FONTS*");
|
||||||
*READ*
|
sb.AppendLine(@"*READ*");
|
||||||
0,300 15,000 130,000 100,000 25,000
|
sb.AppendLine(@"0,300 15,000 130,000 100,000 25,000");
|
||||||
*TIMING*
|
sb.AppendLine(@"*TIMING*");
|
||||||
1 25 0
|
sb.AppendLine(@"1 25 0");
|
||||||
*TIMED BACKUP NAME*
|
sb.AppendLine(@"*TIMED BACKUP NAME*");
|
||||||
C:\
|
sb.AppendLine(@"C:\");
|
||||||
*FORMAT SAMPLE ÅåÉéÌìÕõÛûÿ*
|
sb.AppendLine(@"*FORMAT SAMPLE ÅåÉéÌìÕõÛûÿ*");
|
||||||
*READ ADVANCED*
|
sb.AppendLine(@"*READ ADVANCED*");
|
||||||
< > 1 1 0,300
|
sb.AppendLine(@"< > 1 1 0,300");
|
||||||
*MARKERS*");
|
sb.AppendLine(@"*MARKERS*");
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +142,7 @@ C:\
|
|||||||
string s = line.Trim();
|
string s = line.Trim();
|
||||||
if (regexTimeCodes.IsMatch(s))
|
if (regexTimeCodes.IsMatch(s))
|
||||||
{
|
{
|
||||||
|
// Start and end time separated by "\"
|
||||||
var temp = s.Split('\\');
|
var temp = s.Split('\\');
|
||||||
if (temp.Length > 1)
|
if (temp.Length > 1)
|
||||||
{
|
{
|
||||||
@ -101,8 +159,46 @@ C:\
|
|||||||
p.StartTime = DecodeTimeCode(startParts);
|
p.StartTime = DecodeTimeCode(startParts);
|
||||||
p.EndTime = DecodeTimeCode(endParts);
|
p.EndTime = DecodeTimeCode(endParts);
|
||||||
string text = sb.ToString().Trim();
|
string text = sb.ToString().Trim();
|
||||||
if (text.StartsWith("["))
|
|
||||||
text = "<i>" + text.Remove(0, 1) + "</i>";
|
Boolean positionTop = false;
|
||||||
|
// If text starts with "{", subtitle appears at the top
|
||||||
|
if (text.StartsWith("{"))
|
||||||
|
{
|
||||||
|
positionTop = true;
|
||||||
|
// Remove the tag "{"
|
||||||
|
text = text.Remove(0, 1);
|
||||||
|
}
|
||||||
|
// Replace tags
|
||||||
|
text = text.Replace("[", @"<i>");
|
||||||
|
text = text.Replace("]", @"</i>");
|
||||||
|
|
||||||
|
// Split subtitle lines (one subtitle has one or more lines)
|
||||||
|
var subtitleLines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
int count = 0;
|
||||||
|
var lineSb = new StringBuilder();
|
||||||
|
string tempLine = string.Empty;
|
||||||
|
foreach (string subtitleLine in subtitleLines)
|
||||||
|
{
|
||||||
|
// Append line break in every line except the first one
|
||||||
|
if (count > 0)
|
||||||
|
lineSb.Append(Environment.NewLine);
|
||||||
|
tempLine = subtitleLine;
|
||||||
|
// Close italics in every line (if next line is in italics, SoftNI will use "[" at the beginning)
|
||||||
|
if (Utilities.CountTagInText(tempLine,"<i>") > Utilities.CountTagInText(tempLine,"</i>"))
|
||||||
|
tempLine = tempLine + "</i>";
|
||||||
|
|
||||||
|
lineSb.Append(tempLine);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
text = lineSb.ToString();
|
||||||
|
|
||||||
|
// Replace "</i>line break<i>" with just a line break (Subrip does not need to close italics and open them again in the next line).
|
||||||
|
text = text.Replace("</i>" + Environment.NewLine + "<i>", Environment.NewLine);
|
||||||
|
|
||||||
|
// Subtitle appears at the top (add tag)
|
||||||
|
if (positionTop)
|
||||||
|
text = "{\\an8}" + text;
|
||||||
|
|
||||||
p.Text = text;
|
p.Text = text;
|
||||||
if (text.Length > 0)
|
if (text.Length > 0)
|
||||||
subtitle.Paragraphs.Add(p);
|
subtitle.Paragraphs.Add(p);
|
||||||
|
@ -89,12 +89,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
new ScenaristClosedCaptions(),
|
new ScenaristClosedCaptions(),
|
||||||
new ScenaristClosedCaptionsDropFrame(),
|
new ScenaristClosedCaptionsDropFrame(),
|
||||||
new SmilTimesheetData(),
|
new SmilTimesheetData(),
|
||||||
|
new SoftNiSub(),
|
||||||
new SonyDVDArchitect(),
|
new SonyDVDArchitect(),
|
||||||
new SonyDVDArchitectExplicitDuration(),
|
new SonyDVDArchitectExplicitDuration(),
|
||||||
new SonyDVDArchitectLineAndDuration(),
|
new SonyDVDArchitectLineAndDuration(),
|
||||||
new SonyDVDArchitectTabs(),
|
new SonyDVDArchitectTabs(),
|
||||||
new SonyDVDArchitectWithLineNumbers(),
|
new SonyDVDArchitectWithLineNumbers(),
|
||||||
new SoftNiSub(),
|
|
||||||
new Spruce(),
|
new Spruce(),
|
||||||
new SpruceWithSpace(),
|
new SpruceWithSpace(),
|
||||||
new StructuredTitles(),
|
new StructuredTitles(),
|
||||||
|
Loading…
Reference in New Issue
Block a user