Add templating for assa bog box drawing

This commit is contained in:
niksedk 2022-01-05 15:55:14 +01:00
parent f7a37f9afc
commit 5f2417e0e3
6 changed files with 69 additions and 5 deletions

View File

@ -186,6 +186,7 @@ COPY /Y /V "zlib.net.dll" "temp_zip\"
COPY /Y /V "NHunspell.dll" "temp_zip\"
COPY /Y /V "UtfUnknown.dll" "temp_zip\"
COPY /Y /V "Vosk.dll" "temp_zip\"
COPY /Y /V "NCalc.dll" "temp_zip\"
COPY /Y /V "..\..\DLLs\Interop.QuartzTypeLib.dll" "temp_zip\"
COPY /Y /V "System.Net.Http.Extensions.dll" "temp_zip\"
COPY /Y /V "Newtonsoft.Json.dll" "temp_zip\"

View File

@ -174,6 +174,7 @@ COPY /Y /V "zlib.net.dll" "temp_zip\"
COPY /Y /V "NHunspell.dll" "temp_zip\"
COPY /Y /V "UtfUnknown.dll" "temp_zip\"
COPY /Y /V "Vosk.dll" "temp_zip\"
COPY /Y /V "NCalc.dll" "temp_zip\"
COPY /Y /V "..\..\DLLs\Interop.QuartzTypeLib.dll" "temp_zip\"
COPY /Y /V "System.Net.Http.Extensions.dll" "temp_zip\"
COPY /Y /V "Newtonsoft.Json.dll" "temp_zip\"

View File

@ -305,6 +305,7 @@ Source: {#bindir}\zlib.net.dll; DestDir: {app};
Source: {#bindir}\NHunspell.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\UtfUnknown.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\Vosk.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\NCalc.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: ..\src\ui\DLLs\Interop.QuartzTypeLib.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\Newtonsoft.Json.dll; DestDir: {app}; Flags: ignoreversion; Components: main
Source: {#bindir}\System.Net.Http.Extensions.dll; DestDir: {app}; Flags: ignoreversion; Components: main
@ -343,6 +344,7 @@ Type: files; Name: {app}\zlib.net.dll; Check: IsU
Type: files; Name: {app}\NHunspell.dll; Check: IsUpgrade()
Type: files; Name: {app}\UtfUnknown.dll; Check: IsUpgrade()
Type: files; Name: {app}\Vosk.dll; Check: IsUpgrade()
Type: files; Name: {app}\NCalc.dll; Check: IsUpgrade()
Type: files; Name: {app}\Interop.QuartzTypeLib.dll; Check: IsUpgrade()
Type: files; Name: {app}\Newtonsoft.Json.dll; Check: IsUpgrade()
Type: files; Name: {app}\System.Net.Http.Extensions.dll; Check: IsUpgrade()

View File

@ -14,6 +14,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using NCalc;
namespace Nikse.SubtitleEdit.Forms.Assa
{
@ -530,10 +531,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
var layerAdd = 1;
foreach (var dp in _drawing.Paragraphs.OrderBy(pa => pa.Layer))
{
var pDrawing = new Paragraph(dp.Text, 0, 1000);
pDrawing.Text = pos + pDrawing.Text;
pDrawing.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
pDrawing.EndTime.TotalMilliseconds = p.EndTime.TotalMilliseconds;
var pDrawing = new Paragraph(dp.Text, p.StartTime.TotalMilliseconds, p.EndTime.TotalMilliseconds);
pDrawing.Text = pos + TranslateTemplate(pDrawing.Text, x, top, right, bottom);
pDrawing.Layer = Configuration.Settings.Tools.AssaBgBoxLayer + layerAdd;
pDrawing.Extra = "SE-box-drawing";
subtitle.InsertParagraphInCorrectTimeOrder(pDrawing);
@ -542,6 +541,63 @@ namespace Nikse.SubtitleEdit.Forms.Assa
}
}
private string TranslateTemplate(string input, int left, int top, int right, int bottom)
{
var text = input;
var width = right - left;
var height = bottom - top;
try
{
var startIdx = text.IndexOf('[');
while (startIdx >= 0)
{
var endIdx = text.IndexOf(']', startIdx);
if (endIdx < 0)
{
return input;
}
var expr = text.Substring(startIdx+1, endIdx - startIdx - 1);
expr = expr.ToUpperInvariant()
.Replace("LEFT", left.ToString(CultureInfo.InvariantCulture))
.Replace("TOP", top.ToString(CultureInfo.InvariantCulture))
.Replace("RIGHT", right.ToString(CultureInfo.InvariantCulture))
.Replace("BOTTOM", bottom.ToString(CultureInfo.InvariantCulture))
.Replace("WIDTH", width.ToString(CultureInfo.InvariantCulture))
.Replace("HEIGHT", height.ToString(CultureInfo.InvariantCulture));
var calcExpression = new Expression(expr);
var calcObj = calcExpression.Evaluate();
var calcResult = calcExpression.Evaluate().ToString();
if (calcObj is double numberDouble)
{
calcResult = numberDouble.ToString(CultureInfo.InvariantCulture);
}
else if (calcObj is float numberFloat)
{
calcResult = numberFloat.ToString(CultureInfo.InvariantCulture);
}
else if (calcObj is decimal numberDecimal)
{
calcResult = numberDecimal.ToString(CultureInfo.InvariantCulture);
}
text = text
.Remove(startIdx, endIdx - startIdx + 1)
.Insert(startIdx, calcResult);
startIdx = text.IndexOf('[', startIdx);
}
return text;
}
catch
{
return input;
}
}
private void ApplyCustomStyles_FormClosing(object sender, FormClosingEventArgs e)
{
_closing = true;

View File

@ -61,6 +61,9 @@
<HintPath>DLLs\Interop.QuartzTypeLib.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="NCalc, Version=1.3.8.0, Culture=neutral, PublicKeyToken=973cde3f1cafed03, processorArchitecture=MSIL">
<HintPath>..\..\packages\ncalc.1.3.8\lib\NCalc.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

View File

@ -3,6 +3,7 @@
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net462" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net462" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net462" />
<package id="ncalc" version="1.3.8" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
<package id="NHunspell" version="1.2.5554.16953" targetFramework="net462" />
<package id="Vosk" version="0.3.32" targetFramework="net472" />