public TimedTextProperties(Subtitle subtitle)
        {
            InitializeComponent();
            Application.DoEvents();

            _subtitle = subtitle;
            _NA       = "[" + Configuration.Settings.Language.General.NotAvailable + "]";
            comboBoxDropMode.Items[0] = _NA;
            comboBoxTimeBase.Items[0] = _NA;
            comboBoxDefaultStyle.Items.Add(_NA);
            comboBoxDefaultRegion.Items.Add(_NA);

            _xml = new XmlDocument();
            try
            {
                _xml.LoadXml(subtitle.Header);
            }
            catch
            {
                subtitle.Header = new TimedText10().ToText(new Subtitle(), "tt");
                _xml.LoadXml(subtitle.Header); // load default xml
            }
            _nsmgr = new XmlNamespaceManager(_xml.NameTable);
            _nsmgr.AddNamespace("ttml", "http://www.w3.org/ns/ttml");

            XmlNode node = _xml.DocumentElement.SelectSingleNode("ttml:head/ttml:metadata/ttml:title", _nsmgr);

            if (node != null)
            {
                textBoxTitle.Text = node.InnerText;
            }

            node = _xml.DocumentElement.SelectSingleNode("ttml:head/ttml:metadata/ttml:desc", _nsmgr);
            if (node != null)
            {
                textBoxDescription.Text = node.InnerText;
            }

            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                comboBoxLanguage.Items.Add(ci.Name);
            }
            XmlAttribute attr = _xml.DocumentElement.Attributes["xml:lang"];

            if (attr != null)
            {
                comboBoxLanguage.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:timeBase"];
            if (attr != null)
            {
                comboBoxTimeBase.Text = attr.InnerText;
            }

            comboBoxFrameRate.Items.Add("23.976");
            comboBoxFrameRate.Items.Add("24.0");
            comboBoxFrameRate.Items.Add("25.0");
            comboBoxFrameRate.Items.Add("29.97");
            comboBoxFrameRate.Items.Add("30.0");
            attr = _xml.DocumentElement.Attributes["ttp:frameRate"];
            if (attr != null)
            {
                comboBoxFrameRate.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:frameRateMultiplier"];
            if (attr != null)
            {
                comboBoxFrameRateMultiplier.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:dropMode"];
            if (attr != null)
            {
                comboBoxDropMode.Text = attr.InnerText;
            }

            foreach (string style in TimedText10.GetStylesFromHeader(_subtitle.Header))
            {
                comboBoxDefaultStyle.Items.Add(style);
                node = _xml.DocumentElement.SelectSingleNode("ttml:body", _nsmgr);
                if (node != null && node.Attributes["style"] != null && style == node.Attributes["style"].Value)
                {
                    comboBoxDefaultStyle.SelectedIndex = comboBoxDefaultStyle.Items.Count - 1;
                }
            }
            foreach (string region in TimedText10.GetRegionsFromHeader(_subtitle.Header))
            {
                comboBoxDefaultRegion.Items.Add(region);
                node = _xml.DocumentElement.SelectSingleNode("ttml:body", _nsmgr);
                if (node != null && node.Attributes["region"] != null && region == node.Attributes["region"].Value)
                {
                    comboBoxDefaultRegion.SelectedIndex = comboBoxDefaultRegion.Items.Count - 1;
                }
            }

            var timeCodeFormat = Configuration.Settings.SubtitleSettings.TimedText10TimeCodeFormat.Trim().ToLowerInvariant();

            comboBoxTimeCodeFormat.SelectedIndex = 0;
            for (int index = 0; index < comboBoxTimeCodeFormat.Items.Count; index++)
            {
                var item = comboBoxTimeCodeFormat.Items[index];
                if (item.ToString().ToLowerInvariant() == timeCodeFormat)
                {
                    comboBoxTimeCodeFormat.SelectedIndex = index;
                    return;
                }
            }
        }
Esempio n. 2
0
 private void AddStyleToXml(string name, string fontFamily, string fontWeight, string fontStyle, string color, string fontSize)
 {
     TimedText10.AddStyleToXml(_xml, _xmlHead, _nsmgr, name, fontFamily, fontWeight, fontStyle, color, fontSize);
 }
Esempio n. 3
0
        public TimedTextPropertiesItunes(Subtitle subtitle)
        {
            UiUtil.PreInitialize(this);
            InitializeComponent();
            UiUtil.FixFonts(this);
            Application.DoEvents();

            _subtitle = subtitle;
            var notAvailable = "[" + LanguageSettings.Current.General.NotAvailable + "]";

            comboBoxDropMode.Items[0] = notAvailable;
            comboBoxTimeBase.Items[0] = notAvailable;
            comboBoxDefaultStyle.Items.Add(notAvailable);
            comboBoxDefaultRegion.Items.Add(notAvailable);

            _xml = new XmlDocument();
            try
            {
                _xml.LoadXml(subtitle.Header);
            }
            catch
            {
                subtitle.Header = new TimedText10().ToText(new Subtitle(), "tt");
                _xml.LoadXml(subtitle.Header); // load default xml
            }
            _namespaceManager = new XmlNamespaceManager(_xml.NameTable);
            _namespaceManager.AddNamespace("ttml", TimedText10.TtmlNamespace);
            _namespaceManager.AddNamespace("ttp", TimedText10.TtmlParameterNamespace);
            _namespaceManager.AddNamespace("tts", TimedText10.TtmlStylingNamespace);
            _namespaceManager.AddNamespace("ttm", TimedText10.TtmlMetadataNamespace);

            XmlNode node = _xml.DocumentElement.SelectSingleNode("ttml:head/ttml:metadata/ttml:title", _namespaceManager);

            if (node != null)
            {
                textBoxTitle.Text = node.InnerText;
            }

            node = _xml.DocumentElement.SelectSingleNode("ttml:head/ttml:metadata/ttml:desc", _namespaceManager);
            if (node != null)
            {
                textBoxDescription.Text = node.InnerText;
            }

            foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                comboBoxLanguage.Items.Add(ci.Name);
            }
            XmlAttribute attr = _xml.DocumentElement.Attributes["xml:lang"];

            if (attr != null)
            {
                comboBoxLanguage.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:timeBase"];
            if (attr != null)
            {
                comboBoxTimeBase.Text = attr.InnerText;
            }

            comboBoxFrameRate.Items.Add("23.976");
            comboBoxFrameRate.Items.Add("24.0");
            comboBoxFrameRate.Items.Add("25.0");
            comboBoxFrameRate.Items.Add("29.97");
            comboBoxFrameRate.Items.Add("30.0");
            attr = _xml.DocumentElement.Attributes["ttp:frameRate"];
            if (attr != null)
            {
                comboBoxFrameRate.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:frameRateMultiplier"];
            if (attr != null)
            {
                comboBoxFrameRateMultiplier.Text = attr.InnerText;
            }

            attr = _xml.DocumentElement.Attributes["ttp:dropMode"];
            if (attr != null)
            {
                comboBoxDropMode.Text = attr.InnerText;
            }

            foreach (string style in TimedText10.GetStylesFromHeader(_subtitle.Header))
            {
                comboBoxDefaultStyle.Items.Add(style);
                node = _xml.DocumentElement.SelectSingleNode("ttml:body", _namespaceManager);
                if (node?.Attributes?["style"] != null && style == node.Attributes["style"].Value)
                {
                    comboBoxDefaultStyle.SelectedIndex = comboBoxDefaultStyle.Items.Count - 1;
                }
            }
            foreach (string region in TimedText10.GetRegionsFromHeader(_subtitle.Header))
            {
                comboBoxDefaultRegion.Items.Add(region);
                node = _xml.DocumentElement.SelectSingleNode("ttml:body", _namespaceManager);
                if (node?.Attributes?["region"] != null && region == node.Attributes["region"].Value)
                {
                    comboBoxDefaultRegion.SelectedIndex = comboBoxDefaultRegion.Items.Count - 1;
                }
            }

            var timeCodeFormat = Configuration.Settings.SubtitleSettings.TimedText10TimeCodeFormat.Trim().ToLowerInvariant();

            comboBoxTimeCodeFormat.SelectedIndex = 0;
            for (int index = 0; index < comboBoxTimeCodeFormat.Items.Count; index++)
            {
                var item = comboBoxTimeCodeFormat.Items[index];
                if (item.ToString().ToLowerInvariant() == timeCodeFormat)
                {
                    comboBoxTimeCodeFormat.SelectedIndex = index;
                    break;
                }
            }

            var ext = Configuration.Settings.SubtitleSettings.TimedText10FileExtension;

            comboBoxFileExtensions.SelectedIndex = 0;
            for (var index = 0; index < comboBoxFileExtensions.Items.Count; index++)
            {
                var item = comboBoxFileExtensions.Items[index];
                if (item.ToString() == ext)
                {
                    comboBoxFileExtensions.SelectedIndex = index;
                    break;
                }
            }

            textBoxTopOrigin.Text    = Configuration.Settings.SubtitleSettings.TimedTextItunesTopOrigin;
            textBoxTopExtent.Text    = Configuration.Settings.SubtitleSettings.TimedTextItunesTopExtent;
            textBoxBottomOrigin.Text = Configuration.Settings.SubtitleSettings.TimedTextItunesBottomOrigin;
            textBoxBottomExtent.Text = Configuration.Settings.SubtitleSettings.TimedTextItunesBottomExtent;
        }