Add cps+text-length to custom format - thx aaaxx/philippwr :)

Fix #1437
This commit is contained in:
Nikolaj Olsson 2020-04-17 11:33:36 +02:00
parent 8b89ac2c70
commit f2f8ff5e9c
3 changed files with 50 additions and 18 deletions

View File

@ -273,7 +273,7 @@ namespace Nikse.SubtitleEdit.Forms
translationText = trans.Text;
}
}
string paragraph = ExportCustomTextFormat.GetParagraph(template, start, end, text, translationText, i, p.Actor, p.Duration, arr[3]);
string paragraph = ExportCustomTextFormat.GetParagraph(template, start, end, text, translationText, i, p.Actor, p.Duration, arr[3], Utilities.GetCharactersPerSecond(p));
sb.Append(paragraph);
}
sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[5]));

View File

@ -65,6 +65,9 @@
this.buttonOK = new System.Windows.Forms.Button();
this.groupBoxPreview = new System.Windows.Forms.GroupBox();
this.textBoxPreview = new System.Windows.Forms.TextBox();
this.cpsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cpsperiodToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxTemplate.SuspendLayout();
this.contextMenuStripFooter.SuspendLayout();
this.contextMenuStripParagraph.SuspendLayout();
@ -250,77 +253,80 @@
this.toolStripMenuItemActor,
this.tabToolStripMenuItem,
this.textToolStripMenuItem1,
this.textline2ToolStripMenuItem});
this.textline2ToolStripMenuItem,
this.cpsperiodToolStripMenuItem,
this.cpsToolStripMenuItem,
this.textlengthToolStripMenuItem});
this.contextMenuStripParagraph.Name = "contextMenuStrip1";
this.contextMenuStripParagraph.Size = new System.Drawing.Size(139, 224);
this.contextMenuStripParagraph.Size = new System.Drawing.Size(147, 290);
//
// insertHHMMSSMSToolStripMenuItem
//
this.insertHHMMSSMSToolStripMenuItem.Name = "insertHHMMSSMSToolStripMenuItem";
this.insertHHMMSSMSToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.insertHHMMSSMSToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.insertHHMMSSMSToolStripMenuItem.Text = "{start}";
this.insertHHMMSSMSToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// insertendToolStripMenuItem
//
this.insertendToolStripMenuItem.Name = "insertendToolStripMenuItem";
this.insertendToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.insertendToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.insertendToolStripMenuItem.Text = "{end}";
this.insertendToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// insertnumberToolStripMenuItem
//
this.insertnumberToolStripMenuItem.Name = "insertnumberToolStripMenuItem";
this.insertnumberToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.insertnumberToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.insertnumberToolStripMenuItem.Text = "{number}";
this.insertnumberToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// insertdurationToolStripMenuItem
//
this.insertdurationToolStripMenuItem.Name = "insertdurationToolStripMenuItem";
this.insertdurationToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.insertdurationToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.insertdurationToolStripMenuItem.Text = "{duration}";
this.insertdurationToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textToolStripMenuItem
//
this.textToolStripMenuItem.Name = "textToolStripMenuItem";
this.textToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.textToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textToolStripMenuItem.Text = "{text}";
this.textToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// translationToolStripMenuItem
//
this.translationToolStripMenuItem.Name = "translationToolStripMenuItem";
this.translationToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.translationToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.translationToolStripMenuItem.Text = "{translation}";
this.translationToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// toolStripMenuItemActor
//
this.toolStripMenuItemActor.Name = "toolStripMenuItemActor";
this.toolStripMenuItemActor.Size = new System.Drawing.Size(138, 22);
this.toolStripMenuItemActor.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItemActor.Text = "{actor}";
this.toolStripMenuItemActor.Click += new System.EventHandler(this.InsertTag);
//
// tabToolStripMenuItem
//
this.tabToolStripMenuItem.Name = "tabToolStripMenuItem";
this.tabToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.tabToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.tabToolStripMenuItem.Text = "{tab}";
this.tabToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textToolStripMenuItem1
//
this.textToolStripMenuItem1.Name = "textToolStripMenuItem1";
this.textToolStripMenuItem1.Size = new System.Drawing.Size(138, 22);
this.textToolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
this.textToolStripMenuItem1.Text = "{text-line-1}";
this.textToolStripMenuItem1.Click += new System.EventHandler(this.InsertTag);
//
// textline2ToolStripMenuItem
//
this.textline2ToolStripMenuItem.Name = "textline2ToolStripMenuItem";
this.textline2ToolStripMenuItem.Size = new System.Drawing.Size(138, 22);
this.textline2ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textline2ToolStripMenuItem.Text = "{text-line-2}";
this.textline2ToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
@ -420,6 +426,27 @@
this.textBoxPreview.Size = new System.Drawing.Size(340, 374);
this.textBoxPreview.TabIndex = 0;
//
// cpsToolStripMenuItem
//
this.cpsToolStripMenuItem.Name = "cpsToolStripMenuItem";
this.cpsToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.cpsToolStripMenuItem.Text = "{cps-comma}";
this.cpsToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textlengthToolStripMenuItem
//
this.textlengthToolStripMenuItem.Name = "textlengthToolStripMenuItem";
this.textlengthToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.textlengthToolStripMenuItem.Text = "{text-length}";
this.textlengthToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// cpsperiodToolStripMenuItem
//
this.cpsperiodToolStripMenuItem.Name = "cpsperiodToolStripMenuItem";
this.cpsperiodToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.cpsperiodToolStripMenuItem.Text = "{cps-period}";
this.cpsperiodToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// ExportCustomTextFormat
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -488,5 +515,8 @@
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemActor;
private System.Windows.Forms.ToolStripMenuItem textToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem textline2ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cpsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textlengthToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cpsperiodToolStripMenuItem;
}
}

