float[] range = null;
// read the function type (required)
PDFObject typeObj = obj.getDictRef ("FunctionType");
if (typeObj == null) {
throw new PDFParseException (
"No FunctionType specified in function!");
}
type = typeObj.getIntValue ();
// read the function's domain (required)
PDFObject domainObj = obj.getDictRef ("Domain");
if (domainObj == null) {
throw new PDFParseException ("No Domain specified in function!");
}
PDFObject[] domainAry = domainObj.getArray ();
domain = new float[domainAry.length];
for (int i = 0; i < domainAry.length; i++) {
domain[i] = domainAry[i].getFloatValue ();
}
// read the function's range (optional)
PDFObject rangeObj = obj.getDictRef ("Range");
if (rangeObj != null) {
PDFObject[] rangeAry = rangeObj.getArray ();
range = new float[rangeAry.length];
for (int i = 0; i < rangeAry.length; i++) {
range[i] = rangeAry[i].getFloatValue ();
}
}
// now create the acual function object
switch (type) {
case TYPE_0:
if (rangeObj == null) {
throw new PDFParseException (
"No Range specified in Type 0 Function!");
}
function = new FunctionType0 ();
break;
case TYPE_2:
function = new FunctionType2 ();
break;
case TYPE_3:
function = new FunctionType3 ();
break;
case TYPE_4:
if (rangeObj == null) {
throw new PDFParseException (
"No Range specified in Type 4 Function!");
}
function = new FunctionType4 ();
break;
default:
throw new PDFParseException (
"Unsupported function type: " + type);
}
// fill in the domain and optionally the range
function.setDomain (domain);