Added new improvements for format WebVTT + fixed Issue 119

git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1579 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
niksedk 2013-01-26 09:48:47 +00:00
parent d66869693a
commit dc343663b5
13 changed files with 567 additions and 54 deletions

View File

@ -21,7 +21,7 @@ Subtitle Edit Changelog
* Fixed bug in Dutch language file - thx jan bruyndonckx
* Fixed bug in converting ass to ssa
* Some fixes for xsubtitle - thx Ed
* File -> SSA/ASS properties - now only updates changed fields
* File -> SSA/ASS properties - only update/add changed properties
3.3 (9th December 2012)

View File

@ -460,7 +460,7 @@ namespace Nikse.SubtitleEdit.Controls
if (_settings.Tools.ListViewSyntaxColorLongLines)
{
int noOfLines = paragraph.Text.Split(Environment.NewLine[0]).Length;
string s = Utilities.RemoveHtmlTags(paragraph.Text);
string s = Utilities.RemoveHtmlTags(paragraph.Text, true);
foreach (string line in s.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (line.Length > Configuration.Settings.General.SubtitleLineMaximumLength)

View File

@ -102,10 +102,7 @@ namespace Nikse.SubtitleEdit.Forms
string s = p.Text;
if (checkBoxRemoveStyling.Checked)
{
s = Utilities.RemoveHtmlTags(s);
int indexOfEndBracket = s.IndexOf("}");
if (s.StartsWith("{\\") && indexOfEndBracket > 1 && indexOfEndBracket < 6)
s = s.Remove(0, indexOfEndBracket+1);
s = Utilities.RemoveHtmlTags(s, true);
}
if (radioButtonFormatUnbreak.Checked)

View File

@ -203,6 +203,7 @@
this.contextMenuStripListview = new System.Windows.Forms.ContextMenuStrip(this.components);
this.setStylesForSelectedLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemAssStyles = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebVTT = 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();
@ -369,6 +370,8 @@
this.labelText = new System.Windows.Forms.Label();
this.textBoxListViewTextAlternate = new Nikse.SubtitleEdit.Controls.SETextBox();
this.contextMenuStripTextBoxListView = new System.Windows.Forms.ContextMenuStrip(this.components);
this.toolStripMenuItemWebVttVoice = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparatorWebVTT = new System.Windows.Forms.ToolStripSeparator();
this.cutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -1906,6 +1909,7 @@
this.contextMenuStripListview.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.setStylesForSelectedLinesToolStripMenuItem,
this.toolStripMenuItemAssStyles,
this.toolStripMenuItemWebVTT,
this.toolStripMenuItemDelete,
this.toolStripMenuItemInsertBefore,
this.toolStripMenuItemInsertAfter,
@ -1943,7 +1947,7 @@
this.changeCasingForSelectedLinesToolStripMenuItem,
this.toolStripMenuItemSaveSelectedLines});
this.contextMenuStripListview.Name = "contextMenuStripListview";
this.contextMenuStripListview.Size = new System.Drawing.Size(285, 760);
this.contextMenuStripListview.Size = new System.Drawing.Size(285, 804);
this.contextMenuStripListview.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListviewOpening);
//
// setStylesForSelectedLinesToolStripMenuItem
@ -1959,6 +1963,12 @@
this.toolStripMenuItemAssStyles.Text = "ASS: Styles...";
this.toolStripMenuItemAssStyles.Click += new System.EventHandler(this.toolStripMenuItemAssStyles_Click);
//
// toolStripMenuItemWebVTT
//
this.toolStripMenuItemWebVTT.Name = "toolStripMenuItemWebVTT";
this.toolStripMenuItemWebVTT.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemWebVTT.Text = "WebVTT voice";
//
// toolStripMenuItemDelete
//
this.toolStripMenuItemDelete.Name = "toolStripMenuItemDelete";
@ -3642,6 +3652,8 @@
// contextMenuStripTextBoxListView
//
this.contextMenuStripTextBoxListView.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItemWebVttVoice,
this.toolStripSeparatorWebVTT,
this.cutToolStripMenuItem,
this.copyToolStripMenuItem,
this.pasteToolStripMenuItem,
@ -3661,9 +3673,20 @@
this.superscriptToolStripMenuItem,
this.subscriptToolStripMenuItem});
this.contextMenuStripTextBoxListView.Name = "contextMenuStripTextBoxListView";
this.contextMenuStripTextBoxListView.Size = new System.Drawing.Size(215, 352);
this.contextMenuStripTextBoxListView.Size = new System.Drawing.Size(215, 402);
this.contextMenuStripTextBoxListView.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripTextBoxListViewOpening);
//
// toolStripMenuItemWebVttVoice
//
this.toolStripMenuItemWebVttVoice.Name = "toolStripMenuItemWebVttVoice";
this.toolStripMenuItemWebVttVoice.Size = new System.Drawing.Size(214, 22);
this.toolStripMenuItemWebVttVoice.Text = "WebVTT voice";
//
// toolStripSeparatorWebVTT
//
this.toolStripSeparatorWebVTT.Name = "toolStripSeparatorWebVTT";
this.toolStripSeparatorWebVTT.Size = new System.Drawing.Size(211, 6);
//
// cutToolStripMenuItem
//
this.cutToolStripMenuItem.Name = "cutToolStripMenuItem";
@ -4512,6 +4535,9 @@
private System.Windows.Forms.ToolStripMenuItem copyOriginalTextToCurrentToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemMergeDuplicateText;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebVTT;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemWebVttVoice;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorWebVTT;
}
}

