You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Gerard BUNEL <ge...@ago.fr> on 2003/02/18 08:44:19 UTC

Drawing in a JSVGCanvas

Hello,
I already posted this mail in batik-users but this one is probably a
best place.

I'm using JSVGCanvas do display a Map.
I've to dynamically draw points on this map.
For my first test, I've overloaded the paint(Graphics g) method to do
this job.
The code for this is the following:

  public void paint ( Graphics g) {
    super.paint(g);
    AffineTransform at = new AffineTransform( getRenderingTransform());
    if (at == null)
      return;
    SVGOMRectElement elem =
(SVGOMRectElement)getSVGDocument().getElementById("water");
    SVGMatrix matrix =elem.getCTM();
    AffineTransform transform =
      new AffineTransform(
        matrix.getA(),
        matrix.getB(),
        matrix.getC(),
        matrix.getD(),
        matrix.getE(),
        matrix.getF());
    transform.preConcatenate(at);
    g.setColor(Color.black);
    //((Graphics2D)g).setTransform( new AffineTransform());
    paintPoint(g, 1, -5.0f, 63.0f, transform);
    paintPoint(g, 2, -5.0f, 57.5f, transform);
    paintPoint(g, 3, -5.0f, 52.0f, transform);
    paintPoint(g, 4, 12.0f, 52.0f, transform);
    paintPoint(g, 5, 12.0f, 57.5f, transform);
    paintPoint(g, 6, 12.0f, 63.0f, transform);

    /*
    // inscription des différentes position des structures
    for (int i=0; i<structsSize(); i++) {
     Structure f = structsAt(i);
     paintPoint( g, (i+1), f.getLon(), f.getLat(), transform);
  }
    */
  }

  public void paintPoint ( Graphics g, int a_Index, float a_Lon, float
a_Lat, AffineTransform a_Transform) {
    // inscription des différentes position des structures
    try {
      Point2D ini = new Point2D.Float(a_Lon, a_Lat);
      Point2D p2d = a_Transform.transform( ini, null);
      g.drawRect((int)p2d.getX() - 2, (int)p2d.getY() - 2, 4, 4);
      g.drawString(String.valueOf(a_Index), (int)p2d.getX()+9,
(int)p2d.getY()+11);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

The result is quite strange! As you can see I try to draw the four
corners of my map.
The two upper corner are drawn correctly.
But the to lower are not and seem to be place two times lower than they
should.

Am I right using the getRenderingTransform() method ?
Does anyone have a idea of what happens ?

Gerard

--
gerard.bunel@ago.fr - Atlantide - http://www.ago.fr/atlantide/
Technopole Brest Iroise BP 80802 - 29608 Brest cedex - France -
Tel. : +33 (0)2 98 05 43 21 - Fax. : +33 (0)2 98 05 20 34 - e-mail:
atlantide-brest@ago.fr
Centre Affaires Oberthur - 74D, rue de Paris -  35700 Rennes - France
Tel. : +33 (0)2 99 84 15 84 - Fax : +33 (0)2 99 84 15 85 - e-mail:
atlantide-rennes@ago.fr



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


Re: Drawing in a JSVGCanvas

Posted by Gerard BUNEL <ge...@ago.fr>.
In fact the problem came from the SVG file itself. the viewBox attribute
didn't correspond to other
information provided in the file. So all coordinates calculations was
wrong (in my sense).

I've found the problem by trying many changes in the SVG file. My problem
is that I don't really
understand all informations in that file. I should probably read more
about SVG.
Is there some interesting books or links you should recommend ?

Thanks anyway.
Gerard

Thomas E Deweese a écrit :

> >>>>> "GB" == Gerard BUNEL <ge...@ago.fr> writes:
>
> GB> I already posted this mail in batik-users but this one is
> GB> probably a best place.
>
> GB> I'm using JSVGCanvas do display a Map.  I've to dynamically draw
> GB> points on this map.  For my first test, I've overloaded the
> GB> paint(Graphics g) method to do this job.  The code for this is the
> GB> following:
>
>     So my guess is that you have some of the AffineTransform handling
> wrong (I would need to know a lot more about the context to know
> exactly where - for example it is possible that at the end of
> super.paint(g) the rendering transform has already been applied).  The
> simpliest thing to do is just print out the various transforms to
> figure out what is going on (g2d.getTransform() will tell you the
> transform already in the Graphics2D).
>
>     If you aren't really used to working with them this is the only
> way you will get anywhere.  I am really used to working with them and
> except for really simple cases I have to stop and think for a while
> before I can just write the code.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org

--
gerard.bunel@ago.fr - Atlantide - http://www.ago.fr/atlantide/
Technopole Brest Iroise BP 80802 - 29608 Brest cedex - France -
Tel. : +33 (0)2 98 05 43 21 - Fax. : +33 (0)2 98 05 20 34 - e-mail:
atlantide-brest@ago.fr
Centre Affaires Oberthur - 74D, rue de Paris -  35700 Rennes - France
Tel. : +33 (0)2 99 84 15 84 - Fax : +33 (0)2 99 84 15 85 - e-mail:
atlantide-rennes@ago.fr



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


RE: Drawing in a JSVGCanvas

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "GB" == Gerard BUNEL <ge...@ago.fr> writes:

GB> I already posted this mail in batik-users but this one is
GB> probably a best place.

GB> I'm using JSVGCanvas do display a Map.  I've to dynamically draw
GB> points on this map.  For my first test, I've overloaded the
GB> paint(Graphics g) method to do this job.  The code for this is the
GB> following:

    So my guess is that you have some of the AffineTransform handling
wrong (I would need to know a lot more about the context to know
exactly where - for example it is possible that at the end of
super.paint(g) the rendering transform has already been applied).  The
simpliest thing to do is just print out the various transforms to
figure out what is going on (g2d.getTransform() will tell you the
transform already in the Graphics2D).  

    If you aren't really used to working with them this is the only
way you will get anywhere.  I am really used to working with them and
except for really simple cases I have to stop and think for a while
before I can just write the code.


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