/    Sign up×
Community /Pin to ProfileBookmark

Getting info about Fonts!?

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!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Mar 27.2003 — 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
Copy linkTweet thisAlerts:
@tim_gorauthorMar 27.2003 — 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!
Copy linkTweet thisAlerts:
@locittDec 16.2003 — 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.
×

Success!

Help @tim_gor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...