Work on WebVTT

This commit is contained in:
niksedk 2023-06-26 17:18:12 +02:00
parent 3ec2144a82
commit 36b8a772b7
12 changed files with 328 additions and 63 deletions

View File

@ -1389,6 +1389,9 @@ To use an API key, go to "Options -> Settings -> Tools" to enter your Goog
<TimedTextSetLanguage>Timed Text - set language</TimedTextSetLanguage>
<SamiSetStyle>Sami - set class</SamiSetStyle>
<NuendoSetStyle>Nuendo - set character</NuendoSetStyle>
<WebVttSetStyle>WebVTT - set style</WebVttSetStyle>
<WebVttSetVoice>WebVTT - set voice</WebVttSetVoice>
<WebVttBrowserPreview>WebVTT - browser preview</WebVttBrowserPreview>
<Cut>Cut</Cut>
<Copy>Copy</Copy>
<Paste>Paste</Paste>

View File

@ -5,7 +5,6 @@ using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Nikse.SubtitleEdit.Core.Common
{
@ -315,7 +314,7 @@ namespace Nikse.SubtitleEdit.Core.Common
if (string.IsNullOrEmpty(header))
{
return "STYLE" + Environment.NewLine + rawStyle;
return "WEBVTT" + Environment.NewLine + Environment.NewLine + "STYLE" + Environment.NewLine + rawStyle;
}
if (header.Contains("::cue(." + style.Name + ")"))

View File

@ -291,8 +291,9 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripSeparatorAssa = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItemSetRegion = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemSetLanguage = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebVttStyle = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebVTT = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemPreview = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuWebVttBrowserPreview = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemDelete = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertBefore = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertAfter = new System.Windows.Forms.ToolStripMenuItem();
@ -575,7 +576,6 @@ namespace Nikse.SubtitleEdit.Forms
this.timerOriginalTextUndo = new System.Windows.Forms.Timer(this.components);
this.contextMenuStripShowVideoControls = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemShowVideoControls = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebVttStyle = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
@ -2644,7 +2644,7 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemSetLanguage,
this.toolStripMenuItemWebVttStyle,
this.toolStripMenuItemWebVTT,
this.toolStripMenuItemPreview,
this.toolStripMenuWebVttBrowserPreview,
this.toolStripMenuItemDelete,
this.toolStripMenuItemInsertBefore,
this.toolStripMenuItemInsertAfter,
@ -2778,18 +2778,25 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemSetLanguage.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemSetLanguage.Text = "Timed text - set language";
//
// toolStripMenuItemWebVttStyle
//
this.toolStripMenuItemWebVttStyle.Name = "toolStripMenuItemWebVttStyle";
this.toolStripMenuItemWebVttStyle.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemWebVttStyle.Text = "WebVTT style...";
this.toolStripMenuItemWebVttStyle.Click += new System.EventHandler(this.toolStripMenuItemWebVttStyle_Click);
//
// toolStripMenuItemWebVTT
//
this.toolStripMenuItemWebVTT.Name = "toolStripMenuItemWebVTT";
this.toolStripMenuItemWebVTT.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemWebVTT.Text = "WebVTT voice";
//
// toolStripMenuItemPreview
// toolStripMenuWebVttBrowserPreview
//
this.toolStripMenuItemPreview.Name = "toolStripMenuItemPreview";
this.toolStripMenuItemPreview.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemPreview.Text = "WebVTT browser preview";
this.toolStripMenuItemPreview.Click += new System.EventHandler(this.toolStripMenuItemPreview_Click);
this.toolStripMenuWebVttBrowserPreview.Name = "toolStripMenuWebVttBrowserPreview";
this.toolStripMenuWebVttBrowserPreview.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuWebVttBrowserPreview.Text = "WebVTT browser preview";
this.toolStripMenuWebVttBrowserPreview.Click += new System.EventHandler(this.toolStripMenuItemPreview_Click);
//
// toolStripMenuItemDelete
//
@ -5623,13 +5630,6 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemShowVideoControls.Text = "Show video controls";
this.toolStripMenuItemShowVideoControls.Click += new System.EventHandler(this.toolStripMenuItemShowVideoControls_Click);
//
// toolStripMenuItemWebVttStyle
//
this.toolStripMenuItemWebVttStyle.Name = "toolStripMenuItemWebVttStyle";
this.toolStripMenuItemWebVttStyle.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemWebVttStyle.Text = "WebVTT style...";
this.toolStripMenuItemWebVttStyle.Click += new System.EventHandler(this.toolStripMenuItemWebVttStyle_Click);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -6090,7 +6090,7 @@ namespace Nikse.SubtitleEdit.Forms
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSpellCheckAddToNames;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorSpellCheck;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebVttVoice;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemPreview;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuWebVttBrowserPreview;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorWebVTT;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemModifySelection;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemInverseSelection;

View File

@ -1879,6 +1879,10 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemGoToSourceView.Text = _language.Menu.ContextMenu.GoToSourceView;
toolStripMenuItemGoToListView.Text = _language.Menu.ContextMenu.GoToListView;
toolStripMenuItemWebVttVoice.Text = _language.Menu.ContextMenu.WebVttSetVoice;
toolStripMenuItemWebVttStyle.Text = _language.Menu.ContextMenu.WebVttSetStyle;
toolStripMenuWebVttBrowserPreview.Text = _language.Menu.ContextMenu.WebVttBrowserPreview;
splitLineToolStripMenuItem.Text = _language.Menu.ContextMenu.Split;
toolStripMenuItemMergeLines.Text = _language.Menu.ContextMenu.MergeSelectedLines;
toolStripMenuItemMergeDialog.Text = _language.Menu.ContextMenu.MergeSelectedLinesAsDialog;
@ -8704,7 +8708,7 @@ namespace Nikse.SubtitleEdit.Forms
return;
}
toolStripMenuItemPreview.Visible = formatType == typeof(WebVTT) &&
toolStripMenuWebVttBrowserPreview.Visible = formatType == typeof(WebVTT) &&
!string.IsNullOrEmpty(_videoFileName) &&
(_videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) ||
_videoFileName.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase) ||

