Note that, in Java 2D, a shape cannot "know" its outline design because that depends on another graphics attribute - the Stroke object. The default implementation of that interface is a BasicStroke object with a line width of 1.0f, but that is just the default for the Graphics objects you get from images and components. A different implementation of Stroke may behave entirely differently and a graphics retrieved from a different context may have a different default setting.

Thus, to get a result that includes the "Stroke" you have to consult the Stroke object that will be used to render the object. It implements a "createStrokedShape()" method, part of the Stroke interface, to return the shape that defines the area to be painted when a given Shape is stroked by that object.

If you just want the bounds with the stroke included (as opposed to the actual shape that will be stroked), and if you know that you only ever plan to use a BasicStroke object with a simple line width, then it might be simpler to just take the bounds of the shape, pad it by "linewidth / 2" on every side, and use that. Unfortunately this approximation does have its limitations - the default JOIN attribute on BasicStroke is a MITER stroke which can extend more than lw/2 units away from the shape, depending on how sharp any of the angles in the shape are. To predict if this comes into play you should read up on the subject of MITER joins and the miterlimit attribute. Or, if you are using ROUND or BUTT joins then the lw/2 padding is sufficient for their operation.

Another potential caveat is that the default setting for the STROKE_CONTROL rendering hint, which controls tweaking an outline for aesthetic purposes, is STROKE_NORMALIZE which allows the rendering algorithms to tweak the outline by up to a pixel to increase the chance of consistent line thicknesses. Setting that hint to STROKE_PURE requests that no such normalization occur during rendering...

                        ...jim

jav...@javadesktop.org wrote:
Hi Piet,

Thank you for your input and suggestions.

I also discovered that the problem can be avoided by expanding the clip region 
but this example with the rectangle is only the very simplest case of the 
overall problem I am facing.  I have found that this problem applies with 
shapes of all kinds and complexity and expanding the clip region is not so easy 
given that the shape is not a simple rectangle.

How can I solve this problem in a more general sense with more complex shapes?
[Message sent by forum member 'qu0ll' (qu0ll)]

http://forums.java.net/jive/thread.jspa?messageID=326980

===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
lists...@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to lists...@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
lists...@java.sun.com and include in the body of the message "help".

Reply via email to