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 Selva <se...@yahoo.co.in> on 2006/04/15 09:43:38 UTC

Accessing gradients/symbols from external SVG file

Hi All,

I have declared one SVG file with symbols and gradients like in 
\resources\svg\defs.svg. If I tried to use external gradient from my code, it 
is not applying it properly.

Element rect = doc.createElementNS(svgNS, "rect");
rect.setAttributeNS(null, "x", "30");
rect.setAttributeNS(null, "y", "30");
rect.setAttributeNS(null, "id", "r2");
rect.setAttributeNS(null, "width", "13");
rect.setAttributeNS(null, "height", "13");
            
rect.setAttributeNS(null, "style", "fill:defs.svg#gradient_1");

Also how to change the element’s attributes values, which is available inside 
the symbols/group? 

<g id="extOther" style="stroke:crimson; stroke-width:4">
<rect x="-50" y="-50" width="100" height="100" style="fill:gold; stroke:none"/>
</g>

Here how to change the rectangle element's style attributes using group id?

Thanks,
Selva



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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>     The xlink:href attribute is not a CSS property so you
> don't wrap the URL in 'url()':
> 
>   use.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href", 
>                      "file:///C:/de.svg#extSymbol");

Thanks thomas now it's working fine.

Thanks,
Selva 





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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

news <ne...@sea.gmane.org> wrote on 04/21/2006 05:18:16 AM:

> now i can able to access gradients from external files. but i could not 
access 
> symbols. 

> use.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href", "url 
> (file:///C:/de.svg#extSymbol)");

    The xlink:href attribute is not a CSS property so you
don't wrap the URL in 'url()':

  use.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href", 
                     "file:///C:/de.svg#extSymbol");


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

now i can able to access gradients from external files. but i could not access 
symbols. 

