de.dante.extex.typesetter.impl
Class TypesetterImpl

java.lang.Object
  extended byde.dante.extex.typesetter.impl.TypesetterImpl
All Implemented Interfaces:
ListMaker, ListManager, Localizable, LogEnabled, Typesetter
Direct Known Subclasses:
DumpTypesetter

public class TypesetterImpl
extends java.lang.Object
implements Typesetter, ListManager, Localizable, LogEnabled

This is a reference implementation of the Typesetter interface.

Version:
$Revision: 1.97 $
Author:
Gerd Neugebauer, Michael Niedermair

Constructor Summary
TypesetterImpl()
          Creates a new object and initializes it to receive material.
 
Method Summary
 void add(FixedGlue glue)
          Add a glue node to the list.
 void add(Node node)
          Add an arbitrary node to the internal list of nodes gathered so far.
 void addAndAdjust(NodeList list, TypesetterOptions options)
          Add a node list to the current list maker and adjust the spacing between the elements of the list.
 void addSpace(TypesettingContext typesettingContext, Count spacefactor)
          Add a space node to the list.
 void afterParagraph(ParagraphObserver observer)
          Register an observer to be invoked at the end of the paragraph.
 NodeList buildParagraph(HorizontalListNode nodes)
          Invoke the paragraph builder on a list of nodes.
 void clearShipoutMark()
          Clear the internal state about shipouts.
 NodeList complete(TypesetterOptions context)
          Close the node list.
 void cr(Context context, TypesettingContext tc, UnicodeChar uc)
          Process a carriage return.
 void enableLocalization(Localizer theLocalizer)
          Setter for the localizer.
 void enableLogging(java.util.logging.Logger theLogger)
          Setter for the logger.
 void endParagraph()
          End the current paragraph.
 ListMaker ensureHorizontalMode(Locator locator)
          Switch to horizontal mode if necessary.
 void finish()
          Instructs the typesetter to perform any actions necessary for cleaning up everything at the end of processing.
 BackendDriver getBackendDriver()
          Getter for back-end.
 Node getLastNode()
          Access the last node on the list.
 ListMaker getListMaker()
          Getter for the current list maker.
 Locator getLocator()
          Getter for the locator.
 ListManager getManager()
          Getter for the manager of the list maker stack.
 Mode getMode()
          Getter for the current mode.
 NodeFactory getNodeFactory()
          Getter for the NodeFactory.
 TypesetterOptions getOptions()
          Getter for the options object.
 FixedDimen getPrevDepth()
          Getter for the previous depth parameter.
 long getSpacefactor()
          Getter for the space factor.
 boolean isShipoutMark()
          Query the shipout mark.
 void leftBrace()
          Notification method to deal the case that a left brace has been encountered.
 boolean letter(UnicodeChar uc, TypesettingContext tc, Context context, TokenSource source, Locator locator)
          Add a letter to the current list or treat it in some other appropriate way.
 void mathShift(Context context, TokenSource source, Token t)
          Treat a math shift character.
 void par()
          Emit a new paragraph.
 ListMaker pop()
          Discard the top of the stack of list makers.
 void push(ListMaker list)
          Open a new list maker and put it in the top of the stack as current box.
 void removeLastNode()
          Removes the last node from the list.
 void rightBrace()
          Notification method to deal the case that a right brace has been encountered.
 void setBackend(BackendDriver driver)
          Setter for the back-end driver.
 void setNodeFactory(NodeFactory nodeFactory)
          Setter for the node factory.
 void setOptions(TypesetterOptions options)
          Setter for the typesetter specific options.
 void setOutputRoutine(OutputRoutine output)
          Setter for the output routine.
 void setPageBuilder(PageBuilder pageBuilder)
          Setter for the page builder.
 void setParagraphBuilder(ParagraphBuilder parBuilder)
          Setter for paragraph builder.
 void setPrevDepth(FixedDimen pd)
          Setter for the previous depth parameter.
 void setSpacefactor(FixedCount sf)
          Setter for the space factor
 void shipout(NodeList nodes)
          This is the entry point for the document writer.
 void showlist(java.lang.StringBuffer sb, long depth, long breadth)
          Print the status for \showlists.
 void showlists(java.lang.StringBuffer sb, long depth, long breadth)
          This method produces a diagnostic representation of the current lists in a StringBuffer.
 void subscriptMark(Context context, TokenSource source, Typesetter typesetter, Token t)
          Treat a subscript mark.
 void superscriptMark(Context context, TokenSource source, Typesetter typesetter, Token t)
          Treat a superscript mark.
 void tab(Context context, TokenSource source, Token t)
          Treat a alignment tab character.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypesetterImpl

