/**
* convert stream into an DynamicVector object we can then draw onto screen or tile
*/
ObjectStore localStore = new ObjectStore();
DynamicVectorRenderer glyphDisplay = decodePatternContent(PatternObj, matrix, streamData, localStore);
//get the image
BufferedImage image=glyphDisplay.getSingleImagePattern();
/**
* unashamed hack for very odd file
* Investigate when more examples/time
* (customers-june2011/10664.pdf)
*/
//float[] BBox=PatternObj.getFloatArray(PdfDictionary.BBox);
if(inputs!=null && inputs[0]<1.5 && inputs[3]<1.5 && inputs[1]==0 && inputs[2]==0 &&(image!=null || (rawXStep==-32768 && rawYStep==-32768))){//|| (BBox!=null && rawXStep==BBox[2] && rawYStep==BBox[3])){
//if((rawXStep==-32768 && rawYStep==-32768)){//|| (BBox!=null && rawXStep==BBox[2] && rawYStep==BBox[3])){
//turn upside down
AffineTransform image_at2 =new AffineTransform();
image_at2.scale(1,-1);
image_at2.translate(0,-image.getHeight());
AffineTransformOp invert3= new AffineTransformOp(image_at2, null);
image = invert3.filter(image,null);
//ensure ARGB to avoid issues if we draw to BufferedImage
if(image.getType()!=BufferedImage.TYPE_INT_ARGB)
image=ColorSpaceConvertor.convertToARGB(image);
//return as pattern to use
return new PdfTexturePaint(image, new Rectangle((int) (inputs[4]-image.getWidth()),(int)(inputs[5]-image.getHeight()),image.getWidth(),image.getHeight()));
}
/**
* if image is generated larger than slot we draw it into we
* will lose definition. To avoid this, we draw at full size and
* scale only when drawn onto page
*/
//workout unscaled tile size
float rawWidth=0,rawHeight=0;
boolean isDownSampled=false;
if(matrix!=null){
rawWidth=matrix[0][0];
if(rawWidth==0)
rawWidth=matrix[0][1];
if(rawWidth<0)
rawWidth=-rawWidth;
rawHeight=matrix[1][1];
if(rawHeight==0)
rawHeight=matrix[1][0];
if(rawHeight<0)
rawHeight=-rawHeight;
}
if(matrix!=null){ //this scales/rotated image onto tile - Java cannot handle this so we do it onto an unrotated tile
//image scaled up to fit so create large tile and then draw upscaled version onto it
if(inputs!=null && inputs[0]>1 && inputs[3]>1 && !isRotated){
img=new BufferedImage((int)(XStep*rawWidth),(int)(YStep*rawHeight), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2=img.createGraphics();
g2.setClip(new Rectangle(0,0,img.getWidth(),img.getHeight()));
glyphDisplay.setG2(g2);
glyphDisplay.paint(null,new AffineTransform(matrix[0][0], matrix[0][1], matrix[1][0],matrix[1][1], inputs[4],-inputs[5]/2) ,null);
}else{ //buffer onto unrotated tile
BufferedImage tileImg=null; //tile for image as faster to draw ONCE and then replicate image
/**
* workout dx,dy and ensure positive and scaled
*/
dx=matrix[0][0];
dy=matrix[1][1];
if(dx==0)
dx=matrix[0][1];
if(dx<0)
dx=-dx;
if(dy==0)
dy=matrix[1][0];
if(dy<0)
dy=-dy;
dx=dx*XStep;
dy=dy*YStep;
/**
* workout size required for image
*/
int imgW=XStep,imgH=YStep; //default values for tile size
if(!isRotated){
/**
* special cases
*/
if(isUpsideDown){
int xCount=(int)(XStep/dx),yCount=(int)(YStep/dy);
if(xCount>0 && yCount>0){
imgW=(int)((xCount+1)*dx);
imgH=(int)((yCount+1)*dy);
XStep=imgW;
YStep=imgH;
}
}else if(inputs!=null && inputs[0]>0 && inputs[0]<1 && inputs[3]>0 && inputs[3]<1){
imgW=(int)(dx);
imgH=(int)(dy);
if(imgH==0)
imgH=1;
//workout offsets
input_dxx=(int)inputs[4];
if(input_dxx>XStep){
while(input_dxx>0){
input_dxx=input_dxx-XStep;
if(input_dxx==0)
break;
}
input_dxx=input_dxx/2;
}
//workout offsets
input_dyy=(int)inputs[5];
if(input_dyy>imgH){
while(input_dyy>0)
input_dyy=input_dyy-imgH;
}
}
if(isDownSampled){
img=new BufferedImage((int)(rawWidth+.5f),(int)(rawHeight+.5f),BufferedImage.TYPE_INT_ARGB);
imageScale=AffineTransform.getScaleInstance(XStep/rawWidth,YStep/rawHeight);
}else{
//a few file generate values less than 1 so code defensively for this case
if(imgW<1 || imgH<1)
img=new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
else
img=new BufferedImage(imgW,imgH,BufferedImage.TYPE_INT_ARGB);
}
Graphics2D g2=img.createGraphics();
AffineTransform defaultAf=g2.getTransform();
g2.setClip(new Rectangle(0,0,img.getWidth(),img.getHeight()));
/**
* allow for tile not draw from 0,0
*/
int startX=0;
Rectangle actualTileRect=glyphDisplay.getOccupiedArea().getBounds();
int tileW,tileH;
int dxx=0,dyy=0;
if(actualTileRect.x<0){
tileW=actualTileRect.width-actualTileRect.x;
dxx=actualTileRect.x;
}else
tileW=actualTileRect.width+actualTileRect.x;
if(actualTileRect.y<0){
tileH=actualTileRect.height-actualTileRect.y;
dyy=actualTileRect.y;
}else
tileH=actualTileRect.height+actualTileRect.y;
if(tileH==0)
tileH=1;
if(tesslateOntoImage){
//a few file generate values less than 1 so code defensively for this case
if(tileW<1 || tileH<1)
tileImg=new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
else
tileImg=new BufferedImage(tileW, tileH, BufferedImage.TYPE_INT_ARGB);
Graphics2D tileG2=tileImg.createGraphics();
tileG2.translate(-dxx,-dyy);
glyphDisplay.setG2(tileG2);
glyphDisplay.paint(null,null,null);
}
int rectX=actualTileRect.x;
if(rectX<0 && !tesslateOntoImage)
startX= (int) (-rectX*matrix[0][0]);
//if tile is smaller than Xstep,Ystep, tesselate to fill
float max=YStep;
if(tesslateOntoImage)
max=YStep+(tileImg.getHeight()*2);
//fix for odd pattern on phonbingo
int min=0;
if(matrix[1][1]<0)
min= (int) (-max/2);
//adjustment for pattern on customers-june2011/Verizon PowerPoint Template.pdf
if(needsAdjusting && matrix[0][0]>0 && matrix[1][1]<0)
min=min+(pageHeight-pageWidth);
for(float y=min;y<max;y=y+dy){
for(float x=startX;x<XStep;x=x+dx){
if(isUpsideDown)
g2.translate(x,-y);
else
g2.translate(x,y);
if(tesslateOntoImage){
AffineTransform tileAff=new AffineTransform();
ColorSpaceConvertor.drawImage(g2, tileImg, tileAff, null);
}else{
glyphDisplay.setG2(g2);
glyphDisplay.paint(null,imageScale,null);
}
g2.setTransform(defaultAf);
}
}
}
}
}else{ //no matrix value so just draw onto tile
if(isDownSampled){
img=new BufferedImage((int)(rawWidth+.5f),(int)(rawHeight+.5f),BufferedImage.TYPE_INT_ARGB); //.5 to allow for rounding of decimal
imageScale=AffineTransform.getScaleInstance(XStep/rawWidth,YStep/rawHeight);
}else
img=new BufferedImage(XStep,YStep,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2=img.createGraphics();
glyphDisplay.setG2(g2);
glyphDisplay.paint(null,null,null);
//flip now once for speed if upside down
if(isUpsideDown && img.getHeight()>1){
AffineTransform flip=new AffineTransform();
flip.translate(0, img.getHeight());
flip.scale(1, -1);
AffineTransformOp invert =new AffineTransformOp(flip,ColorSpaces.hints);
img=invert.filter(img,null);
}
}
//now delete any stored images used in content
localStore.flush();
/**
* create paint using image or decoded content if rotated
*/
if(img!=null)