Element use = doc.createElementNS(svgNS, "use");
use.setAttributeNS(null, "x", "265");
use.setAttributeNS(null, "y", "205");
use.setAttributeNS(null, "id", "r1");
use.setAttributeNS(XLINK_NAMESPACE_URI, "xlink:href", "url 
(file:///C:/de.svg#extSymbol)");
use.setAttributeNS(null, "style", "fill:orange");

if i use this code, it is giving following error.

java.io.IOException: Unable to make sense of URL for connection
        at org.apache.batik.util.ParsedURLData.openStreamInternal
(ParsedURLData.java:361)
        at org.apache.batik.util.ParsedURLData.openStream
(ParsedURLData.java:322)
        at org.apache.batik.util.ParsedURL.openStream(ParsedURL.java:384)
        at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument
(SAXSVGDocumentFactory.java:158)
        at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument
(SAXSVGDocumentFactory.java:124)
        at org.apache.batik.bridge.DocumentLoader.loadDocument
(DocumentLoader.java:105)

Thanks,
Selva




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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>     I guess we are down to versions.  What version of Batik are you using?
> What version of Java are you using?  If you aren't using the SVN version 
> of Batik I would suggest downloading it and trying that.

Thank you very much for your help thomas. Since i am using old batik source, 
it gave the error. Now i have tested with batik-svn-06-04-16. It's working 
fine.

Thanks,
Selva


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

> 
>     I guess we are down to versions.  What version of Batik are you using?
> What version of Java are you using?  If you aren't using the SVN version 
> of Batik I would suggest downloading it and trying that.

Right now i am using the batik-src-1.6.zip downloaded from 
http://apache.reverse.net/pub/apache/xml/batik/. 

java version :

java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
Java HotSpot(TM) Client VM (build 1.4.2_10-b03, mixed mode)

Now i am trying to download the batik SVN Version.

Thanks,
Selva




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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

    I guess we are down to versions.  What version of Batik are you using?
What version of Java are you using?  If you aren't using the SVN version 
of
Batik I would suggest downloading it and trying that.

news <ne...@sea.gmane.org> wrote on 04/20/2006 06:40:45 AM:

> Hi Thomas,
> 
> >    Open a DOS window and cut and paste: "type C:\de.svg"
> 
> This is the output i am getting when i use "type C:\de.svg" command.
> 
> C:\>type C:\de.svg
> <?xml version="1.0" standalone="yes"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" 
"http://www.w3.org/TR/2001/REC-
> SVG-20010904/DTD/svg10.dtd">
> <svg xmlns="http://www.w3.org/2000/svg" 
> xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" 
viewBox="0 
> 0 450 500">
> <defs>
> <linearGradient id="MyGradient">
> <stop offset="5%" stop-color="#F60" />
> <stop offset="95%" stop-color="#FF6" />
> </linearGradient>
> </defs>
> <rect id="chessboard" x="25" y="25" width="400" height="400" fill="url
> (#MyGradient)"/>
> </svg>
> 
> C:\>
> 
> Thanks,
> Selva
> 
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    Open a DOS window and cut and paste: "type C:\de.svg"

This is the output i am getting when i use "type C:\de.svg" command.

C:\>type C:\de.svg
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-
SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" viewBox="0 
0 450 500">
<defs>
<linearGradient id="MyGradient">
<stop offset="5%" stop-color="#F60" />
<stop offset="95%" stop-color="#FF6" />
</linearGradient>
</defs>
<rect id="chessboard" x="25" y="25" width="400" height="400" fill="url
(#MyGradient)"/>
</svg>

C:\>

Thanks,
Selva








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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

    'type' is a DOS command that prints a file in the dos window.
This is to make sure that the file is _exactly_ where it is supposed to
be and readable - without all the nonsense of the Explorer/IE.

   Open a DOS window and cut and paste: "type C:\de.svg"

news <ne...@sea.gmane.org> wrote on 04/20/2006 06:31:19 AM:

> >     There isn't one.  It worked first time for me.
> >     What happens if you open a DOS window and run:
> >         type C:\de.svg
> > 
> >     Does your de.svg file appear?
> 
> If i open the file using DOS window or Run, it is opening the de.svg 
file in 
> Internet Explorer and showing the rectangle with gradient(red to 
yellow).
> 
> Is there any other dependencies to access the external gradients?
> 
> Thanks,
> Selva
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>     There isn't one.  It worked first time for me.
>     What happens if you open a DOS window and run:
>         type C:\de.svg
> 
>     Does your de.svg file appear?

If i open the file using DOS window or Run, it is opening the de.svg file in 
Internet Explorer and showing the rectangle with gradient(red to yellow).

Is there any other dependencies to access the external gradients?

Thanks,
Selva





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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

news <ne...@sea.gmane.org> wrote on 04/19/2006 08:14:46 AM:

> i have attached my de.svg and SVGApplication5.java for your reference. 
Please 
> let me know the problem.

    There isn't one.  It worked first time for me.
    What happens if you open a DOS window and run:
        type C:\de.svg

    Does your de.svg file appear?


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    At this point you will either have to provide a complete
> standalone example (including your Java app), or debug the problem
> yourself (you have the source to Batik so you can either step through
> or add System.out to track where and how it goes wrong).

i have attached my de.svg and SVGApplication5.java for your reference. Please 
let me know the problem.


de.svg

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-
SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" viewBox="0 
0 450 500">
<defs>
<linearGradient id="MyGradient">
<stop offset="5%" stop-color="#F60" />
<stop offset="95%" stop-color="#FF6" />
</linearGradient>
</defs>
<rect id="chessboard" x="25" y="25" width="400" height="400" fill="url
(#MyGradient)"/>
</svg>


SVGApplication5.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import javax.swing.*;
import java.awt.*;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter;
import org.apache.batik.swing.svg.SVGDocumentLoaderEvent;
import org.apache.batik.swing.svg.GVTTreeBuilderAdapter;
import org.apache.batik.swing.svg.GVTTreeBuilderEvent;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.bridge.UpdateManager;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
import org.apache.batik.swing.gvt.Interactor;
import org.apache.batik.swing.gvt.AbstractZoomInteractor;
import org.apache.batik.swing.*;
import org.apache.batik.dom.svg.*;
import org.apache.batik.dom.events.*;

public class SVGApplication5 {

    static String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    public static final String XLINK_NAMESPACE_URI 
="http://www.w3.org/1999/xlink";

    JSVGScrollPane scroll;
    static JSVGCanvas svgCanvas = new JSVGCanvas();
    JFrame frame;
    JLabel label = new JLabel();

    String SCALE = "scale";
    String DRAG = "drag";
    String action;
    EventTarget actionNode, actionTgt;
    SVGPoint startPt;
    boolean dragged = false;
    
    Action zoomInAction = svgCanvas.getActionMap().get
(JSVGCanvas.ZOOM_IN_ACTION);
    Action zoomOutAction = svgCanvas.getActionMap().get
(JSVGCanvas.ZOOM_OUT_ACTION);
    JButton zoomInButton = new JButton(zoomInAction);
    JButton zoomOutButton = new JButton(zoomOutAction);

    protected Interactor zoomInteractor = new AbstractZoomInteractor() {
        public boolean startInteraction(InputEvent ie) {
            int mods = ie.getModifiers();
            boolean b = ie.getID() == MouseEvent.MOUSE_PRESSED && (mods & 
InputEvent.CTRL_MASK) != 0;
            return b;
        }
    };

    public static void main(String[] args) {
        SVGApplication5 app = new SVGApplication5();
    }

    public SVGApplication5() {
        JFrame f = new JFrame();
        f.getContentPane().add(createComponents());
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setSize(600, 400);
        f.setVisible(true);
    }

    public JComponent createComponents() {
        final JPanel panel = new JPanel(new BorderLayout());
        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));

        zoomInButton.setText("ZoomIn");
        p.add(zoomInButton);
        p.add(label);
        p.add(zoomOutButton);
        zoomOutButton.setText("ZoomOut");

//        scroll = new JSVGScrollPane(svgCanvas);

        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);

        panel.add("North", p);
        panel.add("Center", svgCanvas);
        svgCanvas.setDocument(doc);
        registerListeners();
        return panel;
    }

    public void registerListeners() {
        svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
            public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loading...");
            }
            public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                System.out.println("Document Loaded.");
            }
        });
        svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            public void gvtBuildStarted(GVTTreeBuilderEvent e) {
                System.out.println("gvt bUILD Started...");
            }
            public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                System.out.println("GVT Build Done...");
                frame.pack();
            }
        });
        svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
            public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
                System.out.println("Renderer Started...");
            }
            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                System.out.println("Renderer Completed...");
                
                UpdateManager um = svgCanvas.getUpdateManager();
                um.getUpdateRunnableQueue().invokeLater(new Runnable() {
                    public void run() {
                        resizeCircle();
                    }
                });
            }
        });

        SVGDocument doc = svgCanvas.getSVGDocument();

        SVGSVGElement svgRoot = doc.getRootElement();
        EventTarget t = (EventTarget)svgRoot;
        t.addEventListener("SVGLoad", new OnLoadAction(), false);
    }

    public class OnLoadAction implements EventListener {
        public void handleEvent(Event evt) {
        }
    }

    private void resizeCircle() throws DOMException {
        try {
            SVGDocument doc = svgCanvas.getSVGDocument();
            SVGSVGElement svgRoot = doc.getRootElement();

            Element rect = doc.createElementNS(svgNS, "rect");
            rect.setAttributeNS(null, "id", "bgrectangle");
            rect.setAttributeNS(null, "x", "0");
            rect.setAttributeNS(null, "y", "0");
            rect.setAttributeNS(null, "width", "100%");
            rect.setAttributeNS(null, "height", "100%");
            rect.setAttributeNS(null, "pointer-events", "fill");
            rect.setAttributeNS(null, "style", "fill:none;stroke:none");

            Element g1 = doc.createElementNS(svgNS, "g");
            g1.setAttributeNS(null, "id", "group1");
            Element use1 = doc.createElementNS(svgNS, "rect");
            use1.setAttributeNS(null, "x", "5");
            use1.setAttributeNS(null, "y", "5");
            use1.setAttributeNS(null, "id", "r1");
            use1.setAttributeNS(null, "width", "13");
            use1.setAttributeNS(null, "height", "13");
            use1.setAttributeNS(null, "style", "fill:red; stroke:black");
            g1.appendChild(use1);

            Element g2 = doc.createElementNS(svgNS, "g");
            g2.setAttributeNS(null, "id", "group2");

            Element use2 = doc.createElementNS(svgNS, "rect");
            use2.setAttributeNS(null, "x", "30");
            use2.setAttributeNS(null, "y", "30");
            use2.setAttributeNS(null, "id", "r2");
            use2.setAttributeNS(null, "width", "13");
            use2.setAttributeNS(null, "height", "13");
            use2.setAttributeNS(null, "style", "fill:url
(file:///C:/de.svg#MyGradient)");

            g2.appendChild(use2);

            svgRoot.appendChild(rect);
            svgRoot.appendChild(g1);
            svgRoot.appendChild(g2);
            
            EventTarget t = (EventTarget)svgRoot;
            t.addEventListener("mousemove", new OnMoveAction(), false);
            t.addEventListener("mousedown", new OnDownAction(), false);
            t.addEventListener("mouseup", new OnUpAction(), false);
        } catch (Exception e) {}
    }

   

    private SVGPoint localPt(Element elem, int x, int y) {
        SVGDocument svgDocument = svgCanvas.getSVGDocument();
        SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
        SVGMatrix imat = mat.inverse();
        SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
        cPt.setX(x);
        cPt.setY(y);
        cPt = cPt.matrixTransform(imat);
        return cPt;
    }


    private class OnDownAction implements EventListener {
        public void handleEvent(Event evt) {
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            actionNode = elEvt.getTarget();
            action = DRAG;
            Node n = ((Element)elEvt.getTarget()).getParentNode();
            startPt = localPt((Element)n, elEvt.getClientX(), elEvt.getClientY
());
            dragged = false;
        }
    }

    private class OnUpAction implements EventListener {
        public void handleEvent(Event evt) {
            if (actionNode != null) {
                actionNode = null;
            }
        }
    }

    private class OnMoveAction implements EventListener {
        public void handleEvent(Event evt) {
            SVGDocument svgDocument = svgCanvas.getSVGDocument();
            if (actionNode == null)return;
            dragged = true;
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            if (action == DRAG) {
                Element ee = (Element)((Element)actionNode).getParentNode();
                if (ee.getParentNode() != null && ee.getParentNode() 
instanceof Element) {
                    SVGPoint pt = localPt((Element)ee.getParentNode(), 
elEvt.getClientX(), elEvt.getClientY());
                    float dx = pt.getX() - startPt.getX();
                    float dy = pt.getY() - startPt.getY();
                    ee.setAttribute("transform", "translate(" + dx + ", " + dy 
+ ")");
                }
            }
        }
    }

}


Thanks,
Selva



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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

news <ne...@sea.gmane.org> wrote on 04/19/2006 06:51:45 AM:

> >    So, do you have a file 'de.svg' at the root of your 'C:' drive?
> 
> I am having de.svg in C: drive. herewith i have attached de.svg content. 

> Please let me know where i am doing the mistake.

   I can't reproduce your problem.  It works for me...

   At this point you will either have to provide a complete
standalone example (including your Java app), or debug the problem
yourself (you have the source to Batik so you can either step through
or add System.out to track where and how it goes wrong).


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

> 
>    Ok, This is odd, something is changing this URL for the message.
> I have tried to reproduce this problem and I only get this error message
> if there is no file 'de.svg' (or it is unreadable) at the root of the 'C:' 
> 
> drive.
> 
>    So, do you have a file 'de.svg' at the root of your 'C:' drive?
> 
> > use2.setAttributeNS(null, "style", 
> "fill:url(file:///C:/de.svg#MyGradient)");
> 

I am having de.svg in C: drive. herewith i have attached de.svg content. 
Please let me know where i am doing the mistake.

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-
SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="500" viewBox="0 
0 450 500">

<defs>
<linearGradient id="MyGradient">
<stop offset="5%" stop-color="#F60" />
<stop offset="95%" stop-color="#FF6" />
</linearGradient>
</defs>

<rect id="chessboard" x="25" y="25" width="400" height="400" fill="url
(#MyGradient)"/>
</svg>

Thanks,
Selva




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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

news <ne...@sea.gmane.org> wrote on 04/19/2006 06:10:44 AM:

> > >>>   use2.setAttributeNS(null, "style", "fill: 
> > url(file:///C:/de.svg#MyGradient)");
> > > 
> > > Even though i tried with correct syntax, it is giving following 
> > exception.
> > > 
> > > org.apache.batik.bridge.BridgeException: null:0
> > > An I/O error occured while processing the URI:
> > > "file:/C:/de.svg#MyGradient"
> 
> >   This is wrong, you must have three (3), [yes three] slashes
> > after the 'file:'.  Cameron's URL is correct.
> 
> i am using 3 slashes in my code, but while throwing exception, it is 
> displaying with single slash. I am using the following syntax like 
Cameron 
> mentioned.

   Ok, This is odd, something is changing this URL for the message.
I have tried to reproduce this problem and I only get this error message
if there is no file 'de.svg' (or it is unreadable) at the root of the 'C:' 

drive.

   So, do you have a file 'de.svg' at the root of your 'C:' drive?

> use2.setAttributeNS(null, "style", 
"fill:url(file:///C:/de.svg#MyGradient)");


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

> >>>   use2.setAttributeNS(null, "style", "fill: 
> url(file:///C:/de.svg#MyGradient)");
> > 
> > Even though i tried with correct syntax, it is giving following 
> exception.
> > 
> > org.apache.batik.bridge.BridgeException: null:0
> > An I/O error occured while processing the URI:
> > "file:/C:/de.svg#MyGradient"

>   This is wrong, you must have three (3), [yes three] slashes
> after the 'file:'.  Cameron's URL is correct.

i am using 3 slashes in my code, but while throwing exception, it is 
displaying with single slash. I am using the following syntax like Cameron 
mentioned.

use2.setAttributeNS(null, "style", "fill:url(file:///C:/de.svg#MyGradient)");

Thanks,
Selva





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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Selva,

news <ne...@sea.gmane.org> wrote on 04/19/2006 05:57:08 AM:

>>>   use2.setAttributeNS(null, "style", "fill: 
url(file:///C:/de.svg#MyGradient)");
> 
> Even though i tried with correct syntax, it is giving following 
exception.
> 
> org.apache.batik.bridge.BridgeException: null:0
> An I/O error occured while processing the URI:
> "file:/C:/de.svg#MyGradient"
       ^^^
  This is wrong, you must have three (3), [yes three] slashes
after the 'file:'.  Cameron's URL is correct.


> specified on the element <rect>
> 
>    at org.apache.batik.bridge.BridgeContext.getReferencedElement
> (BridgeContext.java:612)
> 
>    at org.apache.batik.bridge.PaintServer.convertURIPaint
> (PaintServer.java:348)
> 
>    at org.apache.batik.bridge.PaintServer.convertPaint
> (PaintServer.java:259)
> 
>    at org.apache.batik.bridge.PaintServer.convertFillPaint
> (PaintServer.java:228)
> 
>    at org.apache.batik.bridge.PaintServer.convertFillAndStroke
> (PaintServer.java:146)
> .
> .
> .
> 
> 
> Thanks,
> Selva
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    This is incorrect syntax for the fill property. 
> 
> >   use2.setAttributeNS(null, "style", "fill: 
> url(file:///C:/de.svg#MyGradient)");
> > 
> > which is correct syntax?
> 
>     This is 100% absolutely the correct syntax.


Even though i tried with correct syntax, it is giving following exception.

org.apache.batik.bridge.BridgeException: null:0
An I/O error occured while processing the URI:
"file:/C:/de.svg#MyGradient"
specified on the element <rect>

	at org.apache.batik.bridge.BridgeContext.getReferencedElement
(BridgeContext.java:612)

	at org.apache.batik.bridge.PaintServer.convertURIPaint
(PaintServer.java:348)

	at org.apache.batik.bridge.PaintServer.convertPaint
(PaintServer.java:259)

	at org.apache.batik.bridge.PaintServer.convertFillPaint
(PaintServer.java:228)

	at org.apache.batik.bridge.PaintServer.convertFillAndStroke
(PaintServer.java:146)
.
.
.


Thanks,
Selva





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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

> How about with:
> 
>   use2.setAttributeNS(null, "style", "fill: url
(file:///C:/de.svg#MyGradient)");

Since i am using absolute url, i didn't use url keyword. Even though i used 
with "fill: url(file:///C:/de.svg#MyGradient)", it is not working.

> 
> which is correct syntax?
> 

if i tried with "fill: url(file:///C:/de.svg#MyGradient)", it is throwing null 
pointer exception which i mentioned in earlier mail. if i try 
with "fill:file:///C:/de.svg#MyGradient", neither it is throwing exception nor 
it is applying the gradient.

Thanks,
Selva




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


Re: Accessing gradients/symbols from external SVG file

Posted by th...@kodak.com.
Hi Cameron,

Cameron McCormack <ca...@mcc.id.au> wrote on 04/19/2006 04:30:08 AM:

> > use2.setAttributeNS(null, "style", 
"fill:file:///C:/de.svg#MyGradient");

   This is incorrect syntax for the fill property. 

>   use2.setAttributeNS(null, "style", "fill: 
url(file:///C:/de.svg#MyGradient)");
> 
> which is correct syntax?

    This is 100% absolutely the correct syntax.

    The basic rule in CSS is silently ignore errors (on the grounds that 
it might be new content from a future version of the spec - apparently 
they haven't heard of versioning).  So oddly the fact that we complain 
when we can't load the resource file might be considered a bug in Batik, 
the silent ignoring of the unknown 'named color', 
"file:///C:/de.svg#MyGradient", 
is common CSS behavior.  It is unfortunate that Batik behaves differently 
in these two cases.


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


Re: Accessing gradients/symbols from external SVG file

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Selva.

Selva:
> I have also tried with absolute URL. but it is not working properly. I am 
> using my own application with JSVGCanvas to display SVG elements. When user 
> presses the "create" button, it is supposed to display the rectangle element 
> with gradient fill. But it is displaying rectangle with black fill.
> 
> Element use2 = doc.createElementNS(svgNS, "rect");
> use2.setAttributeNS(null, "x", "30");
> use2.setAttributeNS(null, "y", "30");
> use2.setAttributeNS(null, "id", "r2");
> use2.setAttributeNS(null, "width", "13");
> use2.setAttributeNS(null, "height", "13");
> use2.setAttributeNS(null, "style", "fill:file:///C:/de.svg#MyGradient");

How about with:

  use2.setAttributeNS(null, "style", "fill: url(file:///C:/de.svg#MyGradient)");

which is correct syntax?

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

> Are you running this in Squiggle?  Or your own application with a
> JSVGCanvas?  If you are building up a Document, then displaying it using
> the canvas component's setDocument method, then you should use an
> absolute URL to give the location of your defs.svg (perhaps a local file
> URL such as file:///C:/somewhere/defs.svg on Windows or
> file:/somewhere/defs.svg on Unix, or an http URL).

I have also tried with absolute URL. but it is not working properly. I am 
using my own application with JSVGCanvas to display SVG elements. When user 
presses the "create" button, it is supposed to display the rectangle element 
with gradient fill. But it is displaying rectangle with black fill.

Element use2 = doc.createElementNS(svgNS, "rect");
use2.setAttributeNS(null, "x", "30");
use2.setAttributeNS(null, "y", "30");
use2.setAttributeNS(null, "id", "r2");
use2.setAttributeNS(null, "width", "13");
use2.setAttributeNS(null, "height", "13");
use2.setAttributeNS(null, "style", "fill:file:///C:/de.svg#MyGradient");


Thanks,
Selva


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


Re: Accessing gradients/symbols from external SVG file

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Selva.

Selva:
> if I use fill with  url(defs.svg#gradient_1), it is throwing following 
> exception.

Are you running this in Squiggle?  Or your own application with a
JSVGCanvas?  If you are building up a Document, then displaying it using
the canvas component's setDocument method, then you should use an
absolute URL to give the location of your defs.svg (perhaps a local file
URL such as file:///C:/somewhere/defs.svg on Windows or
file:/somewhere/defs.svg on Unix, or an http URL).

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Accessing gradients/symbols from external SVG file

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

> Element rect = doc.createElementNS(svgNS, "rect");
> rect.setAttributeNS(null, "x", "30");
> rect.setAttributeNS(null, "y", "30");
> rect.setAttributeNS(null, "id", "r2");
> rect.setAttributeNS(null, "width", "13");
> rect.setAttributeNS(null, "height", "13");
> rect.setAttributeNS(null, "style", "fill:defs.svg#gradient_1");

> This sholud be:
> rect.setAttributeNS(null, "style", "fill: url(defs.svg#gradient_1)");

if I use fill with  url(defs.svg#gradient_1), it is throwing following 
exception.

org.apache.batik.bridge.BridgeException: null:0
An I/O error occured while processing the URI:
"//defs.svg#extGrad2"
specified on the element <rect>
at org.apache.batik.bridge.BridgeContext.getReferencedElement
(BridgeContext.java:612)
at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:348)
at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:259)
.
.
.

But if i use fill without url like defs.svg#gradient_1, it is not giving any 
error. but instead of gradient, rectangle is filled with black color. I also 
tried with physical path. but still it is not showing proper gradient.

Please let me know whether where i am doing mistake.

Thanks,
Selva




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


Re: Accessing gradients/symbols from external SVG file

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Selva.

Selva:
> I have declared one SVG file with symbols and gradients like in 
> \resources\svg\defs.svg. If I tried to use external gradient from my code, it 
> is not applying it properly.
> 
> Element rect = doc.createElementNS(svgNS, "rect");
> rect.setAttributeNS(null, "x", "30");
> rect.setAttributeNS(null, "y", "30");
> rect.setAttributeNS(null, "id", "r2");
> rect.setAttributeNS(null, "width", "13");
> rect.setAttributeNS(null, "height", "13");
>             
> rect.setAttributeNS(null, "style", "fill:defs.svg#gradient_1");

This sholud be:

  rect.setAttributeNS(null, "style", "fill: url(defs.svg#gradient_1)");

> Also how to change the element’s attributes values, which is available inside 
> the symbols/group? 
> 
> <g id="extOther" style="stroke:crimson; stroke-width:4">
> <rect x="-50" y="-50" width="100" height="100" style="fill:gold; stroke:none"/>
> </g>
> 
> Here how to change the rectangle element's style attributes using group id?

You can use the DOM Core[1] methods to navigate to the rect from the g.
So, if you want to set the style attribute of the first element child
of the g:

  var g = document.getElementById("extOther");
  var rect = g.firstChild;
  while (rect.nodeType != Node.ELEMENT_NODE) {
    rect = rect.nextSibling;
  }
  rect.setAttributeNS(null, "style", whatever);

Cameron

[1] http://www.w3.org/TR/DOM-Level-2-Core/core.html

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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