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 Guido Kämper <gk...@exclamation.de> on 2005/02/23 16:06:05 UTC

Color problems after merging two svgs

Hi,

i've experimented a little bit with the batik libraries and it's really great, how easy you can achive the first results :-)

My sourcecode below merges two images from JSVGCanvas svg1, svg2 to svgResult. The images have the same structure, but different colors and text. in the mixed image only the colors of the second image are used. It looks like a mixture of two 256 color images in old Windows 3.11 times :-(

Does SVG use palette colors or why do i get those errors? Did anybody solve this problem yet? Is there any way to force SVGs to use direct color codes like #FF45F3 instead of names?

thanks a lot,
Guido
________________________________________________________________
private JSVGCanvas svg1 = new JSVGCanvas();
private JSVGCanvas svg2 = new JSVGCanvas();
private JSVGCanvas svgResult = new JSVGCanvas();

... here is the function 
(implemented as a actionPerformed of a button):


DOMImplementation domImpl =
   SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument document = (SVGDocument)domImpl.createDocument(svgNS, "svg", null);

SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

boolean useCSS = false; // we want to use CSS style attribute
svgGenerator.setSVGCanvasSize(new Dimension(600,400));
			        
Element root = document.getDocumentElement();

SVGDocument ndoc=svg1.getSVGDocument();
Element next=ndoc.getRootElement();
next.setAttribute("x","0");
next.setAttribute("y","0");
Node n=document.importNode(next, true);
root.appendChild(n);
			        
ndoc=svg2.getSVGDocument();
next=ndoc.getRootElement();
next.setAttribute("x","300");
next.setAttribute("y","0");
n=document.importNode(next, true);
root.appendChild(n);

svgResult.setSVGDocument(document);
					


-- 
bis dann,
 Guido                          mailto:gk@exclamation.de



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


Re: Color problems after merging two svgs

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Guido,

Guido Kämper wrote:

> TD>     I would just use the image element to put the two
> TD> documents side by side is there a reason this won't work?
> 
> I'm sorry... As I wrote before, i'm not very experienced with 
> SVGs and especially with Batik. This was the first way I 
> tested to merge the images. What do you mean with "image element"? 
> Is there an easier way to put the documents side by side? Do you 
> have some sample lines of code? This would help a lot:-)

 From the top of my head, this is all pretty standard
SVG/DOM (you might pick up a good SVG book - SVG Unleashed
is commonly reccomended, it will focus on javascript but
most of the stuff maps pretty directly back to Java,
thanks to DOM).

   String svgns = "http://www.w3.org/2000/svg";
   String xlinkns = "http://www.w3.org/XML/1998/namespace";

   Element root = document.getRootElement();
   Element img1 = document.createElementNS(svgns, "image");
   img1.setAttribute("x", "0");
   img1.setAttribute("y", "0");
   img1.setAttribute("width", "300");
   img1.setAttribute("height", "400");
   img1.setAttributeNS(xlinkns, "xlink:href", <URL to document 1>);
   root.appendChild(img1);

   Element img2 = document.createElementNS(svgns, "image");
   img2.setAttribute("x", "300");
   img2.setAttribute("y", "0");
   img2.setAttribute("width", "300");
   img2.setAttribute("height", "400");
   img2.setAttributeNS(xlinkns, "xlink:href", <URL to document 2>);
   root.appendChild(img2);

   svgResult.setSVGDocument(document);


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


Re[2]: Color problems after merging two svgs

Posted by Guido Kämper <gk...@exclamation.de>.
Hello Thomas,

TD>    Possible yes, easy no.

That's what i guessed :-)

>> This is important, because I don't have any influence over
>>  the input files.
TD>     Then you will also have problems with id conflicts (use
TD> references etc).
>> in the attachment is one of the test input svgs. 
TD>     I would just use the image element to put the two
TD> documents side by side is there a reason this won't work?

