if (shader != null) {
return shader;
}
// read the type (required)
PDFObject typeObj = shaderObj.getDictRef("ShadingType");
if (typeObj == null) {
throw new PDFParseException("No shader type defined!");
}
int type = typeObj.getIntValue();
// create the shader
switch (type) {
case AXIAL_SHADING:
shader = new ShaderType2();
break;
case FUNCTION_SHADING:
case RADIAL_SHADING:
case FREE_FORM_SHADING:
case LATTICE_SHADING:
case COONS_PATCH_MESH_SHADING:
case TENSOR_PRODUCTS_MESH_SHADING:
default:
throw new PDFParseException("Unsupported shader type: " + type);
}
// read the color space (required)
PDFObject csObj = shaderObj.getDictRef("ColorSpace");
if (csObj == null) {
throw new PDFParseException("No colorspace defined!");
}
PDFColorSpace cs = PDFColorSpace.getColorSpace(csObj, resources);
shader.setColorSpace(cs);
// read the background color (optional)
PDFObject bgObj = shaderObj.getDictRef("Background");
if (bgObj != null) {
PDFObject[] bgObjs = bgObj.getArray();
float[] bgArray = new float[bgObjs.length];
for (int i = 0; i < bgArray.length; i++) {
bgArray[i] = bgObjs[i].getFloatValue();
}
PDFPaint paint = cs.getPaint(bgArray);
shader.setBackground(paint);
}
// read the bounding box (optional)
PDFObject bboxObj = shaderObj.getDictRef("BBox");
if (bboxObj != null) {
shader.setBBox(PDFFile.parseNormalisedRectangle(bboxObj));
}
// parse the shader-specific attributes