View File

@ -2312,7 +2312,7 @@ namespace Nikse.SubtitleEdit.Forms
_fileDateTime = File.GetLastWriteTime(fileName);
if (GetCurrentSubtitleFormat().IsFrameBased)
if (format != null && format.IsFrameBased)
_subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
else
_subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
@ -5098,9 +5098,10 @@ namespace Nikse.SubtitleEdit.Forms
private void ContextMenuStripListviewOpening(object sender, System.ComponentModel.CancelEventArgs e)
{
if ((GetCurrentSubtitleFormat().GetType() == typeof(AdvancedSubStationAlpha) || GetCurrentSubtitleFormat().GetType() == typeof(SubStationAlpha))
&& SubtitleListview1.SelectedItems.Count > 0)
var formatType = GetCurrentSubtitleFormat().GetType();
if ((formatType == typeof(AdvancedSubStationAlpha) || formatType == typeof(SubStationAlpha)) && SubtitleListview1.SelectedItems.Count > 0)
{
toolStripMenuItemWebVTT.Visible = false;
var styles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
setStylesForSelectedLinesToolStripMenuItem.DropDownItems.Clear();
foreach (string style in styles)
@ -5109,7 +5110,7 @@ namespace Nikse.SubtitleEdit.Forms
}
setStylesForSelectedLinesToolStripMenuItem.Visible = styles.Count > 1;
toolStripMenuItemAssStyles.Visible = true;
if (GetCurrentSubtitleFormat().GetType() == typeof(AdvancedSubStationAlpha))
if (formatType == typeof(AdvancedSubStationAlpha))
{
toolStripMenuItemAssStyles.Text = _language.Menu.ContextMenu.AdvancedSubStationAlphaStyles;
setStylesForSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.AdvancedSubStationAlphaSetStyle;
@ -5120,8 +5121,9 @@ namespace Nikse.SubtitleEdit.Forms
setStylesForSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.SubStationAlphaSetStyle;
}
}
else if ((GetCurrentSubtitleFormat().GetType() == typeof(TimedText10) || GetCurrentSubtitleFormat().GetType() == typeof(ItunesTimedText)) && SubtitleListview1.SelectedItems.Count > 0)
else if ((formatType == typeof(TimedText10) || formatType == typeof(ItunesTimedText)) && SubtitleListview1.SelectedItems.Count > 0)
{
toolStripMenuItemWebVTT.Visible = false;
toolStripMenuItemAssStyles.Text = _language.Menu.ContextMenu.TimedTextStyles;
var styles = TimedText10.GetStylesFromHeader(_subtitle.Header);
setStylesForSelectedLinesToolStripMenuItem.DropDownItems.Clear();
@ -5133,8 +5135,9 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemAssStyles.Visible = true;
setStylesForSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.TimedTextSetStyle;
}
else if ((GetCurrentSubtitleFormat().GetType() == typeof(Sami) || GetCurrentSubtitleFormat().GetType() == typeof(SamiModern)) && SubtitleListview1.SelectedItems.Count > 0)
else if ((formatType == typeof(Sami) || formatType == typeof(SamiModern)) && SubtitleListview1.SelectedItems.Count > 0)
{
toolStripMenuItemWebVTT.Visible = false;
toolStripMenuItemAssStyles.Text = _language.Menu.ContextMenu.TimedTextStyles;
var styles = Sami.GetStylesFromHeader(_subtitle.Header);
setStylesForSelectedLinesToolStripMenuItem.DropDownItems.Clear();
@ -5146,10 +5149,26 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemAssStyles.Visible = false;
setStylesForSelectedLinesToolStripMenuItem.Text = _language.Menu.ContextMenu.SamiSetStyle;
}
else if ((formatType == typeof(WebVTT) && SubtitleListview1.SelectedItems.Count > 0))
{
setStylesForSelectedLinesToolStripMenuItem.Visible = false;
toolStripMenuItemAssStyles.Visible = false;
toolStripMenuItemWebVTT.Visible = true;
var voices = WebVTT.GetVoices(_subtitle);
toolStripMenuItemWebVTT.DropDownItems.Clear();
foreach (string style in voices)
{
toolStripMenuItemWebVTT.DropDownItems.Add(style, null, WebVTTSetVoice);
}
toolStripMenuItemWebVTT.DropDownItems.Add("Set new voice...", null, WebVTTSetNewVoice); //TODO: Translate
if (voices.Count > 0)
toolStripMenuItemWebVTT.DropDownItems.Add("Remove voices", null, WebVTTRemoveVoices); //TODO: Translate
}
else
{
setStylesForSelectedLinesToolStripMenuItem.Visible = false;
toolStripMenuItemAssStyles.Visible = false;
toolStripMenuItemWebVTT.Visible = false;
}
@ -5222,7 +5241,7 @@ namespace Nikse.SubtitleEdit.Forms
toolStripMenuItemMergeDialogue.Visible = false;
}
if (GetCurrentSubtitleFormat().GetType() != typeof(SubRip))
if (formatType != typeof(SubRip))
{
karokeeEffectToolStripMenuItem.Visible = false;
toolStripSeparatorAdvancedFunctions.Visible = SubtitleListview1.SelectedItems.Count == 1 && noNetWorkSession;
@ -5241,6 +5260,98 @@ namespace Nikse.SubtitleEdit.Forms
}
}
void WebVTTSetVoice(object sender, EventArgs e)
{
string voice = (sender as ToolStripItem).Text;
if (!string.IsNullOrEmpty(voice))
{
foreach (int index in SubtitleListview1.SelectedIndices)
{
_subtitle.Paragraphs[index].Text = WebVTT.RemoveTag("v", _subtitle.Paragraphs[index].Text);
_subtitle.Paragraphs[index].Text = string.Format("<v {0}>{1}", voice, _subtitle.Paragraphs[index].Text);
SubtitleListview1.SetText(index, _subtitle.Paragraphs[index].Text);
}
RefreshSelectedParagraph();
}
}
void WebVTTSetNewVoice(object sender, EventArgs e)
{
var form = new WebVttNewVoice();
if (form.ShowDialog(this) == DialogResult.OK)
{
string voice = form.VoiceName;
if (!string.IsNullOrEmpty(voice))
{
foreach (int index in SubtitleListview1.SelectedIndices)
{
_subtitle.Paragraphs[index].Text = WebVTT.RemoveTag("v", _subtitle.Paragraphs[index].Text);
_subtitle.Paragraphs[index].Text = string.Format("<v {0}>{1}", voice, _subtitle.Paragraphs[index].Text);
SubtitleListview1.SetText(index, _subtitle.Paragraphs[index].Text);
}
RefreshSelectedParagraph();
}
}
}
void WebVTTRemoveVoices(object sender, EventArgs e)
{
foreach (int index in SubtitleListview1.SelectedIndices)
{
_subtitle.Paragraphs[index].Text = WebVTT.RemoveTag("v", _subtitle.Paragraphs[index].Text);
SubtitleListview1.SetText(index, _subtitle.Paragraphs[index].Text);
}
RefreshSelectedParagraph();
}
void WebVTTSetVoiceTextBox(object sender, EventArgs e)
{
string voice = (sender as ToolStripItem).Text;
if (!string.IsNullOrEmpty(voice))
{
TextBox tb = textBoxListViewText;
if (textBoxListViewTextAlternate.Focused)
tb = textBoxListViewTextAlternate;
if (tb.SelectionLength > 0)
{
string s = tb.SelectedText;
s = WebVTT.RemoveTag("v", s);
if (tb.SelectedText == tb.Text)
s = string.Format("<v {0}>{1}", voice, s);
else
s = string.Format("<v {0}>{1}</v>", voice, s);
tb.SelectedText = s;
}
}
}
void WebVTTSetNewVoiceTextBox(object sender, EventArgs e)
{
var form = new WebVttNewVoice();
if (form.ShowDialog(this) == DialogResult.OK)
{
string voice = form.VoiceName;
if (!string.IsNullOrEmpty(voice))
{
TextBox tb = textBoxListViewText;
if (textBoxListViewTextAlternate.Focused)
tb = textBoxListViewTextAlternate;
if (tb.SelectionLength > 0)
{
string s = tb.SelectedText;
s = WebVTT.RemoveTag("v", s);
if (tb.SelectedText == tb.Text)
s = string.Format("<v {0}>{1}", voice, s);
else
s = string.Format("<v {0}>{1}</v>", voice, s);
tb.SelectedText = s;
}
}
}
}
private void BoldToolStripMenuItemClick(object sender, EventArgs e)
{
ListViewToggleTag("b");
@ -5748,13 +5859,7 @@ namespace Nikse.SubtitleEdit.Forms
Utilities.GetLineLengths(singleLine, text);
buttonSplitLine.Visible = false;
string s = Utilities.RemoveHtmlTags(text).Replace(Environment.NewLine, string.Empty); // we don't count new line in total length... correct?
if (s.StartsWith("{\\"))
{
int k = s.IndexOf("}");
if (k < 10)
s = s.Remove(0, k + 1);
}
string s = Utilities.RemoveHtmlTags(text, true).Replace(Environment.NewLine, string.Empty); // we don't count new line in total length... correct?
if (s.Length < Configuration.Settings.General.SubtitleLineMaximumLength * 1.9)
{
@ -14562,6 +14667,26 @@ namespace Nikse.SubtitleEdit.Forms
superscriptToolStripMenuItem.Visible = false;
subscriptToolStripMenuItem.Visible = false;
}
var formatType = GetCurrentSubtitleFormat().GetType();
if ((formatType == typeof(WebVTT) && tb.SelectionLength > 0))
{
toolStripSeparatorWebVTT.Visible = true;
toolStripMenuItemWebVttVoice.Visible = true;
var voices = WebVTT.GetVoices(_subtitle);
toolStripMenuItemWebVttVoice.DropDownItems.Clear();
foreach (string style in voices)
{
toolStripMenuItemWebVttVoice.DropDownItems.Add(style, null, WebVTTSetVoiceTextBox);
}
toolStripMenuItemWebVttVoice.DropDownItems.Add("Set new voice...", null, WebVTTSetNewVoiceTextBox); //TODO: Translate
}
else
{
toolStripSeparatorWebVTT.Visible = false;
toolStripMenuItemWebVttVoice.Visible = false;
}
}
private void ToolStripMenuItemExportPngXmlClick(object sender, EventArgs e)
@ -15025,13 +15150,7 @@ namespace Nikse.SubtitleEdit.Forms
int extraNewLineLength = Environment.NewLine.Length - 1;
int lineBreakPos = textBox.Text.IndexOf(Environment.NewLine);
int pos = textBox.SelectionStart;
var s = Utilities.RemoveHtmlTags(textBox.Text).Replace(Environment.NewLine, string.Empty); // we don't count new line in total length... correct?
if (s.StartsWith("{\\"))
{
int k = s.IndexOf("}");
if (k < 10)
s = s.Remove(0, k + 1);
}
var s = Utilities.RemoveHtmlTags(textBox.Text, true).Replace(Environment.NewLine, string.Empty); // we don't count new line in total length... correct?
int totalLength = s.Length;
string totalL = " " + string.Format(_languageGeneral.TotalLengthX, totalLength);
if (lineBreakPos == -1 || pos <= lineBreakPos)
@ -15542,7 +15661,24 @@ namespace Nikse.SubtitleEdit.Forms
{
var styles = new SubStationAlphaStyles(_subtitle, GetCurrentSubtitleFormat());
if (styles.ShowDialog(this) == DialogResult.OK)
{
_subtitle.Header = styles.Header;
var styleList = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
if (styleList.Count > 0)
{
for (int i=0; i<_subtitle.Paragraphs.Count; i++)
{
Paragraph p = _subtitle.Paragraphs[i];
if (p.Extra == null || p.Extra != styleList[0])
{
p.Extra = styleList[0];
SubtitleListview1.SetExtraText(i, p.Extra, SubtitleListview1.ForeColor);
}
}
}
}
}
else if (formatType == typeof(TimedText10) || formatType == typeof(ItunesTimedText))
{

View File

@ -681,7 +681,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAATABHAEwARwBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAZABHAGQARwBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
@ -729,7 +729,7 @@
<value>150, 95</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
<value>420</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

110
src/Forms/WebVttNewVoice.Designer.cs generated Normal file
View File

@ -0,0 +1,110 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class WebVttNewVoice
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.buttonOK = new System.Windows.Forms.Button();
this.labelVoiceName = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(166, 68);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 21);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Location = new System.Drawing.Point(12, 36);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(229, 20);
this.textBox1.TabIndex = 4;
//
// buttonOK
//
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(85, 68);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 21);
this.buttonOK.TabIndex = 5;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// labelVoiceName
//
this.labelVoiceName.AutoSize = true;
this.labelVoiceName.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.labelVoiceName.Location = new System.Drawing.Point(9, 20);
this.labelVoiceName.Name = "labelVoiceName";
this.labelVoiceName.Size = new System.Drawing.Size(76, 13);
this.labelVoiceName.TabIndex = 3;
this.labelVoiceName.Text = "Name of voice";
//
// WebVttNewVoice
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(253, 101);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.labelVoiceName);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "WebVttNewVoice";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "WebVTT - set new voice";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.WebVttNewVoice_KeyDown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonCancel;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Label labelVoiceName;
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Forms
{
public partial class WebVttNewVoice : Form
{
public string VoiceName { get; set; }
public WebVttNewVoice()
{
InitializeComponent();
//Text = Configuration.Settings.Language.GoToLine.Title; //TODO: Translate
buttonOK.Text = Configuration.Settings.Language.General.OK;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
FixLargeFonts();
}
private void FixLargeFonts()
{
Graphics graphics = this.CreateGraphics();
SizeF textSize = graphics.MeasureString(buttonOK.Text, this.Font);
if (textSize.Height > buttonOK.Height - 4)
{
int newButtonHeight = (int)(textSize.Height + 7 + 0.5);
Utilities.SetButtonHeight(this, newButtonHeight, 1);
}
}
private void WebVttNewVoice_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
else if (e.KeyCode == Keys.Enter)
{
VoiceName = textBox1.Text;
DialogResult = DialogResult.OK;
}
}
private void buttonOK_Click(object sender, EventArgs e)
{
VoiceName = textBox1.Text;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -41,6 +41,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override bool IsMine(List<string> lines, string fileName)
{
if (lines.Count > 0 && lines[0].ToUpper().StartsWith("WEBVTT"))
return false;
var subtitle = new Subtitle();
LoadSubtitle(subtitle, lines, fileName);
return subtitle.Paragraphs.Count > _errorCount;

View File

@ -101,11 +101,6 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
else if (p != null && line.Trim().Length > 0)
{
string text = line.Trim();
text = RemoveFormatting("v", text);
text = RemoveFormatting("rt", text);
text = RemoveFormatting("ruby", text);
text = RemoveFormatting("c", text);
text = RemoveFormatting("span", text);
p.Text = (p.Text + Environment.NewLine + text).Trim();
}
}
@ -114,7 +109,54 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
subtitle.Renumber(1);
}
private string RemoveFormatting(string tag, string text)
public override void RemoveNativeFormatting(Subtitle subtitle)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
if (p.Text.IndexOf("<") >= 0)
{
string text = p.Text;
text = RemoveTag("v", text);
text = RemoveTag("rt", text);
text = RemoveTag("ruby", text);
text = RemoveTag("c", text);
text = RemoveTag("span", text);
p.Text = text;
}
}
}
public static List<string> GetVoices(Subtitle subtitle)
{
var list = new List<string>();
if (subtitle != null && subtitle.Paragraphs != null)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
string s = p.Text;
int startIndex = s.IndexOf("<v ");
while (startIndex >= 0)
{
int endIndex = s.IndexOf(">", startIndex);
if (endIndex > startIndex)
{
string voice = s.Substring(startIndex + 2, endIndex - startIndex - 2).Trim();
if (list.IndexOf(voice) == -1)
list.Add(voice);
}
if (startIndex == s.Length - 1)
startIndex = -1;
else
startIndex = s.IndexOf("<v ", startIndex +1);
}
}
}
return list;
}
public static string RemoveTag(string tag, string text)
{
int indexOfTag = text.IndexOf("<" + tag + " ");
if (indexOfTag >= 0)
@ -123,7 +165,9 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (indexOfEnd > 0)
{
text = text.Remove(indexOfTag, indexOfEnd - indexOfTag + 1);
text = text.Replace("</" + tag + ">", string.Empty);
}
}
return text;
}

