You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Laurent Caron <la...@gmail.com> on 2005/11/25 09:51:58 UTC
Need a sample to merge SVG Documents
Hi,
I've got 6 different documents that represents "layers" (like photoshop
ones). They all have the same size.
To represent the layers, I've simply built a Frame, and JSVGCanvas (1 per
layer), and simply use frame.add(canvas).
This works fine, but it is a bit slow, and I need to implement scrollbars.
My first idea is to merge all layers in one unique document. Does anybody
can provide me a piece of code that
can achieve this goal ?
Thanks,
Laurent
Re: Need a sample to merge SVG Documents
Posted by Laurent Caron <la...@gmail.com>.
Hi,
Forget it, I found another message in the archive. Anyway, the solution is :
// Merge
File file1 = new File("first.svg");
File file2 = new File("second.svg");
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new
SAXSVGDocumentFactory(parser);
SVGDocument document1 = null;
SVGDocument document2 = null;
try {
document1 = (SVGDocument) factory.createDocument(file1.toURL
().toString());
document2 = (SVGDocument) factory.createDocument(file2.toURL
().toString());
} catch (MalformedURLException e1) {
e1.printStackTrace();
System.exit(1);
} catch (IOException e1) {
e1.printStackTrace();
System.exit(1);
}
// Copy the document2 inside document 1
Node newDocument = document1.importNode(document2.getDocumentElement(),
true);
// And append the result
document1.getDocumentElement().appendChild(newDocument);
canvas.setSVGDocument(document1);
Not so difficult :)
On 11/25/05, Laurent Caron <la...@gmail.com> wrote:
>
> Hi,
>
> I've got 6 different documents that represents "layers" (like photoshop
> ones). They all have the same size.
>
> To represent the layers, I've simply built a Frame, and JSVGCanvas (1 per
> layer), and simply use frame.add(canvas).
> This works fine, but it is a bit slow, and I need to implement scrollbars.
>
> My first idea is to merge all layers in one unique document. Does anybody
> can provide me a piece of code that
> can achieve this goal ?
>
> Thanks,
>
> Laurent
>
>
>
>
>