diff --git a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_Characters.cs b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_Characters.cs index d0f9240..cd35669 100644 --- a/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_Characters.cs +++ b/osu.Framework.Font/Graphics/Sprites/LyricSpriteText_Characters.cs @@ -377,7 +377,7 @@ public RectangleF GetCharacterDrawRectangle(int index, bool drawSizeOnly = false throw new ArgumentOutOfRangeException(nameof(index)); var character = characters[charIndex]; - var drawRectangle = TextBuilderGlyphUtils.GetCharacterRectangle(character, drawSizeOnly); + var drawRectangle = drawSizeOnly ? character.DrawRectangle : TextBuilderGlyphUtils.GetCharacterSizeRectangle(character); return getComputeCharacterDrawRectangle(drawRectangle); } @@ -386,7 +386,7 @@ public RectangleF GetRubyTagDrawRectangle(PositionText rubyTag, bool drawSizeOnl if (!rubyCharactersBacking.TryGetValue(rubyTag, out var glyphs)) throw new ArgumentOutOfRangeException(nameof(rubyTag)); - var drawRectangle = glyphs.Select(x => TextBuilderGlyphUtils.GetCharacterRectangle(x, drawSizeOnly)) + var drawRectangle = glyphs.Select(x => drawSizeOnly ? x.DrawRectangle : TextBuilderGlyphUtils.GetCharacterSizeRectangle(x)) .Aggregate(RectangleF.Union); return getComputeCharacterDrawRectangle(drawRectangle); } @@ -396,7 +396,7 @@ public RectangleF GetRomajiTagDrawRectangle(PositionText romajiTag, bool drawSiz if (!romajiCharactersBacking.TryGetValue(romajiTag, out var glyphs)) throw new ArgumentOutOfRangeException(nameof(romajiTag)); - var drawRectangle = glyphs.Select(x => TextBuilderGlyphUtils.GetCharacterRectangle(x, drawSizeOnly)) + var drawRectangle = glyphs.Select(x => drawSizeOnly ? x.DrawRectangle : TextBuilderGlyphUtils.GetCharacterSizeRectangle(x)) .Aggregate(RectangleF.Union); return getComputeCharacterDrawRectangle(drawRectangle); } diff --git a/osu.Framework.Font/Text/PositionTextFormatter.cs b/osu.Framework.Font/Text/PositionTextFormatter.cs index 74c5e51..a10d159 100644 --- a/osu.Framework.Font/Text/PositionTextFormatter.cs +++ b/osu.Framework.Font/Text/PositionTextFormatter.cs @@ -70,15 +70,15 @@ private static Vector2 getPositionTextStartPosition(RectangleF mainTextRect, flo } private static Vector2 getPositionTextSize(TextBuilderGlyph[] glyphs) - => glyphs.Select(x => TextBuilderGlyphUtils.GetCharacterRectangle(x, false)) + => glyphs.Select(TextBuilderGlyphUtils.GetCharacterSizeRectangle) .Aggregate(RectangleF.Union).Size; private RectangleF getMainCharacterRectangleF(int startCharIndex, int endCharIndex) { var starCharacter = characterList[startCharIndex]; var endCharacter = characterList[endCharIndex - 1]; - var startCharacterRectangle = TextBuilderGlyphUtils.GetCharacterRectangle(starCharacter, false); - var endCharacterRectangle = TextBuilderGlyphUtils.GetCharacterRectangle(endCharacter, false); + var startCharacterRectangle = TextBuilderGlyphUtils.GetCharacterSizeRectangle(starCharacter); + var endCharacterRectangle = TextBuilderGlyphUtils.GetCharacterSizeRectangle(endCharacter); var position = startCharacterRectangle.TopLeft; diff --git a/osu.Framework.Font/Utils/TextBuilderGlyphUtils.cs b/osu.Framework.Font/Utils/TextBuilderGlyphUtils.cs index b07a342..cfcba9e 100644 --- a/osu.Framework.Font/Utils/TextBuilderGlyphUtils.cs +++ b/osu.Framework.Font/Utils/TextBuilderGlyphUtils.cs @@ -15,28 +15,18 @@ private static float getCharacterTopOffset(ICharacterGlyph character) private static float getCharacterBottomOffset(ICharacterGlyph character) => character.Baseline * 0.03f; - public static RectangleF GetCharacterRectangle(TextBuilderGlyph character, bool drawSizeOnly) - { - if (drawSizeOnly) - return character.DrawRectangle; - - return character.DrawRectangle.Inflate(new MarginPadding + public static RectangleF GetCharacterSizeRectangle(TextBuilderGlyph character) + => character.DrawRectangle.Inflate(new MarginPadding { Top = character.YOffset - getCharacterTopOffset(character), Bottom = character.Baseline - character.Height - character.YOffset + getCharacterBottomOffset(character), }); - } - - public static RectangleF GetCharacterRectangle(PositionTextBuilderGlyph character, bool drawSizeOnly) - { - if (drawSizeOnly) - return character.DrawRectangle; - return character.DrawRectangle.Inflate(new MarginPadding + public static RectangleF GetCharacterSizeRectangle(PositionTextBuilderGlyph character) + => character.DrawRectangle.Inflate(new MarginPadding { Top = character.YOffset - getCharacterTopOffset(character), Bottom = character.Baseline - character.Height - character.YOffset + getCharacterBottomOffset(character), }); - } } }