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 ra...@blueyonder.co.uk on 2006/03/17 20:21:24 UTC

zooming problem

Hi Thomas,

I've added red circles programmatically to the svg document, but I'm
having the problem when I zoomIn the circles also get bigger - is there a
way I can set the size attribute so that it is fixed?

Many thx

yasmin




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


Re: zooming problem

Posted by ra...@blueyonder.co.uk.
Hi Thomas,

I tried pasting the code u emailed at the end of my code after I created
the 'circleGroup' and added the 'circles' but I'm getting an error that
the circleGroup variable is not declared?

Thx

yasmin



> Hi Yasmin,
>
> rafiqy@blueyonder.co.uk wrote on 03/18/2006 08:04:49 AM:
>
>> It's not working for me - here's the code again, I made the relevant
> changes:
>
>    What part of it is not working?  I just noticed that the stroker
> doesn't like the 'trick' we are playing so the outline doesn't cover
> it's self properly.  Anyway it is looking like you will need to
> run through all the children of the circleGroup and change the
> 'r' attribute to something different, sorry about that:
>
>         String newR = ""+4;
>         for (Node child = circleGroup.getFirstChild();
>              child != null;
>              child = child.getNextSibling()) {
>            if (!(child instanceof Element)) continue;
>            Element e = (Element)child;
>            child.setAttributeNS(null, "r", newR);
>         }
>
>> e.setAttributeNS(null,"stroke-width","20");
>> e.setAttributeNS(null,"stroke","red");
>> e.setAttributeNS(null,"cx",""+pt2d.getX());
>> e.setAttributeNS(null,"cy",""+pt2d.getY());
>> e.setAttributeNS(null,"r","0.001");
>>
>> Thx
>>
>> yasmin
>>
>>
>>
>> > Hi Yasmin,
>> >
>> > rafiqy@blueyonder.co.uk wrote on 03/18/2006 07:12:47 AM:
>> >
>> >> I've tried changing my code so that instead of filling the circle, it
>> > uses
>> >> strokes, but batik does not recognise the strokes, so doesn't draw
> them
>> > to
>> >> the canvas - here's the snippet of my code that is relevant:
>> >>
>> >> e.setAttributeNS(null,"r","0.001");
>> >> e.setAttributeNS(null,"style","stroke-width:20");
>> >> e.setAttributeNS(null,"style","stroke:red");
>> >
>> >    What is the style attribute after this?  I strongly
>> > suggest avoiding using style unless you want to use the
>> > SAC interface.  I once again strongly suggest that you
>> > switch all uses of 'style' to the underlying presentation
>> > attributes:
>> >
>> > e.setAttributeNS(null,"stroke-width","20");
>> > e.setAttributeNS(null,"stroke","red");
>> >
>> >    If you use the style attribute you then need to use
>> > the SAC (Simple API for CSS) to do all your property
>> > manipulation (which is fine but it's a whole other
>> > set of APIs to learn).
>> >
>> >> I now the error is the way I've coded the stroke?
>> >
>> >    Yes.
>> >
>> >
>> >> > rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
>> >> >
>> >> >> I've added red circles programmatically to the svg document, but
> I'm
>> >> >> having the problem when I zoomIn the circles also get bigger - is
>> > there
>> >> > a
>> >> >> way I can set the size attribute so that it is fixed?
>> >> >
>> >> >    No you can't set the size attribute so it is fixed.  However if
> you
>> >> > use the 'stroke' to set the 'size' of the circles:
>> >> >
>> >> >    <g id="circleGroup" stroke-width="8" stroke="red">
>> >> >         <circle cx="10" cy="10" r="0.001"/>
>> >> >    <g>
>> >> >
>> >> >    You can then just update the stroke-width on the circleGroup
>> >> > and it will cascade down to all the circle elements.
>> >> >
>> >> >    You can find out when the canvas zooms by registering an
>> >> > onzoom event listener on the Document.
>> >> >
>> >> >
>> >> >
> ---------------------------------------------------------------------
>> >> > 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
>> >>
>> >
>> >
>> > ---------------------------------------------------------------------
>> > 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
>>
>
>
> ---------------------------------------------------------------------
> 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: zooming problem

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

rafiqy@blueyonder.co.uk wrote on 03/18/2006 08:04:49 AM:

> It's not working for me - here's the code again, I made the relevant 
changes:

   What part of it is not working?  I just noticed that the stroker
