On Fri February 27 2009 8:51:50 pm [email protected] wrote:
> Hi Roberto,
>
> Roberto Villarreal <[email protected]> wrote on 02/27/2009 06:45:43
>
> PM:
> > I have an SVG file that is wrapping a PNG via xlink:href=[filename].
> > I can load this image in perfectly and display it.  Per the
> > PrettyPrinter, the document that is displaying perfectly is:
>
>    So the file displays fine in Squiggle right?

I hadn't thought about trying that, but I just got done verifying that it does 
display correctly.

[snip]

> > Now, there are only two differences between these two SVGs that I can
> > see (and keep in mind these both open correctly in an external
> > viewer):
>
>    Well the open fine in Batik's squiggle as well.  So it almost
> has to be your DOM manipulation code. Writing a 'broken' dom out
> and reading it back will often fix problems with namespaces.

I definitely don't question your judgement, but based on my findings, this 
sounds like it will be very hard to diagnose.  I'm open to any tips, but 
first, I assumed that the PrettyPrinter only manipulated whitespace.  Is 
there any chance that the PrettyPrinter is altering the tree in it's 
presentation (outside of whitespace)?  In other words, should I be debugging 
the code (if the PrettyPrinter could be "fixing" my broken DOM), or just the 
SVG output from the PrettyPrinter?

> > I can also post code if
> > need be, but this *seems* to be an issue of how Batik interacts with
> > SVG itself.
>
>    I think it's the code.

The snippet itself is below; a compilable working example is attached.

Thanks,
Roberto

//This is pretty much copy/paste from one of the how-tos
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svg = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument doc = (SVGDocument) impl.createDocument( svg, "svg", null );
Element svg_root = doc.getDocumentElement();
svg_root.setAttributeNS( null, "width", "680" );
svg_root.setAttributeNS( null, "height", "520" );

Element border = doc.createElementNS( svg, "rect" );
//Add more attributes using border.setAttributeNS( null, key, value )
svg_root.appendChild( border );
//doc should be a valid SVG with only a black rectangle
//Also copy/paste from one of the Batik sites
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory( parser );
String uri = new File( "file.svg" ).toURL().toString();
SVGDocument kid = f.createSVGDocument( uri );
Element svg_root_parent = doc.getDocumentElement();
Element svg_root_child = kid.getDocumentElement();
                                
NodeList list = svg_root_child.getChildNodes();
for ( int i = 0; i < list.getLength(); i++ ) {
    Node n = list.item( i );
    if ( n.getNodeType() != Node.ELEMENT_NODE ) {
    continue; }
    n = doc.importNode( n, true );
    svg_root_parent.appendChild( n ); } }
canvas.setDocument( doc );
//this gives the messed up picture and the SVG output in my original post
//but if you do canvas.setDocument( kid ) instead, it works perfectly



Attachment: test.tar.gz
Description: application/tgz

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to