xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steiner, Dominik" <Dominik.Stei...@gigatronik.com>
Subject AW: Clipping SVG documents
Date Thu, 08 Jun 2006 13:14:31 GMT
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 <defs> tag of the document     
	NodeList n1 = doc.getRootElement().getElementsByTagName(			SVGConstants.SVG_DEFS_TAG);
	Element defs = (Element) n1.item(0);

	// create the <clip-path> 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 <defs> 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


Mime
View raw message