Function for calculating variable width font
Posted on 2006-03-20
I wish to write a underline function that can use the indicated character to underline the certain text, eg
This is the example
In this example, the function simply append a carriage return and add 13 "=".
For fixed width font like courier, we know that "This is the example" has 13 characters, we can easily use 13 "=" to underline it.
The problem is for variable width font like Times New Roman. Arial, etc, we cannot be certain that how many "=" we should use in order to underline certain text perfectly.
Is there any written function on the web that can help us to calculate this based on the font type?
(For example, If we input "Times new roman", <font size>, "This is the example", and "=" as parameter to the function, it should return approximately how many "=" should be use based on the length of the text)
(Or, If we input "Times new roman", <font size>, "This is the example" to the function, the function should return us the length of string based on certain unit, and we use the return information to calculate our own)
(Or even there don't have any function avaialable, but there is a table of the width of font for certain font type, we write the function ourself)
(Or, something that is workable)