xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tilo Behrmann" <T.behrm...@gmx.net>
Subject AW: Clipping SVG documents
Date Fri, 09 Jun 2006 06:19:02 GMT
Hi Dominik,

i have found my failure. My next Question is it is possible to generate a
SVG Document that only contains the svg code from the clipping path. The
main Problem is i have tree JSVGCanvas in the first i show the hole map in
the second a part of this map (like a district) and in the last i show only
a special point of the map. The problem is when i have a svg File that is
1Mb big the batik needs 600 Mb Memory and the system works very slow. Have
anybody a idea to solve this problem.

-----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 <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


---------------------------------------------------------------------
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