Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

Postscript.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2006-02-09 16:32:56 +0100 (Thu, 09 Feb 2006) $ by $Author: tack $
00011  *     $Revision: 2943 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  See the file "LICENSE" for information on usage and
00018  *  redistribution of this file, and for a
00019  *     DISCLAIMER OF ALL WARRANTIES.
00020  *
00021  */
00022 
00023 package org.gecode.gist.postscript;
00024 
00025 import org.gecode.gist.*;
00026 import java.io.*;
00027 import java.util.*;
00028 
00029 public class Postscript {
00030 
00031     private static final double scale = 0.72;
00032     private static final double translatex = 306.0;
00033     private static final double translatey = 396.0;
00034     
00035     private static final int translatexI = 311;
00036     private static final int translateyI = 390;
00037 
00038     public static void emitComments(Writer out, BoundingBox b) throws IOException
00039     {
00040         int maxx=b.maxx+10;
00041         out.write("%!PS-Adobe-3.0 EPSF-3.0\n");
00042         out.write("%%Creator: Gecode/J PS library\n");
00043         out.write("%%For: Who knows?\n");
00044         out.write("%%Title: figure\n");
00045         out.write("%%CreationDate: Fri Jul 16 13:58:16 2004\n");
00046         out.write("%%BoundingBox: "+b.minx+" "+b.miny+" "+
00047                   maxx+" "+b.maxy+"\n");
00048         out.write("%%Pages: 1\n");
00049         out.write("%%DocumentData: Clean7Bit\n");
00050         out.write("%%Orientation: Portrait\n");
00051         out.write("%%EndComments\n\n");
00052     }
00053 
00054     public static void emitHeader(Writer out) throws IOException
00055     {
00056         out.write("%%BeginProlog\n");
00057         out.write("50 dict begin\n\n");
00058         out.write("%%EndProlog\n");
00059         out.write("%%Page: 1 1\n");
00060         out.write("save\n");
00061         out.write(translatexI+" "+translateyI+" translate\n");
00062         out.write(scale+" "+scale+" scale\n");
00063     }
00064 
00065     public static void emitFooter(Writer out) throws IOException
00066     {
00067         out.write("restore showpage\n\n"+
00068                   "%%Trailer\n"+
00069                   "end\n"+
00070                   "%%EOF\n");
00071     }
00072     
00073     private static void savePath(ArrayList<Path> ps, File f)
00074                         throws IOException
00075     {
00076         BoundingBox b = new BoundingBox(100000,0,100000,0);
00077         for (Path p : ps) {
00078             b.merge(p.bb());
00079         }
00080         b.translate(scale, translatex, translatey);
00081         Writer out = new BufferedWriter(new FileWriter(f));
00082         emitComments(out, b);
00083         emitHeader(out);
00084         for (Path p : ps) {
00085             p.emit(out);
00086         }
00087         emitFooter(out);
00088         out.close();
00089     }
00090     public static void saveAs(SpaceNode root, File f)
00091                        throws IOException
00092     {
00093         ArrayList<Path> ps = new ArrayList<Path>();
00094         PostscriptCursor cursor = new PostscriptCursor(root, ps);
00095         PreOrderNodeVisitor visitor = new PreOrderNodeVisitor(cursor);
00096         visitor.run();
00097         
00098         savePath(ps, f);
00099     }
00100 }