Hi

I have managed to crop our svg map that we have using batik but I have
noticed that once I open the cropped image within Inkscape it shows any
line, rect etc that may interconnect with the viewable area.  So I was
wondering is there a better way of doing this in batik or is there
something Im missing that somebody could point me towards please.

Here is my code sample of the crop function:

private void crop()throws NullPointerException, IOException{
                // Create a rectangle at the position and size we wish to crop 
to
                SVGRect rectangle = 
this.svgDocument.getRootElement().createSVGRect();
                rectangle.setX(new Float(this.topXPosition));
                rectangle.setY(new Float(this.topYPosition));
                rectangle.setWidth(new Float(this.imageWidth));
                rectangle.setHeight(new Float(this.imageHeight));

                NodeList croppedNodes =
this.svgDocument.getRootElement().getIntersectionList(rectangle, null);

                Element g = this.newSVGDocument.createElementNS(this.svgNS, 
"g");

                Element rect = this.newSVGDocument.createElementNS(this.svgNS,
"rect");
                rect.setAttribute("x", "0px");
                rect.setAttribute("y", "0px");
                rect.setAttribute("width", "" + this.imageWidth);
                rect.setAttribute("height", "" + this.imageHeight);
                rect.setAttribute("fill", "#FFFFFF");

                g.appendChild(rect);

                for(int i = 0; i < croppedNodes.getLength(); i++){


                        Node childNode = (Node)croppedNodes.item(i);

                        if(childNode.getNodeType() == Node.ELEMENT_NODE){
                                Element e =
this.newSVGDocument.createElement(childNode.getNodeName());

                                // Process the attributes
                                if(childNode.hasAttributes()){
                                        this.addAttributes(e, 
croppedNodes.item(i).getAttributes());
                                }

                                // Process the children
                                if(childNode.hasChildNodes()){
                                        this.addChildNodes(e, 
childNode.getChildNodes());
                                }

                                g.appendChild(e);

                                
this.newSVGDocument.getDocumentElement().appendChild(g);
                        }
                }

                try{
                        FileWriter fstream = new FileWriter(this.newPath);
                        DOMUtilities.writeDocument(this.newSVGDocument, 
fstream);
                        fstream.flush();
                        fstream.close();
                } catch(IOException ioe){
                        System.out.println("Unable to write to file in crop: " +
ioe.getLocalizedMessage());
                }
        }

Thanks for every ones help so far.

Barry

Reply via email to