ID:2644799
 
Resolved
MeasureText() got incorrect measurements in some cases where a space between wrapped lines of text was counted toward the width, even if it exceeded the available width.
BYOND Version:513
Operating System:Windows 10 Pro 64-bit
Web Browser:Chrome 87.0.4280.88
Applies to:Dream Seeker
Status: Resolved (513.1540)

This issue has been resolved.
Descriptive Problem Summary:
MeasureText proc sometimes does not follow the width parameter.

Code Snippet (if applicable) to Reproduce Problem:
mob
verb
TestMeasureText()
var/textWidth = input(src,"Width?","MeasureText Width", 215) as num
var/textMessage = input(src, "Text to Measure", "MeasureText Text", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") as text
var/measureText = src.client.MeasureText(textMessage, null, textWidth)
src << "MeasureText Dimensions [measureText]"


Expected Results:
Outputs 215x[Something]
Actual Results:
Outputs 218x196

Does the problem occur:
Every time? Or how often? Every time
In other games? N/A
In other user accounts? N/A
On other computers? N/A

When does the problem NOT occur? Seems to be inconsistent when it respects it and when it doesn't. I thought it was isolated to br tags or /n in the text, but it seems to be something other than that as you can see in the demo.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.) Did not test previous BYOND versions.

Workarounds: Unknown

I had an issue where I had to measure the text twice, as the first time is incorrect, dunno if same issue tho.
In response to Kozuma3
Koz, if you can replicate that in a test project I'd love to take a look. If so, please post a bug report and I'll absolutely look at it after the holidays if not sooner.
Can you send me a test project to replicate this? The measurements will obviously depend on fonts and styling and such so I want to make sure I'm on the exact same page as you when I test.
Lummox JR wrote:
Can you send me a test project to replicate this? The measurements will obviously depend on fonts and styling and such so I want to make sure I'm on the exact same page as you when I test.

I totally didn't see that you replied and that you were waiting on something from me! Essentially, the code snippet from the OP is the example project. I didn't pass it a styles arg, so it should use the default map control's styles, if any. If you still need the example project that includes this code, I have included it as an attachment below:
http://files.byondhome.com/Hinashou/MeasureTextDemo.zip
Thanks. I'll look into that.
Lummox JR resolved issue with message:
MeasureText() got incorrect measurements in some cases where a space between wrapped lines of text was counted toward the width, even if it exceeded the available width.