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 "Nazar Stasiv (Lohika, Inc)" <ns...@lohika.com> on 2006/08/21 16:38:39 UTC

AffineTransform

Hello,
what I'm trying to do is to zoom SVG diagram in size.  Is that the right 
way ?

    public static SVGDocument parseSvg(String uri) {
        UserAgentAdapter userAgent = new UserAgentAdapter();
        DocumentLoader loader = new DocumentLoader(userAgent);
        SVGDocument doc = (SVGDocument) loader.loadDocument(uri);
        BridgeContext ctx = new BridgeContext(userAgent, loader);
        ctx.setDynamicState(BridgeContext.DYNAMIC);
        GVTBuilder builder = new GVTBuilder();
        GraphicsNode gvtRoot = builder.build(ctx, doc);
        AffineTransform at = AffineTransform.getScaleInstance(0.5, 
0.5);               
        gvtRoot.setTransform(at);
        return doc;
    }



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


Re: AffineTransform

Posted by th...@kodak.com.
Hi Nazar,

"Nazar Stasiv (Lohika, Inc)" <ns...@lohika.com> wrote on 08/22/2006 
06:49:43 AM:

> thomas.deweese@kodak.com wrote:
> >
> >
> >    I would suggest looking at the code in 
> > batik.transcoder.SVGAbstractTranscoder, in particular around the
> > call 'setViewingTransform'.  This is in some sense the 'correct'
> > way to handle this.
> > 
> I see transcode method which does setViewingTransform. And I've got two 
> questions
> 1. transcode method is applied to every GraphicsNode in GVTTree or 
> applying it to root node is enough?

   Applying it to the root is enough.

> 2. setViewingTransform is the method of type CanvasGraphicsNode and I 
> get a ClassCastException when casting GraphicsNode

   Normally the CanvasGraphicNode is the first child of the 
RootGraphicsNode.
See code from SVGAbstractTranscoder (two lines above setViewingTransform):

    CanvasGraphicsNode cgn = getCanvasGraphicsNode(gvtRoot); 

   And the method that calls (9 lines after setViewingTransform):

    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;
    }

> Nothing happens for the code below, the condition is false
>         if (gvtRoot instanceof CanvasGraphicsNode){
>             ((CanvasGraphicsNode)gvtRoot).setViewingTransform(Px);
>         }
> 
> 
> Nazar
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: AffineTransform

Posted by "Nazar Stasiv (Lohika, Inc)" <ns...@lohika.com>.
Hello Thomas,
see my comments inline
thomas.deweese@kodak.com wrote:
>
>
>    I would suggest looking at the code in 
> batik.transcoder.SVGAbstractTranscoder, in particular around the
> call 'setViewingTransform'.  This is in some sense the 'correct'
> way to handle this.
>   
I see transcode method which does setViewingTransform. And I've got two 
questions
1. transcode method is applied to every GraphicsNode in GVTTree or 
applying it to root node is enough?
2. setViewingTransform is the method of type CanvasGraphicsNode and I 
get a ClassCastException when casting GraphicsNode

Nothing happens for the code below, the condition is false
        if (gvtRoot instanceof CanvasGraphicsNode){
            ((CanvasGraphicsNode)gvtRoot).setViewingTransform(Px);
        }


Nazar

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


Re: AffineTransform

Posted by th...@kodak.com.
Hi Nazar,

"Nazar Stasiv (Lohika, Inc)" <ns...@lohika.com> wrote on 08/21/2006 
10:38:39 AM:

> what I'm trying to do is to zoom SVG diagram in size.  Is that the right 

> way ?

   I would suggest looking at the code in 
batik.transcoder.SVGAbstractTranscoder, in particular around the
call 'setViewingTransform'.  This is in some sense the 'correct'
way to handle this.

   I suspect your way will work for many cases, but I think
certain SVG DOM calls will return wrong/misleading values
(things like getCTM/getScreenCTM).

>     public static SVGDocument parseSvg(String uri) {
>         UserAgentAdapter userAgent = new UserAgentAdapter();
>         DocumentLoader loader = new DocumentLoader(userAgent);
>         SVGDocument doc = (SVGDocument) loader.loadDocument(uri);
>         BridgeContext ctx = new BridgeContext(userAgent, loader);
>         ctx.setDynamicState(BridgeContext.DYNAMIC);
>         GVTBuilder builder = new GVTBuilder();
>         GraphicsNode gvtRoot = builder.build(ctx, doc);
>         AffineTransform at = AffineTransform.getScaleInstance(0.5, 
> 0.5); 
>         gvtRoot.setTransform(at);
>         return doc;
>     }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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