Calculating text pixels

C

Conax

Hi,

Just wondering if there is a way in ASP, to calculate with of a string of
text in pixels. The result is to be used to set table width so that texts
don't get wrapped to second line.

Thank you.
Conway
 
C

Conax

Hi William,

I tested with the em unit but it created a table width much more than
required. Here's my test code:

<HTML>
<TABLE border="1" style="width:50em">
<TR>
<TD>
<FONT face="arial">123 56 8 012 456 890 2 45 7 9 1 3 5 7890 234 678 0</FONT>
</TD>
</TR>
</TABLE>
</HTML>

The result is like this:
123 56 8 012 456 890 2 45 7 9 1 3 5 7890 234 678 0


Can you (or someone) show me where I'm doing it wrong please?

Thank you.
Conway
 
D

Dan Brussee

Hi William,

I tested with the em unit but it created a table width much more than
required. Here's my test code:

<HTML>
<TABLE border="1" style="width:50em">
<TR>
<TD>
<FONT face="arial">123 56 8 012 456 890 2 45 7 9 1 3 5 7890 234 678 0</FONT>
</TD>
</TR>
</TABLE>
</HTML>

The result is like this:
123 56 8 012 456 890 2 45 7 9 1 3 5 7890 234 678 0

Read up on the definition of an "em". 1em = the width of the character
"M" in the current font. Given the fact that the font you are using is
probably proportional, not many (if any at all) of you numbers are as
wide as a captital M. Therefore, a space that is as wide as 50 "M"'s
will difinitely be wider than the characters you chose to put into it.

Now, to give a possible answer for your spacing delema, you might try
using <NOBR> </NOBR> and do not give a width property to the TD, but
some would say this is a bad idea.
 
C

Conax

Thanks William and Dan,

Sorry William I don't have a URL as I'm testing on my own PC that cannot be
accessed from outside.

When I posted the result it had a table border on my screen around the
numbers but somehow that border is gone after the message reached the news
server...
But it was looking something like this:

| 123 56 8 012 456 890 2 45 7 9 1 3 5 7890 234 678 0
|

When it comes to worse, I can just use rough estimate of : (average
character width) x (number of characters) to calculate the table width. :)

Thank you all.
Conway
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top