I have an application in Java that draws a face using custom classes. I have created primitives like SemiCircle,circle,square, line, etc. I am using the paint method and using Line2D to draw a line between two points.
SVGGraphivs does not seem to recognize Line2D, unless the problem is somewhere else. Below is the error message.
I am following the example code given at Batik SvGGenerator page and trying to create a SVG file for the drawing.The code is inside of my main class:

  public static void main(String argv[])  throws IOException {
          frame =
new MyFrame();
          MyAdapter MyAdapterObject =
new MyAdapter();
          MyMotionAdapter MyMotionObject =
new MyMotionAdapter();

          frame.addMouseListener(MyAdapterObject);
          frame.addMouseMotionListener(MyMotionObject);

          frame.setSize(Size);
          frame.setVisible(
true);
          frame.addWindowListener(
new ApplicationClosingWindowListener());
                 
// Get a DOMImplementation
                DOMImplementation domImpl =
                GenericDOMImplementation.getDOMImplementation();

                                
// Create an instance of org.w3c.dom.Document
                Document document = domImpl.createDocument(null, "svg", null);

                                
// Create an instance of the SVG Generator
                SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

                                
// Ask the test to render into the SVG Graphics2D implementation
                //TestSVGGen test = new TestSVGGen();
                frame.paint(svgGenerator);

                                
// Finally, stream out SVG to the standard output using UTF-8
                                // character to byte encoding
                                boolean useCSS = true; // we want to use CSS style attribute
                Writer out = new OutputStreamWriter(System.out, "UTF-8");
                svgGenerator.stream(out, useCSS);


        }
      }

The paint method I am trying to use is this one:

        
public void paint (Graphics2D g2d) {
          
super.paint(g2d);
           g2d.setColor(Color.red);
           s.paint(g2d);
//         g2d.setPaint(Color.red);
//         g2d.fill(new Rectangle(10, 10, 100, 100));

           }
The other two paint methods that show on the error messages are:
 
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
   g2.setXORMode(Color.white);
   SegmentIterator si = iterator();
  
for (; si.hasNext();) {
     Segment s = si.next();
     s.paint(g2);
    }
 }
 
public void paint(Graphics g) {   // paint needs to be changed to plot result segment & base line for test
     CoordIterator it = iterator();
     Graphics2D g2 = (Graphics2D)g;
    
if (it.hasNext()) {
       Coord prev = it.next();
// go to the first element
       while (it.hasNext()) {
         Coord c = it.next();
// this is subsequent element
         g2.draw(new Line2D.Double(prev.x, prev.y,c.x,c.y));
         prev=c;
       }
     }
Error msg:

XOR Mode is not supported by Graphics2D SVG Generator
java.lang.NullPointerException
        at org.apache.batik.svggen.SVGGeneratorContext.doubleString(Unknown Source)
        at org.apache.batik.svggen.SVGGraphicObjectConverter.doubleString(Unknown Source)
        at org.apache.batik.svggen.SVGLine.toSVG(Unknown Source)
        at org.apache.batik.svggen.SVGShape.toSVG(Unknown Source)
        at org.apache.batik.svggen.SVGGraphics2D.draw(Unknown Source)
        at faceLL.Segment.paint(Segment.java:222)
        at faceLL.Contour.paint(Contour.java:55)
        at faceLL.Face.paint(Face.java:45)
        at faceLL.ElasticFace$MyFrame.paint(ElasticFace.java:107)
        at faceLL.ElasticFace.main(ElasticFace.java:243)

I would appreciate if someone can help me.
Alice

Alice Cristina Mello Cavallo
Interdisciplinary PhD Candidate at Tufts University
Learning, Technology and Drama
http://www.media.mit.edu/~mello/

Reply via email to