private List <AssLine> ParseLine(AssDialogue dialogue, AssStyle style, AssStyleOptions styleOptions) { AssLine line = new AssLine( TimeUtil.RoundTimeToFrameCenter(dialogue.Start), TimeUtil.RoundTimeToFrameCenter(dialogue.End) ) { AnchorPoint = style.AnchorPoint }; string[] effects = dialogue.Effect.Split(';'); if (effects.Contains(EffectNames.NoAndroidDarkTextHack)) { line.AndroidDarkTextHackAllowed = false; } AssTagContext context = new AssTagContext { Document = this, InitialStyle = style, InitialStyleOptions = styleOptions, Style = style, StyleOptions = styleOptions, Line = line, Section = new AssSection() }; ApplyStyle(context.Section, style, styleOptions); CreateTagSections(line, dialogue.Text, context); CreateRubySections(line); List <AssLine> lines = new List <AssLine> { line }; foreach (AssTagContext.PostProcessor postProcessor in context.PostProcessors) { List <AssLine> extraLines = postProcessor(); if (extraLines != null) { lines.AddRange(extraLines); } } return(lines); }
private List <AssLine> ParseLine(AssDialogue dialogue, AssStyle style, AssStyleOptions styleOptions) { DateTime startTime = TimeUtil.SnapTimeToFrame(dialogue.Start.AddMilliseconds(32)); DateTime endTime = TimeUtil.SnapTimeToFrame(dialogue.End).AddMilliseconds(32); AssLine line = new AssLine(startTime, endTime) { AnchorPoint = style.AnchorPoint, KaraokeType = SimpleKaraokeType }; AssTagContext context = new AssTagContext { Document = this, InitialStyle = style, InitialStyleOptions = styleOptions, Style = style, StyleOptions = styleOptions, Line = line, Section = new AssSection(null) }; ApplyStyle(context.Section, style, styleOptions); CreateTagSections(line, dialogue.Text, context); CreateRubySections(line); List <AssLine> lines = new List <AssLine> { line }; foreach (AssTagContext.PostProcessor postProcessor in context.PostProcessors) { List <AssLine> extraLines = postProcessor(); if (extraLines != null) { lines.AddRange(extraLines); } } return(lines); }
private List <AssLine> ParseLine(AssDialogue dialogue, AssStyle style, AssStyleOptions styleOptions) { DateTime startTime = TimeUtil.SnapTimeToFrame(dialogue.Start.AddMilliseconds(32)); DateTime endTime = TimeUtil.SnapTimeToFrame(dialogue.End).AddMilliseconds(32); AssLine line = new AssLine(startTime, endTime) { AnchorPoint = style.AnchorPoint }; AssTagContext context = new AssTagContext { Document = this, Dialogue = dialogue, InitialStyle = style, InitialStyleOptions = styleOptions, Style = style, StyleOptions = styleOptions, Line = line, Section = new AssSection(null) }; ApplyStyle(context.Section, style, styleOptions); string text = Regex.Replace(dialogue.Text, @"(?:\\N)+$", ""); int start = 0; foreach (Match match in Regex.Matches(text, @"\{(?:\\(?<tag>fn|\d?[a-z]+)(?<arg>\([^\{\}\(\)]*\)|[^\{\}\(\)\\]*))+\}")) { int end = match.Index; if (end > start) { context.Section.Text = text.Substring(start, end - start).Replace("\\N", "\r\n"); line.Sections.Add(context.Section); context.Section = (AssSection)context.Section.Clone(); context.Section.Text = null; context.Section.Duration = TimeSpan.Zero; } CaptureCollection tags = match.Groups["tag"].Captures; CaptureCollection arguments = match.Groups["arg"].Captures; for (int i = 0; i < tags.Count; i++) { if (_tagHandlers.TryGetValue(tags[i].Value, out AssTagHandlerBase handler)) { handler.Handle(context, arguments[i].Value); } } start = match.Index + match.Length; } if (start < text.Length) { context.Section.Text = text.Substring(start, text.Length - start).Replace("\\N", "\r\n"); line.Sections.Add(context.Section); } if (line.RubyPosition != RubyPosition.None) { CreateRubySections(line); } List <AssLine> lines = new List <AssLine> { line }; foreach (AssTagContext.PostProcessor postProcessor in context.PostProcessors) { List <AssLine> extraLines = postProcessor(); if (extraLines != null) { lines.AddRange(extraLines); } } return(lines); }