Skip to content

Commit

Permalink
Merge pull request #203 from andy840119/implement-new-way-for-calcula…
Browse files Browse the repository at this point in the history
…te-position-text-position

Write position text formatter to move adjust the text position.
  • Loading branch information
andy840119 authored May 21, 2022
2 parents 511c996 + ef6667f commit 95d1e97
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 447 deletions.
12 changes: 12 additions & 0 deletions osu.Framework.Font.Tests/Graphics/Sprites/LyricSpriteTextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ namespace osu.Framework.Font.Tests.Graphics.Sprites
{
public class LyricSpriteTextTest
{
[TestCase("カラオケ", new[] { "[0,1]:か" }, new[] { "[0,1]:か" })]
[TestCase("カラオケ", new[] { "[0,1]:", "[0,1]:" }, new string[] { })] // will filter those empty text time-tags.
[TestCase("カラオケ", new[] { "[0,1]:か", "[0,1]:か" }, new[] { "[0,1]:か" })] // will filter the duplicated
[TestCase("カラオケ", new[] { "[0,1]:か", "[0,1]:ら" }, new[] { "[0,1]:か", "[0,1]:ら" })] // will not filter even if index are same.
[TestCase("カラオケ", new[] { "[0,1]:か", "[1,0]:か" }, new[] { "[0,1]:か" })] // will give it a fix and filter the duplicated.
public void TestGetFixedPositionTexts(string lyric, string[] positionTexts, string[] fixedPositionTexts)
{
var expected = TestCaseTagHelper.ParsePositionTexts(fixedPositionTexts);
var actual = LyricSpriteText.GetFixedPositionTexts(TestCaseTagHelper.ParsePositionTexts(positionTexts), lyric);
Assert.AreEqual(expected, actual);
}

[TestCase("カラオケ", "[0,1]:か", "[0,1]:か")]
[TestCase("カラオケ", "[3,4]:か", "[3,4]:か")]
[TestCase("カラオケ", "[-1,1]:か", "[0,1]:か")] // fix out of range issue.
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework.Font.Tests/Helper/TestCaseTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Tuple<double, TextIndex> ParseTimeTag(string str)
return new Tuple<double, TextIndex>(time, new TextIndex(index, state));
}

public static PositionText[] ParseParsePositionTexts(IEnumerable<string> strings)
public static PositionText[] ParsePositionTexts(IEnumerable<string> strings)
=> strings?.Select(ParsePositionText).ToArray();

public static IReadOnlyDictionary<double, TextIndex> ParseTimeTags(IEnumerable<string> strings)
Expand Down
200 changes: 0 additions & 200 deletions osu.Framework.Font.Tests/Text/PositionTextBuilderTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public TestSceneKaraokeSpriteText()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケ!",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[2,3]:お" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[1,2]:ra", "[3,4]:ke" }),
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[2,3]:お" }),
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[1,2]:ra", "[3,4]:ke" }),
LeftTextColour = Color4.Green,
RightTextColour = Color4.Red,
Scale = new Vector2(2),
Expand Down Expand Up @@ -96,7 +96,7 @@ public void TestRuby(string[] rubyTags, bool boo)
{
AddStep("Change ruby", () =>
{
var ruby = TestCaseTagHelper.ParseParsePositionTexts(rubyTags);
var ruby = TestCaseTagHelper.ParsePositionTexts(rubyTags);
karaokeSpriteText.Rubies = ruby;
});
}
Expand All @@ -106,7 +106,7 @@ public void TestRomaji(string[] romajiTags, bool boo)
{
AddStep("Change romaji", () =>
{
var romajies = TestCaseTagHelper.ParseParsePositionTexts(romajiTags);
var romajies = TestCaseTagHelper.ParsePositionTexts(romajiTags);
karaokeSpriteText.Romajies = romajies;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public TestSceneKaraokeSpriteTextWithShader()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケ!",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:500", "[1,start]:600", "[2,start]:1000", "[3,start]:1500", "[4,start]:2000" }),
Scale = new Vector2(2),
LeftTextColour = Color4.Green,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public void TestText(string text, string[] rubyTags, string[] romajiTags)
AddStep("Create lyric", () => setContents(() => new LyricSpriteText
{
Text = text,
Rubies = TestCaseTagHelper.ParseParsePositionTexts(rubyTags),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(romajiTags),
Rubies = TestCaseTagHelper.ParsePositionTexts(rubyTags),
Romajies = TestCaseTagHelper.ParsePositionTexts(romajiTags),
}));
}

Expand Down Expand Up @@ -238,12 +238,12 @@ public DefaultLyricSpriteText(bool ruby = true, bool romaji = true)

if (ruby)
{
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" });
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" });
}

if (romaji)
{
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" });
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public TestSceneLyricSpriteTextCharacterPosition()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケyo-",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け", "[4,5]:-" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke", "[4,5]:yo" }),
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け", "[4,5]:-" }),
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke", "[4,5]:yo" }),
},
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public TestSceneLyricSpriteTextWithColour()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケ",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
Y = 60,
},
new BufferedContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public TestSceneLyricSpriteTextWithShader()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "カラオケ",
Rubies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParseParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
Rubies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:か", "[1,2]:ら", "[2,3]:お", "[3,4]:け" }),
Romajies = TestCaseTagHelper.ParsePositionTexts(new[] { "[0,1]:ka", "[1,2]:ra", "[2,3]:o", "[3,4]:ke" }),
Scale = new Vector2(2)
};
}
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework.Font/Graphics/Sprites/LyricSpriteText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public LyricSpriteText()
AddLayout(parentScreenSpaceCache);
AddLayout(localScreenSpaceCache);
AddLayout(textBuilderCache);
AddLayout(rubyTextBuilderCache);
AddLayout(romajiTextBuilderCache);
}

[BackgroundDependencyLoader]
Expand Down
Loading

0 comments on commit 95d1e97

Please sign in to comment.