Example #1
0
        private static TimedTextElement CreateTimedTextElement(TimedTextElementBase element, RegionElement region)
        {
            var captionElement = element is SetElement
                                    ? (TimedTextElement)BuildCaptionAnimationElement(element)
                                    : new CaptionElement();

            var endTime = element.End.TotalSeconds >= TimeSpan.MaxValue.TotalSeconds
                ? TimeSpan.MaxValue
                : TimeSpan.FromSeconds(element.End.TotalSeconds);

            captionElement.End   = endTime;
            captionElement.Begin = TimeSpan.FromSeconds(element.Begin.TotalSeconds);

            if (element is BrElement)
            {
                captionElement.CaptionElementType = TimedTextElementType.LineBreak;
            }
            else if (element is AnonymousSpanElement)
            {
                var span = element as AnonymousSpanElement;
                captionElement.CaptionElementType = TimedTextElementType.Text;
                captionElement.Content            = HttpUtility.HtmlDecode(span.Text);
                captionElement.Style = TimedTextStyleParser.MapStyle(element, region);
            }
            else if (!(element is SetElement))
            {
                captionElement.CaptionElementType = TimedTextElementType.Container;
                captionElement.Style = TimedTextStyleParser.MapStyle(element, region);
            }

            return(captionElement);
        }
Example #2
0
        private static TimedTextAnimation BuildCaptionAnimationElement(TimedTextElementBase element)
        {
            var propertyName = element.Attributes
                               .Where(i => TimedTextStyleParser.IsValidAnimationPropertyName(i.LocalName))
                               .Select(i => i.LocalName)
                               .FirstOrDefault();

            return(!propertyName.IsNullOrWhiteSpace()
                    ? new TimedTextAnimation
            {
                CaptionElementType = TimedTextElementType.Animation,
                PropertyName = propertyName,
                Style = TimedTextStyleParser.MapStyle(element, null)
            }
                    : null);
        }
Example #3
0
        private static CaptionRegion MapToCaptionRegion(RegionElement regionElement)
        {
            var endTime = regionElement.End.TotalSeconds >= TimeSpan.MaxValue.TotalSeconds
                            ? TimeSpan.MaxValue
                            : TimeSpan.FromSeconds(regionElement.End.TotalSeconds);

            var captionRegion = new CaptionRegion
            {
                Id           = regionElement.Id,
                Begin        = TimeSpan.FromSeconds(regionElement.Begin.TotalSeconds),
                End          = endTime,
                Style        = TimedTextStyleParser.MapStyle(regionElement, null),
                TunneledData = regionElement.Root.Images.ToDictionary(ie => ie.Key, ie => new TunneledData()
                {
                    Data = ie.Value.Data, Encoding = ie.Value.Encoding, MimeType = ie.Value.ImageType
                })
            };



            foreach (TimedTextElementBase element in regionElement.Children)
            {
                TimedTextElement child = BuildTimedTextElements(element, null);
                if (child != null && child.CaptionElementType == TimedTextElementType.Animation)
                {
#if HACK_XAMLTYPEINFO
                    var children = captionRegion.Animations as MediaMarkerCollection <TimedTextAnimation>;
#else
                    var children = captionRegion.Animations;
#endif
                    children.Add(child as TimedTextAnimation);
                }
            }

            return(captionRegion);
        }