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) }; foreach (TimedTextElementBase element in regionElement.Children) { TimedTextElement child = BuildTimedTextElements(element, null); if (child != null && child.CaptionElementType == TimedTextElementType.Animation) { captionRegion.Animations.Add(child as TimedTextAnimation); } } return(captionRegion); }
/// <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); } } }
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 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) { timedTextElement.Animations.Add((TimedTextAnimation)child); } else if (timedTextElement is CaptionElement && child is CaptionElement) { ((CaptionElement)child).Index = timedTextElement.Children.Count; timedTextElement.Children.Add((CaptionElement)child); } } return(timedTextElement); }
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)); } } }
/// <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; } }