コード例 #1
0
ファイル: MainForm.cs プロジェクト: Raak15/xingsub
        void OKButton_Click(object sender, EventArgs e)
        {
            List<SubStationStyle> _styles = new List<SubStationStyle>();
            string[] lines =  subInfoForm.stylesText.Text.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            bool isStyle = false;

            foreach (string s in lines)
            {
                string line = s.Trim();
                if (line.Replace(" ", "") == "Format:Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding")
                {
                    isStyle = true;
                }

                if (isStyle)
                {
                    if (line.Length > 6)
                    {
                        if (line.Substring(0, 6) == "Style:")
                        {
                            SubStationStyle _style = new SubStationStyle(line);
                            _styles.Add(_style);
                        }
                    }
                }
            }

            if (!isStyle || _styles.Count == 0)
            {
                MessageBox.Show(Localizable.InvaildStyles, Localizable.InvaildStylesTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            subtitles.Styles = _styles;
            subtitles.ScriptInfo.PlayResX = int.Parse(subInfoForm.resWidth.Text);
            subtitles.ScriptInfo.PlayRexY = int.Parse(subInfoForm.resHeight.Text);

            subInfoForm.Close();
        }
コード例 #2
0
        /// <summary>
        /// 从 ASS 加载
        /// </summary>
        /// <param name="text">ASS 文本</param>
        public void LoadAss(string text)
        {
            _styles = new List<SubStationStyle>();
            _events = new List<SubStationEvent>();

            string[] lines = text.Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            int mode = 0;

            int playRexX = 0;
            int playRexY = 0;
            bool isStyle = false;
            bool isEvent = false;

            foreach (string s in lines)
            {
                string line = s.Trim();

                if (line == "[Script Info]")
                {
                    mode = 1;
                    System.Diagnostics.Debug.WriteLine(line);
                }
                else if (line == "[V4+ Styles]")
                {
                    mode = 2;
                    System.Diagnostics.Debug.WriteLine(line);
                }
                else if (line == "[Events]")
                {
                    mode = 3;
                    System.Diagnostics.Debug.WriteLine(line);
                }
                else
                {
                    switch (mode)
                    {
                        case 1:
                            if (line.Length > 9)
                            {
                                if (line.Substring(0, 9) == "PlayResX:")
                                {
                                    playRexX = int.Parse(line.Substring(9).Trim());
                                }
                                else if (line.Substring(0, 9) == "PlayResY:")
                                {
                                    playRexY = int.Parse(line.Substring(9).Trim());
                                }
                                
                                if (playRexX > 0 && playRexY > 0)
                                {
                                    _scriptInfo = new SubStationInfo(playRexX, playRexY);
                                }
                            }
                            break;
                        case 2:
                            if (line.Replace(" ", "") == "Format:Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding")
                            {
                                isStyle = true;
                            }

                            if (isStyle)
                            {
                                if (line.Length > 6)
                                {
                                    if (line.Substring(0, 6) == "Style:")
                                    {
                                        SubStationStyle substyle = new SubStationStyle(line);
                                        _styles.Add(substyle);
                                    }
                                }
                            }
                            break;
                        case 3:
                            if (line.Replace(" ", "") == "Format:Layer,Start,End,Style,Actor,MarginL,MarginR,MarginV,Effect,Text")
                            {
                                isEvent = true;
                            }

                            if (isEvent)
                            {
                                if (line.Length > 9)
                                {
                                    if (line.Substring(0, 9) == "Dialogue:")
                                    {
                                        SubStationEvent subevent = new SubStationEvent(line);
                                        _events.Add(subevent);
                                    }
                                }
                            }
                            break;
                        default:
                            //do nothing
                            break;
                    }
                }
            }

            bool hasDefault = false;
            foreach (SubStationStyle _style in _styles)
            {
                if (_style.Name == "Default") hasDefault = true;
            }
            if (!hasDefault) _styles.Insert(0, new SubStationStyle());
        }