Fixed bug regarding new-line in writing af PAC files - thx Ranger :)

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1532 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2012-12-09 10:56:42 +00:00
parent 2297bc2bc0
commit 42dfec0515

View File

@ -679,7 +679,6 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
GetCodePage(null, 0, 0); GetCodePage(null, 0, 0);
string text = MakePacItalicsAndRemoveOtherTags(p.Text); string text = MakePacItalicsAndRemoveOtherTags(p.Text);
text = text.Replace(Environment.NewLine, Encoding.Default.GetString(new byte[] { 0xfe, 0x02, 0x03 })); // fix line breaks
Encoding encoding = GetEncoding(_codePage); Encoding encoding = GetEncoding(_codePage);
byte[] textBuffer; byte[] textBuffer;
@ -1088,34 +1087,45 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
int extra = 0; int extra = 0;
while (i < text.Length) while (i < text.Length)
{ {
string letter = text.Substring(i, 1); if (text.Substring(i).StartsWith(Environment.NewLine))
int idx = LatinLetters.IndexOf(letter);
if (idx >= 0)
{ {
int byteValue = LatinCodes[idx]; buffer[i + extra] = 0xfe;
if (byteValue < 256) i++;
{ buffer[i + extra] = 2;
buffer[i + extra] = (byte)byteValue; extra++;
} buffer[i + extra] = 3;
else
{
int high = byteValue / 256;
int low = byteValue % 256;
buffer[i + extra] = (byte)high;
extra++;
buffer[i + extra] = (byte)low;
}
} }
else else
{ {
var values = encoding.GetBytes(letter); string letter = text.Substring(i, 1);
for (int k = 0; k < values.Length; k++) int idx = LatinLetters.IndexOf(letter);
if (idx >= 0)
{ {
byte v = values[k]; int byteValue = LatinCodes[idx];
if (k > 0) if (byteValue < 256)
{
buffer[i + extra] = (byte)byteValue;
}
else
{
int high = byteValue / 256;
int low = byteValue % 256;
buffer[i + extra] = (byte)high;
extra++; extra++;
buffer[i + extra] = v; buffer[i + extra] = (byte)low;
}
}
else
{
var values = encoding.GetBytes(letter);
for (int k = 0; k < values.Length; k++)
{
byte v = values[k];
if (k > 0)
extra++;
buffer[i + extra] = v;
}
} }
} }
i++; i++;
@ -1150,59 +1160,70 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
int extra = 0; int extra = 0;
while (i < text.Length) while (i < text.Length)
{ {
bool doubleCharacter = false; if (text.Substring(i).StartsWith(Environment.NewLine))
string letter = string.Empty;
int idx = -1;
if (i + 1 < text.Length)
{ {
letter = text.Substring(i, 2); buffer[i + extra] = 0xfe;
idx = letters.IndexOf(letter); i++;
if (idx >= 0) buffer[i + extra] = 2;
doubleCharacter = true; extra++;
} buffer[i + extra] = 3;
if (idx < 0)
{
letter = text.Substring(i, 1);
idx = letters.IndexOf(letter);
}
if (idx >= 0)
{
int byteValue = codes[idx];
if (byteValue < 256)
{
buffer[i + extra] = (byte)byteValue;
}
else
{
int high = byteValue / 256;
int low = byteValue % 256;
buffer[i + extra] = (byte)high;
if (doubleCharacter)
{
i++;
doubleCharacter = false;
}
else
{
extra++;
}
buffer[i + extra] = (byte)low;
}
} }
else else
{ {
var values = Encoding.Default.GetBytes(letter); bool doubleCharacter = false;
for (int k = 0; k < values.Length; k++) string letter = string.Empty;
int idx = -1;
if (i + 1 < text.Length)
{ {
byte v = values[k]; letter = text.Substring(i, 2);
if (k > 0) idx = letters.IndexOf(letter);
extra++; if (idx >= 0)
buffer[i + extra] = v; doubleCharacter = true;
} }
if (idx < 0)
{
letter = text.Substring(i, 1);
idx = letters.IndexOf(letter);
}
if (idx >= 0)
{
int byteValue = codes[idx];
if (byteValue < 256)
{
buffer[i + extra] = (byte)byteValue;
}
else
{
int high = byteValue / 256;
int low = byteValue % 256;
buffer[i + extra] = (byte)high;
if (doubleCharacter)
{
i++;
doubleCharacter = false;
}
else
{
extra++;
}
buffer[i + extra] = (byte)low;
}
}
else
{
var values = Encoding.Default.GetBytes(letter);
for (int k = 0; k < values.Length; k++)
{
byte v = values[k];
if (k > 0)
extra++;
buffer[i + extra] = v;
}
}
if (doubleCharacter)
i++;
} }
i++; i++;
if (doubleCharacter)
i++;
} }
byte[] result = new byte[i + extra]; byte[] result = new byte[i + extra];