Back to index

wims  3.65+svn20090927
LatexOutput.java
Go to the documentation of this file.
00001 /*
00002  * Created on 30.03.2006
00003  *
00004  */
00005 package rene.zirkel.graphics;
00006 
00007 import java.io.*;
00008 
00009 import rene.gui.*;
00010 
00011 public class LatexOutput 
00012 {      PrintWriter Out;
00013        double W,H;
00014        boolean DoubleDollar,Dollar,NoDollar;
00015 
00016        public LatexOutput (PrintWriter out)
00017        {      Out=out;
00018               DoubleDollar=Global.getParameter("options.doubledollar",true);
00019               Dollar=Global.getParameter("options.dollar",true);
00020               NoDollar=Global.getParameter("options.nodollar",false);
00021        }
00022        
00023        public void open (double w, double h, double dpi, String picfilename)
00024        {      W=w; H=h;
00025               Out.println("\\setlength{\\unitlength}{"+(2.54/dpi)+"cm}");
00026               Out.println("\\begin{picture}("+round(w)+","+round(h)+")");
00027               String s=picfilename.replace('\\','/');
00028               Out.println("\\put(0,0){\\includegraphics[width="+
00029                             round(w/dpi*2.54)+"cm]{"+s+"}}");
00030               Out.println("%\\put(0,0){\\includegraphics[width="+
00031                             round(w/dpi*2.54)+"cm,bb=0 0 "+((int)w)+" "+((int)h)+"]{"+s+"}}");
00032        }
00033        
00034        public void close ()
00035        {      Out.println("\\end{picture}");
00036               Out.close();
00037        }
00038 
00039        public boolean println (String s, double x, double y, boolean force)
00040        {      if (s.startsWith("$$"))
00041               {      if (!DoubleDollar) return false;
00042                      s=s.substring(1);
00043                      if (s.endsWith("$$")) s=s.substring(0,s.length()-1);
00044                      if (!s.endsWith("$")) s=s+"$";
00045               }
00046               else if (!force && s.startsWith("$"))
00047               {      if (!Dollar) return false;
00048                      if (!s.endsWith("$")) s=s+"$";
00049               }
00050               else if (!force)
00051               {      if (!NoDollar) return false;
00052               }
00053               // Out.println("\\put("+round(x)+","+round(H-y)+"){\\makebox(0,0)[lt]{"+s+"}}");
00054               Out.println("\\put("+round(x)+","+round(H-y)+"){"+s+"}");
00055               return true;
00056        }
00057        public boolean println (String s, double x, double y)
00058        {      return println(s,x,y,false);
00059        }
00060        
00061        public double round (double x)
00062        {      return Math.floor(x*1000+0.5)/1000;
00063        }
00064        
00065        public boolean printDollar ()
00066        {      return Dollar;
00067        }
00068 }