示例#1
0
        private static TimedTextElement BuildTimedTextElements(TimedTextElementBase element, RegionElement region)
        {
            TimedTextElement timedTextElement = CreateTimedTextElement(element, region);

            foreach (TimedTextElementBase c in element.Children)
            {
                TimedTextElement child = BuildTimedTextElements(c, region);
                if (child is TimedTextAnimation)
                {
#if HACK_XAMLTYPEINFO
                    var children = timedTextElement.Animations as MediaMarkerCollection <TimedTextAnimation>;
#else
                    var children = timedTextElement.Animations;
#endif
                    children.Add((TimedTextAnimation)child);
                }
                else if (timedTextElement is CaptionElement && child is CaptionElement)
                {
#if HACK_XAMLTYPEINFO
                    var children = timedTextElement.Children as MediaMarkerCollection <TimedTextElement>;
#else
                    var children = timedTextElement.Children;
#endif
                    ((CaptionElement)child).Index = children.Count;
                    children.Add((CaptionElement)child);
                }
            }

            return(timedTextElement);
        }
示例#2
0
        /// <summary>
        /// Recursively update the caption elements
        /// </summary>
        /// <param name="captionElement">the caption element</param>
        /// <param name="level">the 0-based level of the caption element</param>
        private static void UpdateElement(
            TT.TimedTextElement captionElement,
            uint level)
        {
            if (level == 0)
            {
                if (ClosedCaptionProperties.RegionColor != ClosedCaptionColor.Default || ClosedCaptionProperties.RegionOpacity != ClosedCaptionOpacity.Default)
                {
                    captionElement.Style.BackgroundColor = GetComputedColor(ClosedCaptionProperties.ComputedRegionColor, ClosedCaptionProperties.RegionOpacity);
                }
            }
            else if (level == 1)
            {
                if (ClosedCaptionProperties.BackgroundColor != ClosedCaptionColor.Default || ClosedCaptionProperties.BackgroundOpacity != ClosedCaptionOpacity.Default)
                {
                    captionElement.Style.BackgroundColor = GetComputedColor(ClosedCaptionProperties.ComputedBackgroundColor, ClosedCaptionProperties.BackgroundOpacity);
                }
            }

            if (ClosedCaptionProperties.FontColor != ClosedCaptionColor.Default || ClosedCaptionProperties.FontOpacity != ClosedCaptionOpacity.Default)
            {
                captionElement.Style.Color = GetComputedColor(ClosedCaptionProperties.ComputedFontColor, ClosedCaptionProperties.FontOpacity);
            }

            if (ClosedCaptionProperties.FontSize != ClosedCaptionSize.Default)
            {
                captionElement.Style.FontSize = new TT.Length
                {
                    Unit  = captionElement.Style.FontSize.Unit,
                    Value = GetComputedFontPercent(ClosedCaptionProperties.FontSize) * captionElement.Style.FontSize.Value
                };
            }

            var fontFamily = GetFontFamily();

            if (fontFamily != null)
            {
                captionElement.Style.FontFamily = fontFamily;

#if WINDOWS_PHONE
                if (userSettings.FontFamily == FontFamily.Cursive)
                {
                    captionElement.Style.FontStyle = System.Windows.FontStyles.Italic;
                }
#endif
            }

            ApplyFontStyle(captionElement);

            var children = captionElement.Children as TT.MediaMarkerCollection <TT.TimedTextElement>;

            if (children != null)
            {
                foreach (var child in children)
                {
                    UpdateElement(child, level + 1);
                }
            }
        }
示例#3
0
        private void HideCaption(TimedTextElement timedTextElement)
        {
            var caption = timedTextElement as CaptionElement;

            if (caption != null && _activeElements.ContainsKey(caption))
            {
                CaptionsPanel.Children.Remove(_activeElements[caption]);
                _activeElements.Remove(caption);
            }
        }
示例#4
0
        private void ShowCaption(TimedTextElement timedTextElement)
        {
            var caption = timedTextElement as CaptionElement;

            if (caption != null)
            {
                caption.CalculateCurrentStyle(_mediaPosition);
                var uiElement = RenderElement(caption);
                if (uiElement != null)
                {
                    if (_activeElements.ContainsKey(caption))
                    {
                        HideCaption(timedTextElement);
                    }
                    _activeElements.Add(caption, uiElement);
                    CaptionsPanel.Children.Clear();
                    _activeElements.OrderBy(i => i.Key.Index)
                    .ForEach(i => CaptionsPanel.Children.Add(i.Value));
                }
            }
        }
