Add WebVTT setting for split of style tags - thx Oliver :)

This commit is contained in:
Nikolaj Olsson 2024-07-24 17:27:19 +02:00
parent 93d7a29cde
commit 02817e3bef
11 changed files with 78 additions and 29 deletions

View File

@ -3453,6 +3453,7 @@ Keep changes?</KeepChangesMessage>
<WebVttProperties>
<UseXTimeStamp>Use X-TIMESTAMP-MAP header value</UseXTimeStamp>
<MergeLines>Merge lines with same text on load</MergeLines>
<MergeStyleTags>Merge style tags</MergeStyleTags>
</WebVttProperties>
<WebVttStyleManager>
<Title>WebVTT styles</Title>

View File

@ -439,6 +439,13 @@ namespace Nikse.SubtitleEdit.Core.Common
}
public static string AddStyleToText(string input, WebVttStyle style, List<WebVttStyle> webVttStyles)
{
if (Configuration.Settings.SubtitleSettings.WebVttDoNoMergeTags)
{
var text = "<c." + style.Name.TrimStart('.') + ">" + input + "</c>";
return text;
}
else
{
var text = input;
if (text.Contains("<c."))
@ -461,6 +468,7 @@ namespace Nikse.SubtitleEdit.Core.Common
return text;
}
}
public static List<string> GetParagraphStyles(Paragraph paragraph)
{
@ -509,10 +517,21 @@ namespace Nikse.SubtitleEdit.Core.Common
return text;
}
var prefix = "<c" + string.Join("", styles.Select(s => s.Name)) + ">";
if (Configuration.Settings.SubtitleSettings.WebVttDoNoMergeTags)
{
foreach (var style in styles)
{
text = "<c." + style.Name.TrimStart('.') + ">" + text + "</c>";
}
return text;
}
else
{
var prefix = "<c" + string.Join("", styles.Select(s => s.Name)) + ">";
return prefix + text + "</c>";
}
}
public static string RemoveUnusedColorStylesFromText(string input, string header)
{

View File

@ -4838,6 +4838,12 @@ namespace Nikse.SubtitleEdit.Core.Settings
{
settings.SubtitleSettings.WebVttMergeLinesWithSameText = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("WebVttDoNoMergeTags");
if (subNode != null)
{
settings.SubtitleSettings.WebVttDoNoMergeTags = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
}
// Proxy
@ -9412,6 +9418,7 @@ namespace Nikse.SubtitleEdit.Core.Settings
textWriter.WriteElementString("WebVttUseXTimestampMap", settings.SubtitleSettings.WebVttUseXTimestampMap.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttUseMultipleXTimestampMap", settings.SubtitleSettings.WebVttUseMultipleXTimestampMap.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttMergeLinesWithSameText", settings.SubtitleSettings.WebVttMergeLinesWithSameText.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttDoNoMergeTags", settings.SubtitleSettings.WebVttDoNoMergeTags.ToString(CultureInfo.InvariantCulture));
textWriter.WriteEndElement();
textWriter.WriteStartElement("Proxy", string.Empty);

View File

@ -89,6 +89,7 @@ namespace Nikse.SubtitleEdit.Core.Settings
public bool WebVttUseXTimestampMap { get; set; }
public bool WebVttUseMultipleXTimestampMap { get; set; }
public bool WebVttMergeLinesWithSameText { get; set; }
public bool WebVttDoNoMergeTags { get; set; }
public long WebVttTimescale { get; set; }
public string WebVttCueAn1 { get; set; }
public string WebVttCueAn2 { get; set; }

View File

@ -18,7 +18,6 @@ using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.VobSub;
using Nikse.SubtitleEdit.Forms.Assa;
using Nikse.SubtitleEdit.Forms.AudioToText;
using Nikse.SubtitleEdit.Forms.FormatProperties;
using Nikse.SubtitleEdit.Forms.Networking;
using Nikse.SubtitleEdit.Forms.Ocr;
using Nikse.SubtitleEdit.Forms.Options;

View File

@ -1,5 +1,5 @@

namespace Nikse.SubtitleEdit.Forms.FormatProperties
namespace Nikse.SubtitleEdit.Forms.VTT
{
partial class WebVttProperties
{
@ -52,6 +52,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.labelAn7 = new System.Windows.Forms.Label();
this.checkBoxUseXTimestampMap = new System.Windows.Forms.CheckBox();
this.checkBoxAutoMerge = new System.Windows.Forms.CheckBox();
this.checkBoxMergeStyleTags = new System.Windows.Forms.CheckBox();
this.groupBoxAlignment.SuspendLayout();
this.SuspendLayout();
//
@ -60,7 +61,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(465, 333);
this.buttonCancel.Location = new System.Drawing.Point(465, 342);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 23;
@ -72,7 +73,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(384, 333);
this.buttonOK.Location = new System.Drawing.Point(384, 342);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 22;
@ -105,7 +106,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.groupBoxAlignment.Controls.Add(this.labelAn7);
this.groupBoxAlignment.Location = new System.Drawing.Point(12, 22);
this.groupBoxAlignment.Name = "groupBoxAlignment";
this.groupBoxAlignment.Size = new System.Drawing.Size(528, 249);
this.groupBoxAlignment.Size = new System.Drawing.Size(528, 258);
this.groupBoxAlignment.TabIndex = 24;
this.groupBoxAlignment.TabStop = false;
this.groupBoxAlignment.Text = "Alignment";
@ -267,7 +268,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
//
this.checkBoxUseXTimestampMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxUseXTimestampMap.AutoSize = true;
this.checkBoxUseXTimestampMap.Location = new System.Drawing.Point(12, 290);
this.checkBoxUseXTimestampMap.Location = new System.Drawing.Point(12, 295);
this.checkBoxUseXTimestampMap.Name = "checkBoxUseXTimestampMap";
this.checkBoxUseXTimestampMap.Size = new System.Drawing.Size(212, 17);
this.checkBoxUseXTimestampMap.TabIndex = 25;
@ -278,18 +279,30 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
//
this.checkBoxAutoMerge.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxAutoMerge.AutoSize = true;
this.checkBoxAutoMerge.Location = new System.Drawing.Point(12, 313);
this.checkBoxAutoMerge.Location = new System.Drawing.Point(12, 318);
this.checkBoxAutoMerge.Name = "checkBoxAutoMerge";
this.checkBoxAutoMerge.Size = new System.Drawing.Size(188, 17);
this.checkBoxAutoMerge.TabIndex = 26;
this.checkBoxAutoMerge.Text = "Merge lines with same text on load";
this.checkBoxAutoMerge.UseVisualStyleBackColor = true;
//
// checkBoxMergeStyleTags
//
this.checkBoxMergeStyleTags.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxMergeStyleTags.AutoSize = true;
this.checkBoxMergeStyleTags.Location = new System.Drawing.Point(12, 341);
this.checkBoxMergeStyleTags.Name = "checkBoxMergeStyleTags";
this.checkBoxMergeStyleTags.Size = new System.Drawing.Size(103, 17);
this.checkBoxMergeStyleTags.TabIndex = 27;
this.checkBoxMergeStyleTags.Text = "Merge style tags";
this.checkBoxMergeStyleTags.UseVisualStyleBackColor = true;
//
// WebVttProperties
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(552, 368);
this.ClientSize = new System.Drawing.Size(552, 377);
this.Controls.Add(this.checkBoxMergeStyleTags);
this.Controls.Add(this.checkBoxAutoMerge);
this.Controls.Add(this.checkBoxUseXTimestampMap);
this.Controls.Add(this.groupBoxAlignment);
@ -337,5 +350,6 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
private System.Windows.Forms.Label labelAn7;
private System.Windows.Forms.CheckBox checkBoxUseXTimestampMap;
private System.Windows.Forms.CheckBox checkBoxAutoMerge;
private System.Windows.Forms.CheckBox checkBoxMergeStyleTags;
}
}

View File

@ -1,10 +1,10 @@
using Nikse.SubtitleEdit.Core.Common;
using System;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.FormatProperties
namespace Nikse.SubtitleEdit.Forms.VTT
{
public sealed partial class WebVttProperties : Form
{
@ -43,9 +43,11 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
checkBoxUseXTimestampMap.Text = LanguageSettings.Current.WebVttProperties.UseXTimeStamp;
checkBoxAutoMerge.Text = LanguageSettings.Current.WebVttProperties.MergeLines;
checkBoxMergeStyleTags.Text = LanguageSettings.Current.WebVttProperties.MergeStyleTags;
checkBoxUseXTimestampMap.Checked = Configuration.Settings.SubtitleSettings.WebVttUseXTimestampMap;
checkBoxAutoMerge.Checked = Configuration.Settings.SubtitleSettings.WebVttMergeLinesWithSameText;
checkBoxMergeStyleTags.Checked = !Configuration.Settings.SubtitleSettings.WebVttDoNoMergeTags;
}
private void buttonOK_Click(object sender, EventArgs e)
@ -62,6 +64,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
Configuration.Settings.SubtitleSettings.WebVttUseXTimestampMap = checkBoxUseXTimestampMap.Checked;
Configuration.Settings.SubtitleSettings.WebVttMergeLinesWithSameText = checkBoxAutoMerge.Checked;
Configuration.Settings.SubtitleSettings.WebVttDoNoMergeTags = !checkBoxMergeStyleTags.Checked;
DialogResult = DialogResult.OK;
}

View File

@ -3885,6 +3885,7 @@ Keep changes?",
{
UseXTimeStamp = "Use X-TIMESTAMP-MAP header value",
MergeLines = "Merge lines with same text on load",
MergeStyleTags = "Merge style tags",
};
WebVttStyleManager = new LanguageStructure.WebVttStyleManager

View File

@ -9433,6 +9433,9 @@ namespace Nikse.SubtitleEdit.Logic
case "WebVttProperties/MergeLines":
language.WebVttProperties.MergeLines = reader.Value;
break;
case "WebVttProperties/MergeStyleTags":
language.WebVttProperties.MergeStyleTags = reader.Value;
break;
case "WebVttStyleManager/Title":
language.WebVttStyleManager.Title = reader.Value;
break;

View File

@ -3694,6 +3694,7 @@
{
public string UseXTimeStamp { get; set; }
public string MergeLines { get; set; }
public string MergeStyleTags { get; set; }
}
public class WebVttStyleManager