doesn't like the 'trick' we are playing so the outline doesn't cover
it's self properly.  Anyway it is looking like you will need to
run through all the children of the circleGroup and change the
'r' attribute to something different, sorry about that:

        String newR = ""+4;
        for (Node child = circleGroup.getFirstChild();
             child != null;
             child = child.getNextSibling()) {
           if (!(child instanceof Element)) continue;
           Element e = (Element)child;
           child.setAttributeNS(null, "r", newR);
        }

> e.setAttributeNS(null,"stroke-width","20");
> e.setAttributeNS(null,"stroke","red");
> e.setAttributeNS(null,"cx",""+pt2d.getX());
> e.setAttributeNS(null,"cy",""+pt2d.getY());
> e.setAttributeNS(null,"r","0.001");
> 
> Thx
> 
> yasmin
> 
> 
> 
> > Hi Yasmin,
> >
> > rafiqy@blueyonder.co.uk wrote on 03/18/2006 07:12:47 AM:
> >
> >> I've tried changing my code so that instead of filling the circle, it
> > uses
> >> strokes, but batik does not recognise the strokes, so doesn't draw 
them
> > to
> >> the canvas - here's the snippet of my code that is relevant:
> >>
> >> e.setAttributeNS(null,"r","0.001");
> >> e.setAttributeNS(null,"style","stroke-width:20");
> >> e.setAttributeNS(null,"style","stroke:red");
> >
> >    What is the style attribute after this?  I strongly
> > suggest avoiding using style unless you want to use the
> > SAC interface.  I once again strongly suggest that you
> > switch all uses of 'style' to the underlying presentation
> > attributes:
> >
> > e.setAttributeNS(null,"stroke-width","20");
> > e.setAttributeNS(null,"stroke","red");
> >
> >    If you use the style attribute you then need to use
> > the SAC (Simple API for CSS) to do all your property
> > manipulation (which is fine but it's a whole other
> > set of APIs to learn).
> >
> >> I now the error is the way I've coded the stroke?
> >
> >    Yes.
> >
> >
> >> > rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
> >> >
> >> >> I've added red circles programmatically to the svg document, but 
I'm
> >> >> having the problem when I zoomIn the circles also get bigger - is
> > there
> >> > a
> >> >> way I can set the size attribute so that it is fixed?
> >> >
> >> >    No you can't set the size attribute so it is fixed.  However if 
you
> >> > use the 'stroke' to set the 'size' of the circles:
> >> >
> >> >    <g id="circleGroup" stroke-width="8" stroke="red">
> >> >         <circle cx="10" cy="10" r="0.001"/>
> >> >    <g>
> >> >
> >> >    You can then just update the stroke-width on the circleGroup
> >> > and it will cascade down to all the circle elements.
> >> >
> >> >    You can find out when the canvas zooms by registering an
> >> > onzoom event listener on the Document.
> >> >
> >> >
> >> > 
---------------------------------------------------------------------
> >> > 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
> >>
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 


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


Re: zooming problem

Posted by ra...@blueyonder.co.uk.
Thomas,

It's not working for me - here's the code again, I made the relevant changes:

e.setAttributeNS(null,"stroke-width","20");
e.setAttributeNS(null,"stroke","red");
e.setAttributeNS(null,"cx",""+pt2d.getX());
e.setAttributeNS(null,"cy",""+pt2d.getY());
e.setAttributeNS(null,"r","0.001");

Thx

yasmin



> Hi Yasmin,
>
> rafiqy@blueyonder.co.uk wrote on 03/18/2006 07:12:47 AM:
>
>> I've tried changing my code so that instead of filling the circle, it
> uses
>> strokes, but batik does not recognise the strokes, so doesn't draw them
> to
>> the canvas - here's the snippet of my code that is relevant:
>>
>> e.setAttributeNS(null,"r","0.001");
>> e.setAttributeNS(null,"style","stroke-width:20");
>> e.setAttributeNS(null,"style","stroke:red");
>
>    What is the style attribute after this?  I strongly
> suggest avoiding using style unless you want to use the
> SAC interface.  I once again strongly suggest that you
> switch all uses of 'style' to the underlying presentation
> attributes:
>
> e.setAttributeNS(null,"stroke-width","20");
> e.setAttributeNS(null,"stroke","red");
>
>    If you use the style attribute you then need to use
> the SAC (Simple API for CSS) to do all your property
> manipulation (which is fine but it's a whole other
> set of APIs to learn).
>
>> I now the error is the way I've coded the stroke?
>
>    Yes.
>
>
>> > rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
>> >
>> >> I've added red circles programmatically to the svg document, but I'm
>> >> having the problem when I zoomIn the circles also get bigger - is
> there
>> > a
>> >> way I can set the size attribute so that it is fixed?
>> >
>> >    No you can't set the size attribute so it is fixed.  However if you
>> > use the 'stroke' to set the 'size' of the circles:
>> >
>> >    <g id="circleGroup" stroke-width="8" stroke="red">
>> >         <circle cx="10" cy="10" r="0.001"/>
>> >    <g>
>> >
>> >    You can then just update the stroke-width on the circleGroup
>> > and it will cascade down to all the circle elements.
>> >
>> >    You can find out when the canvas zooms by registering an
>> > onzoom event listener on the Document.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > 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
>>
>
>
> ---------------------------------------------------------------------
> 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: zooming problem

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

