Exemplo n.º 1
0
        internal void CreateTagSections(AssLine line, string text, AssTagContext context)
        {
            text = Regex.Replace(text, @"(?:\\N)+$", "");
            HashSet <string> handledWholeLineTags = new HashSet <string>();

            int start = 0;

            foreach (Match tagGroupMatch in Regex.Matches(text, @"\{(.*?)\}"))
            {
                int end = tagGroupMatch.Index;

                if (end > start || (context.Section.Duration > TimeSpan.Zero && Regex.IsMatch(tagGroupMatch.Groups[1].Value, @"\\k\s*\d+")))
                {
                    if (end == start)
                    {
                        context.Section.Text = "\x200B";
                    }
                    else
                    {
                        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;
                }

                foreach (Match tagMatch in Regex.Matches(tagGroupMatch.Groups[1].Value, @"\\(?<tag>fn|\d?[a-z]+)\s*(?<arg>\([^\(\)]*(?:\)|$)|[^\\\(\)]*)"))
                {
                    if (!_tagHandlers.TryGetValue(tagMatch.Groups["tag"].Value, out AssTagHandlerBase handler))
                    {
                        continue;
                    }

                    if (handler.AffectsWholeLine && !handledWholeLineTags.Add(tagMatch.Groups["tag"].Value))
                    {
                        continue;
                    }

                    handler.Handle(context, tagMatch.Groups["arg"].Value.Trim());
                }

                start = tagGroupMatch.Index + tagGroupMatch.Length;
            }

            if (start < text.Length)
            {
                context.Section.Text = text.Substring(start, text.Length - start).Replace("\\N", "\r\n");
                line.Sections.Add(context.Section);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }