org.apache.pdfbox.pdmodel.common.function
Class PDFunction

java.lang.Object
  extended by org.apache.pdfbox.pdmodel.common.function.PDFunction
All Implemented Interfaces:
COSObjectable
Direct Known Subclasses:
PDFunctionType0, PDFunctionType2, PDFunctionType3, PDFunctionType4

public abstract class PDFunction
extends Object
implements COSObjectable

This class represents a function in a PDF document.

Version:
$Revision: 1.3 $
Author:
Ben Litchfield

Constructor Summary
PDFunction(COSBase function)
          Constructor.
 
Method Summary
protected  COSArray clipToRange(COSArray inputArray)
          Clip the given input values to the ranges.
protected  float clipToRange(float x, float rangeMin, float rangeMax)
          Clip the given input value to the given range.
static PDFunction create(COSBase function)
          Create the correct PD Model function based on the COS base function.
abstract  COSArray eval(COSArray input)
          Evaluates the function at the given input.
 COSBase getCOSObject()
          Returns the COSObject.
 COSDictionary getDictionary()
          Returns the stream.
 PDRange getDomainForInput(int n)
          This will get the range for a certain input parameter.
abstract  int getFunctionType()
          Returns the function type.
 int getNumberOfInputParameters()
          This will get the number of input parameters that have a domain specified.
 int getNumberOfOutputParameters()
          This will get the number of output parameters that have a range specified.
protected  PDStream getPDStream()
          Returns the underlying PDStream.
 PDRange getRangeForOutput(int n)
          This will get the range for a certain output parameters.
protected  COSArray getRangeValues()
          Returns all ranges for the output values as COSArray .
protected  float interpolate(float x, float xRangeMin, float xRangeMax, float yRangeMin, float yRangeMax)
          For a given value of x, interpolate calculates the y value on the line defined by the two points (xRangeMin , xRangeMax ) and (yRangeMin , yRangeMax ).
 void setDomainValues(COSArray domainValues)
          This will set the domain values.
 void setRangeValues(COSArray rangeValues)
          This will set the range values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFunction

public PDFunction(COSBase function)
Constructor.

Parameters:
functionStream - The function stream.
Method Detail

getFunctionType

public abstract int getFunctionType()
Returns the function type. Possible values are: 0 - Sampled function 2 - Exponential interpolation function 3 - Stitching function 4 - PostScript calculator function

Returns:
the function type.

getCOSObject

public COSBase getCOSObject()
Returns the COSObject. Convert this standard java object to a COS object.

Specified by:
getCOSObject in interface COSObjectable
Returns:
The cos object that matches this Java object.

getDictionary

public COSDictionary getDictionary()
Returns the stream.

Returns:
The stream for this object.

getPDStream

protected PDStream getPDStream()
Returns the underlying PDStream.

Returns:
The stream.

create

public static PDFunction create(COSBase function)
                         throws IOException
Create the correct PD Model function based on the COS base function.

Parameters:
function - The COS function dictionary.
Returns:
The PDModel Function object.
Throws:
IOException - If we are unable to create the PDFunction object.

getNumberOfOutputParameters

public int getNumberOfOutputParameters()
This will get the number of output parameters that have a range specified. A range for output parameters is optional so this may return zero for a function that does have output parameters, this will simply return the number that have the rnage specified.

Returns:
The number of input parameters that have a range specified.

getRangeForOutput

public PDRange getRangeForOutput(int n)
This will get the range for a certain output parameters. This is will never return null. If it is not present then the range 0 to 0 will be returned.

Parameters:
n - The output parameter number to get the range for.
Returns:
The range for this component.

setRangeValues

public void setRangeValues(COSArray rangeValues)
This will set the range values.

Parameters:
range - The new range values.

getNumberOfInputParameters

public int getNumberOfInputParameters()
This will get the number of input parameters that have a domain specified.

Returns:
The number of input parameters that have a domain specified.

getDomainForInput

public PDRange getDomainForInput(int n)
This will get the range for a certain input parameter. This is will never return null. If it is not present then the range 0 to 0 will be returned.

Parameters:
n - The parameter number to get the domain for.
Returns:
The domain range for this component.

setDomainValues

public void setDomainValues(COSArray domainValues)
This will set the domain values.

Parameters:
range - The new domain values.

eval

public abstract COSArray eval(COSArray input)
                       throws IOException
Evaluates the function at the given input. ReturnValue = f(input)

Parameters:
input - The array of input values for the function. In many cases will be an array of a single value, but not always.
Returns:
The of outputs the function returns based on those inputs. In many cases will be an array of a single value, but not always.
Throws:
IOException

getRangeValues

protected COSArray getRangeValues()
Returns all ranges for the output values as COSArray . Required for type 0 and type 4 functions

Returns:
the ranges array.

clipToRange

protected COSArray clipToRange(COSArray inputArray)
Clip the given input values to the ranges.

Parameters:
inputArray - the input values
Returns:
the clipped values

clipToRange

protected float clipToRange(float x,
                            float rangeMin,
                            float rangeMax)
Clip the given input value to the given range.

Parameters:
x - the input value
rangeMin - the min value of the range
rangeMax - the max value of the range
Returns:
the clipped value

interpolate

protected float interpolate(float x,
                            float xRangeMin,
                            float xRangeMax,
                            float yRangeMin,
                            float yRangeMax)
For a given value of x, interpolate calculates the y value on the line defined by the two points (xRangeMin , xRangeMax ) and (yRangeMin , yRangeMax ).

Parameters:
x -
xRangeMin -
xRangeMax -
yRangeMin -
yRangeMax -
Returns:
the interpolated y value


Copyright © 2002-2010 The Apache Software Foundation. All Rights Reserved.