SubtitleEdit/libse/SsaStyle.cs

303 lines
10 KiB
C#
Raw Normal View History

2016-02-08 21:11:03 +01:00
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
using System.Drawing;
using System.Text;
namespace Nikse.SubtitleEdit.Core
{
public class SsaStyle
{
public string Name { get; set; }
public string FontName { get; set; }
public int FontSize { get; set; }
public bool Italic { get; set; }
public bool Bold { get; set; }
public bool Underline { get; set; }
public Color Primary { get; set; }
public Color Secondary { get; set; }
public Color Tertiary { get; set; }
public Color Outline { get; set; }
public Color Background { get; set; }
public decimal ShadowWidth { get; set; }
public decimal OutlineWidth { get; set; }
2016-02-08 21:11:03 +01:00
public string Alignment { get; set; }
public int MarginLeft { get; set; }
public int MarginRight { get; set; }
public int MarginVertical { get; set; }
public string BorderStyle { get; set; }
public string RawLine { get; set; }
public bool LoadedFromHeader { get; set; }
public SsaStyle()
{
FontName = Configuration.Settings.SubtitleSettings.SsaFontName;
FontSize = (int)Configuration.Settings.SubtitleSettings.SsaFontSize;
Primary = Color.FromArgb(Configuration.Settings.SubtitleSettings.SsaFontColorArgb);
Secondary = Color.Yellow;
Outline = Color.Black;
Background = Color.Black;
Alignment = "2";
OutlineWidth = Configuration.Settings.SubtitleSettings.SsaOutline;
ShadowWidth = Configuration.Settings.SubtitleSettings.SsaShadow;
MarginLeft = 10;
MarginRight = 10;
MarginVertical = 10;
BorderStyle = "1";
if (Configuration.Settings.SubtitleSettings.SsaOpaqueBox)
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
BorderStyle = "3";
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
RawLine = string.Empty;
LoadedFromHeader = false;
}
public SsaStyle(SsaStyle ssaStyle)
{
Name = ssaStyle.Name;
FontName = ssaStyle.FontName;
FontSize = ssaStyle.FontSize;
Italic = ssaStyle.Italic;
Bold = ssaStyle.Bold;
Underline = ssaStyle.Underline;
Primary = ssaStyle.Primary;
Secondary = ssaStyle.Secondary;
Tertiary = ssaStyle.Tertiary;
Outline = ssaStyle.Outline;
Background = ssaStyle.Background;
ShadowWidth = ssaStyle.ShadowWidth;
OutlineWidth = ssaStyle.OutlineWidth;
Alignment = ssaStyle.Alignment;
MarginLeft = ssaStyle.MarginLeft;
MarginRight = ssaStyle.MarginRight;
MarginVertical = ssaStyle.MarginVertical;
BorderStyle = ssaStyle.BorderStyle;
RawLine = ssaStyle.RawLine;
LoadedFromHeader = ssaStyle.LoadedFromHeader;
}
public string ToRawSsa(string styleFormat)
{
var sb = new StringBuilder();
sb.Append("Style: ");
var format = styleFormat.ToLowerInvariant().Substring(8).Split(',');
2016-02-08 21:11:03 +01:00
for (int i = 0; i < format.Length; i++)
{
string f = format[i].Trim();
2016-02-08 21:11:03 +01:00
if (f == "name")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Name);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "fontname")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(FontName);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "fontsize")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(FontSize);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "primarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ColorTranslator.ToWin32(Primary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "secondarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ColorTranslator.ToWin32(Secondary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "tertiarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ColorTranslator.ToWin32(Tertiary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "outlinecolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ColorTranslator.ToWin32(Outline));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "backcolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ColorTranslator.ToWin32(Background));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "bold")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Bold));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "italic")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Italic));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "underline")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Underline));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "outline")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Outline);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "shadow")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(OutlineWidth);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginl")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginLeft);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginr")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginRight);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginv")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginVertical);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "borderstyle")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(BorderStyle);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "encoding")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('1');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "strikeout")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "scalex")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append("100");
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "scaley")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append("100");
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "spacing")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "angle")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
sb.Append(',');
}
string s = sb.ToString().Trim();
return s.Substring(0, s.Length - 1);
}
public string ToRawAss(string styleFormat)
{
var sb = new StringBuilder();
sb.Append("Style: ");
var format = styleFormat.ToLowerInvariant().Substring(8).Split(',');
2016-02-08 21:11:03 +01:00
for (int i = 0; i < format.Length; i++)
{
string f = format[i].Trim();
2016-02-08 21:11:03 +01:00
if (f == "name")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Name);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "fontname")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(FontName);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "fontsize")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(FontSize);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "primarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Primary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "secondarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Secondary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "tertiarycolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Tertiary));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "outlinecolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Outline));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "backcolour")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(AdvancedSubStationAlpha.GetSsaColorString(Background));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "bold")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Bold));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "italic")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Italic));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "underline")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Convert.ToInt32(Underline));
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "outline")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(OutlineWidth);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "shadow")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(ShadowWidth);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "alignment")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(Alignment);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginl")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginLeft);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginr")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginRight);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "marginv")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(MarginVertical);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "borderstyle")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append(BorderStyle);
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "encoding")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('1');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "strikeout")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "scalex")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append("100");
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "scaley")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append("100");
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "spacing")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
else if (f == "angle")
2019-01-19 14:40:37 +01:00
{
2016-02-08 21:11:03 +01:00
sb.Append('0');
2019-01-19 14:40:37 +01:00
}
2016-02-08 21:11:03 +01:00
sb.Append(',');
}
string s = sb.ToString().Trim();
return s.Substring(0, s.Length - 1);
}
}
}