Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust full sizing calculation #205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Framework.Font/Text/PositionTextFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 14 additions & 24 deletions osu.Framework.Font/Utils/TextBuilderGlyphUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,26 @@

namespace osu.Framework.Utils
{
public class TextBuilderGlyphUtils
public static class TextBuilderGlyphUtils
{
public static RectangleF GetCharacterRectangle(TextBuilderGlyph character, bool drawSizeOnly)
{
if (drawSizeOnly)
return character.DrawRectangle;
private static float getCharacterTopOffset(ICharacterGlyph character)
=> character.Baseline * 0.3f;

// todo: should get the real value.
var topReduce = character.Baseline * 0.3f;
var bottomIncrease = character.Baseline * 0.2f;
return character.DrawRectangle.Inflate(new MarginPadding
private static float getCharacterBottomOffset(ICharacterGlyph character)
=> character.Baseline * 0.03f;

public static RectangleF GetCharacterSizeRectangle(TextBuilderGlyph character)
=> character.DrawRectangle.Inflate(new MarginPadding
{
Top = character.YOffset - topReduce,
Bottom = character.Baseline - character.Height - character.YOffset + bottomIncrease,
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;

// todo: should get the real value.
var topReduce = character.Baseline * 0.3f;
var bottomIncrease = character.Baseline * 0.2f;
return character.DrawRectangle.Inflate(new MarginPadding
public static RectangleF GetCharacterSizeRectangle(PositionTextBuilderGlyph character)
=> character.DrawRectangle.Inflate(new MarginPadding
{
Top = character.YOffset - topReduce,
Bottom = character.Baseline - character.Height - character.YOffset + bottomIncrease,
Top = character.YOffset - getCharacterTopOffset(character),
Bottom = character.Baseline - character.Height - character.YOffset + getCharacterBottomOffset(character),
});
}
}
}