"TextWidth" always returns zero

Just starting out? Need help? Post your questions and find answers here.
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

"TextWidth" always returns zero

Post by orangetek »

Hi, what am i doing wrong?

Code: Select all

loginwindow = OpenWindow(#PB_Any, 0, 0, 400, 300, "", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
canvas = CanvasGadget(#PB_Any, 0, 0, 400, 300)
text.s = "test"

If StartDrawing(CanvasOutput(canvas))
  Debug "Text Width: " + TextWidth(text) ; <---- Always Zero ??
  Debug "Text Height: " + TextHeight(text)
  DrawText(0, 0, text)
  StopDrawing()
EndIf
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: "TextWidth" always returns zero

Post by Peter »

orangetek wrote:Hi, what am i doing wrong?
works here:
Image
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Re: "TextWidth" always returns zero

Post by orangetek »

I am using a linux environment. I just tested it in Windows and it works.
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Re: "TextWidth" always returns zero

Post by orangetek »

Brave browser "cross-site fingerprinting blocked" .. so its a browser issue, but only on width? how strange
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: "TextWidth" always returns zero

Post by Peter »

orangetek wrote:Brave browser "cross-site fingerprinting blocked" .. so its a browser issue, but only on width? how strange
interesting:
support.mozilla.org wrote:These are some of the characteristics of your device and browser that fingerprints can collect:

Extensions you use
Operating system and model of your device
Screen resolution and language
Information about your network connection
Fonts installed on your computer
orangetek wrote:but only on width?
Width and Height are determined differently.

Code: Select all

function spider_TextWidth(a) {
    return Math.ceil(spider.drawing.context.measureText(a).width)
}
and

Code: Select all

function spider_TextHeight(a) {
    a = spider_2ddrawing_getTextHeight(spider.drawing.context.font);
    return a.ascent + a.descent
}
For this reason measureText(a).width is probably responsible for the error message
orangetek
Posts: 19
Joined: Fri Dec 08, 2017 2:32 pm

Re: "TextWidth" always returns zero

Post by orangetek »

Thanks peter. I have another issue with loading fonts but ill create a new topic
Post Reply