Browse Source

commit: changes about RUBY

HOME 3 years ago
parent
commit
5e017132e2

+ 0 - 1
BeatLyrics.Shared/Models/LyricDetail.cs

@@ -3,7 +3,6 @@
     public class LyricDetail
     {
         public string Text { get; set; }
-        public string TextWithRuby { get; set; }
         public int TimeMs { get; set; }
         public int DurationMs { get; set; }
     }

+ 7 - 21
BeatLyrics.Tool/UserControls/TextArrangeUserControl.cs

@@ -176,7 +176,6 @@ namespace BeatLyrics.Tool.UserControls
                 item.Text = RegRemoveRuby2.Replace(item.Text, "");
                 item.Text = RegRemoveRuby3.Replace(item.Text, "");
                 item.Text = RegRubyConvert.Replace(item.Text, match => match.Groups[2].Value);
-                item.TextWithRuby = null;
                 LeftLyricsObjectListView.UpdateObject(item);
             }
         }
@@ -187,7 +186,6 @@ namespace BeatLyrics.Tool.UserControls
             {
                 var arr = JapanesePhonetic.GetWords(item.Text);
                 item.Text = string.Join("", arr.Select(p => p.ToString()));
-                item.TextWithRuby = string.Join("", arr.Select(p => p.ToRubyTmpString()));
                 LeftLyricsObjectListView.UpdateObject(item);
             }
         }
@@ -261,27 +259,15 @@ namespace BeatLyrics.Tool.UserControls
             if (e.KeyCode == Keys.F2 && olv.SelectedObject != null)
             {
                 var item = (LyricDetailExt)olv.SelectedObject;
-                if (ModifierKeys == Keys.Shift) //TODO: Double Line Input Box
-                {
-                    ContextDialog.PopTextBox(MousePosition, item.TextWithRuby, (r, s) =>
-                    {
-                        if (r == DialogResult.OK)
-                        {
-                            item.TextWithRuby = s;
-                        }
-                    });
-                }
-                else
+
+                ContextDialog.PopTextBox(MousePosition, item.Text, (r, s) =>
                 {
-                    ContextDialog.PopTextBox(MousePosition, item.Text, (r, s) =>
+                    if (r == DialogResult.OK)
                     {
-                        if (r == DialogResult.OK)
-                        {
-                            item.Text = s;
-                            olv.UpdateObject(item);
-                        }
-                    });
-                }
+                        item.Text = s;
+                        olv.UpdateObject(item);
+                    }
+                });
             }
         }
     }

+ 13 - 0
BeatLyrics.Tool/Utils/JapanesePhonetic.cs

@@ -2,6 +2,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Linq;
 using System.Linq.Expressions;
 using System.Reflection;
 using System.Text.RegularExpressions;
@@ -139,6 +140,18 @@ namespace BeatLyrics.Tool.Utils
                         var kan2 = match.Groups[3].Value;
                         var hira2 = match.Groups[4].Value;
 
+                        // 聞き飽き
+                        if (match.Groups.Count == 5 
+                            && Enumerable.Range(1, 4).All(p => match.Groups[p].Value.Length == 1) 
+                            && hira1 == hira2 && displayText.Length == yomiText.Length)
+                        {
+                            lst.Add(new TextTuple { Text = displayText[0].ToString(), Ruby = yomiText[0].ToString() });
+                            lst.Add(new TextTuple { Text = hira1, Ruby = hira1 });
+                            lst.Add(new TextTuple { Text = displayText[2].ToString(), Ruby = yomiText[2].ToString() });
+                            lst.Add(new TextTuple { Text = hira2, Ruby = hira2 });
+                            continue;
+                        }
+
                         var split = yomiText.Split(new[] { hira1, hira2 }, StringSplitOptions.RemoveEmptyEntries);
 
                         lst.Add(new TextTuple { Text = kan1, Ruby = split[0] });

+ 1 - 1
BeatLyrics/LyricsComponent.cs

@@ -134,7 +134,7 @@ namespace BeatLyrics
                 else
                 {
                     //Show LRC
-                    _text.UnditedText = _lyricFile.Main?.Where(p => p.TimeMs <= milliseconds && p.TimeMs + p.DurationMs >= milliseconds).Select(p => p.TextWithRuby ?? p.Text).FirstOrDefault()
+                    _text.UnditedText = _lyricFile.Main?.Where(p => p.TimeMs <= milliseconds && p.TimeMs + p.DurationMs >= milliseconds).Select(p => p.Text).FirstOrDefault()
                                  + Environment.NewLine + _lyricFile.Subtitle?.FirstOrDefault(p => p.TimeMs <= milliseconds && p.TimeMs + p.DurationMs >= milliseconds)?.Text;
                 }
             }

+ 3 - 3
BeatLyrics/RubyTextMeshProUGUI.cs

@@ -18,8 +18,8 @@ namespace BeatLyrics
             BASE_ALIGNMENT
         }
 
-        // ruby tag
-        private static readonly Regex RubyRegex = new Regex(@"<r(uby)?=(?<ruby>[\s\S]*?)>(?<val>[\s\S]*?)<\/r(uby)?>");
+        // ruby tag <亜=あ>
+        private static readonly Regex RubyRegex = new Regex(@"<(?<val>[\s\S]+?)=(?<ruby>[\s\S]+?)>");
 
         [Tooltip("v offset ruby. (em, px, %).")]
         [SerializeField] private string rubyVerticalOffset = "1em";
@@ -69,7 +69,7 @@ namespace BeatLyrics
             var matches = RubyRegex.Matches(str);
             foreach (Match match in matches)
             {
-                if (match.Groups.Count != 5) continue;
+                if (match.Groups.Count != 3) continue;
                 var fullMatch = match.Groups[0].ToString();
                 var rubyText = match.Groups["ruby"].ToString();
                 var baseText = match.Groups["val"].ToString();