Interesting thing I’ve noticed in my application.  As some of you know, I draw to a glass pane using a Graphics2D object to simulate the “ghost line” of an element before it’s rendered to the canvas.  When the mouse is released, the element is actually created and rendered to the document where it’s displayed by the JSVGCanvas, not by a Graphics2D object.

 

Graphics2D seems to do things “wrong”.  If I set a stroke width of 4 and start to draw a line, the line is started with the mouse “centered” in the endpoint of the line.  So the first “end point” of the line is actually a 4x4 “box” with the mouse in the center.  When the mouse is released, Batik renders the line as starting where the mouse pointer starts and ending where the mouse pointer ends.  It results in a shorter line because Graphics2D centers endpoints on the mouse while Batik STARTS endpoints at the mouse.

 

When I increase stroke width, the problem is readily apparent; the user releases the mouse and the rendered version of the line has “shrunk” on both ends by (stroke width / 2) pixels.  I’d previously solved this problem with a complicated Pythagoras formula.  Now I’m working with Bezier curves and calculating the points AND doing Pythagoras to maintain line length is getting very complicated.

 

Is there a better way to make the two line up properly?  Essentially I need to either shorten Graphics2D lines or lengthen Batik lines by (stroke width / 2) on each end.

 

Michael Bishop

Reply via email to