public TypesetterImpl()
Creates a new object and initializes it to receive material. To make it fully functionality is required that the paragraph builder and the ligature builder are provided before they are used.

Method Detail

add

public void add(FixedGlue glue)
         throws TypesetterException
Description copied from interface: ListMaker
Add a glue node to the list.

Specified by:
add in interface ListMaker
Parameters:
glue - the glue to add
Throws:
TypesetterException - in case of an error
See Also:
ListMaker.add( de.dante.extex.interpreter.type.glue.FixedGlue)

add

public void add(Node node)
         throws TypesetterException,
                ConfigurationException
Description copied from interface: ListMaker
Add an arbitrary node to the internal list of nodes gathered so far. The node should not be one of the special nodes treated by methods of their own.

Specified by:
add in interface ListMaker
Parameters:
node - the node to add
Throws:
ConfigurationException - in case of a configuration error
TypesetterException - in case of an error
See Also:
ListMaker.add( de.dante.extex.typesetter.type.Node)

addAndAdjust

public void addAndAdjust(NodeList list,
                         TypesetterOptions options)
                  throws TypesetterException,
                         ConfigurationException
Description copied from interface: ListMaker
Add a node list to the current list maker and adjust the spacing between the elements of the list.

Specified by:
addAndAdjust in interface ListMaker
Parameters:
list - the list
options - the options to use
Throws:
TypesetterException - in case of an error
ConfigurationException - in case of a configuration error
See Also:
ListMaker.addAndAdjust( de.dante.extex.typesetter.type.NodeList, de.dante.extex.typesetter.TypesetterOptions)

addSpace

public void addSpace(TypesettingContext typesettingContext,
                     Count spacefactor)
              throws TypesetterException,
                     ConfigurationException
Description copied from interface: ListMaker
Add a space node to the list.

Specified by:
addSpace in interface ListMaker
Parameters:
typesettingContext - the typesetting context for the space
spacefactor - the space factor to use for this space or null to indicate that the default space factor should be used.
Throws:
ConfigurationException - in case of a configuration error
TypesetterException - in case of an error
See Also:
de.dante.extex.typesetter.ListMaker#addSpace( de.dante.extex.interpreter.context.TypesettingContext, de.dante.extex.interpreter.type.count.Count)

afterParagraph

public void afterParagraph(ParagraphObserver observer)
Description copied from interface: ListMaker
Register an observer to be invoked at the end of the paragraph.

Specified by:
afterParagraph in interface ListMaker
Parameters:
observer - the observer to register
See Also:
ListMaker.afterParagraph( ParagraphObserver)

buildParagraph

public NodeList buildParagraph(HorizontalListNode nodes)
                        throws TypesetterException
Description copied from interface: ListManager
Invoke the paragraph builder on a list of nodes.

Specified by:
buildParagraph in interface ListManager
Parameters:
nodes - the nodes to make a paragraph from
Returns:
the vertical node list containing the lines of the paragraph
Throws:
TypesetterException - in case of an error
See Also:
ListManager.buildParagraph( de.dante.extex.typesetter.type.node.HorizontalListNode)

clearShipoutMark

public void clearShipoutMark()
Description copied from interface: Typesetter
Clear the internal state about shipouts. The shipout mark is reset to false.

Specified by:
clearShipoutMark in interface Typesetter
See Also:
Typesetter.clearShipoutMark()

complete

public NodeList complete(TypesetterOptions context)
                  throws TypesetterException,
                         ConfigurationException
Description copied from interface: ListMaker
Close the node list. This means that everything is done to ship the closed node list to the document writer. Nevertheless the invoking application might decide not to modify the node list and continue processing. In the other case some nodes might be taken from the node list returned by this method. Then the processing has to continue with the reduced node list.

Specified by:
complete in interface ListMaker
Parameters:
context - the typesetter options mapping a fragment of the interpreter context
Returns:
the node list enclosed in this instance
Throws:
ConfigurationException - in case of a configuration error
TypesetterException - in case of an error
See Also:
ListMaker.complete(TypesetterOptions)

cr

public void cr(Context context,
               TypesettingContext tc,
               UnicodeChar uc)
        throws TypesetterException
