Exemplo n.º 1
0
        private static string CutLineLeftToWidth(string line, double width)
        {
            string last3 = line;

            while (Smi.GetLineWidth(line) > width)
            {
                last3 = line;
                line  = line.Substring(1);
            }
            string last1 = line;

            while (Smi.GetLineWidth(line) < width)
            {
                last1 = line;
                line  = " " + line;
            }
            if (width - Smi.GetLineWidth(last1) < Smi.GetLineWidth(line) - width)
            {
                line = last1;
                if (Smi.GetLineWidth(last3) - width < width - Smi.GetLineWidth(line))
                {
                    line = last3;
                }
            }
            return(line);
        }
Exemplo n.º 2
0
        // Cut 함수는 SubtitleObject.dll로 빼는 게 나을 듯?
        private static string CutLineRightToWidth(string line, double width)
        {
            string last3 = line;
            float  t     = 0;

            while ((t = Smi.GetLineWidth(line)) > width)
            {
                last3 = line;
                line  = line.Substring(0, line.Length - 1);
            }
            string last1 = line;

            while (Smi.GetLineWidth(line) < width)
            {
                last1 = line;
                line += " ";
            }
            if (width - Smi.GetLineWidth(last1) < Smi.GetLineWidth(line) - width)
            {
                line = last1;
                if (Smi.GetLineWidth(last3) - width < width - Smi.GetLineWidth(line))
                {
                    line = last3;
                }
            }
            return(line);
        }
Exemplo n.º 3
0
            public SmiPadding(Smi smi)
            {
                start    = smi.start;
                syncType = smi.syncType;

                string[] lines = Combiner.Combined.ToLines(smi.text);
                this.lines = new LinePadding[lines.Length];
                for (int i = 0; i < lines.Length; i++)
                {
                    this.lines[i] = new LinePadding(lines[i]);
                }
            }
Exemplo n.º 4
0
 public CodeWindowManager(IVsCodeWindow codeWindow, SVsServiceProvider serviceProvider, Smi.VisualStudio.Language.LanguagePreferences languagePreferences)
 {
     //System.Diagnostics.Contracts.Contract.Requires<ArgumentNullException>(codeWindow != null, "codeWindow");
     //System.Diagnostics.Contracts.Contract.Requires<ArgumentNullException>(serviceProvider != null, "serviceProvider");
     //System.Diagnostics.Contracts.Contract.Requires<ArgumentNullException>(languagePreferences != null, "languagePreferences");
     Action<EventHandler> unregister = null;
     this._codeWindow = codeWindow;
     this._serviceProvider = serviceProvider;
     this._languagePreferences = languagePreferences;
     if (unregister == null)
     {
         unregister = delegate (EventHandler handler) {
             this._languagePreferences.PreferencesChanged -= handler;
         };
     }
     this._languagePreferences.PreferencesChanged += WeakEvents.AsWeak(new EventHandler(this.HandleLanguagePreferencesChanged), unregister);
 }
