Jim,

Both of your suggestions work like a charm.  Thanks!

-David


On Tue, 8 Jul 2003, Jim Graham wrote:

> Hi David,
>
> I haven't run your example, but I am pretty sure that this is happening
> because thin non-dashed lines are rendered using a fairly fast Bresenham
> algorithm, but dashed lines are rendered using a fairly complex but
> accurate technique of generating "widened" geometry for the line and then
> filling the "widened" geometry.
>
> You can work around this by either turning on antialiasing or by
> using a line width of 1.01 or so for both dashed and non-dashed
> lines.  This is because the antialiasing pipeline always uses the
> accurate line widening technique to draw even thin lines and in
> the second case because a line that is greater than 1.0 pixels
> in width will always go through the widening algorithm...
>
>                         ...jim
>
> --On Tuesday, July 01, 2003 18:26:08 -0400 David Eisner <[EMAIL PROTECTED]>
> wrote:
>
> > I have a GeneralPath that I draw with two different BasicStrokes.
> > The two strokes are (intended to be) identical except that one is
> > dashed.
> >
> > What I'm observing is that in some cases the two stroked outlines
> > do not overlap, as I'd expect them to.  Are my expectations incorrect?
> >
> > I'm including a simple program that demonstrates the problem.
> >
> > You can find a (blown up) screen capture here:
> >
> >     http://cradle.brokenglass.com/images/dash.png
> >
> > This is occurring with (at least) the following:
> >
> >   Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
> >   Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
> >
> > Thanks in advance.
> >
> > -David
> >
> >
> > ----
> >
> > import java.awt.*;
> > import java.awt.geom.*;
> > import javax.swing.*;
> >
> >
> >
> > public class DashTest extends JFrame {
> >
> >     class BoxCanvas extends JPanel {
> >
> >         Stroke      dashStroke_;
> >         Stroke      lineStroke_;
> >         Shape       shape_;
> >
> >
> >         BoxCanvas() {
> >
> >             BasicStroke ds = new BasicStroke();
> >
> >             lineStroke_ = ds;
> >             dashStroke_ = new BasicStroke(
> >                 ds.getLineWidth(), ds.getEndCap(), ds.getLineJoin(),
> >                 ds.getMiterLimit() , new float[] {8, 8}, 0
> >             );
> >
> >             shape_ = makeShape();
> >
> >             setBackground( new Color( 0, 200, 0));
> >             setPreferredSize( new Dimension(100, 100));
> >         }
> >
> >
> >
> >         private Shape
> >         makeShape() {
> >
> >             GeneralPath p = new GeneralPath();
> >
> >             p.moveTo( 20.0f, 70.0f );
> >             p.lineTo( 70.9f, 70.0f);
> >             p.lineTo( 70.9f, 20.0f);
> >             p.lineTo( 20.0f, 20.0f );
> >             p.closePath();
> >
> >             return p;
> >         }
> >
> >
> >
> >         public void
> >         paintComponent( Graphics g ) {
> >             super.paintComponent( g );
> >             Graphics2D g2 = (Graphics2D) g;
> >
> >             g2.setStroke( lineStroke_ );
> >             g2.setColor( Color.BLACK );
> >             g2.draw( shape_ );
> >
> >             g2.setStroke( dashStroke_ );
> >             g2.setColor( Color.WHITE );
> >             g2.draw( shape_ );
> >         }
> >     }
> >
> >
> >
> >     public DashTest() {
> >         super( "DashTest" );
> >
> >         JPanel canvas = new BoxCanvas();
> >         getContentPane().add( canvas );
> >         setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
> >     }
> >
> >
> >
> >     public static void
> >     main( String[] args ) {
> >
> >         DashTest app = new DashTest();
> >         app.pack();
> >         app.setVisible( true );
> >     }
> > }
> >
> >
> >
> >
> >
> > ------------------------+--------------------------+
> > David Eisner            | E-mail: [EMAIL PROTECTED]   |
> > CALCE EPSC              | Phone:  301-405-5341     |
> > University of Maryland  | Fax:    301-314-9269     |
> > ------------------------+--------------------------+
> >
> > =========================================================================
> > == 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".
>
> ===========================================================================
> 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".
>

------------------------+--------------------------+
David Eisner            | E-mail: [EMAIL PROTECTED]   |
CALCE EPSC              | Phone:  301-405-5341     |
University of Maryland  | Fax:    301-314-9269     |
------------------------+--------------------------+

===========================================================================
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