package de.uniulm.mathematik.typo.items; import de.uniulm.mathematik.typo.fonts.*; import de.uniulm.mathematik.typo.fonts.afm.*; import de.uniulm.mathematik.typo.hyphen.*; import de.uniulm.mathematik.tries.*; import java.io.*; public class TestHyphenatedTPar { public static void main(String[] args) { LineBreakerFactory lbf = (new LineBreakerCollection()).getFactory(); lbf.add("triangle", new TriangleLineBreaker.Constructor()); if (args.length != 6) { System.err.println("Usage: TestHyphenatedTPar hyphen.rules " + "font.afm size baselineskip parwidth " + lbf.getAlternatives()); } else { try { TrieReader trie = HyphenationTableLoader.open(args[0]); Hyphenator hyph = new SimpleHyphenator(trie); SequenceHyphenator seqh = new SequenceHyphenator(hyph); FontMetrics fm = new AdobeFontMetrics(args[1]); int fontSize = (new Integer(args[2])).intValue(); int baselineskip = (new Integer(args[3])).intValue(); int parwidth = (new Integer(args[4])).intValue(); String algorithm = args[5]; LineBreaker lb = lbf.create(algorithm); if (lb == null) { System.err.println("No such line breaker algorithm;" + " supported are " + lbf.getAlternatives()); } else { run(seqh, fm, fontSize, baselineskip * 1000, parwidth * 1000, lb, new BufferedReader(new InputStreamReader(System.in))); } } catch (Exception e) { System.out.println("TestHyphenatedTPar: " + e.toString()); } } } // main private static void run(SequenceHyphenator seqh, FontMetrics fm, int fontSize, int baselineskip, int parwidth, LineBreaker lb, BufferedReader in) { PostScriptContext context = new PostScriptContext(); HorizontalSequence hseq = new SimpleHorizontalSequence(); Sequencer s = new Sequencer(hseq); s.setFont(fm, fontSize); try { int ch; while ((ch = in.read()) >= 0) { s.add(ch); } s.finishParagraph(); hseq = seqh.hyphenate(hseq); Item vbox = lb.breakParagraph(hseq, parwidth, baselineskip); System.out.print(EPSWrapper.gen(context, vbox)); } catch (Exception e) { e.printStackTrace(); // System.out.println("Error: " + e.toString()); } } } // class TestHyphenatedTPar