rafiqy@blueyonder.co.uk wrote on 03/18/2006 07:12:47 AM:

> I've tried changing my code so that instead of filling the circle, it 
uses
> strokes, but batik does not recognise the strokes, so doesn't draw them 
to
> the canvas - here's the snippet of my code that is relevant:
> 
> e.setAttributeNS(null,"r","0.001");
> e.setAttributeNS(null,"style","stroke-width:20");
> e.setAttributeNS(null,"style","stroke:red");

   What is the style attribute after this?  I strongly
suggest avoiding using style unless you want to use the
SAC interface.  I once again strongly suggest that you 
switch all uses of 'style' to the underlying presentation 
attributes: 

e.setAttributeNS(null,"stroke-width","20");
e.setAttributeNS(null,"stroke","red");

   If you use the style attribute you then need to use
the SAC (Simple API for CSS) to do all your property
manipulation (which is fine but it's a whole other
set of APIs to learn).

> I now the error is the way I've coded the stroke?

   Yes.


> > rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
> >
> >> I've added red circles programmatically to the svg document, but I'm
> >> having the problem when I zoomIn the circles also get bigger - is 
there
> > a
> >> way I can set the size attribute so that it is fixed?
> >
> >    No you can't set the size attribute so it is fixed.  However if you
> > use the 'stroke' to set the 'size' of the circles:
> >
> >    <g id="circleGroup" stroke-width="8" stroke="red">
> >         <circle cx="10" cy="10" r="0.001"/>
> >    <g>
> >
> >    You can then just update the stroke-width on the circleGroup
> > and it will cascade down to all the circle elements.
> >
> >    You can find out when the canvas zooms by registering an
> > onzoom event listener on the Document.
> >
> >
> > ---------------------------------------------------------------------
> > 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
> 


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


Re: zooming problem

Posted by ra...@blueyonder.co.uk.
Hi Thomas,

I've tried changing my code so that instead of filling the circle, it uses
strokes, but batik does not recognise the strokes, so doesn't draw them to
the canvas - here's the snippet of my code that is relevant:

e.setAttributeNS(null,"r","0.001");
e.setAttributeNS(null,"style","stroke-width:20");
e.setAttributeNS(null,"style","stroke:red");

I now the error is the way I've coded the stroke?

Many thx

yasmin



> Hi Yasmin,
>
> rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
>
>> I've added red circles programmatically to the svg document, but I'm
>> having the problem when I zoomIn the circles also get bigger - is there
> a
>> way I can set the size attribute so that it is fixed?
>
>    No you can't set the size attribute so it is fixed.  However if you
> use the 'stroke' to set the 'size' of the circles:
>
>    <g id="circleGroup" stroke-width="8" stroke="red">
>         <circle cx="10" cy="10" r="0.001"/>
>    <g>
>
>    You can then just update the stroke-width on the circleGroup
> and it will cascade down to all the circle elements.
>
>    You can find out when the canvas zooms by registering an
> onzoom event listener on the Document.
>
>
> ---------------------------------------------------------------------
> 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: zooming problem

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

"Javid Alimohideen" <ja...@gmail.com> wrote on 03/17/2006 08:19:46 PM:

> I have been having the same problem as how to preserve the size of the
> elements in my application. In my case, I have g elements of quite 
complex
> shapes and they have different stroke-width values, for e.g., a 'g' that
> represents the interstate highway sign. So, I tried to do the following:
> 
> private void updateElementsScale() {
> 
>       if (eventsSet.hasChildNodes()) {
>          org.w3c.dom.Node child = eventsSet.getFirstChild();
>          while(child != null) {
>             Element elt = (Element) child;
>             elt.setAttributeNS(null, "transform", "scale(0.5)");
>             child = child.getNextSibling();
>          }
>       }
> 
> }
> 
> But it doesn't work and the SVG specs says so why. The transformation is
> applied first and then the co-ordinates are used.

   If you are willing to use the SVG DOM you can do something like 
