public SubtitlesUnit(SubtitlesUnit su)
 {
     this.beginTime = su.beginTime;
     this.endTime   = su.endTime;
     this.contents  = new List <string>();
     this.contents.AddRange(su.contents);
 }
Example #2
0
        /// <summary>
        /// 计算字符单元内内容的总字符数
        /// </summary>
        /// <param name="srtU">要计算的字符单元</param>
        /// <returns>字符单元内容的总字符数</returns>
        protected int calcContentLens(SubtitlesUnit srtU)
        {
            int length = srtU.Contents.Count, rtn = 0;

            for (int i = 0; i < length; i++)
            {
                rtn += srtU.Contents[i].Length;
            }
            return(rtn);
        }
Example #3
0
        /// <summary>
        /// 分割对话(单行字幕)
        /// </summary>
        /// <param name="breakStr">单元内包含此字符时, 会根据此字符将本单元分割成多个单元</param>
        /// <param name="wordNum">单元内最多的字符个数, 此数字小于等于0时, 无效</param>
        public void breakDialog(string breakStr = "- ", int wordNum = 15)
        {
            int length = subtitlesUnits.Count;
            List <SubtitlesUnit> tempLines = new List <SubtitlesUnit>();

            for (int i = 0; i < length; i++)
            {
                string        tempCont = string.Join(" ", subtitlesUnits[i].Contents);
                string[]      ta0      = tempCont.Split(new string[] { breakStr }, StringSplitOptions.RemoveEmptyEntries);
                List <string> tempArr  = new List <string>();
                for (int j = 0; j < ta0.Length; j++)
                {
                    if (wordNum > 0 && ta0[j].Length >= wordNum)
                    {
                        breakDialogByNum(ta0[j], wordNum);
                    }
                    else
                    {
                        tempArr.Add(ta0[j]);
                    }
                }
                if (tempArr.Count > 1)
                {
                    double totalWord = 0;
                    for (int j = 0; j < tempArr.Count; j++)
                    {
                        tempArr[j] = tempArr[j].Trim();
                        totalWord += tempArr[j].Length;
                    }
                    double totalTime = Math.Max(0, subtitlesUnits[i].EndTime - subtitlesUnits[i].BeginTime);
                    for (int j = 0; j < tempArr.Count; j++)
                    {
                        SubtitlesUnit tempSU = subtitlesUnits[i].clone();
                        if (j == 0)
                        {
                            tempSU.BeginTime = subtitlesUnits[i].BeginTime;
                        }
                        else
                        {
                            tempSU.BeginTime = tempLines[tempLines.Count - 1].EndTime;
                        }
                        tempSU.Contents.Add(tempArr[j]);
                        tempSU.EndTime = tempSU.BeginTime + (uint)(totalTime * ((double)tempArr[j].Length / totalWord));
                        tempLines.Add(tempSU);
                    }
                }
                else
                {
                    tempLines.Add(subtitlesUnits[i]);
                }
            }
            subtitlesUnits = tempLines;
            deleteSpace();
        }
Example #4
0
        /// <summary>
        /// 将单元按照参数分割成多个单元, 只有单元为两行, 并且两行中分隔符的个数相同时, 才进行分割
        /// </summary>
        /// <param name="breakStr">分割参照字符</param>
        public void breakDialogMore(string breakStr = "- ")
        {
            int length = subtitlesUnits.Count;
            List <SubtitlesUnit> tempLines = new List <SubtitlesUnit>();

            for (int i = 0; i < length; i++)
            {
                if (subtitlesUnits[i].Contents.Count == 2)
                {
                    string[] ta0 = subtitlesUnits[i].Contents[0].Split(new string[] { breakStr }, StringSplitOptions.RemoveEmptyEntries);
                    string[] ta1 = subtitlesUnits[i].Contents[1].Split(new string[] { breakStr }, StringSplitOptions.RemoveEmptyEntries);

                    if (ta0.Length == ta1.Length && ta0.Length > 1)
                    {
                        double totalWord = 0;
                        for (int j = 0; j < ta1.Length; j++)
                        {
                            ta0[j]     = ta0[j].Trim();
                            ta1[j]     = ta1[j].Trim();
                            totalWord += ta1[j].Length;
                        }
                        double totalTime = Math.Max(0, subtitlesUnits[i].EndTime - subtitlesUnits[i].BeginTime);
                        for (int j = 0; j < ta1.Length; j++)
                        {
                            SubtitlesUnit tempSU = subtitlesUnits[i].clone();
                            if (j == 0)
                            {
                                tempSU.BeginTime = subtitlesUnits[i].BeginTime;
                            }
                            else
                            {
                                tempSU.BeginTime = tempLines[tempLines.Count - 1].EndTime;
                            }
                            tempSU.Contents.Add(ta0[j]);
                            tempSU.Contents.Add(ta1[j]);
                            tempSU.EndTime = tempSU.BeginTime + (uint)(totalTime * ((double)ta1[j].Length / totalWord));
                            tempLines.Add(tempSU);
                        }
                    }
                    else
                    {
                        tempLines.Add(subtitlesUnits[i]);
                    }
                }
                else
                {
                    tempLines.Add(subtitlesUnits[i]);
                }
            }
            subtitlesUnits = tempLines;
            deleteSpace();
        }
Example #5
0
 public SRTUnit(SubtitlesUnit su) : base(su)
 {
 }
 public ASSUnit(SubtitlesUnit su) : base(su)
 {
 }