Determining the length of text

  • Thread starter Thread starter blue
  • Start date Start date
B

blue

I have a table that I want to have a set width and height. The table has a
title and the text may be larger than the width of the table. If the text
is too large to fit into the table, it either line breaks or stretches the
width of the table depending on how large a word is.

For example, "this is a really long title" would line break, and
"this_is_a_really_long_word", would stretch the width of the title

I need the tables to be an exact size because it's a flowchart program and I
have directional lines connecting the tables to where it thinks the table
coords should be. If the table size changes, the lines go right through the
table and it looks bad.

I've fixed this problem by using tooltips if the number of characters of the
title exceed a certain amount (say 13). The problem is, not all letters
take up the same amount of space. Also, I don't want to hard code a font
face or size in my code. This will be handled by the style sheet later on
and whatever the designer picks for the visual layout should work without
having to change the code.

I can do the lowest common denominator and make the text tooltip at 8
characters (and assume a certain font and size). This is a boundry case and
the typical cases with characters that don't take up so much space look bad
with only a few letters and then "..." at the end telling the user to mouse
over to see the whole line. The 'M' character takes up much more space than
"u" or "o" but I have to handle the case where everything might be
uppercase.

Finally, my question: is there a way to know the length of text? I think
I'll have to pick a font face and stick with it. If there's a way to
determine the length of text by the characters it contains, the font size
and the font face, I'll be able to make it look better.

thanks,

blue
 
I really don't think so. The problem is that depending on the browser, the
text (not to mention the surrounding HTML objects) may be larger or smaller,
or even a different font.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top