View File

@ -857,7 +857,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAAdQBLgHUAS4BEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAdwBLgHcAS4BEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -12,7 +12,6 @@ namespace Nikse.SubtitleEdit.Forms.VTT
public sealed partial class WebVttImportExport : Form
{
private readonly List<WebVttStyle> _styles;
private readonly SubtitleFormat _format;
private readonly bool _export;
public List<WebVttStyle> ImportExportStyles { get; set; }
public string FileName { get; set; }

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms.VTT
{
partial class WebVttStyleManager
sealed partial class WebVttStyleManager
{
/// <summary>
/// Required designer variable.
@ -386,9 +386,9 @@
this.groupBoxAfter.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxAfter.Controls.Add(this.labelAfter);
this.groupBoxAfter.Location = new System.Drawing.Point(249, 259);
this.groupBoxAfter.Location = new System.Drawing.Point(249, 239);
this.groupBoxAfter.Name = "groupBoxAfter";
this.groupBoxAfter.Size = new System.Drawing.Size(229, 136);
this.groupBoxAfter.Size = new System.Drawing.Size(229, 100);
this.groupBoxAfter.TabIndex = 12;
this.groupBoxAfter.TabStop = false;
this.groupBoxAfter.Text = "After";
@ -405,9 +405,9 @@
// groupBoxBefore
//
this.groupBoxBefore.Controls.Add(this.labelBefore);
this.groupBoxBefore.Location = new System.Drawing.Point(10, 259);
this.groupBoxBefore.Location = new System.Drawing.Point(10, 239);
this.groupBoxBefore.Name = "groupBoxBefore";
this.groupBoxBefore.Size = new System.Drawing.Size(233, 136);
this.groupBoxBefore.Size = new System.Drawing.Size(233, 100);
this.groupBoxBefore.TabIndex = 11;
this.groupBoxBefore.TabStop = false;
this.groupBoxBefore.Text = "Before";
@ -444,9 +444,9 @@
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxPreview.Controls.Add(this.pictureBoxPreview);
this.groupBoxPreview.Location = new System.Drawing.Point(7, 401);
this.groupBoxPreview.Location = new System.Drawing.Point(7, 345);
this.groupBoxPreview.Name = "groupBoxPreview";
this.groupBoxPreview.Size = new System.Drawing.Size(472, 192);
this.groupBoxPreview.Size = new System.Drawing.Size(472, 248);
this.groupBoxPreview.TabIndex = 7;
this.groupBoxPreview.TabStop = false;
this.groupBoxPreview.Text = "Preview";
@ -456,7 +456,7 @@
this.pictureBoxPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxPreview.Location = new System.Drawing.Point(3, 16);
this.pictureBoxPreview.Name = "pictureBoxPreview";
this.pictureBoxPreview.Size = new System.Drawing.Size(466, 173);
this.pictureBoxPreview.Size = new System.Drawing.Size(466, 229);
this.pictureBoxPreview.TabIndex = 0;
this.pictureBoxPreview.TabStop = false;
//
@ -485,7 +485,7 @@
this.groupBoxFont.Controls.Add(this.labelFontName);
this.groupBoxFont.Location = new System.Drawing.Point(7, 51);
this.groupBoxFont.Name = "groupBoxFont";
this.groupBoxFont.Size = new System.Drawing.Size(472, 202);
this.groupBoxFont.Size = new System.Drawing.Size(472, 182);
this.groupBoxFont.TabIndex = 2;
this.groupBoxFont.TabStop = false;
this.groupBoxFont.Text = "Font";
@ -494,7 +494,7 @@
//
this.checkBoxShadowEnabled.AutoSize = true;
this.checkBoxShadowEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.checkBoxShadowEnabled.Location = new System.Drawing.Point(282, 119);
this.checkBoxShadowEnabled.Location = new System.Drawing.Point(282, 100);
this.checkBoxShadowEnabled.Name = "checkBoxShadowEnabled";
this.checkBoxShadowEnabled.Size = new System.Drawing.Size(65, 17);
this.checkBoxShadowEnabled.TabIndex = 11;
@ -506,7 +506,7 @@
//
this.checkBoxBackgroundColorEnabled.AutoSize = true;
this.checkBoxBackgroundColorEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.checkBoxBackgroundColorEnabled.Location = new System.Drawing.Point(135, 119);
this.checkBoxBackgroundColorEnabled.Location = new System.Drawing.Point(135, 100);
this.checkBoxBackgroundColorEnabled.Name = "checkBoxBackgroundColorEnabled";
this.checkBoxBackgroundColorEnabled.Size = new System.Drawing.Size(65, 17);
this.checkBoxBackgroundColorEnabled.TabIndex = 10;
@ -518,7 +518,7 @@
//
this.checkBoxColorEnabled.AutoSize = true;
this.checkBoxColorEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.checkBoxColorEnabled.Location = new System.Drawing.Point(16, 119);
this.checkBoxColorEnabled.Location = new System.Drawing.Point(16, 100);
this.checkBoxColorEnabled.Name = "checkBoxColorEnabled";
this.checkBoxColorEnabled.Size = new System.Drawing.Size(65, 17);
this.checkBoxColorEnabled.TabIndex = 9;
@ -529,7 +529,7 @@
// panelShadowColor
//
this.panelShadowColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelShadowColor.Location = new System.Drawing.Point(371, 143);
this.panelShadowColor.Location = new System.Drawing.Point(371, 124);
this.panelShadowColor.Name = "panelShadowColor";
this.panelShadowColor.Size = new System.Drawing.Size(21, 20);
this.panelShadowColor.TabIndex = 7;
@ -537,7 +537,7 @@
//
// buttonShadowColor
//
this.buttonShadowColor.Location = new System.Drawing.Point(282, 142);
this.buttonShadowColor.Location = new System.Drawing.Point(282, 123);
this.buttonShadowColor.Name = "buttonShadowColor";
this.buttonShadowColor.Size = new System.Drawing.Size(84, 23);
this.buttonShadowColor.TabIndex = 6;
@ -552,7 +552,7 @@
0,
0,
65536});
this.numericUpDownShadowWidth.Location = new System.Drawing.Point(286, 171);
this.numericUpDownShadowWidth.Location = new System.Drawing.Point(286, 152);
this.numericUpDownShadowWidth.Name = "numericUpDownShadowWidth";
this.numericUpDownShadowWidth.Size = new System.Drawing.Size(52, 20);
this.numericUpDownShadowWidth.TabIndex = 2;
@ -560,7 +560,7 @@
// panelBackgroundColor
//
this.panelBackgroundColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelBackgroundColor.Location = new System.Drawing.Point(242, 143);
this.panelBackgroundColor.Location = new System.Drawing.Point(242, 124);
this.panelBackgroundColor.Name = "panelBackgroundColor";
this.panelBackgroundColor.Size = new System.Drawing.Size(21, 20);
this.panelBackgroundColor.TabIndex = 3;
@ -569,7 +569,7 @@
// labelShadow
//
this.labelShadow.AutoSize = true;
this.labelShadow.Location = new System.Drawing.Point(344, 173);
this.labelShadow.Location = new System.Drawing.Point(344, 154);
this.labelShadow.Name = "labelShadow";
this.labelShadow.Size = new System.Drawing.Size(46, 13);
this.labelShadow.TabIndex = 2;
@ -577,7 +577,7 @@
//
// buttonBackgroundColor
//
this.buttonBackgroundColor.Location = new System.Drawing.Point(135, 142);
this.buttonBackgroundColor.Location = new System.Drawing.Point(135, 123);
this.buttonBackgroundColor.Name = "buttonBackgroundColor";
this.buttonBackgroundColor.Size = new System.Drawing.Size(101, 23);
this.buttonBackgroundColor.TabIndex = 2;
@ -588,7 +588,7 @@
// panelPrimaryColor
//
this.panelPrimaryColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelPrimaryColor.Location = new System.Drawing.Point(100, 143);
this.panelPrimaryColor.Location = new System.Drawing.Point(100, 124);
this.panelPrimaryColor.Name = "panelPrimaryColor";
this.panelPrimaryColor.Size = new System.Drawing.Size(21, 20);
this.panelPrimaryColor.TabIndex = 1;
@ -598,7 +598,7 @@
//
this.checkBoxStrikeout.AutoSize = true;
this.checkBoxStrikeout.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Strikeout, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.checkBoxStrikeout.Location = new System.Drawing.Point(246, 59);
this.checkBoxStrikeout.Location = new System.Drawing.Point(265, 59);
this.checkBoxStrikeout.Name = "checkBoxStrikeout";
this.checkBoxStrikeout.Size = new System.Drawing.Size(68, 17);
this.checkBoxStrikeout.TabIndex = 8;
@ -608,7 +608,7 @@
//
// buttonPrimaryColor
//
this.buttonPrimaryColor.Location = new System.Drawing.Point(14, 142);
this.buttonPrimaryColor.Location = new System.Drawing.Point(14, 123);
this.buttonPrimaryColor.Name = "buttonPrimaryColor";
this.buttonPrimaryColor.Size = new System.Drawing.Size(80, 23);
this.buttonPrimaryColor.TabIndex = 0;
@ -770,6 +770,7 @@
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "WebVttStyleManager";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.WebVttStyleManager_FormClosing);
this.groupBoxStyles.ResumeLayout(false);
this.contextMenuStripStyles.ResumeLayout(false);
this.groupBoxProperties.ResumeLayout(false);

