If you're not scared of Java, one approach would be to use the
java.awt.FontMetrics class (probably via a temp image's Graphics
instance), specifically the getStringBounds method.  That'll give you
all kinds of goodies about the font and strings written using that
font.

If you don't want that complexity, you could record the pixel width of
each character in your desired font into a struct, and loop over the
string, summing up a length.  Won't be exactly perfect, because of
ligatures and kerning, but it should be close, and I believe that'll
never underestimate, but that'll might not be true.

cheers,
barneyb

On Wed, 11 Aug 2004 12:12:31 -0400, Dirk Sieber <[EMAIL PROTECTED]> wrote:
> Hello everyone,
>
> We're trying to figure out if there's a way in CF to figure out the
> actual, physical length of a string of text - eg, in pixels, inches,
> whatever.
>
> The issue - we need to be able to accept user data for a field, that
> will eventually be printed to a PDF.  That PDF has strict specs as to
> how long a line of text can be.  Of course, that'd be simple enough, if
> it was printed in a fixed-width font... but it's not, and we don't have
> the option of changing it.
>
> So... I need to find a way to detemine how long a string of text will
> be, given the font type, style, & point size.  Anyone have any ideas how
> to do this from within CF?  (This is under MX, BTW).
>
> Many thanks for any suggestions!
> Dirk

--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to