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 Phil Cope <Ph...@Smallworld.co.uk> on 2001/08/09 18:03:01 UTC

Multi-layering SVG output with Batik

Hello Batik developers,

This is a kind of request for help/bug report.

What I would like to do is overlay 2 SVG documents, or overlay
an SVG document on a surface that has a previously rendered 
png/jpeg image.

I had the idea to use Swing's JLayeredPane to layer a JSVGCanvas
over another one, however this doesn't work - the lower document
is always obliterated, even if we call JSVGCanvas.setOpaque(false);

It is possible that this would be fixed by the reworking of the
following code in JGVTComponent

  public void paintComponent(Graphics g) {
       super.paintComponent(g);

       Graphics2D g2d = (Graphics2D)g;

       Dimension d = getSize();
       g2d.setComposite(AlphaComposite.SrcOver);
       g2d.setPaint(getBackground());
       g2d.fillRect(0, 0, d.width, d.height);
	...

An alternative solution would be to have a renderer that isn't
a JComponent, but that HAS a JComponent as its rendering surface
so that I could write my own paintComponent() method on
my own subclass that did something like

  public void paintComponent(Graphics g) {
	//
	clear(bgColor);
	backgroundSVGDocument.render(this); // or g ?
	foregroundSVGDocument.render(this); // or g ?
  }
Where back/foregroundSVGDocument are instances of this
hypothetical SVGrenderer. 
Is there any way of achieving this with the current batik toolkit ?

Many thanks

Phil Cope

Senior Software Engineer
-- 
All opinions expressed in this message are purely personal and do not 
reflect the opinions or policies of GE or GE Smallworld

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


Re: Multi-layering SVG output with Batik

Posted by Stephane Hillion <sh...@ilog.fr>.
On Thursday 09 August 2001 18:03, Phil Cope wrote:
> Hello Batik developers,
>
> This is a kind of request for help/bug report.
>
> What I would like to do is overlay 2 SVG documents, or overlay
> an SVG document on a surface that has a previously rendered
> png/jpeg image.
>
> I had the idea to use Swing's JLayeredPane to layer a JSVGCanvas
> over another one, however this doesn't work - the lower document
> is always obliterated, even if we call JSVGCanvas.setOpaque(false);
>
> It is possible that this would be fixed by the reworking of the
> following code in JGVTComponent
>
>   public void paintComponent(Graphics g) {
>        super.paintComponent(g);
>
>        Graphics2D g2d = (Graphics2D)g;
>
>        Dimension d = getSize();
>        g2d.setComposite(AlphaComposite.SrcOver);
>        g2d.setPaint(getBackground());
>        g2d.fillRect(0, 0, d.width, d.height);
> 	...
>
> An alternative solution would be to have a renderer that isn't
> a JComponent, but that HAS a JComponent as its rendering surface
> so that I could write my own paintComponent() method on
> my own subclass that did something like
>
>   public void paintComponent(Graphics g) {
> 	//
> 	clear(bgColor);
> 	backgroundSVGDocument.render(this); // or g ?
> 	foregroundSVGDocument.render(this); // or g ?
>   }
> Where back/foregroundSVGDocument are instances of this
> hypothetical SVGrenderer.
> Is there any way of achieving this with the current batik toolkit ?
>

A solution is to set the background color of the foreground component to a 
fully transparent color, by calling:
  svgCanvas.setBackground(new Color(0, 0, 0, 0));

The attached file is a modified version of the Batik website's JSVGCanvas 
example which is demonstrating SVG documents layering.
--
  Stephane.