org.extex.unit.color
Class ColorPrimitive

java.lang.Object
  extended by org.extex.interpreter.type.AbstractCode
      extended by org.extex.interpreter.type.AbstractAssignment
          extended by org.extex.unit.color.AbstractColor
              extended by org.extex.unit.color.ColorPrimitive
All Implemented Interfaces:
java.io.Serializable, Code, ColorConvertible, Showable, Theable

public class ColorPrimitive
extends AbstractColor

This class provides an implementation for the primitive \color.

The Primitive \color

The primitive \color sets the current color value to the value given. The value can be any color specification for one of the supported color models.

The color models of ExTeX use components of two bytes. This means that values from 0 to 65535 can be stored in each component. The external representation is a floating point number in the range from 0.0 to 1.0.

The color models of ExTeX support an alpha channel.

The RGB Color Model

The RGB color model provides three values for the red, green, and blue channel. Each is given as floating point number from 0.0 to 1.0.

The CMYK Color Model

The CMYK color model provides four values for cyan, magenta, yellow, and black channel. Each is given as floating point number from 0.0 to 1.0.

The Grayscale Model

The gray-scale color model provides one value for the gray channel. It is given as floating point number from 0.0 to 1.0.

The HSV Color Model

The HSV color model provides three values for the hue, saturation, and value channel. Each is given as floating point number from 0.0 to 1.0.

The Alpha Channel

The alpha channel determines the opactivity of the color. A value of 0 means that the given color completely overwrites the underlying texture. A value of 1.0 is the maximal admissible alpha value. In this case the color is in fact invisible. In between the background shines through to the degree of the alpha value.

Note that the alpha channel may not be supported by any output device. In such a case it is up to the back-end driver to make best use of the alpha value or ignore it at all.

Syntax

The formal description of this primitive is the following:
    ⟨color⟩
      → ⟨prefix⟩ \color ⟨alpha⟩ ⟨color⟩

    ⟨prefix⟩
      →
       |  \global

    ⟨alpha⟩
      →
       |  alpha ⟨number⟩

    ⟨color⟩
      → { ⟨color value⟩ ⟨color value⟩ ⟨color value⟩ }
       |  rgb { ⟨color value⟩ ⟨color value⟩ ⟨color value⟩ }
       |  gray { ⟨color value⟩ }
       |  cmyk { ⟨color value⟩ ⟨color value⟩ ⟨color value⟩ ⟨color value⟩ }
       |  hsv { ⟨color value⟩ ⟨color value⟩ ⟨color value⟩ }
       |  ⟨color convertible⟩

    ⟨color value⟩
      → ⟨number⟩  

Examples

    \color{\r \b \g}  

    \color gray {\gray}  

    \color rgb {\r \b \g}  

    \color rgb {1 .2 .3333}  

    \color hsv {\h \s \v}  

    \color alpha 500 rgb {\r \b \g} 

Version:
$Revision: 6447 $
Author:
Gerd Neugebauer
See Also:
Serialized Form

Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
ColorPrimitive(CodeToken token)
          Creates a new object.
 
Method Summary
 void assign(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          The method assign is the core of the functionality of execute().
 Color convertColor(Context context, TokenSource source, Typesetter typesetter)
          This method converts something into a color.
 
Methods inherited from class org.extex.unit.color.AbstractColor
show, the
 
Methods inherited from class org.extex.interpreter.type.AbstractAssignment
execute
 
Methods inherited from class org.extex.interpreter.type.AbstractCode
getLocalizer, getName, getToken, isIf, isOuter, readResolve, toString, toText, toText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values
Constructor Detail

ColorPrimitive

public ColorPrimitive(CodeToken token)
Creates a new object.

Parameters:
token - the initial token for the primitive
Method Detail

assign

public void assign(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws ConfigurationException,
                   HelpingException,
                   TypesetterException
The method assign is the core of the functionality of execute(). This method is preferable to execute() since the execute() method provided in this class takes care of \afterassignment and \globaldefs as well.

Specified by:
assign in class AbstractAssignment
Parameters:
prefix - the prefix controlling the execution
context - the interpreter context
source - the token source
typesetter - the typesetter
Throws:
ConfigurationException - in case of an configuration error
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
AbstractAssignment.assign( org.extex.interpreter.Flags, org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

convertColor

public Color convertColor(Context context,
                          TokenSource source,
                          Typesetter typesetter)
                   throws HelpingException
This method converts something into a color. It might be necessary to read further tokens to determine which value to use. For instance an additional register number might be required. In this case the additional arguments Context and TokenSource can be used.

Parameters:
context - the interpreter context
source - the source for new tokens
typesetter - the typesetter to use for conversion
Returns:
the converted value
Throws:
HelpingException - in case of an error
See Also:
ColorConvertible.convertColor( org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)