Example #1
0
        private static string GetVerticalAlign(AssStyle style, AssStyleOptions options)
        {
            if (!(options?.HasExistingBackgroundImage ?? false))
            {
                return("middle");
            }

            if (AnchorPointUtil.IsTopAligned(style.AnchorPoint))
            {
                return("top");
            }

            if (AnchorPointUtil.IsBottomAligned(style.AnchorPoint))
            {
                return("bottom");
            }

            return("middle");
        }
        public void MergeSimultaneousLines()
        {
            List <Line> lines = Lines.Where(l => l.Start < l.End)
                                .OrderBy(l => l.Start).ToList();         // Use OrderBy to get a stable sort (List.Sort() is unstable)

            int i = 0;

            while (i < lines.Count)
            {
                if (lines[i].Position != null)
                {
                    i++;
                    continue;
                }

                Line firstLine  = lines[i];
                Line secondLine = null;

                int j = i + 1;
                while (j < lines.Count && lines[j].Start < lines[i].End)
                {
                    if (lines[j].Position == null && lines[j].AnchorPoint == firstLine.AnchorPoint)
                    {
                        secondLine = lines[j];
                        break;
                    }
                    j++;
                }

                if (secondLine == null)
                {
                    i++;
                    continue;
                }

                lines.RemoveAt(j);
                lines.RemoveAt(i);

                if (firstLine.Start < secondLine.Start)
                {
                    InsertConcatenedLine(lines, i, firstLine.Start, secondLine.Start, false, firstLine);
                }

                if (AnchorPointUtil.IsBottomAligned(firstLine.AnchorPoint))
                {
                    InsertConcatenedLine(lines, i, secondLine.Start, TimeUtil.Min(firstLine.End, secondLine.End), false, secondLine, firstLine);
                }
                else
                {
                    InsertConcatenedLine(lines, i, secondLine.Start, TimeUtil.Min(firstLine.End, secondLine.End), false, firstLine, secondLine);
                }

                if (firstLine.End < secondLine.End)
                {
                    InsertConcatenedLine(lines, i, firstLine.End, secondLine.End, true, secondLine);
                }
                else if (secondLine.End < firstLine.End)
                {
                    InsertConcatenedLine(lines, i, secondLine.End, firstLine.End, false, firstLine);
                }
            }

            Lines.Clear();
            Lines.AddRange(lines);
        }