More options for sami html encode

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2447 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2014-01-31 16:38:08 +00:00
parent 2efba69d28
commit 11c1f899fc
3 changed files with 302 additions and 8 deletions

View File

@ -238,7 +238,8 @@ namespace Nikse.SubtitleEdit.Logic
public int CurrentCavena890LanguageId { get; set; }
public bool SamiDisplayTwoClassesAsTwoSubtitles { get; set; }
public bool SamiFullHtmlEncode { get; set; }
public bool SamiFullHtmlEncodeNumeric { get; set; }
public bool SamiFullHtmlEncodeShortName { get; set; }
public string TimedText10TimeCodeFormat { get; set; }
@ -263,7 +264,8 @@ namespace Nikse.SubtitleEdit.Logic
DCinemaFadeUpDownTime = 5;
SamiDisplayTwoClassesAsTwoSubtitles = true;
SamiFullHtmlEncode = true;
SamiFullHtmlEncodeShortName = false;
SamiFullHtmlEncodeNumeric = true;
TimedText10TimeCodeFormat = "Default";
@ -1648,9 +1650,12 @@ namespace Nikse.SubtitleEdit.Logic
subNode = node.SelectSingleNode("SamiDisplayTwoClassesAsTwoSubtitles");
if (subNode != null)
settings.SubtitleSettings.SamiDisplayTwoClassesAsTwoSubtitles = Convert.ToBoolean(subNode.InnerText);
subNode = node.SelectSingleNode("SamiFullHtmlEncode");
subNode = node.SelectSingleNode("SamiFullHtmlEncodeShortName");
if (subNode != null)
settings.SubtitleSettings.SamiFullHtmlEncode = Convert.ToBoolean(subNode.InnerText);
settings.SubtitleSettings.SamiFullHtmlEncodeShortName = Convert.ToBoolean(subNode.InnerText);
subNode = node.SelectSingleNode("SamiFullHtmlEncodeNumeric");
if (subNode != null)
settings.SubtitleSettings.SamiFullHtmlEncodeNumeric = Convert.ToBoolean(subNode.InnerText);
subNode = node.SelectSingleNode("TimedText10TimeCodeFormat");
if (subNode != null)
settings.SubtitleSettings.TimedText10TimeCodeFormat = subNode.InnerText;
@ -2631,7 +2636,8 @@ namespace Nikse.SubtitleEdit.Logic
textWriter.WriteElementString("DCinemaBottomMargin", settings.SubtitleSettings.DCinemaBottomMargin.ToString());
textWriter.WriteElementString("DCinemaFadeUpDownTime", settings.SubtitleSettings.DCinemaFadeUpDownTime.ToString());
textWriter.WriteElementString("SamiDisplayTwoClassesAsTwoSubtitles", settings.SubtitleSettings.SamiDisplayTwoClassesAsTwoSubtitles.ToString());
textWriter.WriteElementString("SamiFullHtmlEncode", settings.SubtitleSettings.SamiFullHtmlEncode.ToString());
textWriter.WriteElementString("SamiFullHtmlEncodeShortName", settings.SubtitleSettings.SamiFullHtmlEncodeShortName.ToString());
textWriter.WriteElementString("SamiFullHtmlEncodeNumeric", settings.SubtitleSettings.SamiFullHtmlEncodeNumeric.ToString());
textWriter.WriteElementString("TimedText10TimeCodeFormat", settings.SubtitleSettings.TimedText10TimeCodeFormat);
textWriter.WriteElementString("FcpFontSize", settings.SubtitleSettings.FcpFontSize.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("FcpFontName", settings.SubtitleSettings.FcpFontName);

View File

@ -134,7 +134,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
text.Substring(i).StartsWith("<s") ||
text.Substring(i).StartsWith("</"))
{
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncode)
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeShortName)
total.Append(Utilities.HtmlEncodeFull(partial.ToString()));
else if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeNumeric)
total.Append(Utilities.HtmlEncodeFull(partial.ToString()));
else
total.Append(Utilities.HtmlEncode(partial.ToString()));
@ -156,7 +158,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
total.Append(text.Substring(i, 1));
}
}
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncode)
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeShortName)
total.Append(Utilities.HtmlEncodeFull(partial.ToString()));
else if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeNumeric)
total.Append(Utilities.HtmlEncodeFull(partial.ToString()));
else
total.Append(Utilities.HtmlEncode(partial.ToString()));
@ -164,7 +168,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
}
else
{
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncode)
if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeShortName)
text = Utilities.HtmlEncodeFull(text);
else if (Configuration.Settings.SubtitleSettings.SamiFullHtmlEncodeNumeric)
text = Utilities.HtmlEncodeFull(text);
else
text = Utilities.HtmlEncode(text);

