JSesh is used and supported by the IFAO
.
JSesh is featured on sun's swing sightings previews 23!
There are a number of reasons for which you might want to produce a picture from an MDC Text. For instance, you might use JSesh as a library in a web application.
Of course, you need to have both jsesh.jar and jseshGlyphs.jar in your classpath. Currently (JSesh 2.13.7) you also need jvectClipboard-1.0.jar, but this is a dependency I will remove in a short while (you will need jvectClipboard-1.0.jar if you want to produce SVG, WMF or the like, of course). Then the following Java code will do:
public static BufferedImage buildImage(String mdcText) throws MDCSyntaxError {
// Create the drawing system:
MDCDrawingFacade drawing = new MDCDrawingFacade();
// Create the picture
BufferedImage result = drawing.createImage(mdcText);
return result
}
That's all. Once you have a BufferedImage, it can be displayed on the screen, or written in JPEG or PNG using ImageIO :
Optionnally, it's possible to customize the rendering. Here is a complete ready-to run example:
/**
* How to use JSesh to create bitmaps in Java.
* compile: javac -cp .:/FOLDER_CONTAINING/jsesh.jar TestJSeshBitmap.java
* run: java -cp .:/FOLDER_CONTAINING/jsesh.jar TestJSeshBitmap
*
* jseshGlyphs.jar and jvectClipboard-1.0.jar should be in the same folder as jsesh.jar.
* (normally, there is no need to add them explicitely to the class path , as jsesh.jar contains the necessary
* information in its manifest.
*/
import javax.imageio.ImageIO;
import java.io.*;
import java.awt.image.* ;
import jsesh.mdcDisplayer.preferences.*;
import jsesh.mdcDisplayer.draw.*;
import jsesh.mdc.*;
public class Test {
public static BufferedImage buildImage(String mdcText) throws MDCSyntaxError {
// Create the drawing system:
MDCDrawingFacade drawing = new MDCDrawingFacade();
// Change the scale, choosing the cadrat height in pixels.
drawing.setCadratHeight(60);
// Change a number of parameters
DrawingSpecification drawingSpecifications = new DrawingSpecificationsImplementation();
PageLayout pageLayout= new PageLayout();
pageLayout.setLeftMargin(5);
pageLayout.setTopMargin(5);
drawingSpecifications.setPageLayout(pageLayout);
drawing.setDrawingSpecifications(drawingSpecifications);
// Create the picture
BufferedImage result = drawing.createImage(mdcText);
return result;
}
public static void main(String args[]) throws MDCSyntaxError, IOException {
// Create the picture
BufferedImage img= buildImage("i-w-r:a-C1-m-p*t:pt");
File f = new File("example.png");
// save it in png (better than jpeg in this case)
ImageIO.write(img, "png", f);
}
}
The size of the signs is controlled using ‘drawing.setCadratHeight();‘.
(note to self: it should be easier to change the size of everything using drawingSpecification !!!)
Example not working with latest releases of JSesh
I experimented some errors trying to use this example with latest releases of JSesh as 2.13.7.
There are problems with instructions setLeftMargin() and setTopMargin() and even commenting that lines I receive this error : java.lang.NoClassDefFoundError: org/qenherkhopeshef/graphics/utils/DoubleDimensions.
Thanks
Michele Moglia
Corrected
I have removed the setLeftMargin and setTopMargin from DrawingSpecifications, and moved them to a new class: PageLayout.
The example has been updated.
Sorry for the inconvenience.
Serge Rosmorduc