Please help.

I have been trying desperately for a few months now to develop a Java
utility using Batik to scale a few SVG files.

Here is what I'm trying to do:

1.) Take a random SVG file.  I have no interaction with this file, no
idea where it came from or anything about it.

2.) I want to get the maximum bounding box around the entire drawing
objects, paths, etc.  I have been using an example of GetBB.java that
uses the GetSensitiveBounds to retrieve the X, Y, Width and Height.

Seemed ok.

3.) Input arbitrary new size (height, width) in inches.
4.) Compute old scale from bounding box height and width.
5.) Compute new scale from inputed height and width.
8.) Move origin point to 0,0.
7.) Transform existing SVG file to new SVG file using new scale.


I am just about ready to pull my F**King hair out trying to get this
to work.  I thought I had it but now some of my images are exact
MIRRORed copies.

The end result that I wish to accomplish is:

Take random SVG image, move origin to 0,0; scale to my new value (in
inches) and save to new SVG file.

I'm using Batik and Java.  

Please help!




Here is the code:

                String parser = XMLResourceDescriptor.getXMLParserClassName();
                SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
    
    String svgURI = new File(args[0]).toURL().toString();               
    dNewWidth = new Double(args[1]);
                SVGDocument indoc = (SVGDocument)f.createDocument(svgURI);

                //Perform processing
    SVGSVGElement svg = (SVGSVGElement)indoc.getRootElement();

        NodeList nl = indoc.getElementsByTagName("g");
        SVGGElement nd = (SVGGElement)nl.item(0);
                Element elt = (Element) nd;
                elt.removeAttribute("transform");
                svg.removeAttribute("viewBox");         



                GVTBuilder builder = new GVTBuilder();
                BridgeContext ctx;
                ctx = new BridgeContext(new UserAgentAdapter());
                GraphicsNode gvtRoot = builder.build(ctx, indoc);
                
                Rectangle2D aoi = new Rectangle2D.Float();

                dPixelsPerInch = 1d;
                
                dOldX = gvtRoot.getSensitiveBounds().getX();
                dOldY = gvtRoot.getSensitiveBounds().getY();
                dOldWidth = gvtRoot.getSensitiveBounds().getWidth();
                dOldHeight = gvtRoot.getSensitiveBounds().getHeight();

//              System.out.println("dOldX: " + dOldX);          
//              System.out.println("dOldY: " + dOldY);          
//              System.out.println("dOldWidth: " + dOldWidth);          
//              System.out.println("dOldHeight: " + dOldHeight);                
                

                dNewWidth = dNewWidth * dPixelsPerInch;
                dScale = (dNewWidth * 90) / dOldWidth;
                dNewHeight = (dOldHeight * dScale) / 90;
                dNewX = dOldX * dScale;
                dNewY = dOldY * dScale;

                aoi.setRect(dNewX, dNewY, dNewWidth, dNewHeight);
                
//              System.out.println("dNewX: " + dNewX);          
//              System.out.println("dNewY: " + dNewY);          
//              System.out.println("dNewWidth: " + dNewWidth);          
//              System.out.println("dNewHeight: " + dNewHeight);                

                elt.setAttribute("transform", "translate(" + (dNewX * -1) + ", 
" +
(dNewY * -1) + ") scale(" + dScale + ")");
                svg.setAttribute("width", dNewWidth + "in");
                svg.setAttribute("height", dNewHeight+ "in");
                svg.setAttribute("viewBox", "0 0 " + dNewWidth + " " + 
dNewHeight);



-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/svg-developers/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to