Exemplo n.º 5
0
        public static List <Smi> Shake(List <Smi> input)
        {
            List <Smi> output = new List <Smi>();

            int phase = 0;

            for (int i = 0; i < input.Count - 1; i++)
            {
                Smi smi = input[i];
                if (smi.text.Replace("&nbsp;", "").Trim().Length == 0)
                {
                    output.Add(smi);
                }
                else
                {
                    int           start = smi.start, end = input[i + 1].start;
                    int           time  = end - start;
                    ShakeSmiLines lines = new ShakeSmiLines(smi.text);

                    int frames = (int)Math.Round(time / FRAME_LENGTH);
                    if (frames < 1)
                    {
                        frames = 1;
                    }
                    for (int frame = 0; frame < frames; frame++)
                    {
                        output.Add(new Smi()
                        {
                            start    = (start * (frames - frame) + end * frame) / frames,
                            syncType = (frame == 0 ? smi.syncType : SyncType.inner),
                            text     = lines.ToSmi(phase++)
                        });
                    }
                }
            }
            if (input.Count > 0)
            {   // 마지막 싱크는 흔들기 처리 없이 루프 밖에 위치
                output.Add(input[input.Count - 1]);
            }
            return(output);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Smi smi = new Smi()
            {
                text = "가<font face='궁서체'>나<font color='#abcdef' face=\"돋움체\" fade=\"in\">다</font>라</font>마<b>바</b>사<br>아<u>자</u>차<b>카<u>타<i>파</i></u></b>하"
            };
            Ass         ass;
            string      text;
            SmiFile     file;
            List <Attr> attrs;
            bool        doThis = false;

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플1");
                Console.WriteLine(smi);
                Console.WriteLine();

                Console.WriteLine("SMI -> 자체 형식");
                attrs = smi.ToAttr();
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> ASS (fade 손실)");
                ass = new Ass().FromAttr(attrs);
                Console.WriteLine(ass.text);
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> SMI");
                smi = new Smi().FromAttr(attrs);
                Console.WriteLine(smi.text);
                Console.WriteLine();

                Console.WriteLine("ASS -> 자체 형식");
                attrs = ass.ToAttr();
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> SMI");
                smi = new Smi().FromAttr(attrs);
                Console.WriteLine(smi.text);
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> ASS");
                ass = new Ass().FromAttr(attrs);
                Console.WriteLine(ass.text);
                Console.WriteLine();

                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플2");
                text = "<Sync Start=1000><P Class=KRCC>\n"
                       + "asdf\n"
                       + "<Sync Start=1250><P Class=KRCC >\n"
                       + "가<font color='#abcdef'>나</font>다<font color='#9abcde' fade='in'>라</font>마<font color='#89abcd' fade='out'>바</font>사\n"
                       + "<Sync Start=1500><P Class=KRCC >\n"
                       + "가<font color='#abcdef'>나</font>다<font color='#9abcde'>라</font>마<font color='#000000'>바</font>사\n"
                ;
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine("가공");
                file = new SmiFile().FromTxt(text);
                Smi.Normalize(file.body);
                text = Smi.Smi2txt(file.body);
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플3");
                text = "<Sync Start=61379><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">I</font><font color=\"#997722\">n the dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In</font> <font color=\"#997722\">the dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=61687><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In t</font><font color=\"#997722\">he dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In th</font><font color=\"#997722\">e dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the</font> <font color=\"#997722\">dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=61957><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In the d</font><font color=\"#997722\">reaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the dr</font><font color=\"#997722\">eaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the dre</font><font color=\"#997722\">aming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the drea</font><font color=\"#997722\">ming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=62595><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In the dream</font><font color=\"#997722\">ing 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the dreami</font><font color=\"#997722\">ng 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the dreamin</font><font color=\"#997722\">g 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<font color=\"#cccc88\">In the dreaming</font> <font color=\"#997722\">誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=63710><P Class=KRCC>\n"
                ;
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine("가공");
                file = new SmiFile().FromTxt(text);
                Smi.FillEmptySync(file.body);
                text = Smi.Smi2txt(file.body);
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플4");
                smi.text = "테스트<font typing='TypeWriter'>테스트</font>테스트";
                Console.WriteLine(smi.text);
                Console.WriteLine();

                Console.WriteLine("SMI -> 자체 형식");
                attrs = smi.ToAttr();
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> ASS");
                ass = new Ass().FromAttr(attrs);
                Console.WriteLine(ass.text);
                Console.WriteLine();

                Console.WriteLine("자체 형식 -> SMI");
                smi = new Smi().FromAttr(attrs);
                Console.WriteLine(smi.text);
                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플5");
                text = "<Sync Start=1000><P Class=KRCC>\n"
                       + "테스트   테스트\n"
                       + "<Sync Start=2000><P Class=KRCC>\n"
                       + "테스트<font typing='typewriter'>텍스트</font>테스트\n"
                       + "<Sync Start=3000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard'>텍스트</font>테스트\n"
                       + "<Sync Start=4000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard'>테스트</font>테스트\n"
                       + "<Sync Start=5000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard(0,1)'>테스트</font>테스트\n"
                       + "<Sync Start=6000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard(1,1)'>테스트</font>테스트\n"
                       + "<Sync Start=7000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard'>테test</font>테스트\n"
                       + "<Sync Start=8000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard invisible'>테test</font>테스트\n"
                       + "<Sync Start=9000><P Class=KRCC>\n"
                       + "테스트<font typing='keyboard hangeul'>테test</font><br>테스트\n"
                       + "<Sync Start=10000><P Class=KRCC>\n"
                       + "테스트테스트<font typing='keyboard'>테스트</font>\n"
                       + "<Sync Start=11000><P Class=KRCC>\n"
                       + "테스트테스트테스트\n"
                ;
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine("가공");
                file = new SmiFile().FromTxt(text);
                Smi.Normalize(file.body);
                text = Smi.Smi2txt(file.body);
                Console.WriteLine(text);
                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                string input = "실홰롻튄즤륢 ㅁㄴㅇㄻㄴ";
                Console.WriteLine("입력값");
                Console.WriteLine(input);
                Console.WriteLine();

                Console.WriteLine("타자기");
                char[] type   = Typing.ToType(input, Typing.Mode.typewriter);
                Typing typing = new Typing(Typing.Mode.typewriter, Typing.Cursor.invisible);
                foreach (char c in type)
                {
                    typing.Type(c);
                    Console.WriteLine(typing.Out());
                }

                Console.WriteLine();

                Console.WriteLine("키보드");
                type   = Typing.ToType(input, Typing.Mode.keyboard);
                typing = new Typing(Typing.Mode.keyboard, Typing.Cursor.invisible);
                foreach (char c in type)
                {
                    typing.Type(c);
                    Console.WriteLine(typing.Out());
                }
            }

            doThis = false;
            if (doThis)
            {
                Console.WriteLine("샘플 몇이냐");
                text = "<Sync Start=1379><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">I</font><font color=\"#997722\">n the dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=61533><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In</font> <font color=\"#997722\">the dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=1687><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In t</font><font color=\"#997722\">he dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=61777><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In th</font><font color=\"#997722\">e dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=61867><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the</font> <font color=\"#997722\">dreaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=1957><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In the d</font><font color=\"#997722\">reaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=62116><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the dr</font><font color=\"#997722\">eaming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=62276><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the dre</font><font color=\"#997722\">aming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=62435><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the drea</font><font color=\"#997722\">ming 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=2595><P Class=KRCC>\n"
                       + "<font color=\"#cccc88\">In the dream</font><font color=\"#997722\">ing 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=62873><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the dreami</font><font color=\"#997722\">ng 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=63152><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the dreamin</font><font color=\"#997722\">g 誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=63431><P Class=KRCC	>\n"
                       + "<font color=\"#cccc88\">In the dreaming</font> <font color=\"#997722\">誰かのために</font><br>In the dreaming 누군가를 위해서\n"
                       + "<Sync Start=3710><P Class=KRCC>asdf\n";
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine("중간싱크 조절 가공");
                file = new SmiFile().FromTxt(text);
                Smi.Normalize(file.body);
                text = Smi.Smi2txt(file.body);
                Console.WriteLine(text);
                Console.WriteLine();

                Console.WriteLine();
            }

            doThis = false;
            if (doThis)
            {
                text = "<Sync Start=1293110><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">나란히 날아가는 한 쌍의 새</font></i>"
                       + "<Sync Start=1299594><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">손을 맞잡은</font></i>"
                       + "<Sync Start=1302545><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">부모·자식이 만드는 그림자</font></i>"
                       + "<Sync Start=1305823><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">저녁 해가 비춘 아름다운 것</font></i>"
                       + "<Sync Start=1312310><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">그런 “평범”한 게 눈부셨어</font></i>"
                       + "<Sync Start=1318632><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">푸른색 벤치가 허전해서</font></i>"
                       + "<Sync Start=1323976><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">나 혼자 외톨이 로 느껴졌어</font></i>"
                       + "<Sync Start=1331612><P Class=KRCC>"
                       + "&nbsp;"
                       + "<Sync Start=1333917><P Class=KRCC>"
                       + "<i><font color=\"#ccbbdd\">평범한 게 좋아서</font></i>";

                doThis = false;
                if (doThis)
                {
                    text = "<Sync Start=65483><P Class=KRCC >\n"
                           + "카나???\n"
                           + "<Sync Start=66293><P Class=KRCC >\n"
                           + "&nbsp;\n"
                           + "<Sync Start=68324><P Class=KRCC>\n"
                           + "하루코 ???\n"
                           + "<Sync Start=69054><P Class=KRCC >\n"
                           + "&nbsp;\n"
                           + "<Sync Start=72223><P Class=KRCC >\n"
                           + "슈퍼바이저\n"
                           + "<Sync Start=73504><P Class=KRCC >\n"
                           + "&nbsp;\n"
                           + "<Sync Start=169787><P Class=KRCC >\n"
                           + "히도미 미나세 이노리\n"
                           + "<Sync Start=170883><P Class=KRCC >\n"
                           + "&nbsp;\n"
                           + "<Sync Start=172325><P Class=KRCC >\n"
                           + "진유\n"
                           + "사와시로 미유키\n"
                           + "<Sync Start=173349><P Class=KRCC >\n"
                           + "&nbsp;\n"
                           + "<Sync Start=175555><P Class=KRCC >\n"
                           + "라하루\n"
                           + "하야시바라 메구미\n"
                           + "<Sync Start=176463><P Class=KRCC >\n"
                           + "슈퍼바이저 캐릭터 원안 주제가\n"
                           + "<Sync Start=177671><P Class=KRCC >\n"
                           + "&nbsp;";
                }

                file = new SmiFile().FromTxt(text);
                List <Ass> assBody = new AssFile().FromSync(file.ToSync()).body;
                foreach (Ass line in assBody)
                {
                    Console.WriteLine(line.ToTxt());
                }
            }

            System.Threading.Thread.Sleep(int.MaxValue);
        }