View File

@ -475,7 +475,8 @@ namespace Nikse.SubtitleEdit.Logic
s = s.Replace(" ", " ");
s = s.Replace(" ", " ");
string temp = RemoveHtmlTags(s);
string temp = RemoveHtmlTags(s, true);
if (temp.Length < mergeLinesShorterThan)
{
string[] lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
@ -734,6 +735,34 @@ namespace Nikse.SubtitleEdit.Logic
return RemoveHtmlFontTag(s);
}
public static string RemoveHtmlTags(string s, bool alsoSsaTags)
{
if (s == null)
return null;
s = RemoveHtmlTags(s);
int k = s.IndexOf("{");
while (k >= 0)
{
int l = s.IndexOf("}", k);
if (l > k)
{
s = s.Remove(k, l - k + 1);
if (s.Length > 1 && s.Length > k)
k = s.IndexOf("{", k);
else
k = -1;
}
else
{
k = -1;
}
}
return s;
}
public static string RemoveHtmlFontTag(string s)
{
s = s.Replace("</font>", string.Empty);
@ -1003,7 +1032,7 @@ namespace Nikse.SubtitleEdit.Logic
double optimalCharactersPerSecond = Configuration.Settings.General.SubtitleOptimalCharactersPerSeconds;
if (optimalCharactersPerSecond < 2 || optimalCharactersPerSecond > 100)
optimalCharactersPerSecond = 14.7;
double duration = (RemoveHtmlTags(text).Length / optimalCharactersPerSecond) * 1000.0;
double duration = (RemoveHtmlTags(text, true).Length / optimalCharactersPerSecond) * 1000.0;
if (duration < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
duration = Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds;
@ -1381,7 +1410,7 @@ namespace Nikse.SubtitleEdit.Logic
int maxLength = 0;
foreach (string line in text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
string s = RemoveHtmlTags(line);
string s = RemoveHtmlTags(line, true);
if (s.Length > maxLength)
maxLength = s.Length;
}
@ -1396,13 +1425,7 @@ namespace Nikse.SubtitleEdit.Logic
const string zeroWhiteSpace = "\u200B";
const string zeroWidthNoBreakSpace = "\uFEFF";
string s = Utilities.RemoveHtmlTags(paragraph.Text).Replace(Environment.NewLine, string.Empty).Replace(zeroWhiteSpace, string.Empty).Replace(zeroWidthNoBreakSpace, string.Empty);
if (s.StartsWith("{\\"))
{
int k = s.IndexOf("}");
if (k < 10)
s = s.Remove(0, k+1);
}
string s = Utilities.RemoveHtmlTags(paragraph.Text, true).Replace(Environment.NewLine, string.Empty).Replace(zeroWhiteSpace, string.Empty).Replace(zeroWidthNoBreakSpace, string.Empty);
return s.Length / paragraph.Duration.TotalSeconds;
}
@ -1598,13 +1621,7 @@ namespace Nikse.SubtitleEdit.Logic
public static void GetLineLengths(Label label, string text)
{
label.ForeColor = Color.Black;
string cleanText = Utilities.RemoveHtmlTags(text).Replace(Environment.NewLine, "|");
if (cleanText.StartsWith("{\\"))
{
int k = cleanText.IndexOf("}");
if (k < 10)
cleanText = cleanText.Remove(0, k + 1);
}
string cleanText = Utilities.RemoveHtmlTags(text, true).Replace(Environment.NewLine, "|");
string[] lines = cleanText.Split('|');
const int max = 3;

View File

@ -632,6 +632,12 @@
<Compile Include="Forms\GoogleOrMicrosoftTranslate.Designer.cs">
<DependentUpon>GoogleOrMicrosoftTranslate.cs</DependentUpon>
</Compile>
<Compile Include="Forms\WebVttNewVoice.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\WebVttNewVoice.Designer.cs">
<DependentUpon>WebVttNewVoice.cs</DependentUpon>
</Compile>
<Compile Include="Forms\YouTubeAnnotationsImport.cs">
<SubType>Form</SubType>
</Compile>
@ -1221,6 +1227,9 @@
<EmbeddedResource Include="Forms\GoogleOrMicrosoftTranslate.resx">
<DependentUpon>GoogleOrMicrosoftTranslate.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\WebVttNewVoice.resx">
<DependentUpon>WebVttNewVoice.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\YouTubeAnnotationsImport.resx">
<DependentUpon>YouTubeAnnotationsImport.cs</DependentUpon>
</EmbeddedResource>