I'm sorry... As I wrote before, i'm not very experienced with SVGs and especially with Batik. This was the first way I tested to merge the images. What do you mean with "image element"? Is there an easier way to put the documents side by side? Do you have some sample lines of code? This would help a lot:-)

-- 
cu,
 Guido                            mailto:gk@exclamation.de



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


Re: Color problems after merging two svgs

Posted by Thomas DeWeese <Th...@Kodak.com>.
Guido Kämper wrote:

> thanks for the fast answer, Thomas:-) I think you're right. 
> the images have CSS style sheets. Is it possible to convert 
> the images automatically to non-css images? 

   Possible yes, easy no.

> This is important, because I don't have any influence over
>  the input files.

    Then you will also have problems with id conflicts (use
references etc).

> in the attachment is one of the test input svgs. 

    I would just use the image element to put the two
documents side by side is there a reason this won't work?

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


Re[2]: Color problems after merging two svgs

Posted by Guido Kämper <gk...@exclamation.de>.
Hi,

thanks for the fast answer, Thomas:-) I think you're right. the images have CSS style sheets. Is it possible to convert the images automatically to non-css images? This is important, because I don't have any influence over the input files.

in the attachment is one of the test input svgs. 

thank you,
Guido

--
on Wednesday, February 23, 2005, at 4:15:02 PM, you wrote:

TD> Guido K�mper wrote:

>> i've experimented a little bit with the batik libraries and it's really
>> great, how easy you can achive the first results :-)
>> 
>> My sourcecode below merges two images from JSVGCanvas svg1, svg2 to
>> svgResult. The images have the same structure, but different colors
>> and text. in the mixed image only the colors of the second image are
>> used. It looks like a mixture of two 256 color images in old Windows
>> 3.11 times :-(
>> 
>> Does SVG use palette colors or why do i get those errors? 

TD>     Batik does not use palette colors, everything is 24bit color with
TD> an 8bit alpha channel.  My best guess is that there is some conflict
TD> between the two documents you are trying to merge, for example if
TD> they are using CSS classes to set color/style properties and the
TD> class names are replicated between the two documents you might have
TD> problems like this.

TD>     Providing the content in question might help solve the problem,
TD> or a standalone test case.

>> Did anybody solve this problem yet? 
>> Is there any way to force SVGs to use direct color codes like 
>> #FF45F3 instead of names?

TD>     Sure:
TD> 	<rect fill="#FF45F3" .../>        -or-
TD>          <rect style="fill:#FF45F3" .../>
TD>     Both work.

TD>     So far I suspect the problem is with your content not with Batik.

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


-- 
cu,
 Guido                            mailto:gk@exclamation.de

Re: Color problems after merging two svgs

Posted by Thomas DeWeese <Th...@Kodak.com>.
Guido Kämper wrote:

> i've experimented a little bit with the batik libraries and it's really 
> great, how easy you can achive the first results :-)
> 
> My sourcecode below merges two images from JSVGCanvas svg1, svg2 to 
> svgResult. The images have the same structure, but different colors 
> and text. in the mixed image only the colors of the second image are 
> used. It looks like a mixture of two 256 color images in old Windows 
> 3.11 times :-(
> 
> Does SVG use palette colors or why do i get those errors? 

    Batik does not use palette colors, everything is 24bit color with
an 8bit alpha channel.  My best guess is that there is some conflict
between the two documents you are trying to merge, for example if
they are using CSS classes to set color/style properties and the
class names are replicated between the two documents you might have
problems like this.

    Providing the content in question might help solve the problem,
or a standalone test case.

> Did anybody solve this problem yet? 
> Is there any way to force SVGs to use direct color codes like 
> #FF45F3 instead of names?

    Sure:
	<rect fill="#FF45F3" .../>        -or-
         <rect style="fill:#FF45F3" .../>
    Both work.

    So far I suspect the problem is with your content not with Batik.

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