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

Just starting out? Need help? Post your questions and find answers here.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

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

Post 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
Last edited by walbus on Sun Nov 12, 2017 8:27 pm, edited 2 times in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Post by Dude »

As a guess, could it be due to automatic font kerning of entire words, versus no font kerning for individual characters?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Post 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)
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Post by Wolfram »

Here, on 10.7 it is both 64 and it must be both the same otherwise it makes no sense.
macOS Catalina 10.15.7
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Post 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.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: TextWidth Missmatch PB561 OS 10.12 - 10.13

Post 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
Post Reply