示例#5
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);
        }
        /// <summary>
        /// Apply the font style
        /// </summary>
        /// <param name="captionElement">the caption element</param>
        /// <param name="userSettings">the user settings</param>
        private static void ApplyFontStyle(TimedTextElement captionElement, CustomCaptionSettings userSettings)
        {
            var outlineWidth = 1.0;

            if (userSettings.FontSize.HasValue)
            {
                outlineWidth = System.Convert.ToDouble(userSettings.FontSize.Value) / 100.0;
            }

            var outlineColor = Media.Colors.Black;

            if (userSettings.FontColor != null)
            {
                outlineColor = Media.Color.FromArgb(255, 0, 0, 0);
            }

            switch (userSettings.FontStyle)
            {
                case FontStyle.Default:
                    captionElement.Style.TextStyle = TextStyle.Default;

                    // Todo: look at code for calculation of OutlineWidth and OutlineBlur
                    captionElement.Style.OutlineWidth = new Length { Value = outlineWidth, Unit = LengthUnit.Pixel };
                    captionElement.Style.OutlineColor = outlineColor;
                    break;

                case FontStyle.DepressedEdge:
                    captionElement.Style.TextStyle = TextStyle.DepressedEdge;
                    captionElement.Style.OutlineColor = outlineColor;
                    captionElement.Style.OutlineWidth = new Length { Value = outlineWidth, Unit = LengthUnit.Pixel };
                    break;

                case FontStyle.DropShadow:
                    captionElement.Style.TextStyle = TextStyle.DropShadow;

                    // Todo: look at code for calculation of OutlineWidth and OutlineBlur
                    captionElement.Style.OutlineColor = outlineColor;
                    captionElement.Style.OutlineWidth = new Length { Value = outlineWidth, Unit = LengthUnit.Pixel };
                    break;

                case FontStyle.None:
                    captionElement.Style.TextStyle = TextStyle.None;
                    break;

                case FontStyle.Outline:
                    captionElement.Style.TextStyle = TextStyle.Outline;
                    captionElement.Style.OutlineWidth = new Length { Value = outlineWidth, Unit = LengthUnit.Pixel };
                    captionElement.Style.OutlineColor = outlineColor;
                    break;

                case FontStyle.RaisedEdge:
                    captionElement.Style.TextStyle = TextStyle.RaisedEdge;
                    captionElement.Style.OutlineWidth = new Length { Value = outlineWidth, Unit = LengthUnit.Pixel };
                    captionElement.Style.OutlineColor = outlineColor;
                    break;
            }
        }
        /// <summary>
        /// Recursively update the caption elements
        /// </summary>
        /// <param name="captionElement">the caption element</param>
        /// <param name="userSettings">the user settings</param>
        /// <param name="level">the 0-based level of the caption element</param>
        private static void UpdateElement(
            TimedTextElement captionElement,
            CustomCaptionSettings userSettings,
            uint level)
        {
            if (level == 0)
            {
                if (userSettings.WindowColor != null)
                {
                    captionElement.Style.BackgroundColor = userSettings.WindowColor.ToColor();
                }
            }
            else if (level == 1)
            {
                if (userSettings.BackgroundColor != null)
                {
                    captionElement.Style.BackgroundColor = userSettings.BackgroundColor.ToColor();
                }
            }

            if (userSettings.FontColor != null)
            {
                captionElement.Style.Color = userSettings.FontColor.ToColor();
            }

            if (userSettings.FontSize.HasValue)
            {
                captionElement.Style.FontSize = new Length
                {
                    Unit = captionElement.Style.FontSize.Unit,
                    Value = System.Convert.ToDouble(userSettings.FontSize.Value) * captionElement.Style.FontSize.Value / 100.0
                };
            }

            var fontFamily = GetFontFamily(userSettings);

            if (fontFamily != null)
            {
                captionElement.Style.FontFamily = fontFamily;

#if WINDOWS_PHONE
                if (userSettings.FontFamily == FontFamily.Cursive)
                {
                    captionElement.Style.FontStyle = System.Windows.FontStyles.Italic;
                }
#endif
            }

            ApplyFontStyle(captionElement, userSettings);

            var children = captionElement.Children as MediaMarkerCollection<TimedTextElement>;

            if (children != null)
            {
                foreach (var child in children)
                {
                    UpdateElement(child, userSettings, level + 1);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Apply the font style
        /// </summary>
        /// <param name="captionElement">the caption element</param>
        private static void ApplyFontStyle(TT.TimedTextElement captionElement)
        {
            var outlineWidth = 1.0;

            if (ClosedCaptionProperties.FontSize != ClosedCaptionSize.Default)
            {
                outlineWidth = GetComputedFontPercent(ClosedCaptionProperties.FontSize);
            }

            var outlineColor = Colors.Black;

            if (ClosedCaptionProperties.FontColor != ClosedCaptionColor.Default)
            {
                outlineColor = Color.FromArgb(255, 0, 0, 0);
            }

            switch (ClosedCaptionProperties.FontEffect)
            {
            case ClosedCaptionEdgeEffect.Default:
                captionElement.Style.TextStyle = TT.TextStyle.Default;

                // Todo: look at code for calculation of OutlineWidth and OutlineBlur
                captionElement.Style.OutlineWidth = new TT.Length {
                    Value = outlineWidth, Unit = TT.LengthUnit.Pixel
                };
                captionElement.Style.OutlineColor = outlineColor;
                break;

            case ClosedCaptionEdgeEffect.Depressed:
                captionElement.Style.TextStyle    = TT.TextStyle.DepressedEdge;
                captionElement.Style.OutlineColor = outlineColor;
                captionElement.Style.OutlineWidth = new TT.Length {
                    Value = outlineWidth, Unit = TT.LengthUnit.Pixel
                };
                break;

            case ClosedCaptionEdgeEffect.DropShadow:
                captionElement.Style.TextStyle = TT.TextStyle.DropShadow;

                // Todo: look at code for calculation of OutlineWidth and OutlineBlur
                captionElement.Style.OutlineColor = outlineColor;
                captionElement.Style.OutlineWidth = new TT.Length {
                    Value = outlineWidth, Unit = TT.LengthUnit.Pixel
                };
                break;

            case ClosedCaptionEdgeEffect.None:
                captionElement.Style.TextStyle = TT.TextStyle.None;
                break;

            case ClosedCaptionEdgeEffect.Uniform:
                captionElement.Style.TextStyle    = TT.TextStyle.Outline;
                captionElement.Style.OutlineWidth = new TT.Length {
                    Value = outlineWidth, Unit = TT.LengthUnit.Pixel
                };
                captionElement.Style.OutlineColor = outlineColor;
                break;

            case ClosedCaptionEdgeEffect.Raised:
                captionElement.Style.TextStyle    = TT.TextStyle.RaisedEdge;
                captionElement.Style.OutlineWidth = new TT.Length {
                    Value = outlineWidth, Unit = TT.LengthUnit.Pixel
                };
                captionElement.Style.OutlineColor = outlineColor;
                break;
            }
        }
        private void HideCaption(TimedTextElement timedTextElement)
        {
            var caption = timedTextElement as CaptionElement;

            if (caption != null && _activeElements.ContainsKey(caption))
            {
                CaptionsPanel.Children.Remove(_activeElements[caption]);
                _activeElements.Remove(caption);
            }
        }
 private void ShowCaption(TimedTextElement timedTextElement)
 {
     var caption = timedTextElement as CaptionElement;
     if (caption != null)
     {
         caption.CalculateCurrentStyle(_mediaPosition);
         var uiElement = RenderElement(caption);
         if (uiElement != null)
         {
             if (_activeElements.ContainsKey(caption))
             {
                 HideCaption(timedTextElement);
             }
             _activeElements.Add(caption, uiElement);
             CaptionsPanel.Children.Clear();
             _activeElements.OrderBy(i => i.Key.Index)
                            .ForEach(i => CaptionsPanel.Children.Add(i.Value));
         }
     }
 }
 void _captionManager_MarkerReached(IMarkerManager<TimedTextElement> sender, TimedTextElement marker)
 {
     _mediaPosition = marker.Begin;
     ShowCaption(marker);
 }
 void _captionManager_MarkerLeft(IMarkerManager<TimedTextElement> sender, TimedTextElement marker)
 {
     _mediaPosition = marker.End;
     HideCaption(marker);
 }
示例#13
0
 void _captionManager_MarkerReached(IMarkerManager <TimedTextElement> sender, TimedTextElement marker)
 {
     _mediaPosition = marker.Begin;
     ShowCaption(marker);
 }
示例#14
0
 void _captionManager_MarkerLeft(IMarkerManager <TimedTextElement> sender, TimedTextElement marker)
 {
     _mediaPosition = marker.End;
     HideCaption(marker);
 }