Unified Typesetting API M1-20040817

de.inghuimische.uta.test
Class SimpleTypesetter

java.lang.Object
  extended byde.inghuimische.uta.typeset.AbstractTypesetter
      extended byde.inghuimische.uta.typeset.ExtensibleTypesetter
          extended byde.inghuimische.uta.test.SimpleTypesetter
All Implemented Interfaces:
QManageable, ScriptListener, Typesetter

public class SimpleTypesetter
extends ExtensibleTypesetter
implements ScriptListener

A simple implementation of a typesetter providing no extra features. This typesetter is meant for testing purposes and does not calculate the correct embedding level right now. The class is currently only able to handle one embedding level.

Author:
Christian Ziesemer

Field Summary
 
Fields inherited from class de.inghuimische.uta.typeset.ExtensibleTypesetter
scripts
 
Fields inherited from class de.inghuimische.uta.typeset.AbstractTypesetter
embeddingLevels, features, previousEmbeddingLevel, previousScript
 
Constructor Summary
SimpleTypesetter(JustificationAlgorithm aJustifier, Script defaultScript)
          Constructs a new typesetter with given fallback script.
SimpleTypesetter(LinebreakAlgorithm aLinebreaker, JustificationAlgorithm aJustifier, Script aDefaultScript)
          Constructs a new typesetter with given typesetter and default script.
SimpleTypesetter(Script defaultScript)
          Constructs a not justifing typesetter with a first-fit linebreaker.
 
Method Summary
 Script addScript(Script aScript)
          Adds a new script to the typesetter and registers itself as a ScriptListener.
protected  int getEmbeddingLevelOrder(int charIndex, Glyph glyph)
          This typesetter does not support bidirectional text.
 GlyphFactory getGlyphFactory()
          Returns the glyph factory used by this typesetter.
protected  Iterator getItemIterator()
          Returns an iterator for iteration over all items.
 JustificationAlgorithm getJustificationAlgorithm()
          Returns the justification algorithm used.
 boolean getJustifyText()
          Tells whether to justify text or not.
 LinebreakAlgorithm getLinebreakAlgorithm()
          The linebreak algorithm used.
 Script getScript(int aChar, Glyph aGlyph)
          This implementation depends on a locale placed in the attributes of the glyph.
 void newItem(ScriptEvent e)
          Invoked when a script generated a new item.
 void setGlyphFactory(GlyphFactory glyphFactory)
          Sets the glyphFactory.
 void setJustifyText(boolean justifyText)
           
 void setLinebreakAlgorithm(FirstFitAlgorithm linebreaker)
          Sets the linebreak algorithm.
 EmbeddingLevel typeset(UtaAttributedString text)
          Typesets a piece of text.
 
Methods inherited from class de.inghuimische.uta.typeset.ExtensibleTypesetter
getScript, getScripts
 
Methods inherited from class de.inghuimische.uta.typeset.AbstractTypesetter
fixItemPositions, fixItemPositions, getActiveEmbeddingLevel, getFeatures, getRootLevel, typeset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTypesetter

public SimpleTypesetter(Script defaultScript)
Constructs a not justifing typesetter with a first-fit linebreaker.

Parameters:
defaultScript - The script used for typesetting.

SimpleTypesetter

public SimpleTypesetter(JustificationAlgorithm aJustifier,
                        Script defaultScript)
Constructs a new typesetter with given fallback script. A FirstFitAlgorithm is used for linebreaking.

Parameters:
defaultScript - The default script to use if no better could be found.

SimpleTypesetter

public SimpleTypesetter(LinebreakAlgorithm aLinebreaker,
                        JustificationAlgorithm aJustifier,
                        Script aDefaultScript)
Constructs a new typesetter with given typesetter and default script.

Parameters:
aLinebreaker - The LinebreakAlgortihm to use.
aDefaultScript - The default/fallback script.
Method Detail

getLinebreakAlgorithm

public LinebreakAlgorithm getLinebreakAlgorithm()
Description copied from interface: Typesetter
The linebreak algorithm used.

