Page 1 of 1
"TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:00 am
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
Re: "TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:12 am
by Peter
orangetek wrote:Hi, what am i doing wrong?
works here:

Re: "TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:24 am
by orangetek
I am using a linux environment. I just tested it in Windows and it works.
Re: "TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:26 am
by orangetek
Brave browser "cross-site fingerprinting blocked" .. so its a browser issue, but only on width? how strange
Re: "TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:38 am
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
Re: "TextWidth" always returns zero
Posted: Mon Jun 22, 2020 8:51 am
by orangetek
Thanks peter. I have another issue with loading fonts but ill create a new topic