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;
}

This is a waste you can just pass on int value in so you coul just do
something like this (sorry it isn't in cfscript its a copy and paste
job from my function):
<cfswitch _expression_="#arguments.style#">
               <cfcase value="plain"><cfset font_style = 0/></cfcase>
               <cfcase value="bold"><cfset font_style = 1/></cfcase>
               <cfcase value="italic"><cfset font_style = 2/></cfcase>
               <cfcase value="bold italic"><cfset font_style = 3/></cfcase>
               <cfcase value="italic bold"><cfset font_style = 3/></cfcase>
               <cfcase value="bolditalic"><cfset font_style = 3/></cfcase>
               <cfcase value="italicbold"><cfset font_style = 3/></cfcase>
       </cfswitch>
That will elminate an object creation right there.
Also for each page request only create the font objects as many times
as there are different font,style,point combinations...that should
also trim down the # of time the object is created.

Adam H

On Mon, 16 Aug 2004 15:03:47 -0400, Dirk Sieber <[EMAIL PROTECTED]> 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]

Reply via email to