473,714 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8888
Ram <St****@gmail.c omwrote in news:1178029544 .763823.300580
@c35g2000hsg.go oglegroups.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.co mwrote:
Ram <Ste...@gmail.c omwrote in news:1178029544 .763823.300580
@c35g2000hsg.go oglegroups.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.c omwrote in
news:11******** **************@ h2g2000hsg.goog legroups.com:
On May 1, 11:38 pm, Good Man <h...@letsgo.co mwrote:
>Ram <Ste...@gmail.c omwrote in news:1178029544 .763823.300580
@c35g2000hsg.g ooglegroups.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.getEle mentsByTagName( "font");
var checkedElem = fonts[0];
var height = checkedElem.off setHeight;
for(var i = 0; i < 100; i++)
{
var tempFont = document.create Element("font") ;
tempFont.style. fontSize = i + "px";
tempFont.innerH TML = checkedElem.inn erHTML;

document.body.a ppendChild(temp Font);
var tempHeight = tempFont.offset Height;
document.body.r emoveChild(temp Font);

if (tempHeight >= height)
{
alert("Font size = " + i + "px");
break;
}
}
}
</script>
<body onload="checkSi ze()">
<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.javas cript 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.javas cript 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7300
by: harrelson | last post by:
I have a list of about 2500 html escape sequences (decimal) that I need to convert to utf-8. Stuff like: 비 행 기 로 보 낼 거
1
3354
by: Bill Sneddon | last post by:
I am using an XML file produced by doing a save-as in Excel. The file has content that looks like one of these three examples lines: <Cell ss:StyleID="s24"><ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">H<Sub>3</Sub><Font>PO</Font><Sub>4 </Sub></ss:Data></Cell> <Cell ss:StyleID="s24"><Data ss:Type="String">GC</Data></Cell> <Cell ss:StyleID="s24"><ss:Data ss:Type="String"
5
3488
by: JJ | last post by:
Hi all, I am using the color dialog box to select a colour to print with. However, the e.Graphics.DrawString method uses Brushes.Black, not Color.Black. How do I convert from Brushes to Colors and back
0
1088
by: Sugan | last post by:
Hi, I'm converting a VB 6.0 project to VB 2005. There are few issues, where i got stuck up. They are 1. 'Ambient' is not a member of 'System.Windows.Forms.UserControl' This is the code that gives this error. If (mbHasFocus Or MyBase.Ambient.DisplayAsDefault) And m_Style <> 0
4
3096
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these applications into Visual Basic.Net. My managers main thought is that Visual Basic 6 is (or has!) stopped being supported by Microsoft.
1
4699
by: nothing1 | last post by:
I'm getting some warning using the code below: Error: failed to open stream: Permission denied in Code: function wwwcopy($url,$dirname){ $file = fopen($url, "r"); if (!$file) { echo"<font color=red>Failed to copy $url!</font><br>"; return false;
1
6226
by: Wizfrog | last post by:
Hello, I want to convert styles from a String to a Form object. So ifound that i can use FontConverter that will do just that... as in the help: // Create the FontConverter. TypeConverter converter = TypeDescriptor.GetConverter(typeof(Font));
1
3562
Brutus
by: Brutus | last post by:
I'm a total newbie in C# and ASP.NET, so I hope I'm in the right forum. My very first project is a custom control that converts strings into images on the fly (through a httphandler) - that works fine, except for 'FontSize'. I have no clue how to convert the FontUnit into a float-value. - This works fine: String sFontSize = context.Request.Params.Get("FontSize"); FontUnitConverter fuc = new FontUnitConverter(); FontUnit fu=...
5
9414
by: almurph | last post by:
RE: Tryign to convert Graphics object to a bitmap Hi, Hope you can help me with this. I have to open a file and add some text to it and then display it. So I create an Image object then import it into a Graphics object and add the text. I then try converting it to a bitmap image using the following line:
1
2241
by: Michelle Sollicito eBarster | last post by:
Ok I know a lot of asp but not a lot of asp.net and C# so please bear with me. I need some help converting.. In my asp project I have some styles in my head tag that change according to a parameter passed in in the query string - fontfamily is the variable that I store the value of the parameter in within my asp code, and then I place that into the styles see below.. <style type="text/css"> a:link,a:visited,a:hover,a:active{font...
0
8802
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4726
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2111
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.