import de.uniulm.mathematik.typo.fonts.*; import de.uniulm.mathematik.typo.fonts.afm.*; import de.uniulm.mathematik.typo.items.*; import java.io.*; public class TableGenerator { private static boolean verbose = false; public static void main(String[] args) { if (args.length != 5) { System.err.println("Usage: TableGenerator font.afm size baselineskip" + " tabwidth alignment"); } else { try { FontMetrics fm = new AdobeFontMetrics(args[0]); int fontSize = (new Integer(args[1])).intValue(); int baselineskip = (new Integer(args[2])).intValue() * 1000; int tabwidth = (new Integer(args[3])).intValue() * 1000; String alignment = args[4]; int columns = alignment.length(); boolean ok = true; if (columns == 0) { System.err.println("TableGenerator: " + "alignment must not be empty"); ok = false; } for (int i = 0; i < columns; ++i) { switch (alignment.charAt(i)) { case 'L': case 'R': case 'Z': break; /* OK */ default: System.err.println("TableGenerator: " + "bad alignment spec: " + alignment.charAt(i)); ok = false; break; } } if (ok) { InputStream in = new BufferedInputStream(System.in); Item box = readRecords(in, tabwidth, columns, baselineskip, fm, fontSize, alignment); PostScriptContext context = new PostScriptContext(); System.out.print(EPSWrapper.gen(context, box)); } } catch (Exception e) { System.err.println("TableGenerator: " + e.toString()); } } } // main private static Item readField(InputStream in, int colwidth, FontMetrics fm, int fontSize, char colspec) throws IOException { HorizontalSequence hseq = new SimpleHorizontalSequence(); Sequencer s = new Sequencer(hseq, fm, fontSize); if (verbose) { s.setWrapper(new FrameWrapper()); } boolean added = false; int ch; while ((ch = in.read()) >= 0 && ch != ',' && ch != '\n') { s.add(ch); added = true; } if (ch < 0 && !added) return null; s.finish(); HorizontalBox box = new HorizontalBox(); HorizontalBox fbox = new HorizontalBox(hseq); int spacewidth = colwidth - fbox.getWidth(); if (colspec == 'Z') spacewidth /= 2; Item space = new Glue(spacewidth, 0, 0); if (verbose) { space = new FramedItem(space); } switch (colspec) { case 'L': box.add(fbox); box.add(space); break; case 'Z': box.add(space); box.add(fbox); box.add(space); break; case 'R': box.add(space); box.add(fbox); break; } if (verbose) { return new LinedItem(box); } return box; } private static Item readRecord(InputStream in, int tabwidth, int columns, FontMetrics fm, int fontSize, String colspecs) throws IOException { int col = 0; boolean added = false; int spacewidth = fm.getWidth(' ') * fontSize; int colwidth = (tabwidth - (columns - 1) * spacewidth) / columns; HorizontalBox hbox = new HorizontalBox(); for (int i = 0; i < columns; ++i) { Item fbox = readField(in, colwidth, fm, fontSize, colspecs.charAt(i)); if (fbox == null) break; if (added) { hbox.add(new Glue(spacewidth, 0, 0)); } hbox.add(fbox); added = true; } if (!added) return null; return hbox; } private static Item readRecords(InputStream in, int tabwidth, int columns, int baselineskip, FontMetrics fm, int fontSize, String colspecs) throws IOException { VerticalBox vbox = new VerticalBox(baselineskip); Item hbox; while ((hbox = readRecord(in, tabwidth, columns, fm, fontSize, colspecs)) != null) { vbox.add(hbox); } return vbox; } } // class TableGenerator