You can set a "clipping region" on the graphics context before painting the
string.  Anything that would be painted outside this region gets "clipped" -
i.e., chopped off.  That should effectively set a maximum size on the area you
paint the text in.

See java.awt.Graphics.setClip()

HTH,

DR

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:[EMAIL PROTECTED] Behalf Of Augusto Sellhorn
> Sent: Thursday, August 26, 2004 7:55 PM
> To: [EMAIL PROTECTED]
> Subject: [JAVA2D] Drawing text inside of a bounding box
>
>
> I have a situation where users are editing a vector drawing
> in a program
> where the font doesn't match what I display in my renderer. In their
> editing program, all that is saved is a world "height" for
> the text, so
> I can use that to scale and match the font once I draw it.
>
> Now, the font they use in the editing program is monospaced,
> so based on
> the height, i can calculate a "maximum width". Saying that, I'm trying
> to find a way to simply draw a string saying and make sure it doesn't
> exceed this bounding box (height and calculated width).
>
> Is there any easy and fast way to do this?
>
> What I have now tries to match the height, and it does, but
> then when it
> goes for the width it has to decrement the size until the width is not
> greater than the calculated width. There are some cases where
> this takes
> too many iterations and is slow.
>
> So if anybody has any idea what I'm talking about :-), what's a good
> idea to just say, draw this string and don't exceed these bounds?
>
> Thanks
>
> Augusto

==============================================================================
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==============================================================================

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to