Specified by:
getLinebreakAlgorithm in interface Typesetter
Returns:
The linebreaker used to split paragraphs up into several lines.

getJustificationAlgorithm

public JustificationAlgorithm getJustificationAlgorithm()
Description copied from interface: Typesetter
Returns the justification algorithm used. Justification is performed after linebreaking.

Specified by:
getJustificationAlgorithm in interface Typesetter
Returns:
The justification algorithm used.

typeset

public EmbeddingLevel typeset(UtaAttributedString text)
Description copied from interface: Typesetter
Typesets a piece of text. The text has to be normalized after Unicode NFKC. This is compatibility decomposition, followed by canonical composition. Therefore compatibility ligatures like U+FB03 (ffi-Ligature) are not preserved, so that simple script implementations do not have to care about all possible substitutions.

Hints which substring should be substituted by a ligature may be embedded in the attributes. Complex script implementations may consult a dictionary when a ligature has to be formed in a word an when not.

Extensive analysis needs to be done with the complete text. Therefore there is no character-by-character based typeset method in this interface.

The method returns the embedding level with the lowest order produced during typesetting. It contains all sub-levels, glyphs and other boxes generated during typesetting.

Specified by:
typeset in interface Typesetter
Parameters:
text - The text to typeset.
Returns:
The embedding level with the lowest order produced during typesetting.

getScript

public Script getScript(int aChar,
                        Glyph aGlyph)
This implementation depends on a locale placed in the attributes of the glyph. The key must be AttributedCharacterIterator.Attribute.LANGUAGE and point to an object of type Locale. If no such attribute exists the default script is returned.

Specified by:
getScript in class AbstractTypesetter

getGlyphFactory

public GlyphFactory getGlyphFactory()
Returns the glyph factory used by this typesetter.

Specified by:
getGlyphFactory in class AbstractTypesetter
Returns:
The glyph factory used by this typesetter.

setLinebreakAlgorithm

public void setLinebreakAlgorithm(FirstFitAlgorithm linebreaker)
Sets the linebreak algorithm.

Parameters:
linebreaker - The linebreaker to set.

setGlyphFactory

public void setGlyphFactory(GlyphFactory glyphFactory)
Sets the glyphFactory.

Parameters:
glyphFactory - The glyphFactory to set.

addScript

public Script addScript(Script aScript)
Adds a new script to the typesetter and registers itself as a ScriptListener. If an old script is replaced by the new script, the typesetter removes itself from the old script as script listener.

Specified by:
addScript in interface Typesetter
Overrides:
addScript in class ExtensibleTypesetter
See Also:
ExtensibleTypesetter.addScript(Script), Typesetter.addScript(Script), ScriptListener, Script.addScriptListener(ScriptListener)

newItem

public void newItem(ScriptEvent e)
Invoked when a script generated a new item. Informs the linebreaker of the newly generated item.

Specified by:
newItem in interface ScriptListener
Parameters:
e - The script event encapsulating the newly generated item. The item can be retrieved by calling ScriptEvent.getNewItem().

getEmbeddingLevelOrder

protected int getEmbeddingLevelOrder(int charIndex,
                                     Glyph glyph)
This typesetter does not support bidirectional text. This method always returns 0.

Specified by:
getEmbeddingLevelOrder in class AbstractTypesetter
Parameters:
charIndex - The index of the char from the unmodified input of AbstractTypesetter.typeset(UtaCharacterIterator).
glyph - The glyph representing the index.
Returns:
Always 0.

getJustifyText

public boolean getJustifyText()
Description copied from class: AbstractTypesetter
Tells whether to justify text or not.

Specified by:
getJustifyText in class AbstractTypesetter
Returns:
Returns the justifyText.

setJustifyText

public void setJustifyText(boolean justifyText)
Parameters:
justifyText - The justifyText to set.

getItemIterator

protected Iterator getItemIterator()
Description copied from class: AbstractTypesetter
Returns an iterator for iteration over all items.

Specified by:
getItemIterator in class AbstractTypesetter
Returns:
An iterator for iteration over all items.

Unified Typesetting API M1-20040817


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