Exemplo n.º 7
0
        public static List <Smi> Combine(List <Smi> inputUpper, List <Smi> inputLower)
        {
            List <CombinedGroup> groups = new List <CombinedGroup>();
            CombinedGroup        lastGroup = new CombinedGroup();
            Combined             last = new Combined();
            int ui = 0, li = 0;

            while (ui < inputUpper.Count && li < inputLower.Count)
            {
                Smi uLine = inputUpper[ui];
                Smi lLine = inputLower[li];

                int comp = uLine.start - lLine.start;
                if (comp < 0)
                {
                    // 위 바뀜

                    if (last.lower.Length == 0)
                    {
                        // 아래가 빈 싱크인 상태로 위가 바뀜 -> 새 그룹
                        groups.Add((lastGroup = new CombinedGroup()));
                    }

                    lastGroup.combineds.Add((last = new Combined()
                    {
                        start = uLine.start,
                        syncType = uLine.syncType,
                        upper = uLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(uLine.text),
                        lower = (string[])last.lower.Clone()
                    }));
                    if (last.upper.Length > lastGroup.upperLineCount)
                    {
                        lastGroup.upperLineCount = last.upper.Length;
                    }

                    ui++;
                }
                else if (comp > 0)
                {
                    // 아래 바뀜

                    if (last.upper.Length == 0)
                    {
                        // 위가 빈 싱크인 상태로 위가 바뀜 -> 새 그룹
                        groups.Add((lastGroup = new CombinedGroup()));
                    }

                    lastGroup.combineds.Add((last = new Combined()
                    {
                        start = lLine.start,
                        syncType = lLine.syncType,
                        upper = (string[])last.upper.Clone(),
                        lower = lLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(lLine.text)
                    }));
                    if (last.lower.Length > lastGroup.lowerLineCount)
                    {
                        lastGroup.lowerLineCount = last.lower.Length;
                    }

                    li++;
                }
                else
                {
                    // 동시

                    // 새 그룹
                    groups.Add((lastGroup = new CombinedGroup()));

                    lastGroup.combineds.Add((last = new Combined()
                    {
                        start = uLine.start,
                        syncType = (uLine.syncType == SyncType.frame || lLine.syncType == SyncType.frame) ? SyncType.frame : SyncType.normal,
                        upper = uLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(uLine.text),
                        lower = lLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(lLine.text)
                    }));
                    lastGroup.upperLineCount = last.upper.Length;
                    lastGroup.lowerLineCount = last.lower.Length;

                    ui++; li++;
                }
            }
            for (; ui < inputUpper.Count; ui++)
            {
                Smi uLine = inputUpper[ui];

                if (last.lower.Length == 0)
                {
                    // 아래가 빈 싱크인 상태로 위가 바뀜 -> 새 그룹
                    groups.Add((lastGroup = new CombinedGroup()));
                }

                lastGroup.combineds.Add((last = new Combined()
                {
                    start = uLine.start,
                    syncType = uLine.syncType,
                    upper = uLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(uLine.text),
                    lower = (string[])last.lower.Clone()
                }));
                if (last.upper.Length > lastGroup.upperLineCount)
                {
                    lastGroup.upperLineCount = last.upper.Length;
                }
            }
            for (; li < inputLower.Count; li++)
            {
                Smi lLine = inputLower[li];

                if (last.upper.Length == 0)
                {
                    // 위가 빈 싱크인 상태로 위가 바뀜 -> 새 그룹
                    groups.Add((lastGroup = new CombinedGroup()));
                }

                lastGroup.combineds.Add((last = new Combined()
                {
                    start = lLine.start,
                    syncType = lLine.syncType,
                    upper = (string[])last.upper.Clone(),
                    lower = lLine.text.Replace("&nbsp;", "").Length == 0 ? new string[] { } : Combined.ToLines(lLine.text)
                }));
                if (last.lower.Length > lastGroup.lowerLineCount)
                {
                    lastGroup.lowerLineCount = last.lower.Length;
                }
            }

            List <Smi> result = new List <Smi>();

            foreach (CombinedGroup group in groups)
            {
                foreach (Combined combined in group.combineds)
                {
                    int   maxUpperIndex = 0, maxLowerIndex = 0;
                    float maxUpperWidth = 0, maxLowerWidth = 0;
                    for (int i = 0; i < combined.upper.Length; i++)
                    {
                        float width = Smi.GetLineWidth(combined.upper[i]);
                        if (width > maxUpperWidth)
                        {
                            maxUpperIndex = i;
                            maxUpperWidth = width;
                        }
                    }
                    for (int i = 0; i < combined.lower.Length; i++)
                    {
                        float width = Smi.GetLineWidth(combined.lower[i]);
                        if (width > maxLowerWidth)
                        {
                            maxLowerIndex = i;
                            maxLowerWidth = width;
                        }
                    }

                    // 정렬용 글자 수 맞춰주기
                    if (combined.upper.Length > 0 && combined.lower.Length > 0)
                    {
                        if (maxUpperWidth > maxLowerWidth)
                        {
                            //string left = Smi.GetLineAppend(combined.lower[maxLowerIndex], maxUpperWidth, true);
                            string left = Width.GetAppend(Smi.GetLineWidth(combined.lower[maxLowerIndex]), maxUpperWidth, true);
                            if (left.Length > 0)
                            {
                                string right = Width.AppendToRight(left);
                                for (int i = 0; i < combined.lower.Length; i++)
                                {
                                    //combined.lower[i] = "<b></b>" + left + combined.lower[i] + right + "<b></b>";
                                    combined.lower[i] = left + combined.lower[i] + right;
                                }
                            }
                        }
                        else
                        {
                            //string left = Smi.GetLineAppend(combined.upper[maxUpperIndex], maxLowerWidth, true);
                            string left = Width.GetAppend(Smi.GetLineWidth(combined.upper[maxUpperIndex]), maxLowerWidth, true);
                            if (left.Length > 0)
                            {
                                string right = Width.AppendToRight(left);
                                for (int i = 0; i < combined.upper.Length; i++)
                                {
                                    //combined.upper[i] = "<b></b>" + left + combined.upper[i] + right + "<b></b>";
                                    combined.upper[i] = left + combined.upper[i] + right;
                                }
                            }
                        }
                    }

                    Smi smi = new Smi()
                    {
                        start    = combined.start,
                        syncType = combined.syncType,
                        text     = ""
                    };
                    for (int i = 0; i < group.upperLineCount - combined.upper.Length; i++)
                    {
                        smi.text += "<b> </b>" + (i < group.upperLineCount - 1 ? "<br>" : "");
                    }
                    for (int i = 0; i < combined.upper.Length; i++)
                    {
                        smi.text += combined.upper[i] + (i < combined.upper.Length - 1 ? "<br>" : "");
                    }
                    if (group.upperLineCount > 0 && group.lowerLineCount > 0)
                    {
                        smi.text += "<br>";
                    }
                    for (int i = 0; i < group.lowerLineCount - combined.lower.Length; i++)
                    {
                        smi.text += "<b> </b>" + (i < (group.lowerLineCount - 1) ? "<br>" : "");
                    }
                    for (int i = 0; i < combined.lower.Length; i++)
                    {
                        smi.text += combined.lower[i] + (i < (combined.lower.Length - 1) ? "<br>" : "");
                    }

                    if (smi.text.Length == 0)
                    {
                        smi.text = "&nbsp;";
                    }
                    else
                    {
                        if (smi.text.StartsWith(" ") || smi.text.StartsWith(" "))
                        {
                            smi.text = "​" + smi.text;
                        }
                        if (smi.text.EndsWith(" ") || smi.text.EndsWith(" "))
                        {
                            smi.text = smi.text + "​";
                        }
                    }

                    result.Add(smi);
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        public static List <Smi> Nico(List <NicoLine> nicoLines, int width)
        {
            int lineCount  = 0;
            int startOfAll = int.MaxValue;
            int endOfAll   = 0;

            foreach (NicoLine line in nicoLines)
            {
                if (line.line > lineCount)
                {
                    lineCount = line.line;
                }
                if (line.start < startOfAll)
                {
                    startOfAll = line.start;
                }
                if (line.end > endOfAll)
                {
                    endOfAll = line.end;
                }
            }

            int startFrame = (int)Math.Round(startOfAll / FRAME_LENGTH);
            int endFrame   = (int)Math.Round(endOfAll / FRAME_LENGTH);

            List <List <NicoLine> > lines = new List <List <NicoLine> >();

            for (int i = 0; i < lineCount; i++)
            {
                lines.Add(new List <NicoLine>());
            }

            foreach (NicoLine line in nicoLines)
            {
                lines[line.line - 1].Add(line);
            }

            string defaultValue = "";

            for (int i = 0; i < width; i++)
            {
                defaultValue += " ";
            }
            NicoLine.lineWidth = Smi.GetLineWidth(defaultValue);

            List <Smi> output = new List <Smi>();

            for (int frame = startFrame; frame < endFrame; frame++)
            {
                Smi smi = new Smi()
                {
                    start    = (int)(frame * FRAME_LENGTH),
                    syncType = (frame == startFrame ? SyncType.frame : SyncType.inner),
                    text     = "​"
                };
                for (int i = 0; i < lineCount; i++)
                {
                    string result = defaultValue;
                    foreach (NicoLine line in lines[i])
                    {
                        float pos = line.CalcLeft(frame);
                        if (pos < 0)
                        {   // 왼쪽이 잘리기 시작
                            float leftWidth = pos + line.width;
                            if (leftWidth > 0)
                            {     // 화면에 남는 부분이 있음
                                if (leftWidth >= NicoLine.lineWidth)
                                { // 남는 부분이 화면보다 큼
                                    result = CutLineLeftToWidth(line.text, leftWidth);
                                    result = CutLineRightToWidth(line.text, NicoLine.lineWidth);
                                }
                                else
                                {   // 남는 부분이 화면보다 작음
                                    string text = CutLineLeftToWidth(line.text, leftWidth);
                                    result = text + CutLineLeftToWidth(result, NicoLine.lineWidth - leftWidth);
                                }
                            }
                        }
                        else if (pos < NicoLine.lineWidth)
                        {   // 화면 안에서 시작
                            string lastResult = result;
                            result = CutLineRightToWidth(result, pos) + line.text;
                            float thisWidth = Smi.GetLineWidth(result);
                            if (thisWidth > NicoLine.lineWidth)
                            {
                                result = CutLineRightToWidth(result, NicoLine.lineWidth);
                            }
                            else
                            {
                                result += CutLineLeftToWidth(lastResult, NicoLine.lineWidth - thisWidth);
                            }
                        }
                    }
                    smi.text += (i == 0 ? "" : "<br>") + result;
                }
                smi.text += "​";
                output.Add(smi);
            }
            output.Add(new Smi()
            {
                start    = (int)(endFrame * FRAME_LENGTH),
                syncType = SyncType.frame,
                text     = "&nbsp;"
            });

            return(output);
        }