(untested):

        Element elt = (Element)child;
        SVGLocatable loc = (SVGLocatable)elt;
        SVGRect bbox = loc.getBBox();
        float cx = bbox.getX()+ bbox.getWidth()/2;
        float cy = bbox.getY()+ bbox.getHeight()/2;

        elt.setAttributeNS(null, "transform", "translate("+cx+","+cy+
                         "), scale(0.5), translate("+(-cx)+","+(-cy)+")");


   This will apply the scale around the center point of 'elt'.  Which 
is likely what you want. 

   You can also do things like have all your 'elements' centered and 
then use the transform to place them (rather than baking the location 
into the element's geometry).

   A final trick which is related to the 'red circle' trick is to use
the fact that markers can scale with 'stroke-width'.  So rather than
haveing 'g' elements or use elements you have paths that consist only
of 'move to' commands whith markers on them.  Then you can adjust the
stroke-width on the group containing all the paths and the markers will
not move but the scale will change.  I will note that markers are 
in general a little hard to work with (there are lots of attributes
that control how a marker is placed/scaled clipped, etc and they all
more or less need to be just right for this to work) so this is really 
and advanced technique.


> -----Original Message-----
> From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
> Sent: Friday, March 17, 2006 6:58 PM
> To: batik-users@xmlgraphics.apache.org
> Cc: batik-users@xmlgraphics.apache.org
> Subject: Re: zooming problem
> 
> 
> Hi Yasmin,
> 
> rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:
> 
> > I've added red circles programmatically to the svg document, but I'm
> > having the problem when I zoomIn the circles also get bigger - is 
there
> a
> > way I can set the size attribute so that it is fixed?
> 
>    No you can't set the size attribute so it is fixed.  However if you
> use the 'stroke' to set the 'size' of the circles:
> 
>    <g id="circleGroup" stroke-width="8" stroke="red">
>         <circle cx="10" cy="10" r="0.001"/>
>    <g>
> 
>    You can then just update the stroke-width on the circleGroup
> and it will cascade down to all the circle elements.
> 
>    You can find out when the canvas zooms by registering an
> onzoom event listener on the Document.
> 
> 
> ---------------------------------------------------------------------
> 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
> 


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


RE: zooming problem

Posted by Javid Alimohideen <ja...@gmail.com>.
Thomas,
I have been having the same problem as how to preserve the size of the
elements in my application. In my case, I have g elements of quite complex
shapes and they have different stroke-width values, for e.g., a 'g' that
represents the interstate highway sign. So, I tried to do the following:

private void updateElementsScale() {

		if (eventsSet.hasChildNodes()) {
			org.w3c.dom.Node child = eventsSet.getFirstChild();
			while(child != null) {
				Element elt = (Element) child;
				elt.setAttributeNS(null, "transform", "scale(0.5)");
				child = child.getNextSibling();
			}
		}

}

But it doesn't work and the SVG specs says so why. The transformation is
applied first and then the co-ordinates are used.

Thanks,
Javid



-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com]
Sent: Friday, March 17, 2006 6:58 PM
To: batik-users@xmlgraphics.apache.org
Cc: batik-users@xmlgraphics.apache.org
Subject: Re: zooming problem


Hi Yasmin,

rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:

> I've added red circles programmatically to the svg document, but I'm
> having the problem when I zoomIn the circles also get bigger - is there
a
> way I can set the size attribute so that it is fixed?

   No you can't set the size attribute so it is fixed.  However if you
use the 'stroke' to set the 'size' of the circles:

   <g id="circleGroup" stroke-width="8" stroke="red">
        <circle cx="10" cy="10" r="0.001"/>
   <g>

   You can then just update the stroke-width on the circleGroup
and it will cascade down to all the circle elements.

   You can find out when the canvas zooms by registering an
onzoom event listener on the Document.


---------------------------------------------------------------------
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: zooming problem

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

rafiqy@blueyonder.co.uk wrote on 03/17/2006 02:21:24 PM:

> I've added red circles programmatically to the svg document, but I'm
> having the problem when I zoomIn the circles also get bigger - is there 
a
> way I can set the size attribute so that it is fixed?

   No you can't set the size attribute so it is fixed.  However if you
use the 'stroke' to set the 'size' of the circles:

   <g id="circleGroup" stroke-width="8" stroke="red">
        <circle cx="10" cy="10" r="0.001"/>
   <g>

   You can then just update the stroke-width on the circleGroup
and it will cascade down to all the circle elements.

   You can find out when the canvas zooms by registering an
onzoom event listener on the Document.


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