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 "Caron, Michael R" <mi...@lmco.com> on 2005/02/01 23:41:23 UTC

Affine Transforms in gvtBuildCompleted callback

Hi 

Thanks for all the help so far in using Batik.

I have a question regarding the use of Affine Transforms in the
gvtBuildCompleted callback. I defined the method to be as follows:

  public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
    System.out.println("GVT Tree Build Complete");
    GraphicsNode g = e.getGVTRoot();
    AffineTransform tx = g.getTransform();
    if (tx != null) {
      Point heightOrig = new Point(docHeight,0);
      Point widthOrig = new Point(0,docWidth);
      Point2D heightNew = tx.transform(heightOrig,null);
      Point2D widthNew = tx.transform(widthOrig,null);
      
      System.out.println("Translated Height: " + heightNew.getY());
      System.out.println("Translated Width: " + widthNew.getX());	
    }
  }

I would assume that since the JSVGCanvas onto which I am loading the
document is constrained by the Jpanel it is contained by, neither of
which have PreferredWidth and Height as large as the SVG document
itself, that there would be an implicit transform. But it turns out that
tx is null. 

Why would the tx be null? And how would I get the translated heights and
widths of the SVG rendered onto the JSVGComponent (not the height and
width of the canvas itself, but the actual image as translated onto the
canvas)?

Thanks!!
Mike


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Re: Affine Transforms in gvtBuildCompleted callback

Posted by Thomas DeWeese <Th...@Kodak.com>.
Caron, Michael R wrote:

> Thanks for all the help so far in using Batik.

   No problem,

> I have a question regarding the use of Affine Transforms in the
> gvtBuildCompleted callback. I defined the method to be as follows:
> 
>     GraphicsNode g = e.getGVTRoot();
>     AffineTransform tx = g.getTransform();

    The root node doesn't have the viewing transform the
the root node is a special 'RootGraphicsNode' which there
can be only one of in a GVT tree.  The actual CanvasGraphicsNode
(which is the peer of an SVG element with a viewing transform)
is the first child of the root graphics node.  Here is sample
code from the JSVGComponent that get's the CanvasGraphicsNode:

     protected CanvasGraphicsNode getCanvasGraphicsNode(GraphicsNode gn) {
         if (!(gn instanceof CompositeGraphicsNode))
             return null;
         CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn;
         List children = cgn.getChildren();
         if (children.size() == 0)
             return null;
         gn = (GraphicsNode)children.get(0);
         if (!(gn instanceof CanvasGraphicsNode))
             return null;
         return (CanvasGraphicsNode)gn;
     }

> I would assume that since the JSVGCanvas onto which I am loading the
> document is constrained by the Jpanel it is contained by, neither of
> which have PreferredWidth and Height as large as the SVG document
> itself, that there would be an implicit transform. But it turns out that
> tx is null. 

    Be a little careful when the Canvas parses a SVG document the
it calls 'setMySize' which set's the preferred size of the component.


> Why would the tx be null? And how would I get the translated heights and
> widths of the SVG rendered onto the JSVGComponent (not the height and
> width of the canvas itself, but the actual image as translated onto the
> canvas)?

	Rectangle2D bounds = canvas.getGraphicsNode().getBounds();

    Because the viewing transform is applied to the child of the
root graphics node it's bounds should be the translated size of
the content.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org