public override void Handle(AssTagContext context, string arg) { List <float> coords = ParseFloatList(arg); if (coords == null || coords.Count != 2 || context.Line.Position != null) { return; } context.Line.Position = new PointF(coords[0], coords[1]); }
private static T FetchColorAnimation <T>( AssTagContext context, DateTime startTime, DateTime endTime, Func <AssSection, Color> getSectionColor, Func <DateTime, DateTime, Color, T> createAnim ) where T : ColorAnimation { return(FetchColorAnimation(context, startTime, endTime, null, getSectionColor, createAnim)); }
private static void HandleTransformShadowColorTag(AssTagContext context, ShadowType shadowType, DateTime startTime, DateTime endTime, float accel, string arg) { ShadowColorAnimation anim = FetchColorAnimation( context, startTime, endTime, a => a.ShadowType == shadowType, s => s.ShadowColors[shadowType], (s, e, c) => new ShadowColorAnimation(shadowType, s, c, e, c, accel) ); anim.EndColor = ParseColor(arg, anim.EndColor.A); }
private static void HandleTransformShadowAlphaTag(AssTagContext context, ShadowType shadowType, DateTime startTime, DateTime endTime, float accel, string arg) { ShadowColorAnimation anim = FetchColorAnimation( context, startTime, endTime, a => a.ShadowType == shadowType, s => s.ShadowColors[shadowType], (s, e, c) => new ShadowColorAnimation(shadowType, s, c, e, c, accel) ); anim.EndColor = ColorUtil.ChangeColorAlpha(anim.EndColor, 255 - (ParseHex(arg) & 255)); }
public override void Handle(AssTagContext context, string arg) { int alpha = 255 - ParseHex(arg); context.Section.ForeColor = ColorUtil.ChangeColorAlpha(context.Section.ForeColor, alpha); context.Section.SecondaryColor = ColorUtil.ChangeColorAlpha(context.Section.SecondaryColor, alpha); context.Section.BackColor = ColorUtil.ChangeColorAlpha(context.Section.BackColor, alpha); foreach (ShadowType shadowType in context.Section.ShadowColors.Keys.ToList()) { context.Section.ShadowColors[shadowType] = ColorUtil.ChangeColorAlpha(context.Section.ShadowColors[shadowType], alpha); } context.Section.Animations.RemoveAll(a => a is ColorAnimation); }
private static void HandleTransformFontSizeTag(AssTagContext context, DateTime startTime, DateTime endTime, int accel, string arg) { if (!TryParseFloat(arg, out float size)) { return; } AssSection section = context.Section; ScaleAnimation prevAnim = section.Animations.OfType <ScaleAnimation>().LastOrDefault(); float startScale = prevAnim?.EndScale ?? context.Section.Scale; float endScale = size / context.Document.DefaultFontSize; context.Section.Animations.Add(new ScaleAnimation(startTime, startScale, endTime, endScale)); }
private static bool TryParseArgs(AssTagContext context, string arg, out SizeF radius, out DateTime startTime, out DateTime endTime) { int defaultRadius = 20; radius = new SizeF(defaultRadius, defaultRadius); startTime = context.Line.Start; endTime = context.Line.End; if (string.IsNullOrWhiteSpace(arg)) { return(true); } List <float> args = ParseFloatList(arg); if (args == null) { return(false); } switch (args.Count) { case 0: return(true); case 1: radius = new SizeF(args[0], args[0]); return(true); case 2: radius = new SizeF(args[0], args[1]); return(true); case 3: radius = new SizeF(args[0], args[0]); startTime = context.Line.Start.AddMilliseconds(args[1]); endTime = context.Line.Start.AddMilliseconds(args[2]); return(true); case 4: radius = new SizeF(args[0], args[1]); startTime = context.Line.Start.AddMilliseconds(args[2]); endTime = context.Line.Start.AddMilliseconds(args[3]); return(true); default: return(false); } }
public override void Handle(AssTagContext context, string arg) { if (!TryParseArgs(context, arg, out DateTime startTime, out DateTime endTime, out int accel, out string modifiers)) { return; } foreach (Match match in Regex.Matches(modifiers, @"\\(?<tag>\d?[a-z]+)(?<arg>[^\\]*)")) { if (TransformTagHandlers.TryGetValue(match.Groups["tag"].Value, out TransformTagHandler handler)) { handler(context, startTime, endTime, accel, match.Groups["arg"].Value.Trim()); } } }
public override void Handle(AssTagContext context, string arg) { if (!TryParseArgs(context, arg, out SizeF radius, out DateTime startTime, out DateTime endTime)) { return; } context.PostProcessors.Add( () => { context.Line.Animations.Add(new ShakeAnimation(startTime, endTime, radius)); return(null); } ); }
public override void Handle(AssTagContext context, string arg) { if (!TryParseArgs(context, arg, out SizeF radius, out DateTime startTime, out DateTime endTime)) { return; } context.PostProcessors.Add( () => { PointF center = context.Line.Position ?? context.Document.GetDefaultPosition(context.Line.AnchorPoint); context.Line.Animations.Add(new ShakeAnimation(startTime, endTime, center, radius)); return(null); } ); }
private static void HandleTransformOutlineAlphaTag(AssTagContext context, DateTime startTime, DateTime endTime, float accel, string arg) { if (!context.Style.HasOutline) { return; } if (context.Style.OutlineIsBox) { BackColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.BackColor, (s, e, c) => new BackColorAnimation(s, c, e, c, accel)); anim.EndColor = ColorUtil.ChangeColorAlpha(anim.EndColor, 255 - (ParseHex(arg) & 255)); } else { HandleTransformShadowAlphaTag(context, ShadowType.Glow, startTime, endTime, accel, arg); } }
public override void Handle(AssTagContext context, string arg) { if (!context.Style.HasShadow) { return; } foreach (KeyValuePair <ShadowType, Color> shadowColor in context.Section.ShadowColors.ToList()) { if (shadowColor.Key != ShadowType.Glow || !context.Style.HasOutline || context.Style.HasOutlineBox) { context.Section.ShadowColors[shadowColor.Key] = ParseColor(arg, shadowColor.Value.A); } } context.Section.Animations.RemoveAll(a => a is ShadowColorAnimation); }
private static void HandleTransformOutlineColorTag(AssTagContext context, DateTime startTime, DateTime endTime, int accel, string arg) { if (!context.Style.HasOutline) { return; } if (context.Style.OutlineIsBox) { BackColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.BackColor, (s, e, c) => new BackColorAnimation(s, c, e, c)); anim.EndColor = ParseColor(arg, anim.EndColor.A); } else { HandleTransformShadowColorTag(context, ShadowType.Glow, startTime, endTime, accel, arg); } }
private static void HandleTransformFontSizeTag(AssTagContext context, DateTime startTime, DateTime endTime, float accel, string arg) { if (!TryParseFloat(arg, out float lineHeight)) { return; } AssSection section = context.Section; section.Animations.RemoveAll(a => a is ScaleAnimation && a.StartTime >= startTime); ScaleAnimation prevAnim = section.Animations.OfType <ScaleAnimation>().LastOrDefault(); float startScale = prevAnim?.EndScale ?? context.Section.Scale; float endScale = lineHeight / context.Document.DefaultStyle.LineHeight; context.Section.Animations.Add(new ScaleAnimation(startTime, startScale, endTime, endScale, accel)); }
public override void Handle(AssTagContext context, string arg) { if (!context.Style.HasOutline) { return; } if (context.Style.OutlineIsBox) { context.Section.BackColor = !string.IsNullOrEmpty(arg) ? ParseColor(arg, context.Section.BackColor.A) : context.Style.OutlineColor; context.Section.Animations.RemoveAll(a => a is BackColorAnimation); } else { context.Section.ShadowColors[ShadowType.Glow] = !string.IsNullOrEmpty(arg) ? ParseColor(arg, context.Section.ShadowColors[ShadowType.Glow].A) : context.Style.OutlineColor; context.Section.Animations.RemoveAll(a => a is ShadowColorAnimation); } }
public override void Handle(AssTagContext context, string arg) { if (!context.Style.HasShadow) { return; } int alpha = 255 - ParseHex(arg); foreach (KeyValuePair <ShadowType, Color> shadowColor in context.Section.ShadowColors.ToList()) { if (shadowColor.Key != ShadowType.Glow || !context.Style.HasOutline || context.Style.HasOutlineBox) { context.Section.ShadowColors[shadowColor.Key] = ColorUtil.ChangeColorAlpha(shadowColor.Value, alpha); } } context.Section.Animations.RemoveAll(a => a is ShadowColorAnimation); }
private List <Section> GenerateCursor(AssDocument doc, AssSection initialFormatting, string cursor) { AssSection section = (AssSection)initialFormatting.Clone(); section.Text = string.Empty; AssLine line = new AssLine(SubtitleDocument.TimeBase, SubtitleDocument.TimeBase); AssTagContext context = new AssTagContext { Document = doc, Line = line, Section = section }; doc.CreateTagSections(line, cursor, context); return(line.Sections); }
public override void Handle(AssTagContext context, string arg) { if (!context.Style.HasOutline) { return; } int alpha = !string.IsNullOrEmpty(arg) ? 255 - (ParseHex(arg) & 255) : context.Style.OutlineColor.A; if (context.Style.OutlineIsBox) { context.Section.BackColor = ColorUtil.ChangeColorAlpha(context.Section.BackColor, alpha); context.Section.Animations.RemoveAll(a => a is BackColorAnimation); } else { context.Section.ShadowColors[ShadowType.Glow] = ColorUtil.ChangeColorAlpha(context.Section.ShadowColors[ShadowType.Glow], alpha); context.Section.Animations.RemoveAll(a => a is ShadowColorAnimation); } }
public override void Handle(AssTagContext context, string arg) { if (!TryParseArgs(arg, out List <Color> colors, out int alpha, out int maxOffsetX, out int maxOffsetY, out int chromaInMs, out int chromeOutMs)) { return; } context.PostProcessors.Add( () => { AssLine originalLine = context.Line; PointF center = originalLine.Position ?? context.Document.GetDefaultPosition(originalLine.AnchorPoint); List <AssLine> chromaLines = new List <AssLine>(); if (colors.Count == 0) { Color baseColor = context.Line.Sections.Count > 0 ? context.Line.Sections[0].ForeColor : Color.White; colors.Add(Color.FromArgb((int)(baseColor.R * alpha / 255.0f), 255, 0, 0)); colors.Add(Color.FromArgb((int)(baseColor.G * alpha / 255.0f), 0, 255, 0)); colors.Add(Color.FromArgb((int)(baseColor.B * alpha / 255.0f), 0, 0, 255)); } if (chromaInMs > 0) { chromaLines.AddRange(CreateChromaLines(originalLine, colors, center, maxOffsetX, maxOffsetY, chromaInMs, true)); originalLine.Start = TimeUtil.SnapTimeToFrame(originalLine.Start.AddMilliseconds(chromaInMs)); } if (chromeOutMs > 0) { chromaLines.AddRange(CreateChromaLines(originalLine, colors, center, maxOffsetX, maxOffsetY, chromeOutMs, false)); originalLine.End = TimeUtil.SnapTimeToFrame(originalLine.End.AddMilliseconds(-chromeOutMs)); } return(chromaLines); } ); }
private static T FetchColorAnimation <T>( AssTagContext context, DateTime startTime, DateTime endTime, Func <T, bool> predicate, Func <AssSection, Color> getSectionColor, Func <DateTime, DateTime, Color, T> createAnim ) where T : ColorAnimation { context.Section.Animations.RemoveAll(a => a is T && a.StartTime > startTime); AssSection section = context.Section; IEnumerable <T> existingAnims = section.Animations.OfType <T>().Where(a => a.StartTime == startTime && a.EndTime == endTime); if (predicate != null) { existingAnims = existingAnims.Where(predicate); } T anim = existingAnims.FirstOrDefault(); if (anim == null) { IEnumerable <T> prevAnims = section.Animations.OfType <T>(); if (predicate != null) { prevAnims = prevAnims.Where(predicate); } T prevAnim = prevAnims.LastOrDefault(); anim = createAnim(startTime, endTime, prevAnim?.EndColor ?? getSectionColor(section)); section.Animations.Add(anim); } return(anim); }
private static void HandleTransformForeColorTag(AssTagContext context, DateTime startTime, DateTime endTime, int accel, string arg) { ForeColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.ForeColor, (s, e, c) => new ForeColorAnimation(s, c, e, c)); anim.EndColor = ParseColor(arg, anim.EndColor.A); }
public override void Handle(AssTagContext context, string arg) { context.Section.SecondaryColor = ParseColor(arg, context.Section.SecondaryColor.A); context.Section.Animations.RemoveAll(a => a is SecondaryColorAnimation); }
public override void Handle(AssTagContext context, string arg) { context.Section.Bold = arg != "0"; }
private static void HandleTransformSecondaryAlphaTag(AssTagContext context, DateTime startTime, DateTime endTime, float accel, string arg) { SecondaryColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.SecondaryColor, (s, e, c) => new SecondaryColorAnimation(s, c, e, c, accel)); anim.EndColor = ColorUtil.ChangeColorAlpha(anim.EndColor, 255 - (ParseHex(arg) & 255)); }
private static void HandleTransformForeAlphaTag(AssTagContext context, DateTime startTime, DateTime endTime, int accel, string arg) { ForeColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.ForeColor, (s, e, c) => new ForeColorAnimation(s, c, e, c)); anim.EndColor = ColorUtil.ChangeColorAlpha(anim.EndColor, 255 - ParseHex(arg)); }
private static void HandleTransformSecondaryColorTag(AssTagContext context, DateTime startTime, DateTime endTime, float accel, string arg) { SecondaryColorAnimation anim = FetchColorAnimation(context, startTime, endTime, s => s.SecondaryColor, (s, e, c) => new SecondaryColorAnimation(s, c, e, c, accel)); anim.EndColor = ParseColor(arg, anim.EndColor.A); }
public override void Handle(AssTagContext context, string arg) { int.TryParse(arg, out int rubyPos); context.Section.RubyPosition = rubyPos == 2 ? RubyPosition.Below : RubyPosition.Above; }
private static bool TryParseArgs(AssTagContext context, string arg, out DateTime startTime, out DateTime endTime, out float accel, out string modifiers) { startTime = context.Line.Start; endTime = context.Line.End; accel = 1; modifiers = null; List <string> args = ParseStringList(arg); if (args == null) { return(false); } switch (args.Count) { case 1: { modifiers = args[0]; return(true); } case 2: { if (!TryParseFloat(args[0], out accel)) { return(false); } modifiers = args[1]; return(true); } case 3: { if (!TryParseInt(args[0], out int t1) || !TryParseInt(args[1], out int t2)) { return(false); } startTime = context.Line.Start.AddMilliseconds(t1); endTime = context.Line.Start.AddMilliseconds(t2); modifiers = args[2]; return(true); } case 4: { if (!TryParseInt(args[0], out int t1) || !TryParseInt(args[1], out int t2) || !TryParseFloat(args[2], out accel)) { return(false); } startTime = context.Line.Start.AddMilliseconds(t1); endTime = context.Line.Start.AddMilliseconds(t2); modifiers = args[3]; return(true); } default: return(false); } }
public override void Handle(AssTagContext context, string arg) { context.Section.Offset = OffsetType.Superscript; }
public override void Handle(AssTagContext context, string arg) { context.Section.Offset = OffsetType.Regular; }