469,271 Members | 1,366 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Converting Font-Size To Pixels

Ram
Hey,
I've got the following code:
<font font-size="7">Hello</font>

How can I calculate the font-size int the actual size in pixels?

Thanks ahead!

--sternr

May 1 '07 #1
11 8671
Ram <St****@gmail.comwrote in news:1178029544.763823.300580
@c35g2000hsg.googlegroups.com:
Hey,
I've got the following code:
<font font-size="7">Hello</font>

How can I calculate the font-size int the actual size in pixels?

Thanks ahead!
that code is insanely bad. you can't do it.

you should be setting font sizes, and everything else related to display,
via CSS instead of in tags themselves.
May 1 '07 #2
Ram
On May 1, 11:38 pm, Good Man <h...@letsgo.comwrote:
Ram <Ste...@gmail.comwrote in news:1178029544.763823.300580
@c35g2000hsg.googlegroups.com:
Hey,
I've got the following code:
<font font-size="7">Hello</font>
How can I calculate the font-size int the actual size in pixels?
Thanks ahead!

that code is insanely bad. you can't do it.

you should be setting font sizes, and everything else related to display,
via CSS instead of in tags themselves.
Hey,
I know this is bad, but it's not my code - long story short - I cant
change this html...
isn't there a way of doing that?

Thanks again

--sternr

May 2 '07 #3
Ram <St****@gmail.comwrote in
news:11**********************@h2g2000hsg.googlegro ups.com:
On May 1, 11:38 pm, Good Man <h...@letsgo.comwrote:
>Ram <Ste...@gmail.comwrote in news:1178029544.763823.300580
@c35g2000hsg.googlegroups.com:
Hey,
I've got the following code:
<font font-size="7">Hello</font>
How can I calculate the font-size int the actual size in pixels?
Thanks ahead!

that code is insanely bad. you can't do it.

you should be setting font sizes, and everything else related to
display, via CSS instead of in tags themselves.

Hey,
I know this is bad, but it's not my code - long story short - I cant
change this html...
isn't there a way of doing that?
you could probably get the "font-size" of the font, but you would not be
able to get the size in pixels.

May 4 '07 #4
Ram wrote:
>>Hey,
I've got the following code:
<font font-size="7">Hello</font>
I think here is a typo. The font element has no attribute "font-size".
Correct is "size":
<font size="7">Hello</font>
>>How can I calculate the font-size int the actual size in pixels?
>>Thanks ahead!
>>--sternr
You can try next approach.
Create in runtime a font element, set it font size to known value in
pixels and compare this element with the font element which size you
want to define. Increase the size in series and at some point of time
you will get required value.
Short example:

<html>
<script type="text/javascript">
function checkSize()
{
var fonts = document.getElementsByTagName("font");
var checkedElem = fonts[0];
var height = checkedElem.offsetHeight;
for(var i = 0; i < 100; i++)
{
var tempFont = document.createElement("font");
tempFont.style.fontSize = i + "px";
tempFont.innerHTML = checkedElem.innerHTML;

document.body.appendChild(tempFont);
var tempHeight = tempFont.offsetHeight;
document.body.removeChild(tempFont);

if (tempHeight >= height)
{
alert("Font size = " + i + "px");
break;
}
}
}
</script>
<body onload="checkSize()">
<font size="7">Hello</font>
</body>
</html>

May 4 '07 #5
You would have to know the visitor's monitor resolution to know how
many pixels relate to point size.

May 4 '07 #6
töff said the following on 5/4/2007 10:11 AM:
You would have to know the visitor's monitor resolution to know how
many pixels relate to point size.
I do? Don't answer that, you probably wouldn't quote it and end up
confusing anybody trying to follow the conversation. Besides, monitor
resolution is trivial.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 4 '07 #7
Perhaps to you but not to many others.

May 5 '07 #8
töff said the following on 5/4/2007 11:17 PM:
Perhaps to you but not to many others.
You have already shown your inability to read and comprehend what you
read so I won't expect you to understand what I am about to explain to
you. I only post it in the hopes that someone else reads it and doesn't
fall into your position.

Just because *you* can't do it doesn't mean it can't be done, it means
you can't do it. Yet you said you would have to know something that is
trivial to determine and in the end it is irrelevant.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 5 '07 #9
Who said I can't do "it"? What is "it" that I can't do? WTF are you
talking about Randy.

May 5 '07 #10
Oh you're the asshole I said I'd ignore, my bad, sorry. Nevermind and
please continue to be a dick.

May 5 '07 #11
töff said the following on 5/5/2007 1:02 AM:
Oh you're the asshole I said I'd ignore, my bad, sorry.
So you are also a self admitting liar? Nice.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 5 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bill Sneddon | last post: by
1 post views Thread by nothing1 | last post: by
1 post views Thread by Wizfrog | last post: by
1 post views Thread by Michelle Sollicito eBarster | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.