This class represents a color space in a pdf document.
Method from org.apache.pdfbox.pdmodel.graphics.color.PDColorSpaceFactory Detail: |
public static PDColorSpace createColorSpace(COSBase colorSpace) throws IOException {
return createColorSpace( colorSpace, null );
}
This will create the correct color space given the name. |
public static PDColorSpace createColorSpace(String colorSpaceName) throws IOException {
return createColorSpace(colorSpaceName, null);
}
This will create the correct color space given the name. |
public static PDColorSpace createColorSpace(COSBase colorSpace,
Map colorSpaces) throws IOException {
PDColorSpace retval = null;
if( colorSpace instanceof COSName )
{
retval = createColorSpace( ((COSName)colorSpace).getName(), colorSpaces );
}
else if( colorSpace instanceof COSArray )
{
COSArray array = (COSArray)colorSpace;
COSName type = (COSName)array.getObject( 0 );
if( type.getName().equals( PDCalGray.NAME ) )
{
retval = new PDCalGray( array );
}
else if( type.getName().equals( PDDeviceRGB.NAME ) )
{
retval = PDDeviceRGB.INSTANCE;
}
else if( type.getName().equals( PDDeviceCMYK.NAME ) )
{
retval = PDDeviceCMYK.INSTANCE;
}
else if( type.getName().equals( PDCalRGB.NAME ) )
{
retval = new PDCalRGB( array );
}
else if( type.getName().equals( PDDeviceN.NAME ) )
{
retval = new PDDeviceN( array );
}
else if( type.getName().equals( PDIndexed.NAME ) ||
type.getName().equals( PDIndexed.ABBREVIATED_NAME ))
{
retval = new PDIndexed( array );
}
else if( type.getName().equals( PDLab.NAME ) )
{
retval = new PDLab( array );
}
else if( type.getName().equals( PDSeparation.NAME ) )
{
retval = new PDSeparation( array );
}
else if( type.getName().equals( PDICCBased.NAME ) )
{
retval = new PDICCBased( array );
}
else if( type.getName().equals( PDPattern.NAME ) )
{
retval = new PDPattern( array );
}
else
{
throw new IOException( "Unknown colorspace array type:" + type );
}
}
else
{
throw new IOException( "Unknown colorspace type:" + colorSpace );
}
return retval;
}
This will create the correct color space given the name. |
public static PDColorSpace createColorSpace(String colorSpaceName,
Map colorSpaces) throws IOException {
PDColorSpace cs = null;
if( colorSpaceName.equals( PDDeviceCMYK.NAME ) ||
colorSpaceName.equals( PDDeviceCMYK.ABBREVIATED_NAME ) )
{
cs = PDDeviceCMYK.INSTANCE;
}
else if( colorSpaceName.equals( PDDeviceRGB.NAME ) ||
colorSpaceName.equals( PDDeviceRGB.ABBREVIATED_NAME ) )
{
cs = PDDeviceRGB.INSTANCE;
}
else if( colorSpaceName.equals( PDDeviceGray.NAME ) ||
colorSpaceName.equals( PDDeviceGray.ABBREVIATED_NAME ))
{
cs = new PDDeviceGray();
}
else if( colorSpaces != null && colorSpaces.get( colorSpaceName ) != null )
{
cs = (PDColorSpace)colorSpaces.get( colorSpaceName );
}
else if( colorSpaceName.equals( PDLab.NAME ) )
{
cs = new PDLab();
}
else if( colorSpaceName.equals( PDPattern.NAME ) )
{
cs = new PDPattern();
}
else
{
throw new IOException( "Error: Unknown colorspace '" + colorSpaceName + "'" );
}
return cs;
}
This will create the correct color space given the name. |
public static PDColorSpace createColorSpace(PDDocument doc,
ColorSpace cs) throws IOException {
PDColorSpace retval = null;
if( cs.isCS_sRGB() )
{
retval = PDDeviceRGB.INSTANCE;
}
else if( cs instanceof ICC_ColorSpace )
{
ICC_ColorSpace ics = (ICC_ColorSpace)cs;
PDICCBased pdCS = new PDICCBased( doc );
retval = pdCS;
COSArray ranges = new COSArray();
for( int i=0; i< cs.getNumComponents(); i++ )
{
ranges.add( new COSFloat( ics.getMinValue( i ) ) );
ranges.add( new COSFloat( ics.getMaxValue( i ) ) );
}
PDStream iccData = pdCS.getPDStream();
OutputStream output = null;
try
{
output = iccData.createOutputStream();
output.write( ics.getProfile().getData() );
}
finally
{
if( output != null )
{
output.close();
}
}
pdCS.setNumberOfComponents( cs.getNumComponents() );
}
else
{
throw new IOException( "Not yet implemented:" + cs );
}
return retval;
}
This will create the correct color space from a java colorspace. |