Exemplo n.º 1
0
        /// <summary>
        /// Reads SRT formatted text file into single captions
        /// </summary>
        /// <param name="fileName">input file name</param>
        /// <returns></returns>
        public static TextSubtitle ReadFile(string fileName)
        {
            var result = new TextSubtitle();

            if (!File.Exists(fileName))
            {
                Log.Debug($"File \"{fileName}\" doesn't exist. Aborting file import");
                return(result);
            }

            string lines;

            using (var reader = File.OpenText(fileName))
            {
                lines = reader.ReadToEnd();
            }
            if (string.IsNullOrEmpty(lines))
            {
                return(result);
            }

            var textCaps = lines.Split(new[] { "\r\n\r\n", "\n\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var textCap in textCaps)
            {
                var capLines = textCap.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

                if (capLines.Length < 3)
                {
                    continue;
                }

                var timings = capLines[1].Split(new[] { " --> " }, StringSplitOptions.RemoveEmptyEntries);

                if (timings.Length < 2)
                {
                    continue;
                }

                var caption = new SubCaption
                {
                    StartTime = DateTime.ParseExact(timings[0], "hh:mm:ss,fff", CInfo).TimeOfDay,
                    EndTime   = DateTime.ParseExact(timings[1], "hh:mm:ss,fff", CInfo).TimeOfDay,
                    Text      = string.Join(Environment.NewLine, capLines, 2, capLines.Length - 2),
                };
                result.Captions.Add(caption);
            }

            result.SetDefaultStyle();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 속성들을 Xml Attribute로 생성합니다.
        /// </summary>
        /// <param name="writer">Attribute를 쓸 Writer</param>
        public override void GenerateXmlAttributes(XmlWriter writer)
        {
            base.GenerateXmlAttributes(writer);

            // NOTE: 자동으로 속성을 XmlAttribute로 생성합니다 (개발 중)
            // ChartExtensions.WriteChartAttribute((ChartBase)this, writer);

            if (Id.IsNotWhiteSpace())
            {
                writer.WriteAttributeString("id", Id);
            }
            if (Caption.IsNotWhiteSpace())
            {
                writer.WriteAttributeString("caption", Caption);
            }
            if (SubCaption.IsNotWhiteSpace())
            {
                writer.WriteAttributeString("subCaption", SubCaption);
            }

            if (Animation.HasValue)
            {
                writer.WriteAttributeString("animation", Animation.Value.GetHashCode().ToString());
            }
            if (DefaultAnimation.HasValue)
            {
                writer.WriteAttributeString("defaultAnimation", DefaultAnimation.Value.GetHashCode().ToString());
            }

            if (Palette.HasValue)
            {
                writer.WriteAttributeString("palette", Palette.Value.ToString());
            }

            if (PaletteThemeColor.HasValue)
            {
                writer.WriteAttributeString("paletteThemeColor", PaletteThemeColor.Value.ToHexString());
            }

            if (ShowPrintMenuItem.HasValue)
            {
                writer.WriteAttributeString("showPrintMenuItem", ShowPrintMenuItem.Value.GetHashCode().ToString());
            }

            if (ShowLabels.HasValue)
            {
                writer.WriteAttributeString("showLabels", ShowLabels.Value.GetHashCode().ToString());
            }
            if (ShowShadow.HasValue)
            {
                writer.WriteAttributeString("ShowShadow", ShowShadow.GetHashCode().ToString());
            }
            if (ShowValues.HasValue)
            {
                writer.WriteAttributeString("ShowValues", ShowValues.GetHashCode().ToString());
            }
            if (RotateValues.HasValue)
            {
                writer.WriteAttributeString("RotateValues", RotateValues.GetHashCode().ToString());
            }

            if (_clickURL != null)
            {
                _clickURL.GenerateXmlAttributes(writer);
            }

            if (_backgroundAttr != null)
            {
                _backgroundAttr.GenerateXmlAttributes(writer);
            }
            if (_borderAttr != null)
            {
                _borderAttr.GenerateXmlAttributes(writer);
            }
            if (_cosmeticAttr != null)
            {
                _cosmeticAttr.GenerateXmlAttributes(writer);
            }
            if (_baseFontAttr != null)
            {
                _baseFontAttr.GenerateXmlAttributes(writer);
            }

            if (_toolTipAttr != null)
            {
                _toolTipAttr.GenerateXmlAttributes(writer);
            }
            if (_logoAttr != null)
            {
                _logoAttr.GenerateXmlAttributes(writer);
            }
            if (_aboutMenuItemAttr != null)
            {
                _aboutMenuItemAttr.GenerateXmlAttributes(writer);
            }
            if (_exportDataMenuItemAttr != null)
            {
                _exportDataMenuItemAttr.GenerateXmlAttributes(writer);
            }
            if (_exportAttr != null)
            {
                _exportAttr.GenerateXmlAttributes(writer);
            }
            if (_legendAttr != null)
            {
                _legendAttr.GenerateXmlAttributes(writer);
            }
            if (_scrollBarAttr != null)
            {
                _scrollBarAttr.GenerateXmlAttributes(writer);
            }
            if (_marginAttr != null)
            {
                _marginAttr.GenerateXmlAttributes(writer);
            }
            if (_numberAttr != null)
            {
                _numberAttr.GenerateXmlAttributes(writer);
            }

            if (CaptionPadding.HasValue)
            {
                writer.WriteAttributeString("CaptionPadding", CaptionPadding.ToString());
            }
            if (XAxisNamePadding.HasValue)
            {
                writer.WriteAttributeString("XAxisNamePadding", XAxisNamePadding.ToString());
            }
            if (LabelPadding.HasValue)
            {
                writer.WriteAttributeString("LabelPadding", LabelPadding.ToString());
            }
            if (ValuePadding.HasValue)
            {
                writer.WriteAttributeString("ValuePadding", ValuePadding.ToString());
            }
            if (CanvasPadding.HasValue)
            {
                writer.WriteAttributeString("CanvasPadding", CanvasPadding.ToString());
            }
            if (LegendPadding.HasValue)
            {
                writer.WriteAttributeString("LegendPadding", LegendPadding.ToString());
            }
            if (PlotSpacePercent.HasValue)
            {
                writer.WriteAttributeString("PlotSpacePercent", PlotSpacePercent.ToString());
            }

            if (_chartMarginAtrr != null)
            {
                _chartMarginAtrr.GenerateXmlAttributes(writer);
            }
            if (_canvasMarginAttr != null)
            {
                _canvasMarginAttr.GenerateXmlAttributes(writer);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an PNG image for given Subtitle caption
        /// </summary>
        /// <param name="caption">Subtitle caption</param>
        /// <param name="style">Subtitle style</param>
        /// <param name="number">Caption number</param>
        /// <param name="videoWidth">Video width</param>
        /// <param name="videoHeight">Video height</param>
        /// <param name="baseFName">File base name</param>
        /// <returns>Generated PNG image</returns>
        public static ImageHolder CreateImage(SubCaption caption, SubtitleStyle style, int number, int videoWidth, int videoHeight, string baseFName)
        {
            _boldStyle      = false;
            _italicStyle    = false;
            _underlineStyle = false;
            _strikeStyle    = false;

            var result = new ImageHolder();

            if (string.IsNullOrEmpty(baseFName))
            {
                return(new ImageHolder());
            }

            var basePath = Path.GetDirectoryName(baseFName);
            var baseName = Path.GetFileNameWithoutExtension(baseFName);

            if (string.IsNullOrEmpty(basePath) || string.IsNullOrEmpty(baseName))
            {
                return(new ImageHolder());
            }

            result.FileName = $"{Path.Combine(basePath, baseName)}_{number:00000}.png";
            var imgSize = new SizeF();

            var styleFontStyle = FontStyle.Regular;

            if (style.Bold)
            {
                styleFontStyle = styleFontStyle | FontStyle.Bold;
            }
            if (style.Italic)
            {
                styleFontStyle = styleFontStyle | FontStyle.Italic;
            }

            var styleFont    = new Font(style.FontName, style.FontSize, styleFontStyle, GraphicsUnit.Point);
            var stringFormat = new StringFormat();

            var lineSizes = new List <SizeF>();

            var rawText = Regex.Replace(caption.Text, "</*?(?:i|b)>", "", RegexOptions.Singleline | RegexOptions.Multiline);

            var rawTextLines = rawText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (var rawTextLine in rawTextLines)
            {
                using (var rawLinePath = new GraphicsPath())
                {
                    rawLinePath.AddString(rawTextLine, styleFont.FontFamily, (int)styleFontStyle,
                                          styleFont.SizeInPoints, new PointF(), stringFormat);
                    lineSizes.Add(rawLinePath.GetBounds().Size);
                }
            }

            var textLines = caption.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var lastLineBreak = 0f;

            foreach (var lineSize in lineSizes)
            {
                imgSize.Height += lineSize.Height;
                lastLineBreak   = lineSize.Height / 3;
                imgSize.Height += lastLineBreak;
                if (lineSize.Width > imgSize.Width)
                {
                    imgSize.Width = lineSize.Width;
                }
            }
            imgSize.Height -= lastLineBreak;

            if (imgSize.IsEmpty)
            {
                return(new ImageHolder());
            }
            stringFormat.SetMeasurableCharacterRanges(new[] { new CharacterRange(0, 1) });

            RectangleF whiteSpace;

            using (Image img = new Bitmap((int)imgSize.Width, (int)imgSize.Height, PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(img))
                {
                    var origin   = new RectangleF(new PointF(0f, 0f), imgSize);
                    var regions2 = g.MeasureCharacterRanges(" .", styleFont, origin, stringFormat);
                    if (!regions2.Any())
                    {
                        return(new ImageHolder());
                    }

                    whiteSpace = regions2[0].GetBounds(g);
                }
            }

            var wordpath       = new GraphicsPath();
            var wordPathShadow = new GraphicsPath();

            var shadowOffset = style.Shadow;

            var wStart = new RectangleF {
                Y = 0, X = 0
            };
            var wStartShadow = wStart;

            wStartShadow.Offset(shadowOffset, shadowOffset);

            for (var i = 0; i < textLines.Length; i++)
            {
                var textLine = textLines[i];
                var lineSize = lineSizes[i];
                wStart.Offset(imgSize.Width / 2 - lineSize.Width / 2, 0);
                wStartShadow.Offset(imgSize.Width / 2 - lineSize.Width / 2, 0);

                var words = textLine.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var word in words)
                {
                    using (GraphicsPath singleWord = new GraphicsPath(),
                           singleWordShadow = new GraphicsPath())
                    {
                        string lWord;
                        var    fontStyle = GetStyleFont(word, out lWord, styleFontStyle);
                        if (string.IsNullOrEmpty(lWord))
                        {
                            continue;
                        }

                        singleWord.AddString(lWord, styleFont.FontFamily, (int)fontStyle, styleFont.SizeInPoints,
                                             wStart.Location, stringFormat);
                        singleWordShadow.AddString(lWord, styleFont.FontFamily, (int)fontStyle,
                                                   styleFont.SizeInPoints, wStartShadow.Location, stringFormat);
                        wordpath.AddPath(singleWord, false);
                        wordPathShadow.AddPath(singleWordShadow, false);
                        wStart.Offset(singleWord.GetBounds().Size.Width + whiteSpace.Size.Width, 0);
                        wStartShadow.Offset(singleWordShadow.GetBounds().Size.Width + whiteSpace.Size.Width, 0);
                    }
                }
                wStart.X = 0;
                wStart.Offset(0, lineSize.Height + lineSize.Height / 3);
                wStartShadow.X = shadowOffset;
                wStartShadow.Offset(0, lineSize.Height + lineSize.Height / 3);
            }

            imgSize.Width  = wordPathShadow.GetBounds().Right;
            imgSize.Height = wordPathShadow.GetBounds().Bottom;

            using (Image img = new Bitmap((int)imgSize.Width + style.MarginL + style.MarginR, (int)imgSize.Height + style.MarginV * 2, PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(img))
                {
                    g.CompositingMode    = CompositingMode.SourceOver;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.TextRenderingHint  = TextRenderingHint.AntiAlias;
                    g.SmoothingMode      = SmoothingMode.HighQuality;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.InterpolationMode  = InterpolationMode.High;

                    Brush primBrush   = new SolidBrush(style.PrimaryColor);
                    Brush shadowBrush = new SolidBrush(Color.FromArgb(64, style.BackColor));

                    var outPen = new Pen(style.OutlineColor)
                    {
                        Alignment = PenAlignment.Outset
                    };

                    if (style.BorderStyle == 1)
                    {
                        outPen.Width  = style.Outline == 0 && style.Shadow > 0 ? 1 : style.Outline;
                        style.Outline = (int)outPen.Width;
                    }
                    g.FillRectangle(Brushes.Transparent, 0, 0, img.Width, img.Height);

                    // draw shadow
                    if (style.BorderStyle == 1 && style.Shadow > 0)
                    {
                        g.FillPath(shadowBrush, wordPathShadow);
                    }

                    g.FillPath(primBrush, wordpath);

                    // draw outline
                    if (style.BorderStyle == 1 && style.Outline > 0)
                    {
                        g.DrawPath(outPen, wordpath);
                    }
                }

                img.Save(result.FileName, ImageFormat.Png);
                result.FileName = Path.GetFileName(result.FileName);
                result.Height   = img.Height;
                result.Width    = img.Width;
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read subtitle file
        /// </summary>
        /// <param name="fileName">Textfile</param>
        /// <returns>parsed <see cref="TextSubtitle"/></returns>
        public static TextSubtitle ReadFile(string fileName)
        {
            var result = new TextSubtitle();

            if (!File.Exists(fileName))
            {
                Log.Debug($"File \"{fileName}\" doesn't exist. Aborting file import");
                return(result);
            }

            string lines;

            using (TextReader reader = File.OpenText(fileName))
            {
                lines = reader.ReadToEnd();
            }
            if (string.IsNullOrEmpty(lines))
            {
                return(result);
            }

            var textLines = lines.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            var textCaps  = new List <string>();

            var sb = new StringBuilder();

            foreach (var line in textLines)
            {
                if (line.Trim().StartsWith("["))
                {
                    if (sb.Length > 0)
                    {
                        textCaps.Add(sb.ToString());
                        sb.Clear();
                    }
                    sb.AppendLine(line.Trim());
                }
                else
                {
                    sb.AppendLine(line.Trim());
                }
            }

            if (sb.Length > 0)
            {
                textCaps.Add(sb.ToString());
            }
            sb.Clear();

            //textCaps = lines.Split(new[] {"\r\n\r\n", "\n\n"}, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (!textCaps.Any())
            {
                return(result);
            }

            var sInfo = textCaps[0];

            if (!sInfo.Any())
            {
                return(result);
            }
            sInfo = Regex.Replace(sInfo, "^;.*$|^Title.*$", "", RegexOptions.Multiline);

            var isAdvancedScript = false;

            try
            {
                var matchAdvanced = Regex.Match(sInfo, @"^\[Script Info\].*ScriptType: v4\.00+.*$", RegexOptions.Singleline | RegexOptions.Multiline);
                var matchResults  = Regex.Match(sInfo, @"^\[Script Info\].*ScriptType: v4\.00.*$", RegexOptions.Singleline | RegexOptions.Multiline);
                if (!matchResults.Success && !matchAdvanced.Success)
                {
                    return(result);
                }
                if (matchAdvanced.Success)
                {
                    isAdvancedScript = true;
                }
            }
            catch (ArgumentException ex)
            {
                Log.Error(ex);
            }

            var setFormat = false;

            for (var i = 1; i <= textCaps.Count - 1; i++)
            {
                var section = textCaps[i];
                try
                {
                    var matchStyles = Regex.Match(section, @"^\[V4.*Styles\].*$", RegexOptions.Multiline);
                    var matchEvents = Regex.Match(section, @"^\[Events\].*$", RegexOptions.Multiline);
                    if (matchStyles.Success && !setFormat)
                    {
                        var styles = section.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                        if (styles.Length < 3)
                        {
                            return(result);
                        }
                        var formatAttribs = styles[1].Split(new[] { "," }, StringSplitOptions.None).ToList();
                        var formatValues  = styles[2].Split(new[] { "," }, StringSplitOptions.None).ToList();

                        for (var index = 0; index <= formatAttribs.Count - 1; index++)
                        {
                            var formatAttrib = formatAttribs[index].Trim();
                            var formatValue  = formatValues[index].Trim();

                            switch (formatAttrib)
                            {
                            case "Fontname":
                                result.Style.FontName = formatValue;
                                break;

                            case "Fontsize":
                                result.Style.FontSize = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "PrimaryColour":
                                result.Style.PrimaryColor = GetCorrectColor(formatValue);
                                break;

                            case "SecondaryColour":
                                result.Style.SecondaryColor = GetCorrectColor(formatValue);
                                break;

                            case "TertiaryColour":
                            case "OutlineColour":
                                result.Style.OutlineColor = GetCorrectColor(formatValue);
                                break;

                            case "BackColour":
                                result.Style.BackColor = GetCorrectColor(formatValue);
                                break;

                            case "Bold":
                                result.Style.Bold = formatValue == "-1";
                                break;

                            case "Italic":
                                result.Style.Italic = formatValue == "-1";
                                break;

                            case "Underline":
                                result.Style.Underline = formatValue == "-1";
                                break;

                            case "StrikeOut":
                                result.Style.StrikeThrough = formatValue == "-1";
                                break;

                            case "BorderStyle":
                                result.Style.BorderStyle = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "Outline":
                                result.Style.Outline = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "Shadow":
                                result.Style.Shadow = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "Alignment":
                                result.Style.Alignment = GetAlignment(formatValue, isAdvancedScript);
                                break;

                            case "MarginL":
                                result.Style.MarginL = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "MarginR":
                                result.Style.MarginR = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "MarginV":
                                result.Style.MarginV = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "Alphalevel":
                                result.Style.AlphaLevel = int.Parse(formatValue, NumberStyles.Integer);
                                break;

                            case "Encoding":
                                result.Style.Encoding = formatValue;
                                break;
                            }
                        }
                        setFormat = true;
                    }
                    else if (matchEvents.Success)
                    {
                        var events = section.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                        if (events.Length < 2)
                        {
                            return(result);
                        }
                        var eventFormat = events[1].Split(new[] { "," }, StringSplitOptions.None).ToList();

                        int startTimeRow = -1, endTimeRow = -1, textRow = -1;

                        for (var j = 0; j <= eventFormat.Count - 1; j++)
                        {
                            var label = eventFormat[j].Trim();
                            if (label.Equals("Start"))
                            {
                                startTimeRow = j;
                            }
                            else if (label.Equals("End"))
                            {
                                endTimeRow = j;
                            }
                            else if (label.Equals("Text"))
                            {
                                textRow = j;
                            }
                        }

                        if (startTimeRow < 0 || endTimeRow < 0 || textRow < 0)
                        {
                            return(result);
                        }

                        for (var j = 2; j <= events.Length - 1; j++)
                        {
                            var eventLine = events[j];
                            var eventRows = eventLine.Split(new[] { "," }, StringSplitOptions.None);
                            if (eventRows.Length < textRow + 1)
                            {
                                continue;
                            }

                            var startTime =
                                DateTime.ParseExact(eventRows[startTimeRow].Trim(), "h:mm:ss.ff", CInfo).
                                TimeOfDay;
                            var endTime =
                                DateTime.ParseExact(eventRows[endTimeRow].Trim(), "h:mm:ss.ff", CInfo).
                                TimeOfDay;
                            var text = string.Join(", ", eventRows, textRow, eventRows.Length - textRow);

                            // line break
                            text = Regex.Replace(text, @"(?:\\N|\\n)", Environment.NewLine, RegexOptions.Multiline);
                            // remove line break strategy
                            text = Regex.Replace(text, @"\\q\d*?", string.Empty, RegexOptions.Multiline);
                            // bold text
                            text = Regex.Replace(text, @"\{\\b1\}(.*?)\{\\b0*?\}", "<b>$1</b>", RegexOptions.Singleline | RegexOptions.Multiline);
                            // italic text
                            text = Regex.Replace(text, @"\{\\i1\}(.*?)\{\\i0*?\}", "<i>$1</i>", RegexOptions.Singleline | RegexOptions.Multiline);
                            // underlined text
                            text = Regex.Replace(text, @"\{\\u1\}(.*?)\{\\u0*?\}", "<u>$1</u>", RegexOptions.Singleline | RegexOptions.Multiline);
                            // strike-through text
                            text = Regex.Replace(text, @"\{\\s1\}(.*?)\{\\s0*?\}", "<s>$1</s>", RegexOptions.Singleline | RegexOptions.Multiline);

                            // remove border and shadow override
                            text = Regex.Replace(text, @"\{\\(?:bord|shad)\d*?\}", string.Empty, RegexOptions.Multiline);
                            // remove blurry text border
                            text = Regex.Replace(text, @"\{\\be(?:1|0)\}", string.Empty, RegexOptions.Multiline);
                            // remove fontname
                            text = Regex.Replace(text, @"\{\\fn.*\}", string.Empty, RegexOptions.Multiline);
                            // remove fontsize
                            text = Regex.Replace(text, @"\{\\fs.*\}", string.Empty, RegexOptions.Multiline);
                            // remove color definition
                            text = Regex.Replace(text, @"\{\\\d?c&H.*&\}", string.Empty, RegexOptions.Multiline);
                            // remove alpha definition
                            text = Regex.Replace(text, @"\{\\\d?(?:a|alpha)&H.*&\}", string.Empty, RegexOptions.Multiline);
                            // remove x/y text scaling
                            text = Regex.Replace(text, @"\{\\(?:fscy|fscx)\d+\}", string.Empty, RegexOptions.Multiline);
                            // remove text spacing
                            text = Regex.Replace(text, @"\{\\fsp\d+\}", string.Empty, RegexOptions.Multiline);
                            // remove charset definition
                            text = Regex.Replace(text, @"\{\\fe.*?\}", string.Empty, RegexOptions.Multiline);
                            // parse and remove text alignment
                            var align     = new Regex(@"\{\\an*?(\d*?)\}", RegexOptions.Multiline);
                            var alignment = GetAlignment(align.Match(text).Value, isAdvancedScript);
                            text = align.Replace(text, string.Empty);
                            // remove x/y/z text rotation
                            text = Regex.Replace(text, @"\{\\fr(?:x|y|z)??(-??\d*?)\}", string.Empty, RegexOptions.Multiline);
                            // remove karaoke formatting
                            text = Regex.Replace(text, @"\{\\(?:k|ko|kf|K)(\d*?)\}", string.Empty, RegexOptions.Multiline);
                            // remove format reset
                            text = Regex.Replace(text, @"\{\\r.*\}", string.Empty, RegexOptions.Multiline);
                            // remove text animation
                            text = Regex.Replace(text, @"\{\\(?:move|pos|t|org|fad|fade|clip)\(.*?\)\}", string.Empty, RegexOptions.Multiline);

                            // remove anything that was not catched above
                            text = Regex.Replace(text, @"\{(?:\\(?:fscy|fscx)\d+|\\fn.*|\\fs.*|\\\d?c&H.*&|\\\d?(?:a|alpha)&H.*&|\\(?:fscy|fscx)\d+|" +
                                                 @"\\fsp\d+|\\fe.*?|\\an*?(\d*?)|\\fr(?:x|y|z)??(-??\d*?)|\\(?:k|ko|kf|K)(\d*?)|\\r.*|" +
                                                 @"\\(?:move|pos|t|org|fad|fade|clip)\(.*?\)\\N|\\n|\\q\d*?|\\(?:b|i|u|s|be)(?:1|0)*?|\\(?:bord|shad)\d*?)*?\}",
                                                 string.Empty, RegexOptions.Multiline);

                            var caption = new SubCaption
                            {
                                StartTime = startTime,
                                EndTime   = endTime,
                                Text      = text,
                                Alignment = alignment
                            };
                            result.Captions.Add(caption);
                        }
                    }
                }
                catch (ArgumentException ex)
                {
                    Log.Error(ex);
                }
            }

            if (!setFormat)
            {
                result.SetDefaultStyle();
            }

            return(result);
        }