You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2006/01/09 20:15:44 UTC
"Marrying" Graphics2D and SVG.
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
Re: "Marrying" Graphics2D and SVG.
Posted by Andrew Plotkin <er...@eblong.com>.
On Mon, 9 Jan 2006, Bishop, Michael W. CONTR J9C880 wrote:
> 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.
I think you want to change the "end cap" parameter on the Graphics2D
stroke. You've got CAP_SQUARE, and you want CAP_BUTT.
--Z
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
*
If the Bush administration hasn't subjected you to searches without a warrant,
it's for one reason: they don't feel like it. Not because of the Fourth
Amendment.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org