mIRC Homepage
Posted By: Wims $width($chr(9)) - 12/03/20 06:57 PM
$width($chr(9),verdana,15) is 0, when $height() returns 19
When /drawtexting the tab character, it definitely takes some width, is this a bug?
Posted By: Khaled Re: $width($chr(9)) - 14/03/20 03:25 PM
Thanks for your bug report. That is the length being returned by Windows APIs for the tab character. When I test this with /drawtext, eg. drawing the letters AB or the letters A $+ $chr(9) $+ B, using different fonts, the letters are spaced the same, ie. no space between the characters A and B. The same applies to several other non-printable characters.
Posted By: Wims Re: $width($chr(9)) - 14/03/20 04:33 PM
Which font did you try? I tried both verdana and segoe ui symbol, width is 0 and there is a space between the two letters for me.
Posted By: Wims Re: $width($chr(9)) - 14/03/20 05:39 PM
Right, I mistested when triyng to replicate the issue outside of my big chunk of code.

The issue only appears when using the drawtext -p switch to support control codes.

Quote
//window -pdCBfo +l @test -1 -1 400 400 | drawrect -fr @test 16777215 0 0 0 400 400 | drawtext -rpn @test 0 "segoe ui symbol" 50 100 100 $+(A,$chr(9),B) | drawdot @test
Posted By: Khaled Re: $width($chr(9)) - 15/03/20 09:22 PM
The -p switch in /drawtext makes it process control codes. You would need to use the same option in $width().
Posted By: Wims Re: $width($chr(9)) - 15/03/20 10:37 PM
Even with $width($chr(9),verdana,25,0,1) or $width($chr(9),segoe ui symbol,25,1,1) I get 0, which should process control code
Posted By: Khaled Re: $width($chr(9)) - 17/03/20 09:28 AM
Right, this is actually a little more complicated. $chr(9) is definitely zero length as returned by Windows APIs. However, some characters in custom @windows are processed slightly differently from normal windows, and this includes tab characters. $width() and $height() work independently of window type, since there is no window parameter. They currently default to the window type in which they are being called. If you call these from a custom @window, they will return the value you expect to match /drawtext. If you call them from any other window, they will return values for normal windows.

To make them match /drawtext, one solution would be to add a switch to $width() and $height() to make them use a custom @window type measurement.

Or, since they will usually be used with /drawtext, make them default to custom @window measurement. But this would break backward compatibility in measurement of text that includes tab characters in non-custom windows.
Posted By: Wims Re: $width($chr(9)) - 17/03/20 06:04 PM
Indeed, indeed.

Where is that width coming from? Are you replacing the tab by some spaces in this case?

I'm fine with a new switch.
© mIRC Discussion Forums