Here is the entire thing.  Thanks:


double actionPositive = new 
Double(request.getParameter("actpos")).doubleValue() * 100.0;
        double actionNegative = new 
Double(request.getParameter("actneg")).doubleValue() * 100.0;
        double reflectionPositive = new 
Double(request.getParameter("refpos")).doubleValue() * 100.0;
        double reflectionNegative = new 
Double(request.getParameter("refneg")).doubleValue() * 100.0;
                       
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
        String uri = new File(getServletContext().getRealPath("/") + 
"svg\\polarity.svg").toURL().toString();
        SVGDocument doc = (SVGDocument) f.createDocument(uri);     
        
        double a = 200;
        double b = 120;
        
        
        
        Element svg = doc.getDocumentElement();


                //Set the viewBox attribute of svg element
        Attr viewBoxAttr = doc.createAttribute("viewBox");
        double upperlefty = 0;
        double upperleftx = -(a + 100.0);
        double lowerrightx = a + 100.0;
        double lowerrighty = 0;
        if (actionPositive >= reflectionPositive) {
            upperlefty = -(actionPositive + 100.0); 
        }
        else {
            upperlefty = -(reflectionPositive + 100);
        }
        if (actionNegative >= reflectionNegative) {
            lowerrighty = actionNegative + 100.0; 
        }
        else {
            lowerrighty = reflectionNegative + 100.0;
        }
        viewBoxAttr.setNodeValue(upperleftx + " " + upperlefty + " " + 
2*lowerrightx + " " + (-upperlefty + lowerrighty));
        svg.setAttributeNode(viewBoxAttr);

        

                //Set the width and height attributes of svg element
        Attr widthAttr = doc.createAttribute("width");
        Attr heightAttr = doc.createAttribute("height");
        
        widthAttr.setNodeValue("" + (-upperleftx + lowerrightx));
        heightAttr.setNodeValue("" + (-upperlefty + lowerrighty));
        
        svg.setAttributeNode(widthAttr);
        svg.setAttributeNode(heightAttr);



                //Get the g element and add a new <path> for a cubic Bezier 
                // curve (new <path> will have id,d and style attributes)
        NodeList gList = svg.getElementsByTagName("g");
        Element g = (Element) gList.item(0);
      
        Element path = doc.createElement("path");

        Attr idAttr = doc.createAttribute("id");
        idAttr.setNodeValue("curveA");
          path.setAttributeNode(idAttr);

        Attr dAttr = doc.createAttribute("d");
        String ad = "M " + Math.round(-b) + "," + Math.round(-actionPositive) +
            " C " + Math.round(-a) + "," + Math.round(-actionPositive) +
            " " + Math.round(-a) + "," + (Math.round(actionPositive - 
actionNegative)/2) +
            " " + Math.round(-a) + "," + (Math.round(actionPositive - 
actionNegative)/2);
        dAttr.setNodeValue(ad);
          path.setAttributeNode(dAttr);
        

        Attr styleAttr = doc.createAttribute("style"); 
          String style = 
"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:10px;" +
            "stroke-linecap:butt;strike-linejoin:miter;stroke-opacity:1"; 
        styleAttr.setNodeValue(style);
        path.setAttributeNode(styleAttr);
                
        g.appendChild(path);
        
        DOMUtil.printDOM(doc); //prints dom to console - no effect if           
                                //withheld
        
        
        response.setContentType("image/png");
        ServletOutputStream out = response.getOutputStream();
        //JPEGTranscoder t = new JPEGTranscoder();
        PNGTranscoder t = new PNGTranscoder();
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
        t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new Float(1000));
        t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
        
        TranscoderInput input = new TranscoderInput(doc);
        
        
        TranscoderOutput output = new TranscoderOutput(out);
        try {
            t.transcode(input, output);
        }
        catch (TranscoderException e) {
            e.printStackTrace();
        }

        out.flush();
        out.close();


this yields: 

&lt;path 
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:10px;stroke-linecap:butt;strike-linejoin:miter;stroke-opacity:1"
 d="M -120,-300 C -200,-300 -200,0 -200,0" id="curveA">

which is within <g> which is within <svg>


-----Original Message-----
From: Cameron McCormack [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 06, 2008 1:58 PM
To: [email protected]
Subject: Re: dynamic changes to svg not appearing

Hi Eric.

Eric Hamacher:
> I am loading an existing SVG file into a Document and adding some nodes
> to it.
> 
> When I take the resulting Document and transcode it to JPEG or PNG, the
> additions (a new <path>) I made do not show up in the image.  I printed
> the dom to inspect it and my additions were present and formatted
> correctly.
…
>             //perform addition of new <path> . . .

I think you’ll have to show us this part of your code to see if there’s
any problem with it.  The rest of the code looks OK.

-- 
Cameron McCormack, http://mcc.id.au/
        xmpp:[EMAIL PROTECTED]  ▪  ICQ 26955922  ▪  MSN [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to