View File

@ -1,25 +1,32 @@
using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms.VTT
{
public partial class WebVttStyleManager : Form
public sealed partial class WebVttStyleManager : Form
{
public string Header { get; set; }
private readonly List<WebVttStyle> _webVttStyles;
private readonly List<WebVttStyle> _originalWebVttStyles;
private WebVttStyle _currentStyle;
private readonly Subtitle _subtitle;
private string _startName;
private string _editedName;
private bool _doUpdate;
private readonly Timer _previewTimer = new Timer();
private Bitmap _backgroundImage;
private readonly bool _backgroundImageDark;
private LibMpvDynamic _mpv;
private string _mpvTextFileName;
public WebVttStyleManager(Subtitle subtitle, int index)
{
@ -32,7 +39,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
_webVttStyles = WebVttHelper.GetStyles(subtitle.Header);
_originalWebVttStyles = WebVttHelper.GetStyles(subtitle.Header);
Header = subtitle.Header;
InitializeStylesListView(_subtitle.GetParagraphOrDefault(index)?.Extra);
InitializeStylesListView();
CheckDuplicateStyles();
var fontNames = new List<string>();
@ -44,9 +51,79 @@ namespace Nikse.SubtitleEdit.Forms.VTT
comboBoxFontName.Items.Clear();
comboBoxFontName.Items.AddRange(fontNames.ToArray<object>());
labelInfo.Text = string.Empty;
Text = LanguageSettings.Current.WebVttStyleManager.Title;
var l = LanguageSettings.Current.SubStationAlphaStyles;
groupBoxStyles.Text = l.Styles;
listViewStyles.Columns[0].Text = l.Name;
listViewStyles.Columns[1].Text = l.FontName;
listViewStyles.Columns[2].Text = l.FontSize;
listViewStyles.Columns[3].Text = LanguageSettings.Current.General.Italic;
listViewStyles.Columns[4].Text = LanguageSettings.Current.GenerateBlankVideo.Background;
listViewStyles.Columns[5].Text = LanguageSettings.Current.General.Text;
listViewStyles.Columns[6].Text = l.UseCount;
groupBoxProperties.Text = l.Properties;
labelStyleName.Text = l.Name;
groupBoxFont.Text = l.Font;
labelFontName.Text = l.FontName;
labelFontSize.Text = l.FontSize;
checkBoxFontItalic.Text = LanguageSettings.Current.General.Italic;
checkBoxFontBold.Text = LanguageSettings.Current.General.Bold;
checkBoxFontUnderline.Text = LanguageSettings.Current.General.Underline;
checkBoxStrikeout.Text = LanguageSettings.Current.General.Strikeout;
buttonPrimaryColor.Text = l.Primary;
//buttonSecondaryColor.Text = l.Secondary;
//buttonOutlineColor.Text = l.Outline;
//buttonBackColor.Text = l.Shadow;
labelShadow.Text = l.Shadow;
buttonImport.Text = l.Import;
buttonExport.Text = l.Export;
buttonCopy.Text = l.Copy;
buttonAdd.Text = l.New;
buttonRemove.Text = l.Remove;
buttonRemoveAll.Text = l.RemoveAll;
groupBoxPreview.Text = LanguageSettings.Current.General.Preview;
deleteToolStripMenuItem.Text = l.Remove;
//removeAndReplaceWithToolStripMenuItem.Text = l.ReplaceWith;
toolStripMenuItemRemoveAll.Text = l.RemoveAll;
moveUpToolStripMenuItem.Text = LanguageSettings.Current.DvdSubRip.MoveUp;
moveDownToolStripMenuItem.Text = LanguageSettings.Current.DvdSubRip.MoveDown;
moveTopToolStripMenuItem.Text = LanguageSettings.Current.MultipleReplace.MoveToTop;
moveBottomToolStripMenuItem.Text = LanguageSettings.Current.MultipleReplace.MoveToBottom;
newToolStripMenuItemNew.Text = l.New;
copyToolStripMenuItemCopy.Text = l.Copy;
toolStripMenuItemImport.Text = l.Import;
toolStripMenuItemExport.Text = l.Export;
checkBoxColorEnabled.Text = LanguageSettings.Current.MultipleReplace.Enabled;
checkBoxBackgroundColorEnabled.Text = LanguageSettings.Current.MultipleReplace.Enabled;
checkBoxShadowEnabled.Text = LanguageSettings.Current.MultipleReplace.Enabled;
buttonApply.Text = LanguageSettings.Current.General.Apply;
buttonOK.Text = LanguageSettings.Current.General.Ok;
buttonCancel.Text = LanguageSettings.Current.General.Cancel;
comboBoxFontName.Left = labelFontName.Right + 5;
labelFontSize.Left = comboBoxFontName.Right + 15;
numericUpDownFontSize.Left = labelFontSize.Right + 5;
checkBoxFontItalic.Left = checkBoxFontBold.Right + 15;
checkBoxFontUnderline.Left = checkBoxFontItalic.Right + 15;
checkBoxStrikeout.Left = checkBoxFontUnderline.Right + 15;
_backgroundImageDark = Configuration.Settings.General.UseDarkTheme;
_previewTimer.Interval = 200;
_previewTimer.Tick += PreviewTimerTick;
}
private void InitializeStylesListView(string currentStyleName)
private void PreviewTimerTick(object sender, EventArgs e)
{
_previewTimer.Stop();
GeneratePreviewReal();
}
private void InitializeStylesListView()
{
listViewStyles.Items.Clear();
foreach (var style in _webVttStyles)
@ -60,7 +137,6 @@ namespace Nikse.SubtitleEdit.Forms.VTT
}
}
public static void AddStyle(ListView lv, WebVttStyle style, Subtitle subtitle)
{
AddStyle(lv, style, subtitle, lv.Items.Count);
@ -154,8 +230,6 @@ namespace Nikse.SubtitleEdit.Forms.VTT
if (listViewStyles.SelectedItems.Count == 1)
{
var styleName = "." + listViewStyles.SelectedItems[0].Text;
_startName = styleName;
_editedName = null;
var style = _webVttStyles.FirstOrDefault(p => p.Name == styleName);
SetControlsFromStyle(style);
_doUpdate = true;
@ -165,13 +239,13 @@ namespace Nikse.SubtitleEdit.Forms.VTT
{
groupBoxProperties.Enabled = false;
_doUpdate = false;
_startName = null;
_currentStyle = null;
pictureBoxPreview.Image?.Dispose();
pictureBoxPreview.Image = new Bitmap(1, 1);
}
UpdateCurrentFileButtonsState();
GeneratePreview();
}
private void SetControlsFromStyle(WebVttStyle style)
@ -484,14 +558,14 @@ namespace Nikse.SubtitleEdit.Forms.VTT
{
styleOn = true;
}
else if (styleOn)
{
// ignore
}
else if (line == string.Empty && styleOn)
{
styleOn = false;
}
else if (styleOn)
{
// ignore
}
else
{
sb.AppendLine(line);
@ -506,7 +580,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
sbStyles.AppendLine(rawStyle);
}
header = sb.ToString().Trim() + Environment.NewLine + Environment.NewLine + sbStyles.ToString();
header = sb.ToString().Trim() + Environment.NewLine + Environment.NewLine + sbStyles;
Header = header;
}
@ -540,7 +614,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
if (listViewStyles.Items.Count == 0)
{
InitializeStylesListView(string.Empty);
InitializeStylesListView();
}
CheckDuplicateStyles();
@ -575,7 +649,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
listViewStyles.Items.Clear();
_webVttStyles.Clear();
InitializeStylesListView(string.Empty);
InitializeStylesListView();
CheckDuplicateStyles();
}
@ -688,6 +762,8 @@ namespace Nikse.SubtitleEdit.Forms.VTT
}
}
}
GeneratePreview();
}
private string GetUniqueName(WebVttStyle style)
@ -701,7 +777,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
while (doRepeat)
{
newName = "." + string.Format(LanguageSettings.Current.SubStationAlphaStyles.CopyXOfY, count, styleName.RemoveChar('.'));
newName = style.Name.Replace(" ", "-");
newName = newName.Replace(" ", "-");
doRepeat = _webVttStyles.FirstOrDefault(p => p.Name == style.Name) != null;
count++;
}
@ -760,6 +836,8 @@ namespace Nikse.SubtitleEdit.Forms.VTT
_currentStyle.Name = "." + newName;
listViewStyles.SelectedItems[0].Text = newName;
}
GeneratePreview();
}
private void checkBoxFontBold_CheckedChanged(object sender, EventArgs e)
@ -779,6 +857,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
}
UpdateRawBeforeStyle();
GeneratePreview();
}
private void checkBoxFontItalic_CheckedChanged(object sender, EventArgs e)
@ -788,7 +867,6 @@ namespace Nikse.SubtitleEdit.Forms.VTT
return;
}
var idx = listViewStyles.SelectedItems[0].Index;
if (checkBoxFontItalic.Checked)
{
_currentStyle.Italic = true;
@ -798,8 +876,9 @@ namespace Nikse.SubtitleEdit.Forms.VTT
_currentStyle.Italic = null;
}
listViewStyles.SelectedItems[0].SubItems[3].Text = _currentStyle.Italic.HasValue && _currentStyle.Italic.Value == true ? LanguageSettings.Current.General.Yes : "-";
listViewStyles.SelectedItems[0].SubItems[3].Text = _currentStyle.Italic.HasValue && _currentStyle.Italic.Value ? LanguageSettings.Current.General.Yes : "-";
UpdateRawBeforeStyle();
GeneratePreview();
}
private void checkBoxFontUnderline_CheckedChanged(object sender, EventArgs e)
@ -819,6 +898,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
}
UpdateRawBeforeStyle();
GeneratePreview();
}
private void checkBoxStrikeout_CheckedChanged(object sender, EventArgs e)
@ -838,6 +918,7 @@ namespace Nikse.SubtitleEdit.Forms.VTT
}
UpdateRawBeforeStyle();
GeneratePreview();
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
@ -982,5 +1063,168 @@ namespace Nikse.SubtitleEdit.Forms.VTT
{
MoveToBottom(listViewStyles);
}
private void GeneratePreview()
{
if (_previewTimer.Enabled)
{
_previewTimer.Stop();
_previewTimer.Start();
}
else
{
_previewTimer.Start();
}
}
private void GeneratePreviewReal()
{
if (_currentStyle == null || listViewStyles.SelectedItems.Count != 1 || pictureBoxPreview.Width <= 0 || pictureBoxPreview.Height <= 0)
{
return;
}
if (GeneratePreviewViaMpv())
{
return;
}
if (_backgroundImage == null)
{
const int rectangleSize = 9;
_backgroundImage = TextDesigner.MakeBackgroundImage(pictureBoxPreview.Width, pictureBoxPreview.Height, rectangleSize, _backgroundImageDark);
}
var defaultStyle = new SsaStyle();
var shadowWidth = (float)numericUpDownShadowWidth.Value;
var outlineColor = _currentStyle.BackgroundColor ?? defaultStyle.Background;
Font font;
var privateFontCollection = new PrivateFontCollection();
try
{
var fontSize = defaultStyle.FontSize;
if (_currentStyle.FontSize.HasValue && _currentStyle.FontSize.Value > 0.1m)
{
fontSize = _currentStyle.FontSize.Value;
}
var fontName = _currentStyle.FontName;
if (string.IsNullOrEmpty(fontName))
{
fontName = Font.FontFamily.Name;
}
font = new Font(fontName, (float)fontSize * 1.1f, checkBoxFontBold.Checked ? FontStyle.Bold : FontStyle.Regular);
if (_currentStyle.Italic.HasValue && _currentStyle.Italic.Value)
{
font = new Font(fontName, (float)fontSize * 1.1f, font.Style | FontStyle.Italic);
}
if (_currentStyle.Underline.HasValue && _currentStyle.Underline.Value)
{
font = new Font(fontName, (float)fontSize * 1.1f, font.Style | FontStyle.Underline);
}
if (_currentStyle.StrikeThrough.HasValue && _currentStyle.StrikeThrough.Value)
{
font = new Font(fontName, (float)fontSize * 1.1f, font.Style | FontStyle.Strikeout);
}
}
catch
{
font = new Font(Font, FontStyle.Regular);
}
var measureBmp = TextDesigner.MakeTextBitmapAssa(
Configuration.Settings.General.PreviewAssaText,
0,
0,
font,
pictureBoxPreview.Width,
pictureBoxPreview.Height,
5, //outlineWidth,
shadowWidth,
null,
_currentStyle.Color ?? defaultStyle.Primary,
outlineColor,
_currentStyle.ShadowColor ?? defaultStyle.Outline,
!(_currentStyle.BackgroundColor.HasValue && _currentStyle.BackgroundColor.Value.A == 0));
var nBmp = new NikseBitmap(measureBmp);
var measuredWidth = nBmp.GetNonTransparentWidth();
var measuredHeight = nBmp.GetNonTransparentHeight();
var left = (pictureBoxPreview.Width - measuredWidth) / 2.0f;
float top = pictureBoxPreview.Height - measuredHeight - 15;
var designedText = TextDesigner.MakeTextBitmapAssa(
Configuration.Settings.General.PreviewAssaText,
(int)Math.Round(left),
(int)Math.Round(top),
font,
pictureBoxPreview.Width,
pictureBoxPreview.Height,
5, //outlineWidth,
shadowWidth,
_backgroundImage,
_currentStyle.Color ?? defaultStyle.Primary,
outlineColor,
_currentStyle.ShadowColor ?? defaultStyle.Outline,
!(_currentStyle.BackgroundColor.HasValue && _currentStyle.BackgroundColor.Value.A == 0));
pictureBoxPreview.Image?.Dispose();
pictureBoxPreview.Image = designedText;
font.Dispose();
privateFontCollection.Dispose();
}
private bool GeneratePreviewViaMpv()
{
var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
{
return false;
}
if (_mpv == null)
{
_mpv = new LibMpvDynamic();
_mpv.Initialize(pictureBoxPreview, fileName, VideoStartLoaded, null);
}
else
{
VideoStartLoaded(null, null);
}
return true;
}
private void VideoStartLoaded(object sender, EventArgs e)
{
if (_currentStyle == null)
{
return;
}
var subtitle = new Subtitle();
var p = new Paragraph(Configuration.Settings.General.PreviewAssaText, 0, 10000);
subtitle.Paragraphs.Add(p);
subtitle.Header = WebVttHelper.AddStyleToHeader(null, _currentStyle);
var assa = WebVttToAssa.Convert(subtitle, new SsaStyle(), _mpv.VideoWidth, _mpv.VideoHeight);
assa.Paragraphs[0].Extra = _currentStyle.Name;
var format = new AdvancedSubStationAlpha();
var text = assa.ToText(format);
_mpvTextFileName = FileUtil.GetTempFileName(format.Extension);
File.WriteAllText(_mpvTextFileName, text);
_mpv.LoadSubtitle(_mpvTextFileName);
_mpv.Pause();
_mpv.CurrentPosition = 0.5;
}
private void WebVttStyleManager_FormClosing(object sender, FormClosingEventArgs e)
{
_mpv?.Dispose();
}
}
}

