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 hardc0d3r <ha...@gmail.com> on 2007/05/26 10:24:31 UTC

how to draw markers

does anyone have an example for drawing markers in batik? or can anyone guide
me through it? thanks
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10814414
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: how to draw markers

Posted by hardc0d3r <ha...@gmail.com>.
sorry i get it now.. thanks for the replies
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10817163
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: how to draw markers

Posted by hardc0d3r <ha...@gmail.com>.
do i need a svg element to load inorder for the marker to work? or can i make
one when creating a new svg?
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10817119
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: how to draw markers

Posted by hardc0d3r <ha...@gmail.com>.
i tried what you said but failed.. here is the code..

            Element defs = doc.createElementNS(svgNS, "defs");
            Element startArrow = doc.createElementNS(svgNS, "marker");
            startArrow.setAttributeNS(null, "id", "startArrow");
            startArrow.setAttributeNS(null, "viewBox", "0 0 10 10");
            startArrow.setAttributeNS(null, "refX", "0");
            startArrow.setAttributeNS(null, "refY", "6");
            startArrow.setAttributeNS(null, "markerUnits", "strokewidth");
            startArrow.setAttributeNS(null, "orient", "auto");
            startArrow.setAttributeNS(null, "markerWidth", "5");
            startArrow.setAttributeNS(null, "markerHeight", "4");
            Attr att = doc.createAttribute("path");
            att.setValue("M0,0 L10,0 L0,5 L10,10 L10,5 z");
            startArrow.setAttributeNode(att); 
            defs.appendChild(startArrow);

and here is how i call the marker:
            
            shape.setAttributeNS(null, "marker-start", "url(#startArrow)");

help..
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10817347
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: how to draw markers

Posted by Robert Lummert <ro...@lummert.net>.
hardc0d3r wrote:
> sir, how do i do this in batik? how do i add the path do the marker element?

after loading the svg containing the marker e.g. into an SVGCanvas named
svgCanvas fetch the document:

org.w3c.dom.Document document = svgCanvas.getSVGDocument();

best do this in a listener callback as loading svg in batik is not
synchronous, like

treeRendererAdapter = new GVTTreeRendererAdapter() {
  public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
    // initialise document root
    document = svgCanvas.getSVGDocument();
  }
};
svgCanvas.addGVTTreeRendererListener(treeRendererAdapter);

The rest can be done via the documents DOM interface:

find your marker element -lets name it markEl- by name, id or path
(svgCanvas.getElementById, svgCanvas.getElementsByName or using sth.
like javax.xml.xpath.XPath)

Then create and attach the attribute:
  org.w3c.dom.Attr att = document.createAttribute("path");
  att.setValue("M0,0 v100");
  markEl.setAttributeNode(att);

Cheers,

     Robert

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


Re: how to draw markers

Posted by hardc0d3r <ha...@gmail.com>.
sir, how do i do this in batik? how do i add the path do the marker element?
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10816891
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: how to draw markers

Posted by Urs Reupke <ur...@gmx.net>.
Hello hardc0d3r,

you asked for help with drawing markers.
When recently I introduced markers into my app, I found
http://www.w3.org/TR/SVG/painting.html#Markers quite helpful.
If you need anything beyond that, please ask for details.

Regards
-Urs

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


Re: how to draw markers

Posted by hardc0d3r <ha...@gmail.com>.
ok.. solved it! i just have to append the path element to the marker..

somethig like these:
            Element defs = doc.createElementNS(svgNS, "defs");
            Element startArrow = doc.createElementNS(svgNS, "marker");
            startArrow.setAttributeNS(null, "id", "startArrow");
            startArrow.setAttributeNS(null, "viewBox", "0 0 10 10");
            startArrow.setAttributeNS(null, "refX", "0");
            startArrow.setAttributeNS(null, "refY", "6");
            startArrow.setAttributeNS(null, "markerUnits", "strokeWidth");
            startArrow.setAttributeNS(null, "orient", "auto");
            startArrow.setAttributeNS(null, "markerWidth", "5");
            startArrow.setAttributeNS(null, "markerHeight", "4");
            defs.appendChild(startArrow);
            
            Element path = doc.createElementNS(svgNS, "path");
            path.setAttribute("d", "M0,1 L5,1 L5,0 L10,1.5 L5,3 L5,2 L0,2
L0,1 Z");
            startArrow.appendChild(path);
-- 
View this message in context: http://www.nabble.com/how-to-draw-markers-tf3819799.html#a10821960
Sent from the Batik - Users mailing list archive at Nabble.com.


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