float strokeOpacity=1.0f;
float x,y ;
int iCount=0,cCount=0,sCount=0,fsCount=-1,lwCount=0,afCount=-1,tCount=0,stCount=0,
fillCount=0,strokeCount=0,trCount=0,opCount=0,
stringCount=0;//note af is 1 behind!
PdfPaint textStrokeCol=null,textFillCol=null,fillCol=null,strokeCol = null;
Stroke currentStroke=null;
//if we reuse image this is pointer to live image
int imageUsed;
if(colorsLocked){
strokeCol=this.strokeCol;
fillCol=this.fillCol;
}
//setup first time something to highlight
if(highlightsNeedToBeGenerated && areas!=null && highlights!=null)
generateHighlights(g2,count, objectTypes,pageObjects, a,b,c,d,afValues1,afValues2,afValues3,afValues4,fsValues,fontBounds);
/**
* now draw all shapes
*/
for(int i=0;drawPDFShapes && i<count;i++){
// if(i>4800)
//break;
boolean ignoreItem=false;
type=objectTypes[i];
//ignore items flagged as deleted
if(type== DynamicVectorRenderer.DELETED_IMAGE)
continue;
Rectangle currentArea=null;
//exit if later paint recall
if(currentThreadID!=paintThreadID){
paintThreadCount--;
return null;
}
if(type>0){
x=x_coord[i];
y=y_coord[i];
currentObject=pageObjects[i];
//swap in replacement image
if(type==DynamicVectorRenderer.REUSED_IMAGE){
type=DynamicVectorRenderer.IMAGE;
imageUsed= (Integer) currentObject;
currentObject=pageObjects[imageUsed];
}else
imageUsed=-1;
/**
* workout area occupied by glyf
*/
if(currentArea==null)
currentArea = getObjectArea(afValues1, fsValues, afValues2,afValues3, afValues4, pageObjects, areas, type, x, y,fsCount, afCount, i);
ignoreItem=false;
//see if we need to draw
if(currentArea!=null){
//was glyphArea, changed back to currentArea to fix highlighting issue in Sams files.
//last width test for odd print issue in phonobingo
if (type < 7 && (userAnnot != null) && ((!userAnnot.intersects(currentArea)))&& currentArea.width>0) {
ignoreItem = true;
}
}
// }else if((optimiseDrawing)&&(rotation==0)&&(dirtyRegion!=null)&&(type!=DynamicVectorRenderer.STROKEOPACITY)&&
// (type!=DynamicVectorRenderer.FILLOPACITY)&&(type!=DynamicVectorRenderer.CLIP)
// &&(currentArea!=null)&&
// ((!dirtyRegion.intersects(currentArea))))
// ignoreItem=true;
if(ignoreItem || (lastItemPainted!=-1 && i<lastItemPainted)){
//keep local counts in sync
switch (type) {
case DynamicVectorRenderer.SHAPE:
sCount++;
break;
case DynamicVectorRenderer.IMAGE:
iCount++;
break;
case DynamicVectorRenderer.REUSED_IMAGE:
iCount++;
break;
case DynamicVectorRenderer.CLIP:
cCount++;
break;
case DynamicVectorRenderer.FONTSIZE:
fsCount++;
break;
case DynamicVectorRenderer.LINEWIDTH:
lwCount++;
break;
case DynamicVectorRenderer.TEXTCOLOR:
tCount++;
break;
case DynamicVectorRenderer.FILLCOLOR:
fillCount++;
break;
case DynamicVectorRenderer.STROKECOLOR:
strokeCount++;
break;
case DynamicVectorRenderer.STROKE:
stCount++;
break;
case DynamicVectorRenderer.TR:
trCount++;
break;
}
}else{
if(!isInitialised && !stopG2setting){
//set hints to produce high quality image
g2.setRenderingHints(hints);
isInitialised=true;
}
paintedCount++;
if(currentTR==GraphicsState.INVISIBLE){
needsHighlights = true;
}
Rectangle highlight = null;
switch (type) {
case DynamicVectorRenderer.SHAPE:
if(debug)
System.out.println("Shape");
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
Shape s=null;
if(endItem!=-1 && endItem<i){
s = g2.getClip();
g2.setClip(defaultClip);
}
renderShape(defaultClip,fillType[sCount],strokeCol,fillCol, currentStroke,(Shape)currentObject,strokeOpacity,fillOpacity);
if(endItem!=-1 && endItem<i)
g2.setClip(s);
sCount++;
break;
case DynamicVectorRenderer.TEXT:
if(debug)
System.out.println("Text");
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
if(!invertHighlight)
highlight = setHighlightForGlyph(currentArea,highlights);
if(hasOCR && highlight!=null){
String key=highlight.x+" "+highlight.y;
if(ocr_used.get(key)==null){
ocr_used.put(key,"x"); //avoid multiple additions
ocr_highlights.addElement(highlight);
}
}
AffineTransform def=g2.getTransform();
renderHighlight(highlight, g2);
g2.transform(new AffineTransform(afValues1[afCount],afValues2[afCount],-afValues3[afCount],-afValues4[afCount],x,y));
renderText(x,y, currentTR,(Area)currentObject, highlight, textStrokeCol,textFillCol,strokeOpacity,fillOpacity);
g2.setTransform(def);
break;
case DynamicVectorRenderer.TRUETYPE:
if(debug)
System.out.println("Truetype");
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
//hack to fix exceptions in a PDF using this code to create ReadOnly image
if(afCount==-1)
break;
AffineTransform aff=new AffineTransform(afValues1[afCount],afValues2[afCount],afValues3[afCount],afValues4[afCount],x,y);
if(!invertHighlight)
highlight = setHighlightForGlyph(currentArea,highlights);
if(hasOCR && highlight!=null){
String key=highlight.x+" "+highlight.y;
if(ocr_used.get(key)==null){
ocr_used.put(key,"x"); //avoid multiple additions
ocr_highlights.addElement(highlight);
}
}
renderHighlight(highlight, g2);
renderEmbeddedText(currentTR,currentObject,DynamicVectorRenderer.TRUETYPE,aff,highlight,textStrokeCol,textFillCol,strokeOpacity,fillOpacity,lineWidth);
break;
case DynamicVectorRenderer.TYPE1C:
if(debug)
System.out.println("Type1c");
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
aff=new AffineTransform(afValues1[afCount],afValues2[afCount],afValues3[afCount],afValues4[afCount],x,y);
if(!invertHighlight)
highlight = setHighlightForGlyph(currentArea,highlights);
if(hasOCR && highlight!=null){
String key=highlight.x+" "+highlight.y;
if(ocr_used.get(key)==null){
ocr_used.put(key,"x"); //avoid multiple additions
ocr_highlights.addElement(highlight);
}
}
renderHighlight(highlight, g2);
renderEmbeddedText(currentTR,currentObject,DynamicVectorRenderer.TYPE1C,aff,highlight,textStrokeCol,textFillCol,strokeOpacity,fillOpacity,lineWidth);
break;
case DynamicVectorRenderer.TYPE3:
if(debug)
System.out.println("Type3");
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
aff=new AffineTransform(afValues1[afCount],afValues2[afCount],afValues3[afCount],afValues4[afCount],x,y);
if(!invertHighlight)
highlight = setHighlightForGlyph(currentArea,highlights);
if(hasOCR && highlight!=null){
String key=highlight.x+" "+highlight.y;
if(ocr_used.get(key)==null){
ocr_used.put(key,"x"); //avoid multiple additions
ocr_highlights.addElement(highlight);
}
}
renderHighlight(highlight, g2);
renderEmbeddedText(currentTR,currentObject,DynamicVectorRenderer.TYPE3,aff,highlight, textStrokeCol,textFillCol,strokeOpacity,fillOpacity,lineWidth);
break;
case DynamicVectorRenderer.IMAGE:
if(newClip){
RenderUtils.renderClip(clipToUse, dirtyRegion,defaultClip,g2);
newClip=false;
}
renderImage(afValues1, afValues2, afValues3,afValues4, pageObjects, imageOptions,currentObject, fillOpacity, x, y, iCount, afCount, imageUsed, i);
iCount++;
break;
case DynamicVectorRenderer.CLIP:
clipToUse=pageClips[cCount];
newClip=true;
cCount++;
break;
case DynamicVectorRenderer.AF:
afCount++;
break;
case DynamicVectorRenderer.FONTSIZE:
fsCount++;
break;
case DynamicVectorRenderer.LINEWIDTH:
lineWidth=lwValues[lwCount];
lwCount++;
break;
case DynamicVectorRenderer.TEXTCOLOR:
if(debug)
System.out.println("TextCOLOR");
textFillType=textFill[tCount];
if(textFillType==GraphicsState.STROKE)
textStrokeCol=(PdfPaint) text_color[tCount];
else
textFillCol=(PdfPaint) text_color[tCount];
tCount++;
break;
case DynamicVectorRenderer.FILLCOLOR:
if(debug)
System.out.println("FillCOLOR");
if(!colorsLocked)
fillCol=(PdfPaint) fill_color[fillCount];
fillCount++;
break;
case DynamicVectorRenderer.STROKECOLOR:
if(debug)
System.out.println("StrokeCOL");
if(!colorsLocked){
strokeCol=(PdfPaint)stroke_color[strokeCount];
if(strokeCol!=null)
strokeCol.setScaling(cropX,cropH,scaling,0 ,0);
}
strokeCount++;
break;
case DynamicVectorRenderer.STROKE:
currentStroke=(Stroke)stroke[stCount];
if(debug)
System.out.println("STROKE");
stCount++;
break;
case DynamicVectorRenderer.TR:
if(debug)
System.out.println("TR");
currentTR=TRvalues[trCount];
trCount++;
break;
case DynamicVectorRenderer.STROKEOPACITY:
if(debug)
System.out.println("Stroke Opacity "+opacity[opCount]+" opCount="+opCount);
strokeOpacity=opacity[opCount];
opCount++;
break;
case DynamicVectorRenderer.FILLOPACITY:
if(debug)
System.out.println("Set Fill Opacity "+opacity[opCount]+" count="+opCount);
fillOpacity=opacity[opCount];
opCount++;
break;
case DynamicVectorRenderer.STRING:
Shape s1 = g2.getClip();
g2.setClip(defaultClip);
AffineTransform defaultAf=g2.getTransform();
String displayValue=(String)currentObject;
double[] af=new double[6];
g2.getTransform().getMatrix(af);
if(af[2]!=0)
af[2]=-af[2];
if(af[3]!=0)
af[3]=-af[3];
g2.setTransform(new AffineTransform(af));
Font javaFont=(Font) javaObjects[stringCount];
g2.setFont(javaFont);
if((currentTR & GraphicsState.FILL)==GraphicsState.FILL){
if(textFillCol!=null)
textFillCol.setScaling(cropX,cropH,scaling,0 ,0);
if(customColorHandler !=null){
customColorHandler.setPaint(g2,textFillCol,pageNumber, isPrinting);
}else if(PdfDecoder.Helper!=null){
PdfDecoder.Helper.setPaint(g2, textFillCol, pageNumber, isPrinting);
}else
g2.setPaint(textFillCol);
}
if((currentTR & GraphicsState.STROKE)==GraphicsState.STROKE){
if(textStrokeCol!=null)
textStrokeCol.setScaling(cropX,cropH,scaling,0 ,0);
if(customColorHandler !=null){
customColorHandler.setPaint(g2,textFillCol,pageNumber, isPrinting);
}else if(PdfDecoder.Helper!=null){
PdfDecoder.Helper.setPaint(g2, textFillCol, pageNumber, isPrinting);