mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
Fix assa tag issue w export to image
This commit is contained in:
parent
aca715115f
commit
91f55901d0
@ -213,17 +213,34 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
var text = p.P.Text;
|
var text = p.P.Text;
|
||||||
if (format.GetType() == typeof(SubStationAlpha) && text.Length > 5)
|
if (format.GetType() == typeof(SubStationAlpha) && text.Length > 5)
|
||||||
{
|
{
|
||||||
text = p.P.Text.Substring(0, 6);
|
var assaTag = GetStartAssaTag(text);
|
||||||
alignment = GetSsaAlignment(text, alignment);
|
alignment = GetSsaAlignment(assaTag, alignment);
|
||||||
}
|
}
|
||||||
else if (text.Length > 6)
|
else if (text.Length > 6)
|
||||||
{
|
{
|
||||||
text = p.P.Text.Substring(0, 6);
|
var assaTag = GetStartAssaTag(text);
|
||||||
alignment = GetAssAlignment(text, alignment);
|
alignment = GetAssAlignment(assaTag, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return alignment;
|
return alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetStartAssaTag(string text)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(text) || !text.StartsWith("{\\", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tagEnd = text.IndexOf('}');
|
||||||
|
if (tagEnd < 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.Substring(0, tagEnd + 1);
|
||||||
|
}
|
||||||
|
|
||||||
private static ContentAlignment GetSsaAlignment(string text, ContentAlignment defaultAlignment)
|
private static ContentAlignment GetSsaAlignment(string text, ContentAlignment defaultAlignment)
|
||||||
{
|
{
|
||||||
//1: Bottom left
|
//1: Bottom left
|
||||||
@ -235,27 +252,52 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
//5: Top left
|
//5: Top left
|
||||||
//6: Top center
|
//6: Top center
|
||||||
//7: Top right
|
//7: Top right
|
||||||
switch (text)
|
|
||||||
|
if (text.Contains("\\a1\\", StringComparison.Ordinal) || text.Contains("\\a1}", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
case "{\\a1}":
|
|
||||||
return ContentAlignment.BottomLeft;
|
return ContentAlignment.BottomLeft;
|
||||||
case "{\\a2}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a2\\", StringComparison.Ordinal) || text.Contains("\\a2}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.BottomCenter;
|
return ContentAlignment.BottomCenter;
|
||||||
case "{\\a3}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a3\\", StringComparison.Ordinal) || text.Contains("\\a3}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.BottomRight;
|
return ContentAlignment.BottomRight;
|
||||||
case "{\\a9}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a9\\", StringComparison.Ordinal) || text.Contains("\\a9}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleLeft;
|
return ContentAlignment.MiddleLeft;
|
||||||
case "{\\a10}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a10\\", StringComparison.Ordinal) || text.Contains("\\a10}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleCenter;
|
return ContentAlignment.MiddleCenter;
|
||||||
case "{\\a11}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a11\\", StringComparison.Ordinal) || text.Contains("\\a11}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleRight;
|
return ContentAlignment.MiddleRight;
|
||||||
case "{\\a5}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a5\\", StringComparison.Ordinal) || text.Contains("\\a5}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopLeft;
|
return ContentAlignment.TopLeft;
|
||||||
case "{\\a6}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a6\\", StringComparison.Ordinal) || text.Contains("\\a6}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopCenter;
|
return ContentAlignment.TopCenter;
|
||||||
case "{\\a7}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\a7\\", StringComparison.Ordinal) || text.Contains("\\a7}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopRight;
|
return ContentAlignment.TopRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultAlignment;
|
return defaultAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,27 +312,52 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
//7: Top left
|
//7: Top left
|
||||||
//8: Top center
|
//8: Top center
|
||||||
//9: Top right
|
//9: Top right
|
||||||
switch (text)
|
|
||||||
|
if (text.Contains("\\an1\\", StringComparison.Ordinal) || text.Contains("\\an1}", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
case "{\\an1}":
|
|
||||||
return ContentAlignment.BottomLeft;
|
return ContentAlignment.BottomLeft;
|
||||||
case "{\\an2}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an2\\", StringComparison.Ordinal) || text.Contains("\\an2}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.BottomCenter;
|
return ContentAlignment.BottomCenter;
|
||||||
case "{\\an3}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an3\\", StringComparison.Ordinal) || text.Contains("\\an3}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.BottomRight;
|
return ContentAlignment.BottomRight;
|
||||||
case "{\\an4}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an4\\", StringComparison.Ordinal) || text.Contains("\\an4}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleLeft;
|
return ContentAlignment.MiddleLeft;
|
||||||
case "{\\an5}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an5\\", StringComparison.Ordinal) || text.Contains("\\an5}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleCenter;
|
return ContentAlignment.MiddleCenter;
|
||||||
case "{\\an6}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an6\\", StringComparison.Ordinal) || text.Contains("\\an6}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.MiddleRight;
|
return ContentAlignment.MiddleRight;
|
||||||
case "{\\an7}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an7\\", StringComparison.Ordinal) || text.Contains("\\an7}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopLeft;
|
return ContentAlignment.TopLeft;
|
||||||
case "{\\an8}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an8\\", StringComparison.Ordinal) || text.Contains("\\an8}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopCenter;
|
return ContentAlignment.TopCenter;
|
||||||
case "{\\an9}":
|
}
|
||||||
|
|
||||||
|
if (text.Contains("\\an9\\", StringComparison.Ordinal) || text.Contains("\\an9}", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
return ContentAlignment.TopRight;
|
return ContentAlignment.TopRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultAlignment;
|
return defaultAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2799,8 +2866,8 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
Bitmap bmp = null;
|
Bitmap bmp = null;
|
||||||
if (!parameter.SimpleRendering && parameter.P.Text.Contains(Environment.NewLine) && (parameter.BoxSingleLine || parameter.P.Text.Contains(BoxSingleLineText)))
|
if (!parameter.SimpleRendering && parameter.P.Text.Contains(Environment.NewLine) && (parameter.BoxSingleLine || parameter.P.Text.Contains(BoxSingleLineText)))
|
||||||
{
|
{
|
||||||
string old = parameter.P.Text;
|
var old = parameter.P.Text;
|
||||||
int oldType3D = parameter.Type3D;
|
var oldType3D = parameter.Type3D;
|
||||||
if (parameter.Type3D == 2) // Half-Top/Bottom 3D
|
if (parameter.Type3D == 2) // Half-Top/Bottom 3D
|
||||||
{
|
{
|
||||||
parameter.Type3D = 0; // fix later
|
parameter.Type3D = 0; // fix later
|
||||||
@ -2815,7 +2882,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
var italicOn = false;
|
var italicOn = false;
|
||||||
var boldOn = false;
|
var boldOn = false;
|
||||||
var fontTag = string.Empty;
|
var fontTag = string.Empty;
|
||||||
var lineWidts = new List<int>();
|
var lineWidths = new List<int>();
|
||||||
foreach (var line in parameter.P.Text.SplitToLines())
|
foreach (var line in parameter.P.Text.SplitToLines())
|
||||||
{
|
{
|
||||||
parameter.P.Text = line;
|
parameter.P.Text = line;
|
||||||
@ -2849,7 +2916,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
}
|
}
|
||||||
|
|
||||||
var lineImage = GenerateImageFromTextWithStyleInner(parameter);
|
var lineImage = GenerateImageFromTextWithStyleInner(parameter);
|
||||||
lineWidts.Add(lineImage.Width);
|
lineWidths.Add(lineImage.Width);
|
||||||
if (bmp == null)
|
if (bmp == null)
|
||||||
{
|
{
|
||||||
bmp = lineImage;
|
bmp = lineImage;
|
||||||
@ -2904,7 +2971,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
l2 = w - lineImage.Width;
|
l2 = w - lineImage.Width;
|
||||||
if (parameter.BoxSingleLine)
|
if (parameter.BoxSingleLine)
|
||||||
{
|
{
|
||||||
l1 = w - lineWidts[0];
|
l1 = w - lineWidths[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2957,7 +3024,7 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var oldBackgroundColor = parameter.BackgroundColor;
|
var oldBackgroundColor = parameter.BackgroundColor;
|
||||||
string oldText = parameter.P.Text;
|
var oldText = parameter.P.Text;
|
||||||
if (parameter.P.Text.Contains(BoxMultiLineText) || parameter.P.Text.Contains(BoxSingleLineText))
|
if (parameter.P.Text.Contains(BoxMultiLineText) || parameter.P.Text.Contains(BoxSingleLineText))
|
||||||
{
|
{
|
||||||
parameter.P.Text = parameter.P.Text.Replace("<" + BoxMultiLineText + ">", string.Empty).Replace("</" + BoxMultiLineText + ">", string.Empty);
|
parameter.P.Text = parameter.P.Text.Replace("<" + BoxMultiLineText + ">", string.Empty).Replace("</" + BoxMultiLineText + ">", string.Empty);
|
||||||
@ -3814,10 +3881,10 @@ $DROP=[DROPVALUE]" + Environment.NewLine + Environment.NewLine +
|
|||||||
|
|
||||||
private static string AssToHtmlTagsIfKnow(string s)
|
private static string AssToHtmlTagsIfKnow(string s)
|
||||||
{
|
{
|
||||||
int k = s.IndexOf("{\\", StringComparison.Ordinal);
|
var k = s.IndexOf("{\\", StringComparison.Ordinal);
|
||||||
while (k >= 0)
|
while (k >= 0)
|
||||||
{
|
{
|
||||||
int l = s.IndexOf('}', k + 1);
|
var l = s.IndexOf('}', k + 1);
|
||||||
if (l < k)
|
if (l < k)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user