View File

@ -2810,6 +2810,288 @@ namespace Nikse.SubtitleEdit.Logic
return sb.ToString();
}
/// <summary>
/// HTML-encodes a string
/// </summary>
/// <param name="text">Text string to encode</param>
/// <returns>HTML-encoded text</returns>
public static string HtmlEncodeFullNumeric(string text)
{
if (text == null)
return string.Empty;
var sb = new StringBuilder(text.Length);
int len = text.Length;
for (int i = 0; i < len; i++)
{
switch (text[i])
{
case '<':
sb.Append("&#" + (int)text[i] + ";");
break;
case '>':
sb.Append("&#" + (int)text[i] + ";");
break;
case '"':
sb.Append("&#" + (int)text[i] + ";");
break;
case '&':
sb.Append("&#" + (int)text[i] + ";");
break;
case '\'':
sb.Append("&#" + (int)text[i] + ";");
break;
case ' ':
sb.Append("&#160;");
break;
case '':
sb.Append("&#" + (int)text[i] + ";");
break;
case '—':
sb.Append("&#" + (int)text[i] + ";");
break;
case '¡':
sb.Append("&#" + (int)text[i] + ";");
break;
case '¿':
sb.Append("&#" + (int)text[i] + ";");
break;
case '“':
sb.Append("&#" + (int)text[i] + ";");
break;
case '”':
sb.Append("&#" + (int)text[i] + ";");
break;
case '':
sb.Append("&#" + (int)text[i] + ";");
break;
case '':
sb.Append("&#" + (int)text[i] + ";");
break;
case '«':
sb.Append("&#" + (int)text[i] + ";");
break;
case '»':
sb.Append("&#" + (int)text[i] + ";");
break;
case '¢':
sb.Append("&#" + (int)text[i] + ";");
break;
case '©':
sb.Append("&#" + (int)text[i] + ";");
break;
case '÷':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'µ':
sb.Append("&#" + (int)text[i] + ";");
break;
case '·':
sb.Append("&#" + (int)text[i] + ";");
break;
case '¶':
sb.Append("&#" + (int)text[i] + ";");
break;
case '±':
sb.Append("&#" + (int)text[i] + ";");
break;
case '€':
sb.Append("&#" + (int)text[i] + ";");
break;
case '£':
sb.Append("&#" + (int)text[i] + ";");
break;
case '®':
sb.Append("&#" + (int)text[i] + ";");
break;
case '§':
sb.Append("&#" + (int)text[i] + ";");
break;
case '™':
sb.Append("&#" + (int)text[i] + ";");
break;
case '¥':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'á':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Á':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'à':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'À':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'â':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Â':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'å':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Å':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ã':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ã':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ä':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ä':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'æ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Æ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ç':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ç':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'é':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'É':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'è':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'È':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ê':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ê':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ë':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ë':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'í':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Í':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ì':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ì':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'î':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Î':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ï':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ï':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ñ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ñ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ó':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ó':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ò':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ò':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ô':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ô':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ø':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ø':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'õ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Õ':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ö':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ö':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ß':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ú':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ú':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ù':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ù':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'û':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Û':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ü':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'Ü':
sb.Append("&#" + (int)text[i] + ";");
break;
case 'ÿ':
sb.Append("&#" + (int)text[i] + ";");
break;
default:
if (text[i] > 127)
sb.Append("&#" + (int)text[i] + ";");
else
sb.Append(text[i]);
break;
}
}
return sb.ToString();
}
/// <summary>
/// HTML-decodes a string
/// </summary>