Class TeXParagraphBuilder

  extended byde.dante.extex.typesetter.paragraphBuilder.texImpl.TeXParagraphBuilder
All Implemented Interfaces:
Localizable, LogEnabled, ParagraphBuilder

public class TeXParagraphBuilder
extends java.lang.Object
implements ParagraphBuilder, Localizable, LogEnabled

This class implements the paragraph breaking algorithm as used in TeX. The implementation stared as a direct translation of the original sources to Java. This includes the original comments. Thus most of the original comments can still be found in this file. They are typeset in italics.

813. Breaking paragraphs into lines.

We come now to what is probably the most interesting algorithm of TeX: the mechanism for choosing the "best possible" breakpoints that yield the individual lines of a paragraph. TeX's line-breaking algorithm takes a given horizontal list and converts it to a sequence of boxes that are appended to the current vertical list. In the course of doing this, it creates a special data structure containing three kinds of records that are not used elsewhere in TeX. Such nodes are created while a paragraph is being processed, and they are destroyed afterwards; thus, the other parts of TeX do not need to know anything about how line-breaking is done.

The method used here is based on an approach devised by Michael F. Plass and the author in 1977, subsequently generalized and improved by the same two people in 1980. A detailed discussion appears in SOFTWARE—Practice & Experience 11 (1981), 1119–1184, where it is shown that the line-breaking problem can be regarded as a special case of the problem of computing the shortest path in an acyclic network. The cited paper includes numerous examples and describes the history of line breaking as it has been practiced by printers through the ages. The present implementation adds two new ideas to the algorithm of 1980: memory space requirements are considerably reduced by using smaller records for inactive nodes than for active ones, and arithmetic overflow is avoided by using "delta distances" instead of keeping track of the total distance from the beginning of the paragraph to the current point.

$Revision: 1.13 $
Gerd Neugebauer

Constructor Summary
          Creates a new object.
Method Summary
 NodeList build(HorizontalListNode nodes)
          Break a horizontal list into lines.
 void enableLocalization(Localizer theLocalizer)
          Setter for the localizer.
 void enableLogging(java.util.logging.Logger theLogger)
          Setter for the logger.
 void setNodefactory(NodeFactory factory)
          Setter for the node factory.
 void setOptions(TypesetterOptions options)
          Setter for options.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public TeXParagraphBuilder()
Creates a new object.

Method Detail


public NodeList build(HorizontalListNode nodes)
               throws TypesetterException
Description copied from interface: ParagraphBuilder
Break a horizontal list into lines. The horizontal list passed in might be modified under way.

Specified by:
build in interface ParagraphBuilder
nodes - the horizontal node list containing all nodes for the paragraph
the VerticalListNode containing the hboxes of the lines
TypesetterException - in case of an error
See Also: de.dante.extex.typesetter.type.node.HorizontalListNode)


public void setNodefactory(NodeFactory factory)
Description copied from interface: ParagraphBuilder
Setter for the node factory.

Specified by:
setNodefactory in interface ParagraphBuilder
factory - the node factory
See Also:
ParagraphBuilder.setNodefactory( de.dante.extex.typesetter.type.node.factory.NodeFactory)


public void setOptions(TypesetterOptions options)
Description copied from interface: ParagraphBuilder
Setter for options.

Specified by:
setOptions in interface ParagraphBuilder
options - the options to set.
See Also:
ParagraphBuilder.setOptions( de.dante.extex.typesetter.TypesetterOptions)


public void enableLogging(java.util.logging.Logger theLogger)
Description copied from interface: LogEnabled
Setter for the logger.

Specified by:
enableLogging in interface LogEnabled
theLogger - the logger to use
See Also:
LogEnabled.enableLogging( java.util.logging.Logger)


public void enableLocalization(Localizer theLocalizer)
Setter for the localizer.

Specified by:
enableLocalization in interface Localizable
theLocalizer - the new value for the localizer
See Also:
Localizable.enableLocalization( de.dante.util.framework.i18n.Localizer)