Differences between revisions 6 and 9 (spanning 3 versions)
Revision 6 as of 2008-08-13 23:46:02
Size: 3156
Editor: JakubMarecek
Comment:
Revision 9 as of 2008-08-13 23:50:28
Size: 2943
Editor: JakubMarecek
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
Line 15: Line 14:
Line 18: Line 16:
 * This should be a quick hack using Apache Batik (http://xmlgraphics.apache.org/batik/). Replace the standard Graphics2D with the Graphics2D from Batik to get SVG export. 

import org.w3c.dom.*;
 * This should be a quick hack using Apache Batik (http://xmlgraphics.apache.org/batik/). Replace the standard Graphics2D with the Graphics2D from Batik to get SVG export.
{{{
Line 23: Line 19:
Line 25: Line 20:

import org.w3c.dom.svg.*;
Line 29: Line 21:



import org.apache.batik.swing.*;
Line 35: Line 22:

import org.apache.batik.svggen.*;
Line 39: Line 23:
Line 41: Line 24:
Line 43: Line 25:
Line 45: Line 26:

import org.apache.batik.transcoder.*;
Line 49: Line 27:


Line 55: Line 30:
 /* ... */
Line 56: Line 32:
  /* ... */  public static void export() {
   DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
   String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
   SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);
   SVGGraphics2D g = new SVGGraphics2D(doc);
Line 58: Line 38:
   /* Here use can use g as if it was the usual canvas */
Line 59: Line 40:
  public static void export() {    /* Here we make it visible */
Line 61: Line 42:
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();    Element root = doc.getDocumentElement();
   g.getRoot(root);
   JSVGCanvas canvas = new JSVGCanvas();
   JFrame f = new JFrame();
   f.getContentPane().add(canvas);
   canvas.setSVGDocument(doc);
   f.pack();
   f.setVisible(true);
Line 63: Line 51:
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;    /* Here we produce the PDF */
Line 65: Line 53:
    SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);



    SVGGraphics2D g = new SVGGraphics2D(doc);

    
    /* Here use g as if it was the usual canvas */


    Element root = doc.getDocumentElement();

    g.getRoot(root);



    JSVGCanvas canvas = new JSVGCanvas();

    JFrame f = new JFrame();

    f.getContentPane().add(canvas);

    canvas.setSVGDocument(doc);

    f.pack();

    f.setVisible(true);



    try {

      PDFTranscoder pdfTranscoder = new PDFTranscoder();

      TranscoderInput tIn = new TranscoderInput(doc);

      FileOutputStream fileOut = new FileOutputStream("test.pdf");

      TranscoderOutput tOut = new TranscoderOutput(fileOut);

      pdfTranscoder.transcode(tIn, tOut);

      fileOut.flush();

      fileOut.close();
   try {
     PDFTranscoder pdfTranscoder = new PDFTranscoder();
     TranscoderInput tIn = new TranscoderInput(doc);
     FileOutputStream fileOut = new FileOutputStream("test.pdf");
     TranscoderOutput tOut = new TranscoderOutput(fileOut); pdfTranscoder.transcode(tIn, tOut); fileOut.flush(); fileOut.close();
Line 113: Line 60:
  }  }
Line 115: Line 62:

}}}

Jakub Marecek

My personal homepage proper is at http://cs.nott.ac.uk/~jxm. This is just SAGE Days related stuff:

Compiling VTK:

  • Even the latest stable version of VTK (5.0.4) makes some weird assumptions about namespaces. In order to make it compile with GCC 4.3, replace #include <string> with #include <string.h> and similarly for other C library headers.

Using Java VTK Wrappers:

  • Add vtk.jar to your classpath. Notice the jar file can end up in a fresh /VTK-build/, even though you have specified other build output directory.
  • Add the directory where libvtkRenderingJava.so resides to your path (export to PATH seems to work just as well as -Djava.library.path=~/VTK-build/bin/ at java's command line)
  • Add libmawt.so to you LD_LIBRARY_PATH in your environment (export seems to work, although -DLD_LIBRARY_PATH at java's command line does not)

SVG and PDF Output for JyScript.

import org.w3c.dom.Element;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.svg.SVGDocument;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.PDFTranscoder;

public class Demo extends Applet {

 /* ... */ 

 public static void export() {
   DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
   String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
   SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);
   SVGGraphics2D g = new SVGGraphics2D(doc); 

   /* Here use can use g as if it was the usual canvas */ 

   /* Here we make it visible */ 

   Element root = doc.getDocumentElement(); 
   g.getRoot(root); 
   JSVGCanvas canvas = new JSVGCanvas();
   JFrame f = new JFrame();
   f.getContentPane().add(canvas);
   canvas.setSVGDocument(doc);
   f.pack();
   f.setVisible(true);

   /* Here we produce the PDF */

   try {
     PDFTranscoder pdfTranscoder = new PDFTranscoder();
     TranscoderInput tIn = new TranscoderInput(doc);
     FileOutputStream fileOut = new FileOutputStream("test.pdf");
     TranscoderOutput tOut = new TranscoderOutput(fileOut); pdfTranscoder.transcode(tIn, tOut); fileOut.flush(); fileOut.close();
    } catch(Exception e) {e.printStackTrace();}

 }

TeX and PS and PDF Output for SAGE plot3s

  • This could perhaps be done using Sketch (http://www.frontiernet.net/~eugene.ressler/). It implements the painter's algorithm (z-buffering), and hence it should be just the output of triangles in the right format it takes.


JakubMarecek (last edited 2022-04-11 03:52:39 by mkoeppe)