/* LineBreaker.java * * Copyright (c) 2000, Ted Nelson and Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the README * file for more details. * */ /* * Written by Tuomas Lukka */ package org.gzigzag; import java.awt.FontMetrics; import java.lang.reflect.*; import java.util.*; /** An interface to line breaking algorithms * This class knows absolutely nothing about characters, words, or so on. * It handles abstract tokens given by integers and asks the related * class LineInfo about the goodness of fitting a particular line * at a particular point. *
* Specific attention is paid to the billowing problem where
* we have to render a paragraph so that the cursor is at the line with
* the first line of the paragraph starts from the beginning of a line.
* This is achieved by specifying the cursor position (from where the lines
* should be counted) and the desired line number for that position.
* This can also be used to render the paragraph starting from the end.
*/
public abstract class LineBreaker {
String rcsid = "$Id: LineBreaker.java,v 1.8.10.1 2001/08/16 13:50:01 bfallenstein Exp $";
static private void pa(String s) { System.out.println(s); }
/** Break the lines between the given addresses.
* @return An array: the first element is the line index the rendering
* starts on, and from the second element onwards the end points of the
* lines are given.
*/
public abstract int[] breakLines(LineInfo li);
static private void test(LineBreaker b, String str, int cursor,
SimpleLineInfo.Layout l) {
SimpleLineInfo inf = new SimpleLineInfo(str, cursor, l);
int[] foo = b.breakLines(inf);
pa("Tested '"+str+"'");
for(int i=0; i