Skip to content
Browse files

Added postscript driver for testing.

  • Loading branch information...
1 parent 3b6058f commit 262a93c25176824f9de8af72765a9a98246499d0 Stuart Moodie committed Sep 25, 2009
View
2 .classpath
@@ -22,5 +22,7 @@
<classpathentry kind="lib" path="lib/apache-log4j-1.2.15/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/stringtemplate-3.2/lib/antlr-2.7.7.jar"/>
<classpathentry kind="lib" path="lib/stringtemplate-3.2/lib/stringtemplate.jar" sourcepath="lib/stringtemplate-3.2/src"/>
+ <classpathentry kind="lib" path="lib/antlr-3.1.2/lib/antlr-3.1.2.jar"/>
+ <classpathentry kind="lib" path="lib/antlr-3.1.2/lib/antlr-runtime-3.1.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
6 build.xml
@@ -21,6 +21,8 @@
<pathelement location="${lib.dir}/CompoundGraph/CompoundGraph.jar" />
<pathelement location="${lib.dir}/BusinessObjects/BusinessObjects.jar" />
<pathelement location="${lib.dir}/Toolkit/toolkit.jar" />
+ <pathelement location="${lib.dir}/stringtemplate-3.2/lib/stringtemplate.jar" />
+ <pathelement location="${lib.dir}/stringtemplate-3.2/lib/antlr-2.7.7.jar" />
</path>
<path id="test.classpath">
@@ -71,10 +73,6 @@
<target name="buildSrc" description="src build task" depends="mkdirs">
<!--echo>running with classpath ${toString:classpath}</echo-->
<javac classpathref="classpath" srcdir="${src.dir}" source="${source}" target="${target}" debug="true" debuglevel="lines,vars,source" destdir="${build.dir.src}">
- <exclude name="**/export/*"/>
- <exclude name="**/ndom/*"/>
- <exclude name="**/ndoAPI/*"/>
- <exclude name="**/validation/*"/>
</javac>
<copy todir="${build.dir.src}">
<fileset dir="${src.dir}">
View
BIN lib/BusinessObjects/BusinessObjects-docs.jar
Binary file not shown.
View
BIN lib/BusinessObjects/BusinessObjects-src.jar
Binary file not shown.
View
BIN lib/BusinessObjects/BusinessObjects.jar
Binary file not shown.
View
18 src/log4j.properties
@@ -0,0 +1,18 @@
+## direct log messages to stdout ###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+### set log levels - for more verbose logging change 'info' to 'debug' ###
+
+log4j.rootLogger=trace, stdout
+#log4j.rootLogger=warn, stdout
+
+log4j.logger.org.pathwayeditor=warn
+#log4j.logger.org.pathwayeditor.businessobjects=debug
+#log4j.logger.org.pathwayeditor.figure=trace
+#log4j.logger.org.pathwayeditor.businessobjects=info
+log4j.logger.org.pathwayeditor.figure.figuredefn=debug
+
+log4j.logger.com.mchange.v2=error
View
3 src/org/pathwayeditor/notations/sbgnpd/export/biopepa/BioPepaExportWriter.java
@@ -40,6 +40,7 @@
import org.pathwayeditor.notations.sbgnpd.ndom.ProcessNodeType;
public class BioPepaExportWriter implements IExportWriter {
+ private static final String BIOPEPA_TEMPLATE_FILE_NAME = "biopepa.stg";
private final IMapDiagram ndom;
private final File exportFile;
private final IReportLog reportLog;
@@ -67,7 +68,7 @@ public IReportLog getReportLog(){
public void writeExport() {
try {
this.stream = new BufferedWriter(new FileWriter(this.exportFile));
- Reader r = new InputStreamReader(this.getClass().getResourceAsStream("biopepa.stg"));
+ Reader r = new InputStreamReader(this.getClass().getResourceAsStream(BIOPEPA_TEMPLATE_FILE_NAME));
stg = new StringTemplateGroup(r);
writeHeader();
writeMapStart();
View
149 src/org/pathwayeditor/notations/sbgnpd/services/NotationInspector.java
@@ -0,0 +1,149 @@
+package org.pathwayeditor.notations.sbgnpd.services;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.pathwayeditor.businessobjects.drawingprimitives.properties.IBooleanPropertyDefinition;
+import org.pathwayeditor.businessobjects.drawingprimitives.properties.IIntegerPropertyDefinition;
+import org.pathwayeditor.businessobjects.drawingprimitives.properties.INumberPropertyDefinition;
+import org.pathwayeditor.businessobjects.drawingprimitives.properties.IPropertyDefinition;
+import org.pathwayeditor.businessobjects.notationsubsystem.INotationSubsystem;
+import org.pathwayeditor.businessobjects.notationsubsystem.INotationSyntaxService;
+import org.pathwayeditor.businessobjects.typedefn.IShapeObjectType;
+import org.pathwayeditor.figure.figuredefn.FigureController;
+import org.pathwayeditor.figure.figuredefn.FigureDrawer;
+import org.pathwayeditor.figure.figuredefn.GenericFont;
+import org.pathwayeditor.figure.figuredefn.GraphicsInstructionList;
+import org.pathwayeditor.figure.figuredefn.IFigureController;
+import org.pathwayeditor.figure.figuredefn.GraphicsInstruction.GraphicalTextAlignment;
+import org.pathwayeditor.figure.figuredefn.IFont.Style;
+import org.pathwayeditor.figure.geometry.Dimension;
+import org.pathwayeditor.figure.geometry.Envelope;
+import org.pathwayeditor.figure.geometry.Point;
+import org.pathwayeditor.figurevm.FigureDefinitionCompiler;
+import org.pathwayeditor.figurevm.IFigureDefinition;
+
+public class NotationInspector {
+ private static final double X_START = 10.0;
+ private static final double Y_START = 10.0;
+ private static final double SEP_WIDTH = 10.0;
+ private static final double MAX_WIDTH = 400.0;
+ private static final double SEP_HEIGHT = 40.0;
+ private static final double SHAPE_WIDTH = 50.0;
+ private static final double SHAPE_HEIGHT = 40.0;
+ private static final double MIN_WIDTH = 100.0;
+ private final INotationSubsystem notationSubsystem;
+ private final PostscriptGraphicsEngine graphicsEngine;
+
+ public NotationInspector(INotationSubsystem ns){
+ this.notationSubsystem = ns;
+ this.graphicsEngine = new PostscriptGraphicsEngine();
+ }
+
+ public INotationSubsystem getNotationSubsystem(){
+ return this.notationSubsystem;
+ }
+
+ public void writeShapes(File psFile) throws IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(psFile));
+ this.graphicsEngine.setWriter(writer);
+ INotationSyntaxService syntaxService = this.notationSubsystem.getSyntaxService();
+ Iterator<IShapeObjectType> iter = syntaxService.shapeTypeIterator();
+ double x = X_START;
+ double y = Y_START;
+ double maxY = 0.0;
+ while(iter.hasNext()){
+ IShapeObjectType objectType = iter.next();
+ String shapeDefn = objectType.getDefaultAttributes().getShapeDefinition();
+ FigureDefinitionCompiler compiler = new FigureDefinitionCompiler(shapeDefn);
+ compiler.compile();
+ IFigureDefinition defn = compiler.getCompiledFigureDefinition();
+ IFigureController controller = new FigureController(defn);
+ Set<IPropertyDefinition> boundProps = getBoundProperties(defn, objectType);
+ assignedBoundValues(controller, boundProps);
+ Dimension shapeSize = objectType.getDefaultAttributes().getSize();
+ controller.setRequestedEnvelope(new Envelope(new Point(x, y), shapeSize));
+ controller.generateFigureDefinition();
+ shapeSize = controller.getEnvelope().getDimension();
+ GraphicsInstructionList graphicsInst = controller.getFigureDefinition();
+ drawGlyph(graphicsInst);
+ writeTypeName(controller.getEnvelope(), objectType);
+ x += Math.max(MIN_WIDTH, shapeSize.getWidth()) + SEP_WIDTH;
+ maxY = Math.max(maxY, shapeSize.getHeight());
+ if(x > MAX_WIDTH){
+ x = X_START;
+ y += maxY + SEP_HEIGHT;
+ maxY = 0.0;
+ }
+ }
+ this.graphicsEngine.end();
+ writer.close();
+ }
+
+ private void writeTypeName(Envelope glyphBox, IShapeObjectType objectType) {
+ String name = objectType.getName();
+ Point textLocation = glyphBox.translate(new Point(0.0, -20.0)).getOrigin();
+ this.graphicsEngine.setFont(new GenericFont(10.0, EnumSet.of(Style.ITALIC)));
+ this.graphicsEngine.drawString(name, textLocation.getX(), textLocation.getY(), GraphicalTextAlignment.E);
+ }
+
+ private void drawGlyph(GraphicsInstructionList graphicsList){
+ FigureDrawer drawer = new FigureDrawer(graphicsList);
+ drawer.drawFigure(this.graphicsEngine);
+ }
+
+ private void assignedBoundValues(IFigureController controller, Set<IPropertyDefinition> boundProps) {
+ for(IPropertyDefinition propDefn : boundProps){
+ if(propDefn instanceof IIntegerPropertyDefinition){
+ controller.setBindInteger(propDefn.getName(), ((IIntegerPropertyDefinition)propDefn).getDefaultValue());
+ }
+ else if(propDefn instanceof IIntegerPropertyDefinition){
+ controller.setBindInteger(propDefn.getName(), ((IIntegerPropertyDefinition)propDefn).getDefaultValue());
+ }
+ else if(propDefn instanceof IBooleanPropertyDefinition){
+ controller.setBindBoolean(propDefn.getName(), ((IBooleanPropertyDefinition)propDefn).getDefaultValue());
+ }
+ else if(propDefn instanceof INumberPropertyDefinition){
+ controller.setBindDouble(propDefn.getName(), ((INumberPropertyDefinition)propDefn).getDefaultValue().doubleValue());
+ }
+ else{
+ controller.setBindString(propDefn.getName(),propDefn.getDefaultValue().toString());
+ }
+ }
+ }
+
+ private Set<IPropertyDefinition> getBoundProperties(IFigureDefinition defn, IShapeObjectType objectType){
+ Set<IPropertyDefinition> boundProperties = new HashSet<IPropertyDefinition>();
+ Set<String> bindVarNames = defn.getBindVariableNames();
+ for(String varName : bindVarNames){
+ if(objectType.getDefaultAttributes().containsPropertyDefinition(varName)){
+ IPropertyDefinition propDefn = objectType.getDefaultAttributes().getPropertyDefinition(varName);
+ boundProperties.add(propDefn);
+
+ }
+ else{
+ throw new RuntimeException("No property found for this bind variable: " + varName);
+ }
+ }
+ return boundProperties;
+ }
+
+ public static final void main(String argv[]){
+ String psFileName = argv[0];
+ NotationInspector insp = new NotationInspector(new SbgnPdNotationSubsystem());
+ try {
+ File shapeFile = new File(psFileName);
+ insp.writeShapes(shapeFile);
+ } catch (IOException e) {
+ System.err.println("Error occurred: " + e.getMessage());
+ System.exit(1);
+ }
+ System.exit(0);
+ }
+}
View
362 src/org/pathwayeditor/notations/sbgnpd/services/PostscriptGraphicsEngine.java
@@ -0,0 +1,362 @@
+package org.pathwayeditor.notations.sbgnpd.services;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.antlr.stringtemplate.StringTemplate;
+import org.antlr.stringtemplate.StringTemplateGroup;
+import org.pathwayeditor.businessobjects.drawingprimitives.attributes.LineStyle;
+import org.pathwayeditor.businessobjects.drawingprimitives.attributes.RGB;
+import org.pathwayeditor.figure.figuredefn.IFont;
+import org.pathwayeditor.figure.figuredefn.IGraphicsEngine;
+import org.pathwayeditor.figure.figuredefn.GraphicsInstruction.GraphicalTextAlignment;
+import org.pathwayeditor.figure.figuredefn.IFont.Style;
+
+public class PostscriptGraphicsEngine implements IGraphicsEngine {
+ private static final String PS_TEMPLATE_FILE_NAME = "postscript.stg";
+ private static final String SOLID_LINE_STYLE = "S";
+ private static final String DASH_DOT_LINESTYLE = "DT";
+ private static final String DASH_LINESTYLE = "D";
+ private static final String DASH_DOT_DOT_LINESTYLE = "DTT";
+ private static final String DOT_LINESTYLE = "T";
+ private BufferedWriter writer;
+ private final StringTemplateGroup stg;
+ private RGB fillColour;
+ private RGB lineColour;
+
+ public PostscriptGraphicsEngine(){
+ Reader r = new InputStreamReader(this.getClass().getResourceAsStream(PS_TEMPLATE_FILE_NAME));
+ stg = new StringTemplateGroup(r);
+ }
+
+ private void writeColour(RGB col){
+ try {
+ StringTemplate t = stg.getInstanceOf("setColour");
+ t.setAttribute("red", col.getRed());
+ t.setAttribute("green", col.getGreen());
+ t.setAttribute("blue", col.getBlue());
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void writeLineColour(){
+ if(this.lineColour != null){
+ writeColour(this.lineColour);
+ }
+ }
+
+ private void writeFillColour(){
+ if(this.fillColour != null){
+ writeColour(this.fillColour);
+ }
+ }
+
+ public void drawArc(double pos, double pos2, double widthSize,
+ double heightSize, double roundedOffset, double roundedLength) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawArc");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("w", widthSize);
+ t.setAttribute("h", heightSize);
+ t.setAttribute("startAng", roundedOffset);
+ t.setAttribute("lenAng", roundedLength);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawLine(double beginPos, double beginPos2, double endPos, double endPos2) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawLine");
+ t.setAttribute("x1", beginPos);
+ t.setAttribute("y1", beginPos2);
+ t.setAttribute("x2", endPos);
+ t.setAttribute("y2", endPos2);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawOval(double pos, double pos2, double widthSize, double heightSize) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawOval");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("w", widthSize);
+ t.setAttribute("h", heightSize);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawPoint(double pos, double pos2) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawPoint");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawPolygon(double[] pointArr) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawPolygon");
+ List<Double> points = new ArrayList<Double>(pointArr.length);
+ for(double point : pointArr){
+ points.add(point);
+ }
+ t.setAttribute("points", points);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawPolyline(double[] pointArr) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawPolyline");
+ List<Double> points = new ArrayList<Double>(pointArr.length);
+ for(double point : pointArr){
+ points.add(point);
+ }
+ t.setAttribute("points", points);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawRectangle(double pos, double pos2, double widthSize, double heightSize) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawRect");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("w", widthSize);
+ t.setAttribute("h", heightSize);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawRoundRectangle(double x, double y, double width,
+ double height, double arcWidthSize, double arcHeightSize) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawRRect");
+ t.setAttribute("x", x);
+ t.setAttribute("y", y);
+ t.setAttribute("w", width);
+ t.setAttribute("h", height);
+ t.setAttribute("cornerWidth", arcWidthSize);
+ t.setAttribute("cornerHeight", arcHeightSize);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void drawString(String text, double pos, double pos2, GraphicalTextAlignment alignment) {
+ try {
+ writeLineColour();
+ StringTemplate t = stg.getInstanceOf("drawString");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("alignment", alignment.toString());
+ t.setAttribute("text", text);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillArc(double pos, double pos2, double widthSize,
+ double heightSize, double roundedOffset, double roundedLength) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillArc");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("w", widthSize);
+ t.setAttribute("h", heightSize);
+ t.setAttribute("startAng", roundedOffset);
+ t.setAttribute("lenAng", roundedLength);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillOval(double pos, double pos2, double widthSize, double heightSize) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillOval");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("w", widthSize);
+ t.setAttribute("h", heightSize);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillPolygon(double[] pointArr) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillPolygon");
+ List<Double> points = new ArrayList<Double>(pointArr.length);
+ for(double point : pointArr){
+ points.add(point);
+ }
+ t.setAttribute("points", points);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillRectangle(double x, double y, double width, double height) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillRect");
+ t.setAttribute("x", x);
+ t.setAttribute("y", y);
+ t.setAttribute("w", width);
+ t.setAttribute("h", height);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillRoundRectangle(double x, double y, double width,
+ double height, double arcWidthSize, double arcHeightSize) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillRRect");
+ t.setAttribute("x", x);
+ t.setAttribute("y", y);
+ t.setAttribute("w", width);
+ t.setAttribute("h", height);
+ t.setAttribute("cornerWidth", arcWidthSize);
+ t.setAttribute("cornerHeight", arcHeightSize);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fillString(String text, double pos, double pos2, GraphicalTextAlignment alignment) {
+ try {
+ writeFillColour();
+ StringTemplate t = stg.getInstanceOf("fillString");
+ t.setAttribute("x", pos);
+ t.setAttribute("y", pos2);
+ t.setAttribute("alignment", alignment.toString());
+ t.setAttribute("text", text);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setFillColor(RGB color) {
+ this.fillColour = color;
+ }
+
+ public void setFont(IFont modifiedFont) {
+ try {
+ StringTemplate t = stg.getInstanceOf("setFont");
+ StringBuilder styles = new StringBuilder();
+ for(Style style : modifiedFont.getStyle()){
+ styles.append(style.toString());
+ }
+ t.setAttribute("styles", styles.toString());
+ t.setAttribute("size", modifiedFont.getFontSize());
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setLineColor(RGB color) {
+ this.lineColour = color;
+ }
+
+ public void setLineStyle(LineStyle ls) {
+ try {
+ String lsStr = getLineStyleMapping(ls);
+ StringTemplate t = stg.getInstanceOf("setLineStyle");
+ t.setAttribute("ls", lsStr);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getLineStyleMapping(LineStyle ls) {
+ String retVal = SOLID_LINE_STYLE;
+ switch(ls){
+ case DASH_DOT:
+ retVal = DASH_DOT_LINESTYLE;
+ break;
+ case DASH_DOT_DOT:
+ retVal = DASH_DOT_DOT_LINESTYLE;
+ break;
+ case DOT:
+ retVal = DOT_LINESTYLE;
+ break;
+ case DASHED:
+ retVal = DASH_LINESTYLE;
+ break;
+ }
+ return retVal;
+ }
+
+ public void setLineWidth(double lineWidthVal) {
+ try {
+ StringTemplate t = stg.getInstanceOf("setLineWidth");
+ t.setAttribute("lw", lineWidthVal);
+ this.writer.append(t.toString());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void setWriter(BufferedWriter writer) throws IOException {
+ this.writer = writer;
+ initialise();
+ }
+
+ private void initialise() throws IOException{
+ StringTemplate t = stg.getInstanceOf("header");
+ this.writer.append(t.toString());
+ }
+
+
+ public void end() throws IOException{
+ StringTemplate t = stg.getInstanceOf("footer");
+ this.writer.append(t.toString());
+ this.writer = null;
+ }
+}
View
2 src/org/pathwayeditor/notations/sbgnpd/services/SbgnPdNotationSyntaxService.java
@@ -86,6 +86,8 @@
private static final String STATE_DEFN = "curbounds /h exch def /w exch def /y exch def /x exch def\n"
+ "h w le {x y w h 1 h mul 1 h mul rrect}\n"
+ "{x y w h 1 w mul 1 w mul rrect} ifelse";
+// private static final String STATE_DEFN = "curbounds /h exch def /w exch def /y exch def /x exch def\n"
+// + "x y w h oval";
private static final String SIMPLE_CHEM_DEFN =
"(C) setanchor\n" +
"curbounds /h exch def /w exch def /y exch def /x exch def\n" +
View
294 src/org/pathwayeditor/notations/sbgnpd/services/postscript.stg
@@ -0,0 +1,294 @@
+group postscript;
+
+header() ::= <<
+%!
+/rrect { /harc exch def /warc exch def /h exch def /w exch def /y exch def /x exch def
+ x y harc add moveto x y x y x warc add y curveto w warc sub warc sub 0 rlineto
+ warc 0 warc 0 warc harc rcurveto 0 h harc sub harc sub rlineto
+ 0 harc 0 harc warc neg harc rcurveto w warc sub warc sub neg 0 rlineto
+ warc neg 0 warc neg 0 warc neg harc neg rcurveto 0 h harc sub harc sub neg rlineto
+ } bind def
+
+/oval {
+/lengthangle exch def
+/startangle exch def
+/startangle startangle def
+/endangle startangle lengthangle add def
+
+/yrad exch 2 div def
+/xrad exch 2 div def
+/rawy exch def
+/rawx exch def
+%rawx rawy xrad 2 mul yrad 2 mul rectstroke
+%rawx rawy 2 0 360 arc fill
+/y rawy yrad add def
+/x rawx xrad add def
+/savematrix matrix currentmatrix def
+x y translate
+xrad yrad neg scale
+0 0 1 startangle endangle arc
+savematrix setmatrix
+%rawx rawy moveto
+%0 -20 rmoveto
+%gsave
+%1 -1 scale
+%startangle 15 string cvs show
+%(, ) show
+%endangle 15 string cvs show
+%grestore
+rawx rawy
+} bind def
+
+/polyline { /arr exch def arr 0 2 getinterval aload pop moveto %10 10 rlineto
+ 2 2 arr length 1 sub {arr exch 2 getinterval aload pop lineto } for
+ } bind def
+
+
+% drawrect x y w h
+/drawrrect { newpath rrect stroke } bind def
+
+% fillrect x y w h
+/fillrrect { newpath rrect fill } bind def
+
+% drawrect x y w h cornerw cornerh
+/drawrect { newpath rectstroke } bind def
+
+% fillrect x y w h cornerw cornerh
+/fillrect { newpath rectfill } bind def
+
+% drawoval x y w h
+/drawoval { newpath 0 360 oval stroke } bind def
+% filloval x y w h
+/filloval { newpath 0 360 oval fill } bind def
+
+% drawarc x y w h startDeg lenDeg
+/drawarc { newpath oval stroke } def
+% fillarc x y w h startDeg lenDeg
+/fillarc { newpath oval lineto closepath fill } bind def
+
+% drawpoint x y
+/drawpoint { /y exch def /x exch def gsave newpath [] 0 setdash x y currentlinewidth 2 sub 0 360 arc fill grestore } bind def
+
+% drawline x1 y1 x2 y2
+/drawline { /y2 exch def /x2 exch def /y1 exch def /x1 exch def newpath x1 y1 moveto x2 y2 lineto stroke } bind def
+
+% drawpolyline
+/drawpolyline { newpath polyline stroke } bind def
+
+% drawpolygon
+/drawpolygon { newpath polyline closepath stroke } bind def
+
+% fillpolygon
+/fillpolygon { newpath polyline closepath fill } bind def
+
+/textAlignmentPosn { /ury exch def /urx exch def /lly exch def /llx exch def
+ /wr urx llx sub 2 div def /hr ury lly sub 2 div def
+ /northy 0 def
+ /middley hr neg def
+ /southy hr 2 mul neg def
+ /westx wr 2 mul neg def
+ /centrex wr neg def
+ /eastx 0 def
+ aligntype (N) eq { centrex northy }
+ {
+ aligntype (NW) eq { westx northy }
+ {
+ aligntype (W) eq { westx middley }
+ {
+ aligntype (SW) eq { westx southy }
+ {
+ aligntype (S) eq { centrex southy }
+ {
+ aligntype (SE) eq { eastx southy }
+ {
+ aligntype (E) eq { eastx middley }
+ {
+ aligntype (NE) eq { eastx northy }
+ {
+ %C
+ centrex middley
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ } bind def
+
+/drawstring { /txt exch def /aligntype exch def /y exch def /x exch def
+ newpath x y moveto gsave txt false charpath pathbbox grestore
+ gsave 1 -1 scale textAlignmentPosn rmoveto txt show grestore
+ } bind def
+
+/fillstring { /txt exch def /aligntype exch def /y exch def /x exch def
+ newpath x y moveto gsave txt false charpath pathbbox grestore
+ gsave 1 -1 scale textAlignmentPosn rmoveto
+ txt true charpath pathbbox /ury exch def /urx exch def /lly exch def /llx exch def
+ llx lly moveto llx ury lineto urx ury lineto urx lly lineto closepath
+ fill
+ grestore
+} bind def
+
+/setfontinfo {
+ /size exch def /styles exch def
+ mark
+ styles (I) search /isItalic exch def
+ styles (B) search /isBold exch def
+ cleartomark
+ isItalic isBold and { /Helvetica-BoldOblique }
+ {
+ isItalic { /Helvetica-Oblique }
+ {
+ isBold { /Helvetica-Bold }
+ {
+ /Helvetica
+ } ifelse
+ } ifelse
+ } ifelse
+ findfont
+ size scalefont
+ setfont
+} bind def
+
+/setlinestyle {
+ /style exch def
+ style (S) eq {
+ []
+ }
+ {
+ style (D) eq {
+ [6]
+ }
+ {
+ style (DT) eq {
+ [6 2 2 2]
+ }
+ {
+ style (DTT) eq {
+ [6 2 2 2 2 2]
+ }
+ {
+ % T - dots
+ [2]
+ } ifelse
+ } ifelse
+ } ifelse
+ } ifelse
+ 0 setdash
+} bind def
+
+% set coordinate system to have origin at top left corner
+% and y-axis pointing down the page and x-axis pointing right
+0 700 translate
+1 -1 scale
+
+% End of Header
+
+>>
+
+
+drawRect(x, y, w, h) ::= <<
+<x> <y> <w> <h> drawrect
+
+>>
+
+fillRect(x, y, w, h) ::= <<
+<x> <y> <w> <h> fillrect
+
+>>
+
+drawRRect(x, y, w, h, cornerWidth, cornerHeight) ::= <<
+<x> <y> <w> <h> <cornerWidth> <cornerHeight> drawrrect
+
+>>
+
+fillRRect(x, y, w, h, cornerWidth, cornerHeight) ::= <<
+<x> <y> <w> <h> <cornerWidth> <cornerHeight> fillrrect
+
+>>
+
+
+drawLine(x1, y1, x2, y2) ::= <<
+<x1> <y1> <x2> <y2> drawline
+
+>>
+
+drawPoint(x1, y1) ::= <<
+<x1> <y1> drawpoint
+
+>>
+
+drawArc(x, y, w, h, startAng, lenAng) ::= <<
+<x> <y> <w> <h> <startAng> <lenAng> drawarc
+
+>>
+
+fillArc(x, y, w, h, startAng, lenAng) ::= <<
+<x> <y> <w> <h> <startAng> <lenAng> fillarc
+
+>>
+
+drawOval(x, y, w, h) ::= <<
+<x> <y> <w> <h> drawoval
+
+>>
+
+fillOval(x, y, w, h) ::= <<
+<x> <y> <w> <h> filloval
+
+>>
+
+drawPolygon(points) ::= <<
+[<points; separator=" ">] drawpolygon
+
+>>
+
+drawPolyline(points) ::= <<
+[<points; separator=" ">] drawpolyline
+
+>>
+
+fillPolygon(points) ::= <<
+[<points; separator=" ">] fillpolygon
+
+>>
+
+drawString(x, y, alignment, text) ::= <<
+<x> <y> (<alignment>) (<text>) drawstring
+
+>>
+
+fillString(x, y, alignment, text) ::= <<
+<x> <y> (<alignment>) (<text>) fillstring
+
+>>
+
+setFont(styles, size) ::= <<
+(<styles>) <size> setfontinfo
+
+>>
+
+setColour(red, green, blue) ::= <<
+<red> <green> <blue> setrgbcolor
+
+>>
+
+setLineWidth(lw) ::= <<
+<lw> setlinewidth
+
+>>
+
+setLineStyle(ls) ::= <<
+(<ls>) setlinestyle
+
+>>
+
+footer() ::= <<
+% footer
+showpage
+>>
+
+
+

0 comments on commit 262a93c

Please sign in to comment.
Something went wrong with that request. Please try again.