tags:

views:

20

answers:

1

I want to draw a math symbol with GeneralPath.

GeneralPath gp1 = new GeneralPath();
gp1.moveTo( 50, 10 );
gp1.lineTo( 50, 80 );
gp1.closePath();

Now I want to draw one line thicker that the other and the connection should look nice. Lets take the < for example where I want the upper line / four times thicker the \ line. If I draw the lines separately the connection looks wrong.

+2  A: 

There is no way to draw two parts of the path with two different line thicknesses in one call to Graphics2D.draw. You would have to do it in two calls. You might be able to address the connection by setting the cap on the lines differently, like to rounded, for example. If you do this, and the two lines end at the same point, the rounded edge should cover the ends and make it look better. As long as you're not using alpha values to set transparency, this should work great.

g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND);

If you're using transparencies, the above approach would make the join be darker because it's being drawn on twice. In this case, you could try a different approach. Define one shape and use Graphics2D.fill and set all of the points and arcs manually, making one line slightly thicker. You would absolutely have to have anti-aliasing turned on for it to work, and I'm not sure how it would look.

Erick Robertson
That hard. Take a V for example. If the left line is much thicker then right site the connection is not looking good even with different bevel modes. If it's not 90 degree it don't work. So probably GeneralPath doesn't help me.
Hannes Licht
Not bevels. Caps. A round cap will add a round circle to the end of each of the lines. These will overlap as long as there's no transparency, and will look okay.
Erick Robertson
Of course caps. Wrong word. Sorry. I tried with 2 lines first--and believe me--it looks awful.
Hannes Licht
Do you have antialiasing turned on? `g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);`
Erick Robertson