Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Converting Font-Size To Pixels

Reply
Thread Tools

Converting Font-Size To Pixels

 
 
Ram
Guest
Posts: n/a
 
      05-01-2007
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

 
Reply With Quote
 
 
 
 
Ram
Guest
Posts: n/a
 
      05-02-2007
On May 1, 11:38 pm, Good Man <(E-Mail Removed)> wrote:
> Ram <(E-Mail Removed)> wrote 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

 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      05-04-2007
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>

 
Reply With Quote
 
töff
Guest
Posts: n/a
 
      05-04-2007
You would have to know the visitor's monitor resolution to know how
many pixels relate to point size.

 
Reply With Quote
 
töff
Guest
Posts: n/a
 
      05-05-2007
Perhaps to you but not to many others.

 
Reply With Quote
 
töff
Guest
Posts: n/a
 
      05-05-2007
Who said I can't do "it"? What is "it" that I can't do? WTF are you
talking about Randy.

 
Reply With Quote
 
töff
Guest
Posts: n/a
 
      05-05-2007
Oh you're the asshole I said I'd ignore, my bad, sorry. Nevermind and
please continue to be a dick.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why don't Sony and Pentax have this problem? Dead pixels, defective pixels RichA Digital Photography 9 04-12-2011 08:54 AM
Converting Font-Size To Pixels Ram HTML 6 05-03-2007 07:39 AM
Can hot pixels become dead pixels? kl_tom Digital Photography 4 10-05-2006 06:52 PM
Pse explain "3.1m effective pixels and 6.0m redorded pixels" notreallyme Digital Photography 14 12-28-2003 03:41 PM
What's the difference between effective pixels and recorded pixels? Mark Grady Digital Photography 10 09-28-2003 11:11 PM



Advertisments