Unified Typesetting API M1-20040817

de.inghuimische.uta
Class AbstractLine

java.lang.Object
  extended byde.inghuimische.uta.AbstractLine
All Implemented Interfaces:
Line
Direct Known Subclasses:
SimpleLine

public abstract class AbstractLine
extends Object
implements Line

An abstract implementation providing badness and demerits calculation in a similar manner TeX does.

The formulas for badness and demerits calculation can be found in the method comments of getBadness() and getDemerits() respectivley. For further information see The TeXbook, Chapter 14 and TeX The Program, Section 859.

Author:
Christian Ziesemer

Field Summary
static double DEFAULT_LINE_PENALTY
          The default penalty for starting a new line (20), as used in plain TeX.
protected  double linePenalty
          Holds the actual penalty for starting a new line.
protected  double lineWidth
          Holds the actual line width.
protected  double preferredLineWidth
          Holds the preferred line width.
 
Constructor Summary
AbstractLine()
           
 
Method Summary
abstract  double getAdjustmentRatio()
          The adjustment ratio of a line is measure of how much whitespace had to shrink or stretch to get the requested line width.
 double getBadness()
          Calculates the badness of this line in a similar manner TeX does.
 double getDemerits()
          Calculates the demerits for this line in a similar manner like TeX does.
 double getLinePenalty()
          Returns the penalty associated with the generation of a line.
 double getOpticalDensity(boolean position)
          Always returns -1, lines wanting to support the density have to override this method.
 double getPreferredWidth()
          Returns the preferred width of this line.
 double getWidth()
          Returns the actual line width.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.inghuimische.uta.Line
getFirstItem, getLastItem
 

Field Detail

lineWidth

protected double lineWidth
Holds the actual line width.


preferredLineWidth

protected double preferredLineWidth
Holds the preferred line width.


DEFAULT_LINE_PENALTY

public static final double DEFAULT_LINE_PENALTY
The default penalty for starting a new line (20), as used in plain TeX.

See Also:
Constant Field Values

linePenalty

protected double linePenalty
Holds the actual penalty for starting a new line.

Constructor Detail

AbstractLine

public AbstractLine()
Method Detail

getPreferredWidth

public double getPreferredWidth()
Description copied from interface: Line
Returns the preferred width of this line. A typesetter may use this value (and the actual width) to justify a line, this is not done by the linebreak algorithm.

Specified by:
getPreferredWidth in interface Line
Returns:
The preferred width of this line.

getWidth

public double getWidth()
Returns the actual line width.

Specified by:
getWidth in interface Line
Returns:
The actual line width.

getLinePenalty

public double getLinePenalty()
Returns the penalty associated with the generation of a line. This is a general penalty that gets added to the penalty for breaking after a concrete item.

Returns:
The penalty associated with the generation of a line.

getOpticalDensity

public double getOpticalDensity(boolean position)
Always returns -1, lines wanting to support the density have to override this method.

Specified by:
getOpticalDensity in interface Line
Parameters:
position - Either the start or the end of the line.
Returns:
Always -1, lines wanting to support the density have to override this method.
See Also:
Item.DENSITY_START, Item.DENSITY_END, Item.getOpticalDensity(boolean, int)

getAdjustmentRatio

public abstract double getAdjustmentRatio()
The adjustment ratio of a line is measure of how much whitespace had to shrink or stretch to get the requested line width. This is the actual shrink/stretch value divided by the absolute shrink-/stretchability. If a line may be stretched by an overall value of 10 points and is actually stretched by 5 points, the adjustment ratio would be 5/10 = 0.5.


getBadness

public double getBadness()
Calculates the badness of this line in a similar manner TeX does.

The formula is (in MathML the browser may not display it correctly):

badness = 100 adjustmentRatio 3

Returns:
The badness of the line.
See Also:
getAdjustmentRatio()

getDemerits

public double getDemerits()
Calculates the demerits for this line in a similar manner like TeX does. The difference is that no distinction between infinite bad penalities is made (compare The TeXbook, Chapter 14 and TeX The Program, Section 859), cause a multiplication is faster than an if-statement in Java nowadays.

The formula is (in MathML the browser may not display it correctly):

demerits = linePenalty badness 2 sgn breakPenalty breakPenalty 2

Specified by:
getDemerits in interface Line
Returns:
An abstract measurement for the total quality of this line.

Unified Typesetting API M1-20040817


An inghuimische.de project.
Copyright (C) 2004 Christian Ziesemer; See the Mozilla Public License for more details.