Skip to content

Fix: Wrong size measurement for WrapTextSegment#1057

Open
Denrage wants to merge 2 commits intoblish-hud:devfrom
Denrage:fix/DrawUtilWrappingFix
Open

Fix: Wrong size measurement for WrapTextSegment#1057
Denrage wants to merge 2 commits intoblish-hud:devfrom
Denrage:fix/DrawUtilWrappingFix

Conversation

@Denrage
Copy link
Collaborator

@Denrage Denrage commented Feb 16, 2026

In specific edge cases DrawUtil.WrapText produces a string that is greater than the maxLineWidth you give him.
This happens because the previous implementation of WrapTextSegment didn't properly measured the string after appending a word.
The size of the space changes depending on which letter the space precedes so we can't use a fixed SpaceWidth for the whole wrapping and we need to measure the actual size of the string to not exceeed the maxLineWidth.

I don't know all the implications this change could occure, but i can't think of any problem with it, but that is limited to the knowledge i have regarding this function and usage all around Blish.

Also i don't know if MeasureString("some string") + MeasureString("some other string") will be the same as MeasureString("some string" + "some other string"). This could create another even more edgy case where we need to measure the resulting string before we create it to not exceed the maxLineWidth

This is intended to not break any existing implementation and should only fix an edge case.

Also unrelated to the current issue: DrawUtil.WrapText adds an unnecessary space at every line at the end.

Minimal reproduction that produces a wrong LineWidth string:

var test = "invidunt ut labore et dolore magna aliquyam erat, sed";
var result = DrawUtil.WrapText(GameService.Content.GetFont(FontFace.Menomonia, FontSize.Size16, FontStyle.Regular), test, 360);
var lineWidth = GameService.Content.GetFont(FontFace.Menomonia, FontSize.Size16, FontStyle.Regular).MeasureString(result); // lineWidth = 363

@Denrage Denrage self-assigned this Feb 16, 2026
@Denrage Denrage requested review from dlamkins and greaka February 16, 2026 12:29
@Denrage
Copy link
Collaborator Author

Denrage commented Feb 16, 2026

I talked with @greaka about the added MeasureString operations and it is sadly something we need to do.
The resulting string has a different MeasureString size than the sum of it parts.
image

@dlamkins
Copy link
Member

Worth bringing in some context from earlier looks into this.

#998
#997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants