processColorToken(currentPdfFile, colorSpace);
}
protected void processColorToken(PdfObjectReader currentPdfFile, PdfObject colorSpace) {
PdfObject indexed=colorSpace.getDictionary(PdfDictionary.Indexed);
PdfObject functionObj=colorSpace.getDictionary(PdfDictionary.tintTransform);
domain = null;
if(colorSpace.getDictionary(PdfDictionary.Process)!=null)
isProcess=true;
//name of color if separation or Components if device and component count
byte[] name=null;
byte[][] components=null;
if(value==ColorSpaces.Separation){
name=colorSpace.getStringValueAsByte(PdfDictionary.Name);
if(name!=null)
components=new byte[][]{name};
componentCount=1;
}else{
components=colorSpace.getStringArray(PdfDictionary.Components);
componentCount=components.length;
}
//test values
cmykMapping=NOCMYK;
int[] values=new int[componentCount];
if(components!=null){
for(int ii=0;ii<componentCount;ii++){
values[ii]=PdfDictionary.generateChecksum(1, components[ii].length-1, components[ii]);
}
}
switch(componentCount){
case 1:
if(components!=null && (values[0]==Black || values[0]==PANTONE_BLACK)){
cmykMapping=Black;
}
break;
case 2:
if(values[0]==Cyan){
if(values[1]==Yellow)
cmykMapping=CY;
else if(values[1]==Magenta)
cmykMapping=CM;
}else if(values[0]==Magenta && values[1]==Yellow)
cmykMapping=MY;
break;
case 3:
if(values[0]==Magenta && values[1]==Yellow && values[2]==Black)
cmykMapping=MYK;
else if(values[0]==Cyan && values[1]==Magenta && values[2]==Yellow)
cmykMapping=CMY;
else if(values[0]==Cyan && values[1]==Magenta && values[2]==Black)
cmykMapping=CMK;
break;
case 4:
if(values[0]==Cyan && values[1]==Magenta && values[2]==Yellow && values[3]==Black)
cmykMapping=CMYB;
break;
case 6:
if(values[0]==Cyan && values[1]==Magenta && values[2]==Yellow && values[3]==Black)
cmykMapping=CMYK;
break;
}
//hard-code myk and cmy
if(cmykMapping!=NOCMYK){
altCS=new DeviceCMYKColorSpace();
}else{
/**
* work out colorspace (can also be direct ie /Pattern)
*/
colorSpace=colorSpace.getDictionary(PdfDictionary.AlternateSpace);
//System.out.println("Set uncached AlCS "+colorSpace.getObjectRefAsString()+" "+this);
altCS =ColorspaceFactory.getColorSpaceInstance(currentPdfFile, colorSpace);
//use alternate as preference if CMYK
if(altCS.getID()==ColorSpaces.ICC && colorSpace.getParameterConstant(PdfDictionary.Alternate)==ColorSpaces.DeviceCMYK)
altCS=new DeviceCMYKColorSpace();
}
if(name!=null){
int len=name.length,jj=0,topHex,bottomHex;
byte[] tempName=new byte[len];
for(int i=0;i<len;i++){
if(name[i]=='#'){
//roll on past #
i++;
topHex=name[i];
//convert to number
if(topHex>='A' && topHex<='F')
topHex = topHex - 55;
else if(topHex>='a' && topHex<='f')
topHex = topHex - 87;
else if(topHex>='0' && topHex<='9')
topHex = topHex - 48;
i++;
while(name[i]==32 || name[i]==10 || name[i]==13)
i++;
bottomHex=name[i];
if(bottomHex>='A' && bottomHex<='F')
bottomHex = bottomHex - 55;
else if(bottomHex>='a' && bottomHex<='f')
bottomHex = bottomHex - 87;
else if(bottomHex>='0' && bottomHex<='9')
bottomHex = bottomHex - 48;
tempName[jj]=(byte) (bottomHex+(topHex<<4));
}else{
tempName[jj]=name[i];
}
jj++;
}
//resize
if(jj!=len){
name=new byte[jj];
System.arraycopy(tempName, 0, name, 0, jj);
}
pantoneName=new String(name);
}
/**
* setup transformation
**/
if(functionObj==null)
colorSpace.getDictionary(PdfDictionary.tintTransform);
if(functionObj==null && indexed!=null)
functionObj=indexed.getDictionary(PdfDictionary.tintTransform);
colorMapper=new ColorMapping(currentPdfFile,functionObj);
domain=functionObj.getFloatArray(PdfDictionary.Domain);
}