View File

@ -1955,6 +1955,9 @@ namespace Nikse.SubtitleEdit.Logic
TimedTextSetLanguage = "Timed Text - set language",
SamiSetStyle = "Sami - set class",
NuendoSetStyle = "Nuendo - set character",
WebVttSetVoice = "WebVTT - set voice",
WebVttSetStyle = "WebVTT - set style",
WebVttBrowserPreview = "WebVTT - browser preview",
Cut = "Cut",
Copy = "Copy",
Paste = "Paste",

View File

@ -4537,6 +4537,15 @@ namespace Nikse.SubtitleEdit.Logic
case "Main/Menu/ContextMenu/NuendoSetStyle":
language.Main.Menu.ContextMenu.NuendoSetStyle = reader.Value;
break;
case "Main/Menu/ContextMenu/WebVttSetStyle":
language.Main.Menu.ContextMenu.WebVttSetStyle = reader.Value;
break;
case "Main/Menu/ContextMenu/WebVttSetVoice":
language.Main.Menu.ContextMenu.WebVttSetVoice = reader.Value;
break;
case "Main/Menu/ContextMenu/WebVttBrowserPreview":
language.Main.Menu.ContextMenu.WebVttBrowserPreview = reader.Value;
break;
case "Main/Menu/ContextMenu/Cut":
language.Main.Menu.ContextMenu.Cut = reader.Value;
break;

