use Horstmann's PS save not mine; it'll handle Japanese char etc.. this way.

This commit is contained in:
Terence Parr 2012-07-14 15:38:33 -07:00
parent 96654531b7
commit 47362b2951
3 changed files with 19 additions and 11 deletions

View File

@ -268,15 +268,17 @@ public class RuleContext implements ParseTree.RuleNode {
public void save(Parser parser, String fileName)
throws IOException, PrintException
{
Trees.writePS(this, parser, fileName);
TreeViewer viewer = new TreeViewer(parser, this);
viewer.save(fileName);
// Trees.writePS(this, parser, fileName); // parrt routine
}
public void save(Parser parser, String fileName,
String fontName, int fontSize)
throws IOException
{
Trees.writePS(this, parser, fileName, fontName, fontSize);
}
// public void save(Parser parser, String fileName,
// String fontName, int fontSize)
// throws IOException
// {
// Trees.writePS(this, parser, fileName, fontName, fontSize);
// }
/** Print out a whole tree, not just a node, in LISP format
* (root child1 .. childN). Print just a node if this is a leaf.

View File

@ -30,7 +30,12 @@
package org.antlr.v4.runtime.misc;
import javax.imageio.ImageIO;
import javax.print.*;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.SimpleDoc;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.*;
@ -105,6 +110,7 @@ public class GraphicsSupport {
job.print(doc, attributes);
}
} else {
// parrt: doesn't seem to do .pdf. 0-length file generated
Rectangle rect = comp.getBounds();
BufferedImage image = new BufferedImage(rect.width, rect.height,
BufferedImage.TYPE_INT_RGB);

View File

@ -34,11 +34,13 @@ import org.abego.treelayout.TreeForTreeLayout;
import org.abego.treelayout.TreeLayout;
import org.abego.treelayout.util.DefaultConfiguration;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.misc.GraphicsSupport;
import org.antlr.v4.runtime.misc.Utils;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.Tree;
import org.antlr.v4.runtime.tree.Trees;
import javax.print.PrintException;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@ -47,6 +49,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@ -324,7 +327,6 @@ public class TreeViewer extends JComponent {
});
}
/** This does not always seem to render the postscript properly
public void save(String fileName) throws IOException, PrintException {
JDialog dialog = new JDialog();
Container contentPane = dialog.getContentPane();
@ -335,10 +337,8 @@ public class TreeViewer extends JComponent {
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.dispose();
// dialog.setVisible(true);
GraphicsSupport.saveImage(this, fileName);
}
*/
// ---------------------------------------------------