Description copied from interface: ListMaker
Process a carriage return.

Specified by:
cr in interface ListMaker
Parameters:
context - the interpreter context
tc - the typesetting context
uc - the character
Throws:
TypesetterException - in case of an error
See Also:
de.dante.extex.typesetter.ListMaker#cr( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.context.TypesettingContext, de.dante.util.UnicodeChar)

enableLocalization

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

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

enableLogging

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

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

endParagraph

public void endParagraph()
                  throws TypesetterException,
                         ConfigurationException
Description copied from interface: ListManager
End the current paragraph.

Specified by:
endParagraph in interface ListManager
Throws:
TypesetterException - in case of an error
ConfigurationException - in case of an configuration problem
See Also:
ListManager.endParagraph()

ensureHorizontalMode

public ListMaker ensureHorizontalMode(Locator locator)
                               throws TypesetterException
Description copied from interface: Typesetter
Switch to horizontal mode if necessary. If the current mode is a horizontal mode then nothing is done.

Specified by:
ensureHorizontalMode in interface Typesetter
Parameters:
locator - the locator
Returns:
the horizontal list maker
Throws:
TypesetterException - in case of an error
See Also:
ListManager.ensureHorizontalMode( de.dante.util.Locator)

finish

public void finish()
            throws TypesetterException,
                   ConfigurationException
Description copied from interface: Typesetter
Instructs the typesetter to perform any actions necessary for cleaning up everything at the end of processing. This should involve a shipout of any material still left unprocessed.

Specified by:
finish in interface Typesetter
Throws:
ConfigurationException - in case of an configuration problem
TypesetterException - in case of an error
See Also:
Typesetter.finish()

getBackendDriver

public BackendDriver getBackendDriver()
Getter for back-end.

Specified by:
getBackendDriver in interface Typesetter
Returns:
the back-end
See Also:
Typesetter.getBackendDriver()

getLastNode

public Node getLastNode()
Description copied from interface: ListMaker
Access the last node on the list.

Specified by:
getLastNode in interface ListMaker
Returns:
the last node in the current list or null if the list is empty
See Also:
ListMaker.getLastNode()

getListMaker

public ListMaker getListMaker()
Description copied from interface: Typesetter
Getter for the current list maker.

Specified by:
getListMaker in interface Typesetter
Returns:
the top list maker or null if the stack is empty
See Also:
Typesetter.getListMaker()

getLocator

public Locator getLocator()
Description copied from interface: ListMaker
Getter for the locator.

Specified by:
getLocator in interface ListMaker
Returns:
the locator
See Also:
ListMaker.getLocator()

getManager

public ListManager getManager()
Getter for the manager of the list maker stack. This instance also acts as a manager.

Specified by:
getManager in interface Typesetter
Returns:
this instance
See Also:
Typesetter.getManager()

getMode

public Mode getMode()
Description copied from interface: ListMaker
Getter for the current mode.

Specified by:
getMode in interface ListMaker
Returns:
the mode which is one of the values defined in Mode.
See Also:
ListMaker.getMode()

getNodeFactory

public NodeFactory getNodeFactory()
Description copied from interface: Typesetter
Getter for the NodeFactory.

Specified by:
getNodeFactory in interface Typesetter
Returns:
the node factory
See Also:
Typesetter.getNodeFactory()

getOptions

public TypesetterOptions getOptions()
Description copied from interface: ListManager
Getter for the options object.

Specified by:
getOptions in interface ListManager
Returns:
the options
See Also:
ListManager.getOptions()

getPrevDepth

public FixedDimen getPrevDepth()
                        throws TypesetterUnsupportedException
Description copied from interface: ListMaker
Getter for the previous depth parameter.

Specified by:
getPrevDepth in interface ListMaker
Returns:
the previous depth
Throws:
TypesetterUnsupportedException - in case of an error
See Also:
ListMaker.getPrevDepth()

getSpacefactor

public long getSpacefactor()
                    throws TypesetterUnsupportedException
Description copied from interface: ListMaker
Getter for the space factor.

Specified by:
getSpacefactor in interface ListMaker
Returns:
the space factor
Throws:
TypesetterUnsupportedException - in case of an error
See Also:
ListMaker.getSpacefactor()

isShipoutMark