View File

@ -1798,6 +1798,9 @@ namespace Nikse.SubtitleEdit.Logic
public string TimedTextSetLanguage { get; set; }
public string SamiSetStyle { get; set; }
public string NuendoSetStyle { get; set; }
public string WebVttSetStyle { get; set; }
public string WebVttSetVoice { get; set; }
public string WebVttBrowserPreview { get; set; }
public string Cut { get; set; }
public string Copy { get; set; }
public string Paste { get; set; }

View File

@ -40,13 +40,13 @@ namespace Nikse.SubtitleEdit.Logic
{
using (var shadowBoxBrush = new SolidBrush(shadowColor))
{
g.FillRectangle(shadowBoxBrush, xPos - outlineWidth + shadowWidth, yPos - outlineWidth + shadowWidth, w + outlineWidth + outlineWidth, h + +outlineWidth + outlineWidth);
g.FillRectangle(shadowBoxBrush, xPos - outlineWidth + shadowWidth, yPos - outlineWidth + shadowWidth, w + outlineWidth + outlineWidth, h + outlineWidth + outlineWidth);
}
}
using (var boxBrush = new SolidBrush(outlineColor))
{
g.FillRectangle(boxBrush, xPos - outlineWidth, yPos - outlineWidth, w + outlineWidth + outlineWidth, h + +outlineWidth + outlineWidth);
g.FillRectangle(boxBrush, xPos - outlineWidth, yPos - outlineWidth, w + outlineWidth + outlineWidth, h + outlineWidth + outlineWidth);
}
path.AddString(text, font.FontFamily, (int)font.Style, font.Size, new Point(xPos, yPos), stringFormat);