public TimedTextElement()
 {
     Type       = "captionelement";
     Style      = new TimedTextStyle();
     Animations = new MediaMarkerCollection <TimedTextAnimation>();
     Children   = new MediaMarkerCollection <TimedTextElement>();
 }
 public TimedTextElement()
 {
     Type = "captionelement";
     Style = new TimedTextStyle();
     Animations = new MediaMarkerCollection<TimedTextAnimation>();
     Children = new MediaMarkerCollection<TimedTextElement>();
 }
        internal static Style MapStyle(TimedTextElementBase styleElement, RegionElement region)
        {
            var style = new Style();

            if (styleElement.Id != null)
            {
                style.Id = styleElement.Id;
            }


            var backgroundColor =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.BackgroundColor.LocalName, region)
                as Color?;

            style.BackgroundColor = backgroundColor.GetValueOrDefault(DefaultStyle.BackgroundColor);

            var color =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Color.LocalName, region) as Color?;

            style.Color = color.GetValueOrDefault(DefaultStyle.Color);

            var extent =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Extent.LocalName, region) as
                TimedTextExtent;

            if (extent != null)
            {
                Length height = new Length {
                    Value = extent.Height, Unit = FromUnit(extent.UnitMeasureVertical)
                };
                Length width = new Length {
                    Value = extent.Width, Unit = FromUnit(extent.UnitMeasureHorizontal)
                };
                style.Extent = new Extent {
                    Height = height, Width = width
                };
            }
            else
            {
                style.Extent = DefaultStyle.Extent;
            }

            var fontFamily =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.FontFamily.LocalName, region) as
                string;

            style.FontFamily = !fontFamily.IsNullOrWhiteSpace()
                                   ? new FontFamily(fontFamily)
                                   : DefaultStyle.FontFamily;

            object oFontSize = styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.FontSize.LocalName,
                                                             region);
            var fontSize = oFontSize as string;

            if (!fontSize.IsNullOrWhiteSpace())
            {
                var parsedFontSize = GetNumberPair(fontSize);
                style.FontSize = new Length
                {
                    Unit  = FromUnit(parsedFontSize.UnitMeasureHorizontal),
                    Value = parsedFontSize.First
                };
            }

            var fontStyle =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.FontStyle.LocalName, region) as
                FontStyleAttributeValue?;

            style.FontStyle = fontStyle.HasValue &&
                              (fontStyle.Value == FontStyleAttributeValue.Italic ||
                               fontStyle.Value == FontStyleAttributeValue.Oblique ||
                               fontStyle.Value == FontStyleAttributeValue.ReverseOblique)
                                  ? FontStyles.Italic
                                  : DefaultStyle.FontStyle;

            var fontWeight =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.FontWeight.LocalName, region) as
                FontWeightAttributeValue?;

            style.FontWeight = fontWeight.HasValue && fontWeight.Value == FontWeightAttributeValue.Bold
                                   ? FontWeights.Bold
                                   : DefaultStyle.FontWeight;

            var lineHeight =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.LineHeight.LocalName, region) as
                LineHeight;

            style.LineHeight = lineHeight != null && !(lineHeight is NormalHeight)
                                   ? new Length
            {
                Unit  = FromUnit(lineHeight.UnitMeasureVertical),
                Value = lineHeight.Height
            }
                                   : null;


            var textOutline = styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.TextOutline.LocalName, region) as TextOutline;

            style.OutlineBlur = new Length
            {
                Unit  = FromUnit(textOutline.UnitMeasureBlur),
                Value = textOutline.Blur
            };
            style.OutlineWidth = new Length
            {
                Unit  = FromUnit(textOutline.UnitMeasureWidth),
                Value = textOutline.Width
            };
            style.OutlineColor = textOutline.StrokeColor;

            var opacity =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Opacity.LocalName, region) as
                double?;

            style.Opacity = opacity.HasValue
                                ? opacity.Value
                                : DefaultStyle.Opacity;

            var origin =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Origin.LocalName, region) as
                TimedTextOrigin;

            style.Origin = origin != null
                               ? new Origin
            {
                Left = new Length
                {
                    Unit =
                        FromUnit(origin.UnitMeasureHorizontal),
                    Value = origin.X
                },
                Top = new Length
                {
                    Unit  = FromUnit(origin.UnitMeasureVertical),
                    Value = origin.Y
                }
            }
                               : DefaultStyle.Origin;

            var overflow =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Overflow.LocalName, region) as
                string;
            Overflow parsedOverflow;

            style.Overflow = overflow.EnumTryParse(true, out parsedOverflow)
                                 ? parsedOverflow
                                 : DefaultStyle.Overflow;

            var padding =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Padding.LocalName, region) as
                PaddingThickness;

            style.Padding = padding != null
                                ? new Padding
            {
                Left = new Length
                {
                    Unit  = FromUnit(padding.WidthStartUnit),
                    Value = padding.WidthStart
                },
                Right = new Length
                {
                    Unit  = FromUnit(padding.WidthEndUnit),
                    Value = padding.WidthEnd
                },
                Top = new Length
                {
                    Unit  = FromUnit(padding.WidthBeforeUnit),
                    Value = padding.WidthBefore
                },
                Bottom = new Length
                {
                    Unit  = FromUnit(padding.WidthAfterUnit),
                    Value = padding.WidthAfter
                }
            }
                                : DefaultStyle.Padding;

            var textAlign =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.TextAlign.LocalName, region) as
                string;
            TextAlignment parsedTextAlign;

            if (textAlign == "start")
            {
                textAlign = "left";
            }
            else if (textAlign == "end")
            {
                textAlign = "right";
            }
            style.TextAlign = textAlign.EnumTryParse(true, out parsedTextAlign)
                                  ? parsedTextAlign
                                  : DefaultStyle.TextAlign;

            var direction =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Direction.LocalName, region) as
                string;

            style.Direction = direction == "rtl" ? Direction.RightToLeft : Direction.LeftToRight;

            var displayAlign =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.DisplayAlign.LocalName, region) as
                string;
            DisplayAlign parsedDisplayAlign;

            style.DisplayAlign = displayAlign.EnumTryParse(true, out parsedDisplayAlign)
                                     ? parsedDisplayAlign
                                     : DefaultStyle.DisplayAlign;

            var visibility =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Visibility.LocalName, region) as
                string;

            style.Visibility = !visibility.IsNullOrWhiteSpace() &&
                               visibility.Equals("hidden", StringComparison.CurrentCultureIgnoreCase)
                                   ? Visibility.Collapsed
                                   : DefaultStyle.Visibility;

            var display =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.Display.LocalName, region) as
                string;

            style.Display = !display.IsNullOrWhiteSpace() &&
                            display.Equals("none", StringComparison.CurrentCultureIgnoreCase)
                                ? Visibility.Collapsed
                                : DefaultStyle.Display;

            var wrapOption =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.WrapOption.LocalName, region) as
                string;
            TextWrapping parsedWrapOption;

            style.WrapOption = wrapOption.EnumTryParse(true, out parsedWrapOption)
                                   ? parsedWrapOption
                                   : DefaultStyle.WrapOption;

            var showBackground =
                styleElement.GetComputedStyle(TimedTextVocabulary.Attributes.Styling.ShowBackground.LocalName, region)
                as string;
            ShowBackground parsedShowBackground;

            style.ShowBackground = showBackground.EnumTryParse(true, out parsedShowBackground)
                                       ? parsedShowBackground
                                       : DefaultStyle.ShowBackground;

            object zindex = styleElement.GetComputedStyle("zIndex", null);

            try
            {
                if (zindex is string == false)
                {
                    var tmp = (double)zindex;
                    style.ZIndex = (int)tmp;
                }
                else
                {
                    style.ZIndex = 0;
                }
            }
            catch
            {
                style.ZIndex = 0;
            }
            return(style);
        }
 private Grid ApplyDropShadowEdge(TimedTextStyle style, double panelWidth, double height, string text, TextBlock textblock)
 {
     Grid grid = new Grid();
     TextBlock block = this.GetStyledTextblock(style, panelWidth, height, true);
     this.SetContent(block, text);
     grid.Children.Add(block);
     double num = block.FontSize * 0.06;
     TranslateTransform transform = new TranslateTransform {
         X = num,
         Y = num
     };
     block.RenderTransform = transform;
     grid.Children.Add(textblock);
     return grid;
 }
 private Grid ApplyDepressedEdge(TimedTextStyle style, double panelWidth, double height, string text, TextBlock textblock)
 {
     return this.ApplyEdge(style, panelWidth, height, text, textblock, 1.0, 1.0, 1.0);
 }
 private TextBlock GetStyledTextblock(TimedTextStyle style, double width, double height, bool fOutline)
 {
     TextBlock block = new TextBlock {
         FontStyle = style.FontStyle,
         FontWeight = style.FontWeight,
         VerticalAlignment = VerticalAlignment.Bottom,
         FontFamily = style.FontFamily
     };
     if (!double.IsNaN(height) && (height != 0.0))
     {
         if ((this.CaptionsOverrideSettings != null) && (this.CaptionsOverrideSettings.CharacterSize != CaptionsOverrideSizes.pct100))
         {
             Length length = new Length {
                 Unit = style.FontSize.Unit,
                 Value = style.FontSize.Value * (((double) this.CaptionsOverrideSettings.CharacterSize.ToPercentage()) / 100.0)
             };
             block.FontSize = Math.Round(length.ToPixelLength(height));
         }
         else
         {
             block.FontSize = Math.Round(style.FontSize.ToPixelLength(height));
         }
     }
     block.Foreground = GetCachedBrush(fOutline ? style.OutlineColor : style.Color);
     block.TextAlignment = style.TextAlign;
     return block;
 }
 private Grid ApplyEdge(TimedTextStyle style, double panelWidth, double height, string text, TextBlock textblock, double size, double offsetX, double offsetY)
 {
     Grid grid = new Grid();
     TextBlock block = this.GetStyledTextblock(style, panelWidth, height, true);
     this.SetContent(block, text);
     grid.Children.Add(block);
     TranslateTransform transform = new TranslateTransform {
         X = -size + offsetX,
         Y = -size + offsetY
     };
     block.RenderTransform = transform;
     block = this.GetStyledTextblock(style, panelWidth, height, true);
     this.SetContent(block, text);
     grid.Children.Add(block);
     TranslateTransform transform2 = new TranslateTransform {
         X = size + offsetX,
         Y = size + offsetY
     };
     block.RenderTransform = transform2;
     block = this.GetStyledTextblock(style, panelWidth, height, true);
     this.SetContent(block, text);
     grid.Children.Add(block);
     TranslateTransform transform3 = new TranslateTransform {
         X = size + offsetX,
         Y = -size + offsetY
     };
     block.RenderTransform = transform3;
     block = this.GetStyledTextblock(style, panelWidth, height, true);
     this.SetContent(block, text);
     grid.Children.Add(block);
     TranslateTransform transform4 = new TranslateTransform {
         X = -size + offsetX,
         Y = size + offsetY
     };
     block.RenderTransform = transform4;
     grid.Children.Add(textblock);
     return grid;
 }
 private TextBlock GetStyledTextblock(TimedTextStyle style, double width, double height, bool fOutline)
 {
     TextBlock textblock = new TextBlock();
     //textblock.Width = width;
     textblock.FontStyle = style.FontStyle;
     textblock.FontWeight = style.FontWeight;
     textblock.VerticalAlignment = VerticalAlignment.Bottom;
     textblock.FontFamily = style.FontFamily;
     if (!double.IsNaN(height) && height != 0)
     {
         textblock.FontSize = Math.Round(style.FontSize.ToPixelLength(height));
     }
     textblock.Foreground = GetCachedBrush(fOutline ? style.OutlineColor : style.Color);
     textblock.Opacity = style.Visibility == Visibility.Visible
                             ? style.Opacity
                             : 0;
     //textblock.TextWrapping = style.WrapOption;
     textblock.TextAlignment = style.TextAlign;
     return textblock;
 }