public boolean isShipoutMark()
Description copied from interface: Typesetter
Query the shipout mark. The shipout mark is an internal state which records whether or not the shipout method has been called recently. This method can be used to get the current state. The method clearShipoutMark() can be used to reset the shipout mark to false. Initially the shipout mark is false.

Specified by:
isShipoutMark in interface Typesetter
Returns:
true iff there has been an invocation to the method shipout() since the last clearing
See Also:
Typesetter.isShipoutMark()

leftBrace

public void leftBrace()
Notification method to deal the case that a left brace has been encountered.

Specified by:
leftBrace in interface ListMaker

letter

public boolean letter(UnicodeChar uc,
                      TypesettingContext tc,
                      Context context,
                      TokenSource source,
                      Locator locator)
               throws TypesetterException
Description copied from interface: ListMaker
Add a letter to the current list or treat it in some other appropriate way.

Specified by:
letter in interface ListMaker
Parameters:
tc - the typesetting context
uc - the character
context - the interpreter context
source - the source for new tokens
locator - the locator
Returns:
true iff the character has been discarded because it is not defined in the current font.
Throws:
TypesetterException - in case of an error
See Also:
de.dante.extex.typesetter.ListMaker#letter( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.context.TypesettingContext, de.dante.util.UnicodeChar, de.dante.util.Locator)

mathShift

public void mathShift(Context context,
                      TokenSource source,
                      Token t)
               throws TypesetterException,
                      ConfigurationException
Description copied from interface: ListMaker
Treat a math shift character. Usually this leads to entering or leaving math mode – maybe after inspection of a following token.

Specified by:
mathShift in interface ListMaker
Parameters:
context - the interpreter context
source - the source for new tokens
t - the actual math shift character token
Throws:
TypesetterException - in case of an error
ConfigurationException - in case of a configuration error
See Also:
ListMaker.mathShift( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.scanner.type.token.Token)

par

public void par()
         throws TypesetterException,
                ConfigurationException
Description copied from interface: ListMaker
Emit a new paragraph. This might be a noop under certain circumstances.

Specified by:
par in interface ListMaker
Throws:
TypesetterException - in case of an error
ConfigurationException - in case of a configuration error
See Also:
ListMaker.par()

pop

public ListMaker pop()
              throws TypesetterException
Description copied from interface: ListManager
Discard the top of the stack of list makers.

Specified by:
pop in interface ListManager
Returns:
the list maker popped from the stack
Throws:
TypesetterException - in case of an error
See Also:
ListManager.pop()

push

public void push(ListMaker list)
          throws TypesetterException
Description copied from interface: Typesetter
Open a new list maker and put it in the top of the stack as current box.

Specified by:
push in interface Typesetter
Parameters:
list - the list maker
Throws:
TypesetterException - in case of an error
See Also:
ListManager.push( de.dante.extex.typesetter.ListMaker)

removeLastNode

public void removeLastNode()
Description copied from interface: ListMaker
Removes the last node from the list. If the list is empty then nothing is done.

Specified by:
removeLastNode in interface ListMaker
See Also:
ListMaker.removeLastNode()

rightBrace

public void rightBrace()
                throws TypesetterException
Description copied from interface: ListMaker
Notification method to deal the case that a right brace has been encountered.

Specified by:
rightBrace in interface ListMaker
Throws:
TypesetterException - in case of an error
See Also:
ListMaker.rightBrace()

setBackend

public void setBackend(BackendDriver driver)
Description copied from interface: Typesetter
Setter for the back-end driver. The back-end driver is addressed whenever a complete page has to be shipped out.

Specified by:
setBackend in interface Typesetter
Parameters:
driver - the new back-end driver
See Also:
Typesetter.setBackend( de.dante.extex.backend.BackendDriver)

setNodeFactory

public void setNodeFactory(NodeFactory nodeFactory)
Description copied from interface: Typesetter
Setter for the node factory.

Specified by:
setNodeFactory in interface Typesetter
Parameters:
nodeFactory - the node factory
See Also:
Typesetter.setNodeFactory( de.dante.extex.typesetter.type.node.factory.NodeFactory)

setOptions

public void setOptions(TypesetterOptions options)
Description copied from interface: Typesetter
Setter for the typesetter specific options.

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

setOutputRoutine

public void setOutputRoutine(OutputRoutine output)
Description copied from interface: Typesetter
Setter for the output routine.

Specified by:
setOutputRoutine in interface Typesetter
Parameters:
output - the output routine
See Also:
de.dante.extex.typesetter.Typesetter#setOutputRoutine( de.dante.extex.typesetter.OutputRoutine)

