Work on export custom text

This commit is contained in:
niksedk 2022-03-08 18:23:52 +01:00
parent aec08e9e13
commit 6925da9400
3 changed files with 35 additions and 22 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], Utilities.GetCharactersPerSecond(p));
string paragraph = ExportCustomTextFormat.GetParagraph(template, start, end, text, translationText, i, p.Actor, p.Duration, arr[3], p);
sb.Append(paragraph);
}
sb.Append(ExportCustomTextFormat.GetHeaderOrFooter(title, subtitle, arr[5]));

View File

@ -58,6 +58,8 @@
this.cpsperiodToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cpsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthnobrToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthbr1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.labelHeader = new System.Windows.Forms.Label();
this.textBoxHeader = new System.Windows.Forms.TextBox();
this.contextMenuStripHeader = new System.Windows.Forms.ContextMenuStrip(this.components);
@ -68,8 +70,7 @@
this.buttonOK = new System.Windows.Forms.Button();
this.groupBoxPreview = new System.Windows.Forms.GroupBox();
this.textBoxPreview = new System.Windows.Forms.TextBox();
this.textlengthnobrToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthbr1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textlengthbr2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBoxTemplate.SuspendLayout();
this.contextMenuStripFooter.SuspendLayout();
this.contextMenuStripParagraph.SuspendLayout();
@ -260,9 +261,10 @@
this.cpsToolStripMenuItem,
this.textlengthToolStripMenuItem,
this.textlengthnobrToolStripMenuItem,
this.textlengthbr1ToolStripMenuItem});
this.textlengthbr1ToolStripMenuItem,
this.textlengthbr2ToolStripMenuItem});
this.contextMenuStripParagraph.Name = "contextMenuStrip1";
this.contextMenuStripParagraph.Size = new System.Drawing.Size(181, 356);
this.contextMenuStripParagraph.Size = new System.Drawing.Size(181, 378);
this.contextMenuStripParagraph.Text = "{text-length-br1}";
//
// insertHHMMSSMSToolStripMenuItem
@ -356,6 +358,20 @@
this.textlengthToolStripMenuItem.Text = "{text-length}";
this.textlengthToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textlengthnobrToolStripMenuItem
//
this.textlengthnobrToolStripMenuItem.Name = "textlengthnobrToolStripMenuItem";
this.textlengthnobrToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textlengthnobrToolStripMenuItem.Text = "{text-length-br0}";
this.textlengthnobrToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textlengthbr1ToolStripMenuItem
//
this.textlengthbr1ToolStripMenuItem.Name = "textlengthbr1ToolStripMenuItem";
this.textlengthbr1ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textlengthbr1ToolStripMenuItem.Text = "{text-length-br1}";
this.textlengthbr1ToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// labelHeader
//
this.labelHeader.AutoSize = true;
@ -452,19 +468,12 @@
this.textBoxPreview.Size = new System.Drawing.Size(340, 374);
this.textBoxPreview.TabIndex = 0;
//
// textlengthnobrToolStripMenuItem
// textlengthbr2ToolStripMenuItem
//
this.textlengthnobrToolStripMenuItem.Name = "textlengthnobrToolStripMenuItem";
this.textlengthnobrToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textlengthnobrToolStripMenuItem.Text = "{text-length-br0}";
this.textlengthnobrToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// textlengthbr1ToolStripMenuItem
//
this.textlengthbr1ToolStripMenuItem.Name = "textlengthbr1ToolStripMenuItem";
this.textlengthbr1ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textlengthbr1ToolStripMenuItem.Text = "{text-length-br1}";
this.textlengthbr1ToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
this.textlengthbr2ToolStripMenuItem.Name = "textlengthbr2ToolStripMenuItem";
this.textlengthbr2ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.textlengthbr2ToolStripMenuItem.Text = "{text-length-br2}";
this.textlengthbr2ToolStripMenuItem.Click += new System.EventHandler(this.InsertTag);
//
// ExportCustomTextFormat
//
@ -539,5 +548,6 @@
private System.Windows.Forms.ToolStripMenuItem cpsperiodToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textlengthnobrToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textlengthbr1ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem textlengthbr2ToolStripMenuItem;
}
}

View File

@ -90,8 +90,8 @@ namespace Nikse.SubtitleEdit.Forms
var newLine = comboBoxNewLine.Text.Replace(LanguageSettings.Current.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, 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)) +
GetParagraph(template, start1, end1, GetText(p1.Text, newLine), GetText("Line 1a." + Environment.NewLine + "Line 1b.", newLine), 0, p1.Actor, p1.Duration, comboBoxTimeCode.Text, p1) +
GetParagraph(template, start2, end2, GetText(p2.Text, newLine), GetText("Line 2a." + Environment.NewLine + "Line 2b.", newLine), 1, p2.Actor, p2.Duration, comboBoxTimeCode.Text, p2) +
GetHeaderOrFooter("Demo", subtitle, textBoxFooter.Text);
}
catch (Exception ex)
@ -119,6 +119,7 @@ namespace Nikse.SubtitleEdit.Forms
s = s.Replace("{text-length}", "{12}");
s = s.Replace("{text-length-br0}", "{13}");
s = s.Replace("{text-length-br1}", "{14}");
s = s.Replace("{text-length-br2}", "{15}");
s = s.Replace("{tab}", "\t");
return s;
}
@ -311,8 +312,9 @@ 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, double cps)
internal static string GetParagraph(string template, string start, string end, string text, string translation, int number, string actor, TimeCode duration, string timeCodeTemplate, Paragraph p)
{
var cps = Utilities.GetCharactersPerSecond(p);
var d = duration.ToString();
if (timeCodeTemplate == "ff" || timeCodeTemplate == "f")
{
@ -397,8 +399,9 @@ namespace Nikse.SubtitleEdit.Forms
cps.ToString(CultureInfo.InvariantCulture).Replace(".", ","),
cps.ToString(CultureInfo.InvariantCulture),
text.Length,
text.RemoveChar('\r','\n').Length,
text.RemoveChar('\r', '\n').Length + lines.Count -1);
p.Text.RemoveChar('\r','\n').Length,
p.Text.RemoveChar('\r', '\n').Length + lines.Count -1,
p.Text.RemoveChar('\r', '\n').Length + lines.Count - 1);
s = s.Replace("@@@@_@@@", "{");
s = s.Replace("@@@_@@@@", "}");
return s;