Page 1 of 1

[Not a bug] TextWidth Missmatch PB561 OS10.12-10.13

Posted: Sun Nov 12, 2017 9:23 am
by walbus
This demo code results different text lengths
Tested PB561 OS 10.12 - 10.13

Meanwhile, I assume a PB bug
It can be very unpleasant and strange for text length calculations
With nearly any text, the difference is approximately one character width

Code: Select all

CreateImage(1, 300, 100)
OpenWindow(1, 0, 0, 300, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StartDrawing(ImageOutput(1))
Debug TextWidth("Hello World")
twidth=TextWidth("H")+TextWidth("e")+TextWidth("l")+TextWidth("l")+TextWidth("o")+
       TextWidth(" ")+TextWidth("W")+TextWidth("o")+TextWidth("r")+TextWidth("l")+TextWidth("d")
Debug twidth
Box(0, 0, twidth, 20, $FF)
DrawText(0, 0, "Hello World")
StopDrawing()
ImageGadget(1, 0, 0, 0, 0, ImageID(1))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Posted: Sun Nov 12, 2017 11:03 am
by Dude
As a guess, could it be due to automatic font kerning of entire words, versus no font kerning for individual characters?

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Posted: Sun Nov 12, 2017 12:26 pm
by walbus
@Dude
Yeah, possible, it's weird.
I used it for a text stretching function
It was not easy to find out why it doesn't work correct on Macs :twisted:

(A hint for BF and DrawText_EX Users : I have add a workaround for Mac, now)

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Posted: Sun Nov 12, 2017 12:42 pm
by Wolfram
Here, on 10.7 it is both 64 and it must be both the same otherwise it makes no sense.

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Posted: Sun Nov 12, 2017 1:04 pm
by Dude
I'm thinking because the text "AW" might only end up being 15 pixels due to kerning the two characters together; but "A" by itself might be 10, and "W" by itself might also be "10", if you know what I mean? Just guessing, though.

What happens if you do it with a fixed-with font, like Courier? That would rule out kerning as the cause.

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Posted: Sun Nov 12, 2017 1:23 pm
by walbus
@Dude
That's logical, I think you're primarily right.
Hmmm, on Mac its also with a row "IIIIIIII"
But, as a result, my workaround for Mac is the only correct method for stretched text on all OSs, "WAWA" is ever different :shock:

The stretched text is and looking very cool
Once you've seen or used this one, you don't want to miss it