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 Archie Cobbs <ar...@dellroad.org> on 2005/03/22 00:55:25 UTC

Strange XML output bug

I'm getting a weird problem when trying to use the SVGGraphics2D class.
I'm creating an SVG document, and have an object that knows how to
render onto a Graphics2D, whose image I want to include as a child node.

To do this I'm doing something like this:

     // Create an embedded <svg> node
     imageNode = addElement(parent, "svg");
     imageNode.setAttribute("viewBox", "0 0 " + width + " " + height);
     imageNode.setAttribute("overflow", "visible");

     // Create a Graphics2D -> SVG encoder
     SVGGraphics2D g = new SVGGraphics2D(parent.getOwnerDocument());

     // Render image, converting it to SVG
     renderer.render(g, new Rectangle(width, height));

     // Get the embedded <svg> node
     imageNode = g.getRoot(imageNode);

In the case that the rendering is just lines, circles, etc. then
everything works fine. But if the rendering includes an image,
I'm getting this output in the resulting XML (edited for brevity):

     <?xml version="1.0" encoding="UTF-8"?>
     <svg overflow="visible" viewBox="0 0 595 842" 
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
     ...
     <svg color-interpolation="auto" ... >
     <!--Generated by the Batik Graphics2D SVG Generator-->
     <defs id="genericDefs"/>
     <g>
     <g>
     <image null:height="40" null:width="150" preserveAspectRatio="none" 
x="0" xlink:href="data:image/png;base64,iVBORw0KGgoAA ... "/>
     ...

Note the "null:" prefix on the height and width attributes.

Has anyone seen anything weird like this?? I'm certainly not using
the string "null" as a namespace prefix anywhere, and in any case
it's Batik that adds those attributes. Another weird thing is:
why only width and height? "preserveAspectRatio" comes out fine...

I suppose this is likely not a Batik bug... I'm using xalan 2.6.0
and xerces 2.6.2.

I tried to create a simple test case that reproduces this bug but
of course when I did that it didn't happen. Will keep trying.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

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


Re: Strange XML output bug

Posted by Jorg Heymans <jh...@domek.be>.

Archie Cobbs wrote:
> I'm getting a weird problem when trying to use the SVGGraphics2D class.
> I'm creating an SVG document, and have an object that knows how to
> render onto a Graphics2D, whose image I want to include as a child node.
> 
> To do this I'm doing something like this:
> 
>     // Create an embedded <svg> node
>     imageNode = addElement(parent, "svg");
>     imageNode.setAttribute("viewBox", "0 0 " + width + " " + height);
>     imageNode.setAttribute("overflow", "visible");
> 
>     // Create a Graphics2D -> SVG encoder
>     SVGGraphics2D g = new SVGGraphics2D(parent.getOwnerDocument());
> 
>     // Render image, converting it to SVG
>     renderer.render(g, new Rectangle(width, height));
> 
>     // Get the embedded <svg> node
>     imageNode = g.getRoot(imageNode);
> 
> In the case that the rendering is just lines, circles, etc. then
> everything works fine. But if the rendering includes an image,
> I'm getting this output in the resulting XML (edited for brevity):
> 
Does using setAttributeNS() help ? It is recommended to always use the 
NS variant when creating elements and attributes. Attributes in batik 
need to be created with null (and not the string "null") namespace, 
otherwise batik doesn't draw them.

>     <?xml version="1.0" encoding="UTF-8"?>
>     <svg overflow="visible" viewBox="0 0 595 842" 
> xmlns="http://www.w3.org/2000/svg" 
> xmlns:xlink="http://www.w3.org/1999/xlink">
>     ...
>     <svg color-interpolation="auto" ... >
>     <!--Generated by the Batik Graphics2D SVG Generator-->
>     <defs id="genericDefs"/>
>     <g>
>     <g>
>     <image null:height="40" null:width="150" preserveAspectRatio="none" 
> x="0" xlink:href="data:image/png;base64,iVBORw0KGgoAA ... "/>
>     ...
> 
> Note the "null:" prefix on the height and width attributes.

How are you dumping the data from the document? Does the image display 
at all?

> 
> Has anyone seen anything weird like this?? I'm certainly not using
> the string "null" as a namespace prefix anywhere, and in any case
> it's Batik that adds those attributes. Another weird thing is:
> why only width and height? "preserveAspectRatio" comes out fine...

that is indeed very wierd. Are you adding those as well manually?


Regards
Jorg


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


Re: Strange XML output bug

Posted by Archie Cobbs <ar...@dellroad.org>.
Thomas DeWeese wrote:
>   I've looked at the code fairly closely and I can't see why
> this would happen.  The only real difference I see is that I
> think width/height get set twice.

That must have something to do with it...

>> I suppose this is likely not a Batik bug... I'm using xalan 2.6.0
>> and xerces 2.6.2.
> 
>    Does this mean that you are using the Xerces DOM Implementation
> as well?  I suppose it's possible that there is a bug where
> setting an attribute twice with a null namespace does this in
> their DOM implementation.

I'm not sure what DOM implementation I'm using, I'm just using
the javax.xml APIs on JDK 1.4.2 (see attachment).

>> I tried to create a simple test case that reproduces this bug but
>> of course when I did that it didn't happen. Will keep trying.
> 
>    Of course ;)
>    Please let us know if you succeed (a Bug report in any case
> might be useful, but especially if there is a reproducible
> test case).

I am determined to track this down today :-) In any case, attached
is my test program, which doesn't yet demonstrate the bug, but does
show basically how I'm doing things.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

Re: Strange XML output bug

Posted by Archie Cobbs <ar...@dellroad.org>.
Thomas DeWeese wrote:
>> Note the "null:" prefix on the height and width attributes.
> 
>    Please let us know if you succeed (a Bug report in any case
> might be useful, but especially if there is a reproducible
> test case).

OK, here is the problem. The Sun JDK 1.4.2 (stupidly IMHO) includes
a old, broken version of Apache Xerces in their rt.jar. If you override
this with the latext Xerces (2.6.2) then the bug goes away.

Of course, since they have it in rt.jar, you have to use the proprietary
-Xbootclasspath flag to put it (and xml-commons-apis.jar) in front of
rt.jar in the boot loader's search path. Bleah.

For anyone having bugs like this I'd suggest trying the newer Xerces.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

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


Re: Strange XML output bug

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

Archie Cobbs wrote:
> I'm getting a weird problem when trying to use the SVGGraphics2D class.

> [...] If the rendering includes an image,
> I'm getting this output in the resulting XML (edited for brevity):

> Note the "null:" prefix on the height and width attributes.

> Has anyone seen anything weird like this?? I'm certainly not using
> the string "null" as a namespace prefix anywhere, and in any case
> it's Batik that adds those attributes. Another weird thing is:
> why only width and height? "preserveAspectRatio" comes out fine...

   I've looked at the code fairly closely and I can't see why
this would happen.  The only real difference I see is that I
think width/height get set twice.


> I suppose this is likely not a Batik bug... I'm using xalan 2.6.0
> and xerces 2.6.2.

    Does this mean that you are using the Xerces DOM Implementation
as well?  I suppose it's possible that there is a bug where
setting an attribute twice with a null namespace does this in
their DOM implementation.

> I tried to create a simple test case that reproduces this bug but
> of course when I did that it didn't happen. Will keep trying.

    Of course ;)
    Please let us know if you succeed (a Bug report in any case
might be useful, but especially if there is a reproducible
test case).

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