Click to See Complete Forum and Search --> : Getting info about Fonts!?


tim_gor
03-27-2003, 04:07 AM
Does anyone know how to get information about Fonts in Javascript?

What I mean is I want to dynamically make tables with some text inside them (namely, some kind of menu system)
I need to know how many pixel wide the whole text is so that the table width isn't too big or too small.

For those familiar with Java, I want something equivalent to what the FontMetrics class does!

khalidali63
03-27-2003, 07:50 AM
With javascript you can not get the default values from browser unless they are explicitly declared in a document.

To do what you want ,my feeling is that you will have to decalre your fonts or any other property which you eant to access at run time like this

<table id="t1" style="font-size:10pt;font-family:cursive;"
etc and then in the with javascript you can access it like this

size = document.getElementById("t1").style.fontSize

and so on.

I hope some one has a better work around for you.

Ceers

Khalid

tim_gor
03-27-2003, 08:56 AM
Thank you but I've come up with (kinda) a workaround now which is quite neat, though still far from perfect -- what I'm doing now is making a hidden layer in which to insert the text, then getting the width of the whole layer by
layer.clientWidth

obviously doesn't work for longer strings so I'd still appreciate anyone with a better idea!

locitt
12-16-2003, 02:23 AM
hi tim_gor,

i've got the same problem and i want to get the width of a text to compare to the width of screen.

could you tell me more about your solution?

Thanks.

locitt.