private string GetSsaColorString(Color c) { if (_isSubStationAlpha) { return(Color.FromArgb(0, c.B, c.G, c.R).ToArgb().ToString(CultureInfo.InvariantCulture)); } return(AdvancedSubStationAlpha.GetSsaColorString(c)); }
public string ToRawAss(string styleFormat = DefaultAssStyleFormat) { var sb = new StringBuilder(); sb.Append("Style: "); var format = styleFormat.ToLowerInvariant().Substring(8).Split(','); for (int i = 0; i < format.Length; i++) { string f = format[i].Trim(); if (f == "name") { sb.Append(Name); } else if (f == "fontname") { sb.Append(FontName); } else if (f == "fontsize") { sb.Append(FontSize.ToString(CultureInfo.InvariantCulture)); } else if (f == "primarycolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Primary)); } else if (f == "secondarycolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Secondary)); } else if (f == "outlinecolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Outline)); } else if (f == "backcolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Background)); } else if (f == "bold") { sb.Append(BoolToRawSsa(Bold)); } else if (f == "italic") { sb.Append(BoolToRawSsa(Italic)); } else if (f == "underline") { sb.Append(BoolToRawSsa(Underline)); } else if (f == "strikeout") { sb.Append(BoolToRawSsa(Strikeout)); } else if (f == "outline") { sb.Append(OutlineWidth.ToString(CultureInfo.InvariantCulture)); } else if (f == "shadow") { sb.Append(ShadowWidth.ToString(CultureInfo.InvariantCulture)); } else if (f == "alignment") { sb.Append(Alignment); } else if (f == "marginl") { sb.Append(MarginLeft); } else if (f == "marginr") { sb.Append(MarginRight); } else if (f == "marginv") { sb.Append(MarginVertical); } else if (f == "borderstyle") { sb.Append(BorderStyle); } else if (f == "encoding") { sb.Append('1'); } else if (f == "strikeout") { sb.Append('0'); } else if (f == "scalex") { sb.Append(ScaleX.ToString(CultureInfo.InvariantCulture)); } else if (f == "scaley") { sb.Append(ScaleY.ToString(CultureInfo.InvariantCulture)); } else if (f == "spacing") { sb.Append(Spacing.ToString(CultureInfo.InvariantCulture)); } else if (f == "angle") { sb.Append(Angle.ToString(CultureInfo.InvariantCulture)); } sb.Append(','); } var s = sb.ToString().Trim(); return(s.Substring(0, s.Length - 1)); }
private void TimerRenderTick(object sender, EventArgs e) { _progessBarSubtitle = new Subtitle(); var script = @"[Script Info] ; This is an Advanced Sub Station Alpha v4+script. ScriptType: v4.00+ Collisions: Normal PlayResX: [VIDEO_WIDTH] PlayResY: [VIDEO_HEIGHT] [V4+ Styles] Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding Style: SE-progress-bar-splitter,Arial,20,[TEXT_COLOR],&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1 Style: SE-progress-bar-bg,Arial,20,[FORE_COLOR],[BACK_COLOR],&H00FFFFFF,&H00000000,0,0,0,0,100,100,0,0,1,0,0,[ALIGNMENT],0,0,0,1 Style: SE-progress-bar-text,[FONT_NAME],[FONT_SIZE],[TEXT_COLOR],&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,[TEXT_ALIGNMENT],0,0,0,1 [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: -255,0:00:00.00,0:43:00.00,SE-progress-bar-bg,,0,0,0,,[PB_DRAWING]"; script = script.Replace("[VIDEO_WIDTH]", _videoInfo.Width.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[VIDEO_HEIGHT]", _videoInfo.Height.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[FORE_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelPrimaryColor.BackColor)); script = script.Replace("[BACK_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelSecondaryColor.BackColor)); script = script.Replace("[TEXT_COLOR]", AdvancedSubStationAlpha.GetSsaColorString(panelTextColor.BackColor)); script = script.Replace("[FONT_SIZE]", numericUpDownFontSize.Value.ToString(CultureInfo.InvariantCulture)); script = script.Replace("[FONT_NAME]", comboBoxFontName.Text); var duration = (int)Math.Round(_videoInfo.TotalMilliseconds / 10.0); script = script.Replace("[PB_DRAWING]", GenerateProgressBar(_videoInfo, (int)numericUpDownHeight.Value, duration)); if (radioButtonPosTop.Checked) { script = script.Replace("[ALIGNMENT]", "7"); } else { script = script.Replace("[ALIGNMENT]", "1"); } if (comboBoxTextHorizontalAlignment.SelectedIndex == 1) { script = script.Replace("[TEXT_ALIGNMENT]", "5"); } else if (comboBoxTextHorizontalAlignment.SelectedIndex == 2) { script = script.Replace("[TEXT_ALIGNMENT]", "6"); } else { script = script.Replace("[TEXT_ALIGNMENT]", "4"); } new AdvancedSubStationAlpha().LoadSubtitle(_progessBarSubtitle, script.SplitToLines(), string.Empty); _progessBarSubtitle.Paragraphs[0].EndTime.TotalMilliseconds = _videoInfo.TotalMilliseconds; if (_chapters?.Paragraphs.Count > 0) { var layer = -254; using (var graphics = CreateGraphics()) { for (int i = 0; i < _chapters.Paragraphs.Count; i++) { Paragraph p = _chapters.Paragraphs[i]; var percentOfDuration = p.StartTime.TotalMilliseconds * 100.0 / _videoInfo.TotalMilliseconds; var position = (int)Math.Round(_videoInfo.Width * percentOfDuration / 100.0); var textPosition = GetTextPosition(position, p, i, percentOfDuration); string posTag; string splitterText; SizeF chapterSize; try { using (var font = new Font(comboBoxFontName.Text, (float)(numericUpDownFontSize.Value * 0.7m), FontStyle.Regular)) { chapterSize = graphics.MeasureString(p.Text, font); } } catch { using (var font = new Font(Font.Name, (float)(numericUpDownFontSize.Value * 0.7m), FontStyle.Regular)) { chapterSize = graphics.MeasureString(p.Text, font); } } if (radioButtonPosTop.Checked) { var top = (int)Math.Round((numericUpDownHeight.Value / 2.0m) + numericUpDownYAdjust.Value); posTag = $"{{\\pos({textPosition}, {top})}}"; var splitterTop = 0; if (numericUpDownSplitterHeight.Value < numericUpDownHeight.Value) { splitterTop += (int)Math.Round((numericUpDownHeight.Value - numericUpDownSplitterHeight.Value) / 2); } splitterText = $"{{\\p1}}m {position} {splitterTop} l " + // top left point $"{position + numericUpDownSplitterWidth.Value} {splitterTop} " + // top right point $"{position + numericUpDownSplitterWidth.Value} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom right point $"{position} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom left point $"{position} {splitterTop}" + // top left point "{{\\p0}}"; } else { posTag = $"{{\\pos({textPosition}, {(int)Math.Round(_videoInfo.Height - (numericUpDownHeight.Value / 2.0m) + numericUpDownYAdjust.Value)})}}"; var splitterTop = _videoInfo.Height - numericUpDownHeight.Value; if (numericUpDownSplitterHeight.Value < numericUpDownHeight.Value) { splitterTop += (int)Math.Round((numericUpDownHeight.Value - numericUpDownSplitterHeight.Value) / 2); } splitterText = $"{{\\p1}}m {position} {splitterTop} l " + // top left point $"{position + numericUpDownSplitterWidth.Value} {splitterTop} " + // top right point $"{position + numericUpDownSplitterWidth.Value} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom right point $"{position} {splitterTop + numericUpDownSplitterHeight.Value} " + // bottom left point $"{position} {splitterTop}" + // top left point "{{\\p0}}"; } if (i > 0) { var splitter = new Paragraph(splitterText, 0, _videoInfo.TotalMilliseconds) { Extra = "SE-progress-bar-splitter", Layer = layer, }; layer++; _progessBarSubtitle.Paragraphs.Add(splitter); } var chapterInfo = new Paragraph(posTag + p.Text, 0, _videoInfo.TotalMilliseconds) { Extra = "SE-progress-bar-text", Layer = -1, Actor = p.StartTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture), }; _progessBarSubtitle.Paragraphs.Add(chapterInfo); } } } textBoxSource.Text = new AdvancedSubStationAlpha().ToText(_progessBarSubtitle, string.Empty); var hashValue = _progessBarSubtitle.GetFastHashCode(string.Empty); if (hashValue != _oldHashValue) { _videoPlayerContainer.SetSubtitleText(string.Empty, new Paragraph(), _progessBarSubtitle); _oldHashValue = hashValue; } _videoPlayerContainer.RefreshProgressBar(); }
internal string ToRawAss(string styleFormat) { var sb = new StringBuilder(); sb.Append("Style: "); var format = styleFormat.ToLower().Substring(8).Split(','); for (int i = 0; i < format.Length; i++) { string f = format[i].Trim().ToLower(); if (f == "name") { sb.Append(Name); } else if (f == "fontname") { sb.Append(FontName); } else if (f == "fontsize") { sb.Append(FontSize); } else if (f == "primarycolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Primary)); } else if (f == "secondarycolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Secondary)); } else if (f == "tertiarycolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Tertiary)); } else if (f == "outlinecolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Outline)); } else if (f == "backcolour") { sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Background)); } else if (f == "bold") { sb.Append(Convert.ToInt32(Bold)); } else if (f == "italic") { sb.Append(Convert.ToInt32(Italic)); } else if (f == "underline") { sb.Append(Convert.ToInt32(Underline)); } else if (f == "outline") { sb.Append(OutlineWidth); } else if (f == "shadow") { sb.Append(ShadowWidth); } else if (f == "alignment") { sb.Append(Alignment); } else if (f == "marginl") { sb.Append(MarginLeft); } else if (f == "marginr") { sb.Append(MarginRight); } else if (f == "marginv") { sb.Append(MarginVertical); } else if (f == "borderstyle") { sb.Append(BorderStyle); } else if (f == "encoding") { sb.Append("1"); } else if (f == "strikeout") { sb.Append("0"); } else if (f == "scalex") { sb.Append("100"); } else if (f == "scaley") { sb.Append("100"); } else if (f == "spacing") { sb.Append("0"); } else if (f == "angle") { sb.Append("0"); } sb.Append(","); } string s = sb.ToString().Trim(); return(s.Substring(0, s.Length - 1)); }