time - my problem here is that this is basically the first time I've
dealt with objects and/or Java in relation to CF. So... how do I go
about reusing the FontMetrics object once I've created it? You'll have
to excuse my ignorance.
Creating one for each font variation, & then using the appropriate one
at the appropriate time definitely seems to make sense. We're dealing
with a limited number of font/style combinations, so it's definitely
feasible.
Thanks,
Dirk
-----Original Message-----
From: Pete Freitag [mailto:[EMAIL PROTECTED]
Sent: Monday, August 16, 2004 12:53 PM
To: CF-Talk
Subject: SUSPECT: Re: slow Java call - Determining physical
length of string - Pt 2
Hi Dirk,
I think most of the slowness is in creating the objects not
calculating
the width. So if you can somehow cache or reuse the objects, it
is much
faster. You will notice that the following code is much faster
than
calling the UDF. So what I would suggest is that if your going
to be
using the same face, style and size that you just create the
FontMetrictsObject once, and reuse it:
<cfscript>
face = "Arial";
style = "Plain";
size = 12;
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);
</cfscript>
<cfset tick = GetTickCount()>
<cfloop from="1" to="5000" index="i">
<cfset size = FontMetricsObject.stringWidth("this string
width")>
</cfloop>
<cfset tock = GetTickCount()>
<cfoutput>#tock-tick#ms</cfoutput>
Dirk Sieber wrote:
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

