Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting Font-Size To Pixels

79 views
Skip to first unread message

Ram

unread,
May 1, 2007, 10:25:44 AM5/1/07
to
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

Good Man

unread,
May 1, 2007, 4:38:45 PM5/1/07
to
Ram <Ste...@gmail.com> wrote in news:1178029544.763823.300580
@c35g2000hsg.googlegroups.com:

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.


Ram

unread,
May 2, 2007, 3:22:11 AM5/2/07
to

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

Good Man

unread,
May 4, 2007, 1:21:04 AM5/4/07
to
Ram <Ste...@gmail.com> wrote in
news:1178090531.7...@h2g2000hsg.googlegroups.com:

you could probably get the "font-size" of the font, but you would not be
able to get the size in pixels.

marss

unread,
May 4, 2007, 5:28:00 AM5/4/07
to
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>

töff

unread,
May 4, 2007, 10:11:26 AM5/4/07
to
You would have to know the visitor's monitor resolution to know how
many pixels relate to point size.

Randy Webb

unread,
May 4, 2007, 5:37:56 PM5/4/07
to
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/

töff

unread,
May 4, 2007, 11:17:45 PM5/4/07
to
Perhaps to you but not to many others.

Randy Webb

unread,
May 4, 2007, 11:56:30 PM5/4/07
to
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.

töff

unread,
May 5, 2007, 1:01:17 AM5/5/07
to
Who said I can't do "it"? What is "it" that I can't do? WTF are you
talking about Randy.

töff

unread,
May 5, 2007, 1:02:29 AM5/5/07
to
Oh you're the asshole I said I'd ignore, my bad, sorry. Nevermind and
please continue to be a dick.

Randy Webb

unread,
May 5, 2007, 5:22:14 PM5/5/07
to
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.

0 new messages