hi,

The CDataSection of batik SVGDOM is splitted into multiple CDataSection
on each new line? is it a bug?

The problem occur when the SVGDom generated by batik is to be
serialized/writing back to text file. Because the result of serialized
is not the same with the loaded one due to different in CDataSection.
Batik itself also unable to open/load the result of serialization.

I attached the file to reproduce the problem.

Regards
Tonny Kohar
/*
 * BugSerialize.java
 *
 * Created on November 15, 2003, 5:34 AM
 */

package kiyut.bug;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;

import org.apache.batik.dom.svg.*;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.util.*;

import org.apache.batik.transcoder.*;
import org.apache.batik.transcoder.svg2svg.*;

import org.w3c.dom.*;
import org.w3c.dom.css.*;
import org.w3c.dom.svg.*;

/**
 *
 * @author  Tonny Kohar
 */
public class BugSerialize {
    File file = null;
    JSVGCanvas lastCanvas;
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BugSerialize bug = new BugSerialize(args);
        bug.run();
    }
    
    /** Creates a new instance of BugSerialize */
    public BugSerialize(String[] args) {
        if (args[0] == null) {
            System.out.println("Please enter the svg filename as argument");
            System.exit(1);
        }
        System.out.println(args[0]); //just checking args
        file = new File(args[0]);
    }
    
    public void run() {
        //doc = loadSVGDocument(file);
        JFrame frame = createFrame(file);
        frame.pack();
        frame.setVisible(true);
    }
    
    private JFrame createFrame(File file) {
        ActionListener actionListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) { buttonActionPerformed(e); }
        };
        
        JButton bugButton = new JButton("bug");
        bugButton.setActionCommand("bug");
        bugButton.addActionListener(actionListener);
        
        JPanel buttonPane = new JPanel();
        buttonPane.add(bugButton);
        
        JSVGCanvas canvas = new JSVGCanvas();
        canvas.setPreferredSize(new Dimension(400,400));
        canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        canvas.setDoubleBufferedRendering(true);
        try {
            canvas.setURI(file.toURL().toString());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        
        lastCanvas = canvas;
        
        // Set the JSVGCanvas listeners.
        canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            public void gvtBuildStarted(GVTTreeBuilderEvent e) {
                System.out.println("Build Started...");
            }
            public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                System.out.println("Build Done.");
            }
        });
        
        canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
            public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
                System.out.println("Rendering Started...");
            }
            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                System.out.println("Rendering Done.");
            }
        });
        
        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(canvas,BorderLayout.CENTER);
        contentPane.add(buttonPane,BorderLayout.SOUTH);
        
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setContentPane(contentPane);
        return frame;
    }
    
    private void buttonActionPerformed(ActionEvent e) {
        // prepare the file
        File outFile = null; 
        
        // serialize the doc
        SVGDocument doc = lastCanvas.getSVGDocument();
        try {
            outFile = File.createTempFile("temp_file",".svg");
            System.out.println("temp file: " + outFile.toString());
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8");
            BufferedWriter writer = new BufferedWriter(osw);
        
            Transcoder transcoder = new SVGTranscoder();
            TranscoderInput in = new TranscoderInput(doc);
            TranscoderOutput out = new TranscoderOutput(writer);
            transcoder.transcode(in, out);
        } catch(Exception ex) {
            ex.printStackTrace();
        }
        
        // load the outFile into new Frame
        JFrame frame = createFrame(outFile);
        frame.pack();
        frame.setVisible(true);
    }
    
}

<<attachment: bug_serialize.svg>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to