de.dante.extex.interpreter.primitives.color
Class ColorPrimitive

java.lang.Object
  extended byde.dante.extex.interpreter.type.AbstractCode
      extended byde.dante.extex.interpreter.type.AbstractAssignment
          extended byde.dante.extex.interpreter.primitives.color.AbstractColor
              extended byde.dante.extex.interpreter.primitives.color.ColorPrimitive
All Implemented Interfaces:
Code, ColorConvertible, Localizable, java.io.Serializable, 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 aa 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 opactness 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: 1.15 $
Author:
Gerd Neugebauer
See Also:
Serialized Form

Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
ColorPrimitive(java.lang.String name)
          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 de.dante.extex.interpreter.primitives.color.AbstractColor
show, the
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractAssignment
execute
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractCode
enableLocalization, getLocalizer, getName, isIf, isOuter, printable, printableControlSequence, readResolve, setName, toString
 
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(java.lang.String name)
Creates a new object.

Parameters:
name - the name for debugging
Method Detail

assign

public void assign(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws InterpreterException
Description copied from class: AbstractAssignment
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:
InterpreterException - in case of an error
See Also:
AbstractAssignment.assign( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

convertColor

public Color convertColor(Context context,
                          TokenSource source,
                          Typesetter typesetter)
                   throws InterpreterException
Description copied from interface: ColorConvertible
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:
InterpreterException - in case of an error
See Also:
ColorConvertible.convertColor( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)