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 Christophe Jolif <cj...@ilog.fr> on 2003/07/01 09:04:40 UTC

Re: exporting RadialGradientPaint to .SVG

Hi,

The SVGGraphics2D implementation only exports to SVG the regular Java 2D Paint 
object. The RadialGradientPaint is a Batik extension and unfortunately its 
export has not be coded in the SVGGraphics2D. However it should be quite 
simple to add such a support, you can even do it from the outside by 
subclassing the DefaultExtensionHandler and redefining the handlePaint() 
method such that it creates the right SVGPaintDescriptor for the 
RadialGradientPaint.

Hope this helps.

Nielsen, Clinton wrote:
> Help...
> Can you explain to me why this displays correctly on the screen, (ie a 
> blue dot and a red ball) but when I export it to a file, it just ends up 
> being two blue balls. How do I export a RadialGradientPaint to SVG?
>  
> I'm currently using  batik-1.5beta4b  along with the jdk1.3.1_07  in a 
> windows environment (windows 2000 Pro).
>  
> Following is a sample application containing the code that is not working...
>  
>  
> please respond to me at tinclon@mindless.com 
> <ma...@mindless.com>.   Thank you for your help
>  
>  
> import javax.swing.*;
> import java.awt.*;
> import java.awt.geom.*;
> import org.apache.batik.ext.awt.RadialGradientPaint;
> 
> //******* for the SVGWriter
> import org.apache.batik.svggen.SVGGraphics2D;
> import org.apache.batik.dom.GenericDOMImplementation;
> import org.w3c.dom.Document;
> import org.w3c.dom.DOMImplementation;
>  
> public class TrivialApplication {
>  
>  private MyFrame myFrame;
>  
>  public static void main(String args[]) {
>         //******* Set Up Frame
>         //**********************************************
>  
>         JFrame myFrame = new MyFrame();
>   myFrame.setLocation(new Point(250,250));
>         myFrame.setSize(new Dimension(100,100));
>   myFrame.setTitle("MTA");
>   myFrame.setVisible(true);
>         myFrame.repaint();
>  
>   //******* Export
>    //**********************************************
>  
>   DOMImplementation domImpl = 
> GenericDOMImplementation.getDOMImplementation();  
>   Document domFactory= domImpl.createDocument(null, "svg", null);
>   org.apache.batik.svggen.SVGGeneratorContext ctx =
>    org.apache.batik.svggen.SVGGeneratorContext.createDefault(domFactory);
>   ctx.setComment("Generated with Batik SVG Generator");
>               SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);   
>  
>   myFrame.paint(svgGenerator);
>   
>   svgGenerator.setSVGCanvasSize(new Dimension(150,150));
>   String useCssStr = System.getProperty("useCss", "true");
>   try{
>    svgGenerator.stream(
>     new java.io.OutputStreamWriter(
>      new java.io.FileOutputStream(
>       new java.io.File("testsvg.svg")),"UTF-8"),
>     useCssStr.equalsIgnoreCase("true"));
>     
>   }catch(java.io.UnsupportedEncodingException e1){}
>    catch(org.apache.batik.svggen.SVGGraphics2DIOException e2){}
>    catch(java.io.FileNotFoundException e3){}
>  }
> }
>  
> public class MyFrame extends JFrame{
>  
>  public void MyFrame(){
>  }
>  
>  public void paint(Graphics g){
>   //******* Blue Dot
>         //**********************************************
>  
>   g.setColor(Color.blue);
>   g.fillOval(30,30,20,20);
>  
>   //******* Red Ball
>         //**********************************************
>  
>   Graphics2D g2 = (Graphics2D)g;
>   Ellipse2D e = new Ellipse2D.Double(40,40,53,53);
>  
>   float[] dist = {0, 1};
>   Color[] colors = {Color.white, Color.red};
>   RadialGradientPaint rgp = new RadialGradientPaint(new 
> Point2D.Double(60,60),30, dist, colors);
>   g2.setPaint(rgp);
>   g2.fill(e);
>  }
> }


-- 
Christophe


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