From batik-users-return-10515-apmail-xmlgraphics-batik-users-archive=xmlgraphics.apache.org@xmlgraphics.apache.org Thu Jun 08 14:30:07 2006 Return-Path: Delivered-To: apmail-xmlgraphics-batik-users-archive@www.apache.org Received: (qmail 21714 invoked from network); 8 Jun 2006 14:30:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Jun 2006 14:30:07 -0000 Received: (qmail 15288 invoked by uid 500); 8 Jun 2006 14:30:06 -0000 Delivered-To: apmail-xmlgraphics-batik-users-archive@xmlgraphics.apache.org Received: (qmail 15273 invoked by uid 500); 8 Jun 2006 14:30:05 -0000 Mailing-List: contact batik-users-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: batik-users@xmlgraphics.apache.org Delivered-To: mailing list batik-users@xmlgraphics.apache.org Delivered-To: moderator for batik-users@xmlgraphics.apache.org Received: (qmail 816 invoked by uid 99); 8 Jun 2006 14:21:48 -0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=RCVD_IN_SORBS_WEB,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of T.behrmann@gmx.net designates 213.165.64.20 as permitted sender) X-Authenticated: #318713 Reply-To: From: "Tilo Behrmann" To: Subject: AW: Clipping SVG documents Date: Thu, 8 Jun 2006 16:21:56 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) In-Reply-To: <5EE5137D79A3CA45970354F512B3F3E368D7E2@m-ex1.gt.local> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Dominik, i have changed the code a little bit, but it dosent work. I get every time a null pointer Exception. public SVGDocument clipMap(SVGDocument svgDocument, java.awt.Shape shape) { // first clone the document SVGDocument doc = (SVGDocument) svgDocument.cloneNode(true); // create an svg element from the clipping shape with the cloned document SVGGraphics2D svgGenerator = new SVGGraphics2D(doc); Element svgShape = svgGenerator.getShapeConverter().toSVG(shape); // add the clipping element to the tag of the document NodeList n1 = doc.getRootElement().getElementsByTagName(SVGConstants. SVG_DEFS_TAG); Element defs = (Element) n1.item(0); if(defs == null) { defs = doc.createElementNS(svgNS, SVGConstants.SVG_DEFS_TAG); doc.getRootElement().appendChild(defs); } // create the tag Element clip = doc.createElementNS(svgNS, SVGConstants.SVG_CLIP_PATH_TAG); clip.setAttributeNS(null, SVGConstants.SVG_ID_ATTRIBUTE, "clipmap"); // append the clip shape to the clip path and the tag clip.appendChild(svgShape); defs.appendChild(clip); // reference the clipping from the element you want to clip Element el = doc.getElementById("myelement"); el.setAttributeNS(null, SVGConstants.SVG_CLIP_PATH_ATTRIBUTE, "url(#clipmap)"); // Get a DOMImplementation DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document SVGDocument docres = (SVGDocument)impl.createDocument(svgNS, "svg", null); Element root = doc.getDocumentElement(); root.appendChild(el); return docres; } -----Ursprüngliche Nachricht----- Von: Steiner, Dominik [mailto:Dominik.Steiner@gigatronik.com] Gesendet: Donnerstag, 8. Juni 2006 15:15 An: batik-users@xmlgraphics.apache.org; T.behrmann@gmx.net Betreff: AW: Clipping SVG documents Hi Tilo, perhaps this one can help: // shape is your clipping shape, so for example a polygon and // svgDocument the document you want to clip public void clipMap(SVGDocument svgDocument, java.awt.Shape shape) { // first clone the document SVGDocument doc = (SVGDocument) svgDocument.cloneNode(true); // create an svg element from the clipping shape with the cloned document SVGGraphics2D svgGenerator = new SVGGraphics2D(doc); Element svgShape = svgGenerator.getShapeConverter().toSVG(shape); // add the clipping element to the tag of the document NodeList n1 = doc.getRootElement().getElementsByTagName( SVGConstants.SVG_DEFS_TAG); Element defs = (Element) n1.item(0); // create the tag Element clip = doc.createElementNS(svgNS, SVGConstants.SVG_CLIP_PATH_TAG); clip.setAttributeNS(null, SVGConstants.SVG_ID_ATTRIBUTE, "clipmap"); // append the clip shape to the clip path and the tag clip.appendChild(svgShape); defs.appendChild(clip); // reference the clipping from the element you want to clip Element el = doc.getElementById("myelement"); el.setAttributeNS(null, SVGConstants.SVG_CLIP_PATH_ATTRIBUTE, "url(#clipmap)"); } Dominik Steiner Dipl-Ing. Informationstechnik (BA) GIGATRONIK Gesellschaft für Automobil- elektronikentwicklung mbH Taunusstr. 21 80807 München Telefon +49 (0) 89 / 353 96 80-70 Telefax +49 (0) 89 / 353 96 80-99 mailto:dominik.steiner@gigatronik.com www.gigatronik.com -----Ursprüngliche Nachricht----- Von: Tilo Behrmann [mailto:T.behrmann@gmx.net] Gesendet: Donnerstag, 8. Juni 2006 14:54 An: Batik User Betreff: Clipping SVG documents Hi all, I have an SVG document and I want to generate an SVG document that contains only a smaller part of this document - just cut a rectangle from the original image. Does anyone have an idea about how to do this using the Batik toolkit ? MfG Tilo --------------------------------------------------------------------- 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 --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org