Class PDFunction

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

public abstract class PDFunction extends Object implements COSObjectable
This class represents a function in a PDF document.
  • Field Details

    • functionStream

      private PDStream functionStream
    • functionDictionary

      private COSDictionary functionDictionary
    • domain

      private COSArray domain
    • range

      private COSArray range
    • numberOfInputValues

      private int numberOfInputValues
    • numberOfOutputValues

      private int numberOfOutputValues
  • Constructor Details

    • PDFunction

      public PDFunction(COSBase function)
      Constructor.
      Parameters:
      function - The function stream.
  • Method Details

    • 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 COSDictionary getCOSObject()
      Returns the stream.
      Specified by:
      getCOSObject in interface COSObjectable
      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, never null.
      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 range specified.
      Returns:
      The number of output 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:
      rangeValues - 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:
      domainValues - The new domain values.
    • eval

      @Deprecated public COSArray eval(COSArray input) throws IOException
      Deprecated.
      Parameters:
      input - The array of input values for the function.
      Returns:
      The of outputs the function returns based on those inputs.
      Throws:
      IOException - if something went wrong.
    • eval

      public abstract float[] eval(float[] 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 - if something went wrong processing the function.
    • 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.
    • getDomainValues

      private COSArray getDomainValues()
      Returns all domains for the input values as COSArray. Required for all function types.
      Returns:
      the domains array.
    • clipToRange

      protected float[] clipToRange(float[] inputValues)
      Clip the given input values to the ranges.
      Parameters:
      inputValues - 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 - the to be interpolated value.
      xRangeMin - the min value of the x range
      xRangeMax - the max value of the x range
      yRangeMin - the min value of the y range
      yRangeMax - the max value of the y range
      Returns:
      the interpolated y value
    • toString

      public String toString()
      Overrides:
      toString in class Object