Hi all,
The following very simple example works fine for me with the SVN
version of Batik
(click on the rect and it will update the viewBox and 'zoom' to the rect).
<svg width="450" height="500" viewBox="0 0 450 500"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
onclick="evt.currentTarget.setAttribute('viewBox', '100 100 250
300')">
<rect x="100" y="100" width="250" height="300" fill="gold"
stroke-width="10" stroke="crimson"/>
</svg>
zhangwisc <[EMAIL PROTECTED]> wrote on 07/25/2006 02:09:24 PM:
> I would like to update viewBox attribute for root svg element based on
newly
> loaded element. But it always fails and I got a blank screen.
I don't see any obvious mistakes below but it's easy to miss things.
In particular do you know that your document was loaded with
proper namespaces associated with the elements? I would print
the namespace of some of the elements that were loaded off disk.
> the saved (updated) document has correct viewBox and I can display
> it with any SVG viewer.
This is not as informational as it might seem. A host of
errors can be masked by the save/load process.
> In the class constructor:
> canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>
> In the event handler
> public void handleEvent(Event evt) {
> // Make some actions here...
> try{
> canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
> Runnable() {
> public void run() {
> try {
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder builder =
factory.newDocumentBuilder();
> Document doc = builder.parse( new
> File(DATA_DIRECTORY+file) );
> Element elem=doc.getDocumentElement();
> String viewBox=elem.getAttribute("viewBox");
>
>
canvas.getSVGDocument().getRootElement().appendChild(rootDoc.importNode(elem,true));
> canvas.getSVGDocument().getRootElement().setAttributeNS(null,
> "viewBox",viewBox);
> XMLSerializer serializer = new
XMLSerializer();
> serializer.setOutputCharStream(new java.io.
> FileWriter("new.xml"));
> serializer.serialize(rootDoc);
> } catch (Exception e)
{System.out.print(e.getMessage());}
> }
> });
> }
>
> --
> View this message in context:
http://www.nabble.com/update-viewBox-based-on-
> newly-added-element-tf1999745.html#a5490448
> Sent from the Batik - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]