Fix for white-space/italic in DCinema SMPTE formats - thx Knut :)

This commit is contained in:
niksedk 2023-03-16 14:13:47 +01:00
parent 4ddee2fb71
commit 5c8a7bd668
5 changed files with 34 additions and 32 deletions

View File

@ -9,6 +9,8 @@
* Add new shortcut for split + auto-br - thx oep42
* Add "Sort by" in "Batch convert" - thx Masina86
* Add image format RhozetHarmonic (only read) - thx Arianna
* Add "Toggle custom surround text with" shortcut - thx HadiSparrow
* Add "Go to next/previous time code from video position" shortcuts - thx faon-92
* IMPROVED:
* Update French translation - thx Pierre
* Update Hungarian translation - thx Zityi
@ -43,6 +45,9 @@
* Fix minor left/right cropping issue in image export - thx nissansz
* Fix possible crash after choosing folder in image export
* Fix italic/font issue with DFXP - thx IngunnHelge
* Fix for image export baseline - thx Matt
* Fix cash in "Generate blank video"
* Fix too many {\an1} in SCC
3.6.11 (30th January 2023)

View File

@ -858,6 +858,16 @@ Dialogue: Marked=0,0:00:01.00,0:00:03.00,Default,NTP,0000,0000,0000,!Effect," +
Assert.IsTrue(text.Contains("<Font Italic=\"yes\" Color=\"FFFF0000\">Red</Font>"));
}
[TestMethod]
public void DcinemaSmpteColorAndItalicNoSpaceBeforeAndAfterFont()
{
var target = new DCinemaSmpte2010();
var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph("<font color=\"#ff0000\"><i>Red</i></font>", 1000, 5000));
var text = target.ToText(subtitle, "title");
Assert.IsTrue(text.Contains("><Font Italic=\"yes\" Color=\"FFFF0000\">Red</Font><"));
}
#endregion DCinema smpte (.xml)
#region DCinema interop (.xml)

View File

@ -563,6 +563,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
Errors = "Error validating xml via SMPTE-428-7-2007-DCST.xsd: " + exception.Message;
}
}
return DCinemaSmpte2010.FixDcsTextSameLine(result);
}

View File

@ -575,11 +575,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
/// </summary>
internal static string FixDcsTextSameLine(string xml)
{
var index = xml.IndexOf("<dcst:Text", StringComparison.Ordinal);
var index = xml.IndexOf("<Text", StringComparison.Ordinal);
var endIndex = 1;
while (index > 0 && endIndex > 0)
{
endIndex = xml.IndexOf("</dcst:Text>", index, StringComparison.Ordinal);
endIndex = xml.IndexOf("</Text>", index, StringComparison.Ordinal);
if (endIndex > 0)
{
var part = xml.Substring(index, endIndex - index);
@ -593,10 +593,24 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
part = part.Replace("> <", "><");
}
xml = xml.Remove(index, endIndex - index).Insert(index, part);
index = xml.IndexOf("<dcst:Text", endIndex, StringComparison.Ordinal);
index = xml.IndexOf("<Text", endIndex, StringComparison.Ordinal);
}
}
xml = xml
.Replace("\n<Font>", "<Font>")
.Replace("\r<Font>", "<Font>")
.Replace("\n<Font>", "<Font>")
.Replace("\r<Font>", "<Font>")
.Replace("</Font>\r", "</Font>")
.Replace("</Font>\n", "</Font>")
.Replace("</Font>\r", "</Font>")
.Replace("</Font>\n", "</Font>")
.Replace("</Font> </Text>", "</Font></Text>")
;
return xml;
}

View File

@ -568,36 +568,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
Errors = "Error validating xml via SMPTE-428-7-2014-DCST.xsd: " + exception.Message;
}
}
return FixDcsTextSameLine(result);
}
/// <summary>
/// All space characters present inside the content of a Text element shall be rendered
/// </summary>
internal static string FixDcsTextSameLine(string xml)
{
var index = xml.IndexOf("<dcst:Text", StringComparison.Ordinal);
var endIndex = 1;
while (index > 0 && endIndex > 0)
{
endIndex = xml.IndexOf("</dcst:Text>", index, StringComparison.Ordinal);
if (endIndex > 0)
{
var part = xml.Substring(index, endIndex - index);
if (part.Contains(Environment.NewLine))
{
part = part.Replace(Environment.NewLine, " ");
while (part.Contains(" "))
{
part = part.Replace(" ", " ");
}
part = part.Replace("> <", "><");
}
xml = xml.Remove(index, endIndex - index).Insert(index, part);
index = xml.IndexOf("<dcst:Text", endIndex, StringComparison.Ordinal);
}
}
return xml;
return DCinemaSmpte2010.FixDcsTextSameLine(result);
}
private void ValidationCallBack(object sender, ValidationEventArgs e)