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 RADIAL_SHADING:
shader = new ShaderType3();
break;
case FUNCTION_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) {
PDFObject[] rectObj = bboxObj.getArray();
float minX = rectObj[0].getFloatValue();
float minY = rectObj[1].getFloatValue();
float maxX = rectObj[2].getFloatValue();
float maxY = rectObj[3].getFloatValue();