mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 20:52:44 +01:00
Allow alpha when chosing text color for ASSA in main window
This commit is contained in:
parent
fc20a3da3d
commit
3ba85674bc
@ -941,6 +941,11 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
return $"#{c.R:x2}{c.G:x2}{c.B:x2}";
|
||||
}
|
||||
|
||||
public static string ColorToHexWithTransparency(Color c)
|
||||
{
|
||||
return $"#{c.A:x2}{c.R:x2}{c.G:x2}{c.B:x2}";
|
||||
}
|
||||
|
||||
public static int GetMaxLineLength(string text)
|
||||
{
|
||||
int maxLength = 0;
|
||||
|
@ -1941,11 +1941,11 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"
|
||||
{
|
||||
if (c.A >= 255)
|
||||
{
|
||||
return $"&H{c.B:X2}{c.G:X2}{c.R:X2}";
|
||||
return $"c&H{c.B:X2}{c.G:X2}{c.R:X2}";
|
||||
}
|
||||
|
||||
var alpha = 255 - c.A; // ASS stores alpha in reverse (0=full intensity and 255=fully transparent)
|
||||
return $"alpha&H{alpha:X2}&\\&H{c.B:X2}{c.G:X2}{c.R:X2}";
|
||||
return $"alpha&H{alpha:X2}&\\c&H{c.B:X2}{c.G:X2}{c.R:X2}";
|
||||
}
|
||||
|
||||
public static string CheckForErrors(string header)
|
||||
|
@ -12826,7 +12826,19 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
string color;
|
||||
var formatType = GetCurrentSubtitleFormat().GetType();
|
||||
if (formatType == typeof(Ebu))
|
||||
if (formatType == typeof(AdvancedSubStationAlpha))
|
||||
{
|
||||
using (var form = new ColorChooser { Color = Color.White })
|
||||
{
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = Utilities.ColorToHexWithTransparency(form.Color);
|
||||
}
|
||||
}
|
||||
else if (formatType == typeof(Ebu))
|
||||
{
|
||||
using (var form = new EbuColorPicker(true))
|
||||
{
|
||||
@ -12896,7 +12908,6 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
var p = _subtitle.GetParagraphOrDefault(item.Index);
|
||||
if (p != null)
|
||||
{
|
||||
|
||||
if (isAssa)
|
||||
{
|
||||
if (!p.Text.Contains(assaColor, StringComparison.OrdinalIgnoreCase))
|
||||
@ -13023,7 +13034,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
if (p != null)
|
||||
{
|
||||
var style = AdvancedSubStationAlpha.GetSsaStyle(p.Extra, _subtitle.Header);
|
||||
text = $"{{\\c{assaColor}&}}{text}{{\\c{AdvancedSubStationAlpha.GetSsaColorStringForEvent(style.Primary)}&}}";
|
||||
text = $"{{\\{assaColor}&}}{text}{{\\{AdvancedSubStationAlpha.GetSsaColorStringForEvent(style.Primary)}&}}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -13098,7 +13109,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
var c = ColorTranslator.FromHtml(color);
|
||||
p.Text = RemoveAssaColor(p.Text);
|
||||
p.Text = "{\\c" + AdvancedSubStationAlpha.GetSsaColorStringForEvent(c) + "&}" + p.Text;
|
||||
p.Text = "{\\" + AdvancedSubStationAlpha.GetSsaColorStringForEvent(c) + "&}" + p.Text;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -13153,6 +13164,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
private static string RemoveAssaColor(string input)
|
||||
{
|
||||
var text = input;
|
||||
text = Regex.Replace(text, "\\\\alpha&H.{1,2}&\\\\", "\\");
|
||||
text = Regex.Replace(text, "{\\\\1c&[abcdefghABCDEFGH\\d]*&}", string.Empty);
|
||||
text = Regex.Replace(text, "{\\\\c&[abcdefghABCDEFGH\\d]*&}", string.Empty);
|
||||
text = Regex.Replace(text, "\\\\c&[abcdefghABCDEFGH\\d]*&", string.Empty);
|
||||
@ -24973,7 +24985,19 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
string color;
|
||||
var formatType = GetCurrentSubtitleFormat().GetType();
|
||||
if (formatType == typeof(Ebu))
|
||||
if (formatType == typeof(AdvancedSubStationAlpha))
|
||||
{
|
||||
using (var form = new ColorChooser { Color = Color.White })
|
||||
{
|
||||
if (form.ShowDialog(this) != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
color = Utilities.ColorToHexWithTransparency(form.Color);
|
||||
}
|
||||
}
|
||||
else if (formatType == typeof(Ebu))
|
||||
{
|
||||
using (var form = new EbuColorPicker(true))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user