View File

@ -90,8 +90,8 @@ namespace Nikse.SubtitleEdit.Forms
var newLine = comboBoxNewLine.Text.Replace(Configuration.Settings.Language.ExportCustomTextFormat.DoNotModify, EnglishDoNotModify);
var template = GetParagraphTemplate(textBoxParagraph.Text);
textBoxPreview.Text = GetHeaderOrFooter("Demo", subtitle, textBoxHeader.Text) +
GetParagraph(template, start1, end1, GetText(p1.Text, newLine), GetText("Line 1a." + Environment.NewLine + "Line 1b.", newLine), 0, p1.Actor, p1.Duration, comboBoxTimeCode.Text) +
GetParagraph(template, start2, end2, GetText(p2.Text, newLine), GetText("Line 2a." + Environment.NewLine + "Line 2b.", newLine), 1, p2.Actor, p2.Duration, comboBoxTimeCode.Text) +
GetParagraph(template, start1, end1, GetText(p1.Text, newLine), GetText("Line 1a." + Environment.NewLine + "Line 1b.", newLine), 0, p1.Actor, p1.Duration, comboBoxTimeCode.Text, Utilities.GetCharactersPerSecond(p1)) +
GetParagraph(template, start2, end2, GetText(p2.Text, newLine), GetText("Line 2a." + Environment.NewLine + "Line 2b.", newLine), 1, p2.Actor, p2.Duration, comboBoxTimeCode.Text, Utilities.GetCharactersPerSecond(p2)) +
GetHeaderOrFooter("Demo", subtitle, textBoxFooter.Text);
}
catch (Exception ex)
@ -114,7 +114,9 @@ namespace Nikse.SubtitleEdit.Forms
s = s.Replace("{actor}", "{7}");
s = s.Replace("{text-line-1}", "{8}");
s = s.Replace("{text-line-2}", "{9}");
s = s.Replace("{actor}", "{7}");
s = s.Replace("{cps-comma}", "{10}");
s = s.Replace("{cps-period}", "{11}");
s = s.Replace("{text-length}", "{12}");
s = s.Replace("{tab}", "\t");
return s;
}
@ -307,7 +309,7 @@ namespace Nikse.SubtitleEdit.Forms
return template;
}
internal static string GetParagraph(string template, string start, string end, string text, string translation, int number, string actor, TimeCode duration, string timeCodeTemplate)
internal static string GetParagraph(string template, string start, string end, string text, string translation, int number, string actor, TimeCode duration, string timeCodeTemplate, double cps)
{
string d = duration.ToString();
if (timeCodeTemplate == "ff" || timeCodeTemplate == "f")
@ -389,7 +391,7 @@ namespace Nikse.SubtitleEdit.Forms
string s = template;
s = s.Replace("{{", "@@@@_@@@{");
s = s.Replace("}}", "}@@@_@@@@");
s = string.Format(s, start, end, text, translation, number + 1, number, d, actor, line1, line2);
s = string.Format(s, start, end, text, translation, number + 1, number, d, actor, line1, line2, cps.ToString(CultureInfo.InvariantCulture).Replace(".", ","), cps.ToString(CultureInfo.InvariantCulture), text.Length);
s = s.Replace("@@@@_@@@", "{");
s = s.Replace("@@@_@@@@", "}");
return s;