setPageBuilder

public void setPageBuilder(PageBuilder pageBuilder)
Setter for the page builder.

Specified by:
setPageBuilder in interface Typesetter
Parameters:
pageBuilder - the new page builder
See Also:
Typesetter.setPageBuilder( de.dante.extex.typesetter.pageBuilder.PageBuilder)

setParagraphBuilder

public void setParagraphBuilder(ParagraphBuilder parBuilder)
Setter for paragraph builder.

Specified by:
setParagraphBuilder in interface Typesetter
Parameters:
parBuilder - the paragraph builder to set.

setPrevDepth

public void setPrevDepth(FixedDimen pd)
                  throws TypesetterUnsupportedException
Description copied from interface: ListMaker
Setter for the previous depth parameter.

Specified by:
setPrevDepth in interface ListMaker
Parameters:
pd - the previous depth parameter
Throws:
TypesetterUnsupportedException - in case of an error
See Also:
ListMaker.setPrevDepth( de.dante.extex.interpreter.type.dimen.FixedDimen)

setSpacefactor

public void setSpacefactor(FixedCount sf)
                    throws TypesetterUnsupportedException,
                           InvalidSpacefactorException
Description copied from interface: ListManager
Setter for the space factor

Specified by:
setSpacefactor in interface ListMaker
Parameters:
sf - the space factor to set
Throws:
TypesetterUnsupportedException - in case of an error
InvalidSpacefactorException - in case of an invalid space factor
See Also:
ListMaker.setSpacefactor( de.dante.extex.interpreter.type.count.FixedCount)

shipout

public void shipout(NodeList nodes)
             throws TypesetterException
This is the entry point for the document writer. Here it receives a complete node list to be sent to the output writer.

Specified by:
shipout in interface Typesetter
Parameters:
nodes - the nodes to send
Throws:
TypesetterException - in case of an error
See Also:
Typesetter.shipout( de.dante.extex.typesetter.type.NodeList)

showlist

public void showlist(java.lang.StringBuffer sb,
                     long depth,
                     long breadth)
Description copied from interface: ListMaker
Print the status for \showlists.

Specified by:
showlist in interface ListMaker
Parameters:
sb - the target buffer
depth - the depth of the list display
breadth - the breadth of the list display
See Also:
ListMaker.showlist(java.lang.StringBuffer, long, long)

showlists

public void showlists(java.lang.StringBuffer sb,
                      long depth,
                      long breadth)
Description copied from interface: Typesetter
This method produces a diagnostic representation of the current lists in a StringBuffer.

Specified by:
showlists in interface Typesetter
Parameters:
sb - the target string buffer
depth - the depth for the display
breadth - the breadth of the display
See Also:
Typesetter.showlists( java.lang.StringBuffer, long, long)

subscriptMark

public void subscriptMark(Context context,
                          TokenSource source,
                          Typesetter typesetter,
                          Token t)
                   throws TypesetterException
Description copied from interface: ListMaker
Treat a subscript mark. This might be meaningful in math mode only.

Specified by:
subscriptMark in interface ListMaker
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
t - the actual sub mark token
Throws:
TypesetterException - in case of an error
See Also:
ListMaker.subscriptMark( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter, de.dante.extex.scanner.type.token.Token)

superscriptMark

public void superscriptMark(Context context,
                            TokenSource source,
                            Typesetter typesetter,
                            Token t)
                     throws TypesetterException
Description copied from interface: ListMaker
Treat a superscript mark. This might be meaningful in math mode only.

Specified by:
superscriptMark in interface ListMaker
Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter
t - the actual super mark token
Throws:
TypesetterException - in case of an error
See Also:
ListMaker.superscriptMark( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, Typesetter, de.dante.extex.scanner.type.token.Token)

tab

public void tab(Context context,
                TokenSource source,
                Token t)
         throws TypesetterException,
                ConfigurationException
Description copied from interface: ListMaker
Treat a alignment tab character.

Specified by:
tab in interface ListMaker
Parameters:
context - the interpreter context
source - the source for new tokens
t - the actual tab token
Throws:
TypesetterException - in case of an error
ConfigurationException - in case of a configuration error
See Also:
ListMaker.tab( Context, TokenSource, de.dante.extex.scanner.type.token.Token)

toString

public java.lang.String toString()
See Also:
Object.toString()