them in the application scope somewhere..... Then you don't have to
create font objects, to pass to system toolkits, to get metrics objects,
on every string measurement. The only thing you should have to do is ask
an existing fontmetrics object for the string width.
You could also cache any results that are likely to be the same, by
building a struct of key-value pairs for your common values, which I
believe is suggested below.
hth
-dov
_____
From: Nathan Strutz [mailto:[EMAIL PROTECTED]
Sent: Monday, August 16, 2004 3:36 PM
To: CF-Talk
Subject: Re: slow Java call - Determining physical length of string - Pt
2
I'm not familiar with what exactly your app is doing, nor the AWT
library, but app caching, yes. Might there be a way to store the string
width with the string? For instance, if it's called from a database, add
a field for width, and recalculate on insert and update, not on select.
Other than that I've got one last idea. What if you calculate the length
of a word (assuming this is normal user-input text)? For example, if
"The" will be 23px wide each time, save it and reuse it. It will be more
calls to the FontObject initially, once per word instead of per
sentence, but will pay off once it caches a couple hundred words.
Ehh, maybe not the easiest, but perhaps worth a try.
-nathan strutz
Dirk Sieber wrote:
> Hello again,
>
>
> Last week, I posted regarding finding the actual length of a text
string
> (original question below), and, thanks to some helpful people, ended
up
> with the idea of instansiating the Java FontObject, which we turned
into
> a function, like this:
> <cffunction name="StringWidth" output="false">
> <cfargument name="String" required="true">
> <cfargument name="Face" default="Arial">
> <cfargument name="Style" default="Plain">
> <cfargument name="Size" default="12">
>
> <cfscript>
> if (Style EQ "Plain" OR Style EQ "Normal") {
> Style = CreateObject("java", "java.awt.Font").PLAIN;
> } else if (Style EQ "Bold") {
> Style = CreateObject("java", "java.awt.Font").BOLD;
> } else if (Style EQ "Italic") {
> Style = CreateObject("java", "java.awt.Font").ITALIC;
> }
>
> FontObject = CreateObject("java","java.awt.Font").init(Face, Style,
> Size);
> FontMetricsObject =
>
CreateObject("java","java.awt.Toolkit").getDefaultToolkit().getFontMetri
> cs(FontObject);
>
> return(FontMetricsObject.stringWidth(String));
>
> </cfscript>
> </cffunction>
>
>
> Now, the problem - it works really well, but it's painfully slow -
we're
> sometimes calling this 50 times on a page, and it's causing the page
> times to be in the 3-5 second range. Removing the call drops it to a
> few hundred milliseconds, so this seems to be the issue.
>
>
> It's not completely intolerable, and it's much nicer than the 'keep a
> table of all the character widths' way of doing things, so we'll stick
> with it, but if anyone's got any ideas on a way to speed this up, I'm
> all ears!
>
>
> Thanks,
> Dirk
>
> > From: Dirk Sieber [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, August 11, 2004 11:13 AM
> > To: CF-Talk
> > Subject: Determining physical length of text string (not char
count)
> >
> >
> > 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
> > _____
> >
> >
>
_____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

