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 vyang <vy...@apt-cafm.com> on 2007/01/09 21:57:47 UTC

Determine points in JSVGCanvas

Hello,

I want to deteremine the points(maybe end points) of a drawing in JSVGCanvas
so that I can implement something like point snapping.  I've been looking
through a few post and thinking of using SVGLocatable > getbbox().  Any
pointers would be much appreciated.  Thanks.
-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8246236
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: Determine points in JSVGCanvas

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Tue, 2007-01-16 at 07:51 -0800, vyang wrote:
> Thanks for explaining those to me.  Now I was wondering, is there a way for
> me to get the point of the element that is returned from those two methods. 
> Specifically, the point where the intersection or enclosure occured so that
> I can determine how close that point is to the point where I clicked?

As far as I know, there is no way to know the exact point where the
intersection, all the method calls is only returned boolean.

However, if you want to go deep down maybe (i am not sure) you could
track the Java API (not SVG API) Shape.intersect and see how they
implemenent that methods. or could search google for algorithm on how to
find intersect between shape

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Determine points in JSVGCanvas

Posted by vyang <vy...@apt-cafm.com>.
Hello,

Thanks for explaining those to me.  Now I was wondering, is there a way for
me to get the point of the element that is returned from those two methods. 
Specifically, the point where the intersection or enclosure occured so that
I can determine how close that point is to the point where I clicked?


Tonny Kohar wrote:
> 
> Hi,
> 
> On Mon, 2007-01-15 at 07:45 -0800, vyang wrote:
>> Well I use JSVGCanvas so it seems its already booted.  But I was just
>> wondering why the document I created in SAXSVGDocumentFactory returns
>> null,
>> while the one I retrieve from canvas works fine.  Both documents do load
>> the
>> correct mage when it is set.
> 
> Because using DocumentFactory does not boot the SVG and CSS so you will
> get NULL, but JSVGCanvas after loading the document using
> DocumentFactory, the JSVGCanvas add additional operation which is boot
> svg and css.
> 
>> Could you also explain getEnclosureList(), I looked at the api(at least
>> the
>> one I found in SVGOMSVGElement - SVGElement page/link not working) but it
>> was vague.
> 
>>>From SVG Specification
> 
> getIntersectionList
>         Returns the list of graphics elements whose rendered content
>         intersects the supplied rectangle, honoring the 'pointer-events'
>         property value on each candidate graphics element.
>         
> getEnclosureList
>         Returns the list of graphics elements whose rendered content is
>         entirely contained within the supplied rectangle, honoring the
>         'pointer-events' property value on each candidate graphics
>         element.
> 
> Regards
> Tonny Kohar
> -- 
> Sketsa 
> SVG Graphics Editor
> http://www.kiyut.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8392452
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: Determine points in JSVGCanvas

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Mon, 2007-01-15 at 07:45 -0800, vyang wrote:
> Well I use JSVGCanvas so it seems its already booted.  But I was just
> wondering why the document I created in SAXSVGDocumentFactory returns null,
> while the one I retrieve from canvas works fine.  Both documents do load the
> correct mage when it is set.

Because using DocumentFactory does not boot the SVG and CSS so you will
get NULL, but JSVGCanvas after loading the document using
DocumentFactory, the JSVGCanvas add additional operation which is boot
svg and css.

> Could you also explain getEnclosureList(), I looked at the api(at least the
> one I found in SVGOMSVGElement - SVGElement page/link not working) but it
> was vague.

>>From SVG Specification

getIntersectionList
        Returns the list of graphics elements whose rendered content
        intersects the supplied rectangle, honoring the 'pointer-events'
        property value on each candidate graphics element.
        
getEnclosureList
        Returns the list of graphics elements whose rendered content is
        entirely contained within the supplied rectangle, honoring the
        'pointer-events' property value on each candidate graphics
        element.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Determine points in JSVGCanvas

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

Attached the enhancement as bug id 41429, it contains the diff files

