OK, now I have some problems with translations. "line" and "rect" elements work as expected, but "ellipse" and "polyline" elements do not. "polyline" elements work unless the canvas is zoomed in or zoomed out. Ellipse elements do not render right at all. I guess it's because both of these elements don't have an upper-left coordinate? I don't know. Here is what I do:
AffineTransform affineTransform = jsvgCanvas.getViewBoxTransform().createInverse(); Double translateX = new Double(affineTransform.getTranslateX()); Double translateY = new Double(affineTransform.getTranslateY()); Double scaleX = new Double(affineTransform.getScaleX()); Double scaleY = new Double(affineTransform.getScaleY()); Then I create a "transform" attribute: transform="translate(translateX, translateY) scale(scaleX, scaleY)" I didn't have problems when I was using the affineTransform.createTransformedShape() to render the objects. I must be missing something or doing something wrong. My SVG reference only does examples with "rect" elements, so that's no help. Any ideas why my glassPane -> SVG elements don't line up when I use SVG's transforming as opposed to the JSVGCanvas's AffineTransform? Michael Bishop -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, October 24, 2005 6:52 PM To: [email protected] Cc: [email protected] Subject: RE: AW: Translations with zoom in and zoom out? Hi Michael, "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on 10/24/2005 04:20:19 PM: > Another thought here, if I can't use the AffineTransform to create a > specific Shape, I imagine I could use it to transform each "piece" of > the Shape; i.e. create a new Rectangle2D with a translated X and Y and a > scaled width and height? You can do this assuming you "know something" about the shape in question. Which you seem to. > I know why it generates a generic Shape object; some AffineTransforms > won't result in the original shape from stretching/skewing/rotating, but > if I can guarantee that behavior won't be an issue, it'd be nice to get > a shape. Defined elements look much better than paths in the > readability of an SVG document as well. Easier to move with an X,Y too! I think you are rapidly approaching the point where you need to consider using the 'transform' attribute. It would allow you to keep the elements as elements. You can also simply adjust the 'translate' portion of the matrix to move elements around the canvas. In the end I suspect it would be less code as all element types could be treated the same. An example transform attribute might be: transform="translate(100,200) scale(3)" > -----Original Message----- > From: Bishop, Michael W. CONTR J9C880 > [mailto:[EMAIL PROTECTED] > Sent: Monday, October 24, 2005 4:08 PM > To: [email protected] > Subject: RE: AW: Translations with zoom in and zoom out? > > OK, I just noticed a problem with this. When I use > affineTransform.createTransformedShape(Shape), and then convert that > Shape to an SVG element, it comes out as a path element! Is there no > way to turn a Rectangle2D into a bigger Rectangle2D? I ran into this > problem trying to move objects around the JSVGCanvas; path has no x/y > attributes! I'd like to have ellipses, rectangles, lines, etc. scale > into bigger/smaller versions of the same shape! Is this possible? I > tried casting a Rectangle2D from the Shape and got a ClassCastException. > > Michael Bishop > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Wednesday, October 19, 2005 11:19 AM > To: [email protected] > Cc: [email protected] > Subject: RE: AW: Translations with zoom in and zoom out? > > Hi Micheal, > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote on > > 10/19/2005 11:10:59 AM: > > > No, my scaling is uniform I believe. I'm simply using the > > JSVGCanvas.ZoomInAction and JSVGCanvas.ZoomOutAction for my respective > > buttons. Given that, the AffineTransform.getScaleX() and > > AffineTransform.getScaleY() should be the same value and I can apply > > either one to the font size? > > Exactly. > > > > > Michael Bishop > > > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > Sent: Wednesday, October 19, 2005 10:54 AM > > To: [email protected] > > Cc: [email protected] > > Subject: RE: AW: Translations with zoom in and zoom out? > > > > Hi Michael, > > > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> wrote > on > > > > 10/19/2005 10:13:49 AM: > > > > > Sure, I don't give the users the ability to rotate text (yet) so > > that's > > > no problem. On my glass pane, I call Graphics2D.setFont(...) and > > > Graphics2D.drawString(...) to render the text. To transform to an > > > Element, I manually create the tag information, including > font-family, > > > font-weight, font-style, and font-size. So if the user has 18pt > font > > > chosen, I can use the AffineTransform.getScaleY() to change the > point > > > size? That makes sense, but what about the width? > > > > Well unless you are allowing for non-uniform scaling > (different > > X & Y scaling, square becomes a rectangle) then setting the font-size > > will change the width correctly as well. If you want to allow for > > non-uniform scaling then you will have to use the transform attribute > > (there are a bunch of different forms, check the SVG spec for > details). > > > > > I'm still shooting for having what you see on the glass pane mirror > > > what you see when you draw to the document. > > > > Sure this shouldn't be an issue. > > > > > > > > Michael Bishop > > > > > > -----Original Message----- > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > Sent: Wednesday, October 19, 2005 10:08 AM > > > To: [email protected] > > > Cc: [email protected] > > > Subject: RE: AW: Translations with zoom in and zoom out? > > > > > > Hi Michael, > > > > > > If you are willing to ignore rotation you can get the X/Y scale > > from > > > the viewBox Affine Transform > > > (AffineTransform.getScaleX(), AffineTransform.getScaleY()), these > can > > > then > > > be used to scale the > > > font-size for example. > > > > > > You could also use the 'transform' attribute with a 'matrix(...)' > > to > > > directly apply the inverse viewBox > > > transform to the text, which would allow you to 'skip' the mapping > of > > > the > > > x & y coords (although at > > > some loss to the readability of the SVG). > > > > > > "Bishop, Michael W. CONTR J9C880" <[EMAIL PROTECTED]> > wrote > > on > > > > > > 10/19/2005 09:53:13 AM: > > > > > > > Yeah, this seems to do the trick for points. You lost me with > > > > GeneralPath, but I currently create polylines with an ArrayList of > > > > Point2D objects, so I can go from there and get the transform. > > > > > > > > Still stumped on fonts though; I can get the x,y coordinate to > place > > > the > > > > font, but I'm not sure how to transform it properly in regards to > a > > > > zoomed JSVGCanvas. > > > > > > > > Michael Bishop > > > > > > > > -----Original Message----- > > > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > > > > Sent: Wednesday, October 19, 2005 5:36 AM > > > > To: [email protected] > > > > Subject: Re: AW: Translations with zoom in and zoom out? > > > > > > > > Hi all, > > > > > > > > Is there a reason you don't use the 'transform' methods that > are > > > > built > > > > into > > > > the AffineTransform class? These would seem to be much easier > than > > > all > > > > of this: > > > > > > > > Point2D transform(Point2D ptSrc, Point2D ptDst) > > > > > > > > There are also a bunch that tack arrays of source and dst > points, > > > that > > > > would probably be really useful for a polyline (BTW a polyline can > > be > > > > done with GeneralPath, just use lineto commands). > > > > > > > > "Steiner, Dominik" <[EMAIL PROTECTED]> wrote on > > > 10/19/2005 > > > > 02:57:07 AM: > > > > > > > > > Hi Michael, > > > > > > > > > > for converting a Point I do as follows: > > > > > > > > > > public static Float convertPointToViewBox(SVGCanvas canvas, > > Point > > > > point) { > > > > > try { > > > > > AffineTransform viewBoxTranfrom = > > > canvas.getViewBoxTransform(); > > > > > viewBoxTranfrom = viewBoxTranfrom.createInverse(); > > > > > return convertPoint(point, viewBoxTranfrom); > > > > > } catch (NoninvertibleTransformException e) { > > > > > e.printStackTrace(); > > > > > } > > > > > return null; > > > > > } > > > > > > > > > > private static Point2D.Float convertPoint(Point point, > > > > AffineTransform > > > > > > > > > viewBoxTranfrom) { > > > > > double[] matrix = new double[6]; > > > > > viewBoxTranfrom.getMatrix(matrix); > > > > > return convertPoint(point, matrix); > > > > > } > > > > > > > > > > public static Point2D.Float convertPoint(Point point, > > > > > double[] matrix) { > > > > > Point2D.Float retP = new Point2D.Float(); > > > > > retP.x = (float) (matrix[0] * point.x + matrix[2] * point.y > + > > > > matrix[4]); > > > > > retP.y = (float) (matrix[1] * point.x + matrix[3] * point.y > + > > > > matrix[5]); > > > > > return retP; > > > > > } > > > > > > > > > > I hope this helps? J > > > > > > > > > > Dominik Steiner > > > > > > > > > > > > > > > Von: Bishop, Michael W. CONTR J9C880 > > > > [mailto:[EMAIL PROTECTED] > > > > > Gesendet: Dienstag, 18. Oktober 2005 19:02 > > > > > An: [email protected] > > > > > Betreff: RE: Translations with zoom in and zoom out? > > > > > > > > > > Oops, forgot Line2D falls in the Shape category. For the text > and > > > the > > > > > > > > > polyline, I really have the same problem; the text is a single > x,y > > > > > > coordinate > > > > > and the polyline is a set of x,y coordinates. If I can figure > out > > > how > > > > > > > > to > > > > > translate those, I should be in good shape. > > > > > > > > > > Michael Bishop > > > > > > > > > > > > > > > From: Bishop, Michael W. CONTR J9C880 > > > > [mailto:[EMAIL PROTECTED] > > > > > Sent: Tue 10/18/2005 12:57 PM > > > > > To: [email protected] > > > > > Subject: RE: Translations with zoom in and zoom out? > > > > > That is precisely what I needed. I was using JSVGCanvas. > > > > > getRenderingTransform() and that didn't quite work. That works > > for > > > my > > > > > > > > boxes > > > > > and ellipses, but is there a similar school of thought, using > the > > > > > AffineTransform for Line2D, a set of points (later used to > create > > a > > > > polyline) and text?? > > > > > > > > > > Michael Bishop > > > > > > > > > > > > > > > From: Steiner, Dominik [mailto:[EMAIL PROTECTED] > > > > > Sent: Tue 10/18/2005 7:46 AM > > > > > To: [email protected] > > > > > Subject: AW: Translations with zoom in and zoom out? > > > > > Hi Michael, > > > > > > > > > > I?m not sure if this helps you, but I would suggest that you > > > transform > > > > > > > > the > > > > > screen coordinates to viewbox coordinates. I first let the user > > draw > > > > on > > > > screen > > > > > coordinates and when he finished I do the transformation to > > viewbox > > > > > coordinates as follows: > > > > > > > > > > public static Shape scaleShapeToViewbox(Shape shape, SVGCanvas > > > > canvas) > > > > { > > > > > try { > > > > > AffineTransform at = > > > > canvas.getViewBoxTransform().createInverse(); > > > > > shape = at.createTransformedShape(shape); > > > > > } catch (NoninvertibleTransformException e1) { > > > > > e1.printStackTrace(); > > > > > } > > > > > return shape; > > > > > } > > > > > > > > > > So this works for my Java2D shapes?. > > > > > I hope it helps? > > > > > > > > > > Dominik > > > > > > > > > > Von: Bishop, Michael W. CONTR J9C880 > > > > [mailto:[EMAIL PROTECTED] > > > > > Gesendet: Montag, 17. Oktober 2005 20:44 > > > > > An: [email protected] > > > > > Betreff: Translations with zoom in and zoom out? > > > > > > > > > > OK, so I have the JSVGCanvas zooming in and zooming out. Since > I > > > have > > > > a > > > > > > > > > whiteboard application, users can draw objects to the canvas. > > Much > > > > like > > > > > > > > > typical art programs, you get an ?outline? of what you?re going > to > > > > draw > > > > before > > > > > it?s placed. For a box, you click, drag the mouse to the > desired > > > size > > > > > > > > and > > > > > release. I guess they call it ?rubber-banding? or whatever. > > > > > > > > > > On to my question. When the canvas is zoomed in/zoomed out, how > > can > > > I > > > > > > > > get the > > > > > translation correct on the glass pane? The glass pane is > > currently > > > > drawing > > > > > based on the coordinates of the JSVGCanvas, but it draws as if > the > > > > > > JSVGCanvas > > > > > isn?t zoomed in or out. In short, what the glass pane is > > rendering > > > is > > > > > > > > not > > > > > zoomed, but what the JSVGCanvas is rendering is. So what you > see > > > > isn?t > > > > what > > > > > you get when you let go of the mouse. How can I translate my > > shapes > > > > > > > based on > > > > > the zoom? If I draw something on a canvas that is zoomed in > 20%, > > > I?d > > > > like to > > > > > scale the outline 20%...etc. That degree of scaling is what I > > don?t > > > > > > > know how to get. > > > > > > > > > > Michael Bishop > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > > > For additional commands, e-mail: > > > [EMAIL PROTECTED] > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: > > [EMAIL PROTECTED] > > > > For additional commands, e-mail: > > > [EMAIL PROTECTED] > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > > For additional commands, e-mail: > > [EMAIL PROTECTED] > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
