Some fixes for 890 + Sami

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1305 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2012-08-05 10:27:42 +00:00
parent 8bf7f2fbbd
commit aadeefad7a
2 changed files with 128 additions and 13 deletions

View File

@ -33,8 +33,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
0x5A, // ת
0x4b, // כ
0x4a, // ך
0x48, // ע
0x48, // ט
0x53, // ף
0x55, // ץ
};
static List<string> _hebrewLetters = new List<string> {
@ -62,8 +63,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
"ת",
"כ",
"ך",
"ע",
"ט",
"ף",
"ץ",
};
public override string Extension
@ -91,7 +93,29 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
if (_language != null && _language.StartsWith("HEB"))
bool isChinese = false;
foreach (Paragraph p in subtitle.Paragraphs)
{
if (p.Text.Contains("的") ||
p.Text.Contains("是") ||
p.Text.Contains("啊") ||
p.Text.Contains("吧") ||
p.Text.Contains("好") ||
p.Text.Contains("吧") ||
p.Text.Contains("亲") ||
p.Text.Contains("爱") ||
p.Text.Contains("的") ||
p.Text.Contains("早") ||
p.Text.Contains("上") ||
p.Text.Contains(""))
{
isChinese = true;
break;
}
}
if (_language != null && _language.StartsWith("HEB") || isChinese)
{
byte[] buffer = new byte[388];
for (int i = 0; i < buffer.Length; i++)
@ -125,9 +149,23 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
buffer[190] = 0x4E;
buffer[191] = 0x4F;
buffer[192] = 0x41;
if (isChinese)
{
buffer[187] = 0x43; // CCKM44
buffer[188] = 0x43;
buffer[189] = 0x4B;
buffer[190] = 0x4D;
buffer[191] = 0x34;
buffer[192] = 0x34;
}
buffer[193] = 0x2E;
buffer[194] = 0x56;
buffer[208] = 0xf6;
buffer[209] = 0x01;
buffer[210] = 0xf3;
@ -220,10 +258,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (lines.Length > 2)
lines = Utilities.AutoBreakLine(text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (lines.Length > 0)
line1 = lines[0];
if (lines.Length > 1)
{
line1 = lines[0];
line2 = lines[1];
}
else if (lines.Length == 1)
{
line2 = lines[0];
}
var buffer = GetTextAsBytes(line1);
fs.Write(buffer, 0, buffer.Length);
@ -246,6 +289,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
for (int i = 0; i < buffer.Length; i++)
buffer[i] = 0x7F;
if (_language != null && _language.StartsWith("CCKM44"))
{
for (int i = 0; i < buffer.Length; i++)
buffer[i] = 0;
}
var encoding = Encoding.Default;
int index = 0;
for (int i = 0; i < text.Length; i++)
@ -278,6 +327,32 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
}
index++;
}
else if (_language != null && _language.StartsWith("CCKM44"))
{
encoding = Encoding.GetEncoding(1201);
if (index < 49)
{
if (i + 3 < text.Length && text.Substring(i, 3) == "<i>")
{
buffer[index] = 0x88;
skipCount = 2;
}
else if (i + 4 <= text.Length && text.Substring(i, 4) == "</i>")
{
buffer[index] = 0x98;
skipCount = 3;
}
else
{
byte[] b = encoding.GetBytes(current);
for (int f = 0; f < b.Length; f++)
{
buffer[index] = b[f];
index++;
}
}
}
}
else
{
if (index < 50)
@ -526,7 +601,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
text = text.Replace(encoding.GetString(new byte[] { 0x7F }), string.Empty); // Used to fill empty space upto 51 bytes
text = text.Replace(encoding.GetString(new byte[] { 0xBE }), string.Empty); // Unknown?
text = Utilities.FixEnglishTextInRightToLeftLanguage(text, "0123456789abcdefghijklmnopqrstuvwxyz");
text = Utilities.FixEnglishTextInRightToLeftLanguage(text, ",.?-'/\"0123456789abcdefghijklmnopqrstuvwxyz");
}
else if (_language == "CCKM44")
{

View File

@ -46,7 +46,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
string languageStyle = string.Format(".{0} [ name: {1}; lang: {2} ; SAMIType: CC ; ]", languageTag, languageName, language.Replace("_", "-"));
languageStyle = languageStyle.Replace("[", "{").Replace("]", "}");
const string header =
string header =
@"<SAMI>
<HEAD>
@ -71,13 +71,40 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
<-- Open play menu, choose Captions and Subtiles, On if available -->
<-- Open tools menu, Security, Show local captions when present -->
";
bool useExtra = false;
if (!string.IsNullOrEmpty(subtitle.Header) && subtitle.Header.ToLower().StartsWith("<style"))
{
useExtra = true;
header =
@"<SAMI>
<HEAD>
<TITLE>_TITLE_</TITLE>
<SAMIParam>
Metrics {time:ms;}
Spec {MSFT:1.0;}
</SAMIParam>
" + subtitle.Header.Trim() + @"
</HEAD>
<BODY>
<-- Open play menu, choose Captions and Subtiles, On if available -->
<-- Open tools menu, Security, Show local captions when present -->
";
}
// Example text (start numbers are milliseconds)
//<SYNC Start=65264><P>Let's go!
//<SYNC Start=66697><P><BR>
string paragraphWriteFormat = @"<SYNC Start={0}><P Class={3}>{2}" + Environment.NewLine +
@"<SYNC Start={1}><P Class={3}>&nbsp;";
string paragraphWriteFormatOpen = @"<SYNC Start={0}><P Class={2}>{1}</P>";
string paragraphWriteFormatOpen = @"<SYNC Start={0}><P Class={2}>{1}";
if (Name == new SamiModern().Name)
{
paragraphWriteFormat = "<SYNC Start=\"{0}\"><P Class=\"{3}\">{2}</P></SYNC>" + Environment.NewLine +
@ -135,10 +162,13 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
else
text = cleanTextBuilder.ToString().Replace(Environment.NewLine, "<br>");
string currentClass = languageTag;
if (useExtra && !string.IsNullOrEmpty(p.Extra))
currentClass = p.Extra;
if (next != null && p.EndTime.TotalMilliseconds <= next.StartTime.TotalMilliseconds && p.EndTime.TotalMilliseconds + 51 > next.StartTime.TotalMilliseconds)
sb.AppendLine(string.Format(paragraphWriteFormatOpen, p.StartTime.TotalMilliseconds, text, languageTag));
sb.AppendLine(string.Format(paragraphWriteFormatOpen, p.StartTime.TotalMilliseconds, text, currentClass));
else
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartTime.TotalMilliseconds, p.EndTime.TotalMilliseconds, text, languageTag));
sb.AppendLine(string.Format(paragraphWriteFormat, p.StartTime.TotalMilliseconds, p.EndTime.TotalMilliseconds, text, currentClass));
count++;
}
sb.AppendLine("</BODY>");
@ -146,12 +176,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
return sb.ToString().Trim();
}
public List<string> GetClasses(Subtitle subtitle)
public static List<string> GetStylesFromHeader(string header)
{
var list = new List<string>();
if (!string.IsNullOrEmpty(subtitle.Header) && subtitle.Header.ToLower().StartsWith("<style"))
if (!string.IsNullOrEmpty(header) && header.ToLower().StartsWith("<style"))
{
foreach (string line in subtitle.Header.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
foreach (string line in header.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
string s = line.Trim();
if (s.StartsWith(".") && s.IndexOf(" ") > 2)
@ -161,6 +191,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
}
}
}
else
{
list.Add("ENUSCC");
}
return list;
}
@ -323,5 +357,11 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
}
subtitle.Renumber(1);
}
public override bool HasStyleSupport
{
get { return true; }
}
}
}