On Mon, 2007-01-22 at 12:07 +0700, Tonny Kohar wrote:
> Hi,
> 
> On Thu, 2007-01-18 at 20:29 -0500, thomas.deweese@kodak.com wrote:
> >   You can use batik.dom.util.DOMUtilities.writeDocument to
> > do this (some people appear to have problems with this, but
> > I don't know why) you can also use the Java XSLT engine to
> > write the document but I'm not familiar with that. 
> > 
> 
> I do not know about other people, but previously we are expecting that
> method writeDocument() is pretty printer enabled. So we didn't use that
> methods but using DOMtranscoder instead. I will see the batik code and
> send patch to reroute it to DOMTranscoder in few days maybe by adding a
> new methods DOMUtilities.writeDocument(Document doc, Map
> transcoderKeyMap), but that's means DOMUtilities will have dependency to
> transcoder, is it ok ?
> 
> Regards
> Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Determine points in JSVGCanvas

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Thu, 2007-01-18 at 20:29 -0500, thomas.deweese@kodak.com wrote:
>   You can use batik.dom.util.DOMUtilities.writeDocument to
> do this (some people appear to have problems with this, but
> I don't know why) you can also use the Java XSLT engine to
> write the document but I'm not familiar with that. 
> 

I do not know about other people, but previously we are expecting that
method writeDocument() is pretty printer enabled. So we didn't use that
methods but using DOMtranscoder instead. I will see the batik code and
send patch to reroute it to DOMTranscoder in few days maybe by adding a
new methods DOMUtilities.writeDocument(Document doc, Map
transcoderKeyMap), but that's means DOMUtilities will have dependency to
transcoder, is it ok ?

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Determine points in JSVGCanvas

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

vyang <vy...@apt-cafm.com> wrote on 01/18/2007 04:13:38 PM:

> Also I'm having trouble updating the svg files. [...]  So what I think 
> its doing is only changing DOM part and not my svg file.  If that is 
> correct how do I change my svg file or would I have to create a new 
> svg file and resave it under same name?

  Correct, you are only manipulating the Document in memory not
on disk. You need to create a new svg file and save it with the
same name.

  You can use batik.dom.util.DOMUtilities.writeDocument to
do this (some people appear to have problems with this, but
I don't know why) you can also use the Java XSLT engine to
write the document but I'm not familiar with that. 

> 
> Thanks in advance
> 
> 
> thomas.deweese wrote:
> > 
> > Hi Vyang,
> > 
> > vyang <vy...@apt-cafm.com> wrote on 01/15/2007 10:45:16 AM:
> > 
> >> I also do use getIntersectionList() and it does return the correct 
> > elements,
> >> however, how do I get the element point that is near where I clicked?
> > 
> >    One needs to be clear what part of element you are interested in. 
If
> > getInstersectionList includes the element then the given rectangle 
> > (probably
> > just a one pixel rect in your case) is in the element.  I suspect you 
are
> > curious what point on the outline of the element is closest to the 
point
> > clicked.
> > 
> >    The problem with this is that several points may be closest to the 
> > point
> > (think clicking in the center of a circle ;).   That all said for SVG
> > <path/> elements you can use the DOM interfaces:
> >         float getTotalLength()
> >         SVGPoint getPointAtLength(float d);
> > 
> >    To sample the path comparing the SVGPoints with your
> > desired Point. 
> > 
> >    If you are a glutton for punishment you can also work your 
> > way through the animatedNormalizedPathSegList and do a more 
> > scientific comparison (for straight lines there is a simple 
> > closed form for closest point on line, it get's harder for 
> > quadratic and cubic beziers, much less elliptical arcs).
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/Determine-
> points-in-JSVGCanvas-tf2948761.html#a8439152
> 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
> 


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


Re: Determine points in JSVGCanvas

Posted by vyang <vy...@apt-cafm.com>.
Thank you for helping.  I will look into that and hopefully can get it
figured out.  Also I'm having trouble updating the svg files.  For example,
I change the size of a rectangle with a click, and my canvas does show the
change.  But when I restart or look at the svg file its not changed.  I'm
using the setattributns inside of runnable.  So what I think its doing is
only changing DOM part and not my svg file.  If that is correct how do I
change my svg file or would I have to create a new svg file and resave it
under same name?

Thanks in advance


thomas.deweese wrote:
> 
> Hi Vyang,
> 
> vyang <vy...@apt-cafm.com> wrote on 01/15/2007 10:45:16 AM:
> 
>> I also do use getIntersectionList() and it does return the correct 
> elements,
>> however, how do I get the element point that is near where I clicked?
> 
>    One needs to be clear what part of element you are interested in.  If
> getInstersectionList includes the element then the given rectangle 
> (probably
> just a one pixel rect in your case) is in the element.  I suspect you are
> curious what point on the outline of the element is closest to the point
> clicked.
> 
>    The problem with this is that several points may be closest to the 
> point
> (think clicking in the center of a circle ;).   That all said for SVG
> <path/> elements you can use the DOM interfaces:
>         float getTotalLength()
>         SVGPoint getPointAtLength(float d);
> 
>    To sample the path comparing the SVGPoints with your
> desired Point. 
> 
>    If you are a glutton for punishment you can also work your 
> way through the animatedNormalizedPathSegList and do a more 
> scientific comparison (for straight lines there is a simple 
> closed form for closest point on line, it get's harder for 
> quadratic and cubic beziers, much less elliptical arcs).
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8439152
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: Determine points in JSVGCanvas

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

vyang <vy...@apt-cafm.com> wrote on 01/15/2007 10:45:16 AM:

> I also do use getIntersectionList() and it does return the correct 
elements,
> however, how do I get the element point that is near where I clicked?

   One needs to be clear what part of element you are interested in.  If
getInstersectionList includes the element then the given rectangle 
(probably
just a one pixel rect in your case) is in the element.  I suspect you are
curious what point on the outline of the element is closest to the point
clicked.

   The problem with this is that several points may be closest to the 
point
(think clicking in the center of a circle ;).   That all said for SVG
<path/> elements you can use the DOM interfaces:
        float getTotalLength()
        SVGPoint getPointAtLength(float d);

   To sample the path comparing the SVGPoints with your
desired Point. 

   If you are a glutton for punishment you can also work your 
way through the animatedNormalizedPathSegList and do a more 
scientific comparison (for straight lines there is a simple 
closed form for closest point on line, it get's harder for 
quadratic and cubic beziers, much less elliptical arcs).


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


Re: Determine points in JSVGCanvas

Posted by vyang <vy...@apt-cafm.com>.
Hello,

Well I use JSVGCanvas so it seems its already booted.  But I was just
wondering why the document I created in SAXSVGDocumentFactory returns null,
while the one I retrieve from canvas works fine.  Both documents do load the
correct mage when it is set.

I also do use getIntersectionList() and it does return the correct elements,
however, how do I get the element point that is near where I clicked?

Could you also explain getEnclosureList(), I looked at the api(at least the
one I found in SVGOMSVGElement - SVGElement page/link not working) but it
was vague.


Tonny Kohar wrote:
> 
> Hi,
> 
> On Fri, 2007-01-12 at 09:01 -0800, vyang wrote:
>> then I would get a null bbox.  But when I get SVGDocument from
>> JSVGCanvas,
>> my bbox is not null.  I also checked to see if the documents where the
>> same
>> by viewing it on JSVGCanvas, and it appears that they are the same.  Why
>> is
>> it that when I use the one created by SAXSVGDocumentFactory I get null? 
>> Is
>> it because I passed null to SAXSVGDocumentFactory?
> 
> I think you need to boot the svg and css properly for bbox to be
> available. Please read this wiki
> http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom
> 
>> Also, it appears that bbox is not what I need.  What I am doing is
>> drawing a
>> dot on click on an overlay.  And then if the user would click near the
>> edge
>> of a circle for example, it would draw the dot on the circle's edge. 
>> Anyone
>> hints on how I would implement this?  Again any hints would be much
>> appreciated.  Thanks.
> 
> I do not know you need the bbox or not, but you need to know the
> bounding box of the circle (bbox is providing this info) and compare it
> with the point/dot click. You might also use getIntersectionList() or
> getEnclosureList() for checking the intersect of point and circle
> 
> Regards
> Tonny Kohar
> -- 
> Sketsa 
> SVG Graphics Editor
> http://www.kiyut.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8373645
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: Determine points in JSVGCanvas

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Fri, 2007-01-12 at 09:01 -0800, vyang wrote:
> then I would get a null bbox.  But when I get SVGDocument from JSVGCanvas,
> my bbox is not null.  I also checked to see if the documents where the same
> by viewing it on JSVGCanvas, and it appears that they are the same.  Why is
> it that when I use the one created by SAXSVGDocumentFactory I get null?  Is
> it because I passed null to SAXSVGDocumentFactory?

I think you need to boot the svg and css properly for bbox to be
available. Please read this wiki
http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom

> Also, it appears that bbox is not what I need.  What I am doing is drawing a
> dot on click on an overlay.  And then if the user would click near the edge
> of a circle for example, it would draw the dot on the circle's edge.  Anyone
> hints on how I would implement this?  Again any hints would be much
> appreciated.  Thanks.

I do not know you need the bbox or not, but you need to know the
bounding box of the circle (bbox is providing this info) and compare it
with the point/dot click. You might also use getIntersectionList() or
getEnclosureList() for checking the intersect of point and circle

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Re: Determine points in JSVGCanvas

Posted by vyang <vy...@apt-cafm.com>.
Hello,

Thanks for helping.

When I create my SVGDocument using

SAXSVGDocumentFactory saxDocFac = new SAXSVGDocumentFactory(null);
try {
     svgDocument = saxDocFac.createSVGDocument(iconLibrary.getIconURL());
} catch (IOException ex) {
     ex.printStackTrace();
}

then I would get a null bbox.  But when I get SVGDocument from JSVGCanvas,
my bbox is not null.  I also checked to see if the documents where the same
by viewing it on JSVGCanvas, and it appears that they are the same.  Why is
it that when I use the one created by SAXSVGDocumentFactory I get null?  Is
it because I passed null to SAXSVGDocumentFactory?

Also, it appears that bbox is not what I need.  What I am doing is drawing a
dot on click on an overlay.  And then if the user would click near the edge
of a circle for example, it would draw the dot on the circle's edge.  Anyone
hints on how I would implement this?  Again any hints would be much
appreciated.  Thanks.
-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8302026
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: Determine points in JSVGCanvas

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

vyang <vy...@apt-cafm.com> wrote on 01/11/2007 11:26:00 AM:

> public void mouseClicked(MouseEvent e) {
>         JGVTComponent c = (JGVTComponent)e.getSource();
>         SVGSVGElement rootElement = svgDocument.getRootElement();

   First off you need to make sure that 'svgDocument' is
the same as 'JSVGCanvas.getDocument()'.

>         if(rootElement instanceof SVGLocatable)
>             System.out.println("instance of locatable");
> 
>         SVGLocatableSupport svgLoc = new SVGLocatableSupport();
>         SVGRect bbox = svgLoc.getBBox(ele);

   So the right thing to do here is:

        SVGRect bbox = rootElement.getBBox();

   There is very little reason for anyone to be poking
around in the batik.dom.svg package, unless they are
working on SVG/Batik DOM extensions.

>         System.out.println(bbox);

Re: Determine points in JSVGCanvas

Posted by vyang <vy...@apt-cafm.com>.
I tried using bbox but my bbox is null.  My coding is as follows:

private void renderIcon(String url){
       
canvasIcon.setDocumentState(org.apache.batik.swing.JSVGCanvas.ALWAYS_DYNAMIC);
        canvasIcon.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
         public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                System.out.println("gvt tree build done");
            }
         });
        
        canvasIcon.setURI(url);
}

public void mouseClicked(MouseEvent e) {
        JGVTComponent c = (JGVTComponent)e.getSource();
        SVGSVGElement rootElement = svgDocument.getRootElement();
        
        System.out.println(rootElement);
        System.out.println(rootElement.getTagName());

        if(rootElement instanceof SVGLocatable)
            System.out.println("instance of locatable");

        SVGLocatableSupport svgLoc = new SVGLocatableSupport();
        SVGRect bbox = svgLoc.getBBox(ele);
        System.out.println(bbox);
        ...

What am I doing wrong here?  Any hints is much appreciated.
-- 
View this message in context: http://www.nabble.com/Determine-points-in-JSVGCanvas-tf2948761.html#a8278076
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