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 sweetmovesdude <de...@tu-dortmund.de> on 2011/06/22 15:09:25 UTC

Combine SVG out of single SVG files

Hey everyone,

I have some .svg files in a folder, each representing a single component.
What I want is to create a 100x100 px SVG document with these components,
e.g. the "login.svg" uses the "background_green.svg" and the
"login_component.svg".

I used Batik to create a 100x100 px document, but now wonder how I can
"import" SVG files from a specific path, let's say
$home/documents/components/ 

What I have so far is

...
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
Document doc = impl.createDocument(svgNS, "svg", null);

Element svgRoot = doc.getDocumentElement();
svgRoot.setAttributeNS(svgNS, "width", "100");
svgRoot.setAttributeNS(svgNS, "height", "100");


How can I import the SVG components and attach them to svgRoot?

Thank you all for helping!

--
View this message in context: http://batik.2283329.n4.nabble.com/Combine-SVG-out-of-single-SVG-files-tp3616984p3616984.html
Sent from the Batik - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Combine SVG out of single SVG files

Posted by sweetmovesdude <de...@tu-dortmund.de>.
Thank you both so much! =)

I will try the different ways and give feedback. The link is also very
helpful and I am impressed by the amount of answers and how quick you
responded. ^^

Great work, thanks!

--
View this message in context: http://batik.2283329.n4.nabble.com/Combine-SVG-out-of-single-SVG-files-tp3616984p3629887.html
Sent from the Batik - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Combine SVG out of single SVG files

Posted by jonathan wood <jo...@gmail.com>.
For completeness (and to cover the simplest solution that I didn't present
earlier)....

adding svg:image elements with the xlink:hrefs pointing to the external
files would also work.

On Wed, Jun 22, 2011 at 9:45 PM, jonathan wood
<jo...@gmail.com>wrote:

> Thanks for the additional info Helder.
>
> Note that even with a use tag, if you want to add the existing svg to a top
> level template programatically, you'd still need to follow the prior
> instructions with the following modification.  Note that this is not the use
> case specified by the requester as there is no element reuse in the
> originally described scenario.
>
> - uniquely id the new element
> - create a defs element and append the imported node to the defs element.
> - create and add a use element with the xlink:href attribute set to
> "url(#newnodeid)"
>
>
> 2011/6/22 Helder Magalhães <he...@gmail.com>
>
>> Hi everyone,
>>
>> > One way to do it...assumes the file was read and placed into a byte
>> array by
>> > loadMyFile() (your implementation).
>> > All fluff and exception handling removed, but the basic sequence is:
>> [...]
>>
>> Apart from this (good) suggestion, note that SVG also has an "import"
>> mechanism, namely the 'use' element [1]. Just in case someone missed
>> it! ;-)
>>
>> Cheers,
>>  Helder
>>
>>
>> [1] http://www.w3.org/TR/SVG11/struct.html#UseElement
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>>
>>
>

Re: Combine SVG out of single SVG files

Posted by jonathan wood <jo...@gmail.com>.
Thanks for the additional info Helder.

Note that even with a use tag, if you want to add the existing svg to a top
level template programatically, you'd still need to follow the prior
instructions with the following modification.  Note that this is not the use
case specified by the requester as there is no element reuse in the
originally described scenario.

- uniquely id the new element
- create a defs element and append the imported node to the defs element.
- create and add a use element with the xlink:href attribute set to
"url(#newnodeid)"


2011/6/22 Helder Magalhães <he...@gmail.com>

> Hi everyone,
>
> > One way to do it...assumes the file was read and placed into a byte array
> by
> > loadMyFile() (your implementation).
> > All fluff and exception handling removed, but the basic sequence is:
> [...]
>
> Apart from this (good) suggestion, note that SVG also has an "import"
> mechanism, namely the 'use' element [1]. Just in case someone missed
> it! ;-)
>
> Cheers,
>  Helder
>
>
> [1] http://www.w3.org/TR/SVG11/struct.html#UseElement
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

Re: Combine SVG out of single SVG files

Posted by Helder Magalhães <he...@gmail.com>.
Hi everyone,

> One way to do it...assumes the file was read and placed into a byte array by
> loadMyFile() (your implementation).
> All fluff and exception handling removed, but the basic sequence is:
[...]

Apart from this (good) suggestion, note that SVG also has an "import"
mechanism, namely the 'use' element [1]. Just in case someone missed
it! ;-)

Cheers,
 Helder


[1] http://www.w3.org/TR/SVG11/struct.html#UseElement

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Combine SVG out of single SVG files

Posted by jonathan wood <jo...@gmail.com>.
One way to do it...assumes the file was read and placed into a byte array by
loadMyFile() (your implementation).

All fluff and exception handling removed, but the basic sequence is:

byte[] inFIleBytes = loadMyFile();
ByteArrayInputStream bais =  new ByteArrayInputStream(inFileBytes);
SAXSVGDocumentFactory svgDocumentFactory = new
SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
Element inElement = svgDocumentFactory.createDocument(null,
bais).getDocumentElement();
inElement = (Element) document.importNode(inElement, true);
svgRoot.appendChild(inElement);


On Wed, Jun 22, 2011 at 9:09 AM, sweetmovesdude <dennis.kuehn@tu-dortmund.de
> wrote:

> Hey everyone,
>
> I have some .svg files in a folder, each representing a single component.
> What I want is to create a 100x100 px SVG document with these components,
> e.g. the "login.svg" uses the "background_green.svg" and the
> "login_component.svg".
>
> I used Batik to create a 100x100 px document, but now wonder how I can
> "import" SVG files from a specific path, let's say
> $home/documents/components/
>
> What I have so far is
>
> ...
> String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
> Document doc = impl.createDocument(svgNS, "svg", null);
>
> Element svgRoot = doc.getDocumentElement();
> svgRoot.setAttributeNS(svgNS, "width", "100");
> svgRoot.setAttributeNS(svgNS, "height", "100");
>
>
> How can I import the SVG components and attach them to svgRoot?
>
> Thank you all for helping!
>
> --
> View this message in context:
> http://batik.2283329.n4.nabble.com/Combine-SVG-out-of-single-SVG-files-tp3616984p3616984.html
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>