public static void sh(String shadingObject,PdfObjectCache cache, GraphicsState gs,
boolean isPrinting, Map shadingColorspacesObjects, int pageNum,
PdfObjectReader currentPdfFile,
PdfPageData pageData, DynamicVectorRenderer current) {
PdfObject Shading= (PdfObject) cache.localShadings.get(shadingObject);
if(Shading==null){
Shading= (PdfObject) cache.globalShadings.get(shadingObject);
}
//workout shape
Shape shadeShape=null;
/**if(gs.CTM!=null){
int x=(int)gs.CTM[2][0];
int y=(int)gs.CTM[2][1];
int w=(int)gs.CTM[0][0];
if(w==0){
w=(int)gs.CTM[1][0];
}
if(w<0)
w=-w;
int h=(int)gs.CTM[1][1];
if(h==0)
h=(int)gs.CTM[0][1];
if(h<0)
h=-h;
shadeShape=new Rectangle(x,y,w,h);
}/**/
if(shadeShape==null)
shadeShape=gs.getClippingShape();
if(shadeShape==null && gs.CTM!=null && gs.CTM[0][1]>0 && gs.CTM[0][0]==0 && gs.CTM[1][1]==0){ //special case
int x=(int)gs.CTM[2][0];
int y=(int)gs.CTM[2][1];
int w=(int)gs.CTM[0][0];
if(w==0)
w=(int)gs.CTM[0][1];
if(w<0)
w=-w;
int h=(int)gs.CTM[1][1];
if(h==0)
h=(int)gs.CTM[1][0];
if(h<0)
h=-h;
//don't understand but works on example I have!
if(gs.CTM[1][0]<0){
x=x+(int)gs.CTM[1][0];
x=-x;
w=(int)gs.CTM[2][0]-x;
}
shadeShape=new Rectangle(x,y,w,h);
}
/**
* corner case for odd rotated shading
*/
if(shadeShape==null && gs.CTM[0][1]<0 && gs.CTM[1][0]<0){
int x=(int)-gs.CTM[0][1];
int y=(int)(gs.CTM[2][1]+gs.CTM[1][0]);
int w=(int)gs.CTM[2][0]-x;
int h=(int)-gs.CTM[1][0];
shadeShape=new Rectangle(x,y,w,h);
//System.out.println(">>"+tokenNumber+" "+shadingObject+" "+gs.getClippingShape());
}
/**
* corner case for odd rotated shading
*/
if(shadeShape==null && gs.CTM[0][0]>0 && gs.CTM[1][1]<0){
int x=(int)gs.CTM[2][0];
int h=(int)gs.CTM[1][1];
int y=(int)(gs.CTM[2][1]);
int w=(int)gs.CTM[0][0];
shadeShape=new Rectangle(x,y,w,h);
}
/**
* corner case for odd rotated shading
*/
if(shadeShape==null && gs.CTM[0][0]<0 && gs.CTM[1][1]>0){
int x=(int)gs.CTM[2][0];
int h=(int)gs.CTM[1][1];
int y=(int)(gs.CTM[2][1]);
int w=(int)gs.CTM[0][0];
shadeShape=new Rectangle(x,y,w,h);
// System.out.println(">>"+shadeShape.getBounds());
}
if(shadeShape==null)
shadeShape=new Rectangle(pageData.getMediaBoxX(pageNum),pageData.getMediaBoxY(pageNum),pageData.getMediaBoxWidth(pageNum),pageData.getMediaBoxHeight(pageNum));
/**
* generate the appropriate shading and then colour in the current clip with it
*/
try{
/**
* workout colorspace
**/
PdfObject ColorSpace=Shading.getDictionary(PdfDictionary.ColorSpace);
GenericColorSpace newColorSpace= ColorspaceFactory.getColorSpaceInstance(currentPdfFile, ColorSpace, shadingColorspacesObjects);
newColorSpace.setPrinting(isPrinting);